GNU bug report logs - #35074
12.1.2; TeX-complete-symbol doesn't work in math mode for user-defined command

Previous Next

Package: auctex;

Reported by: Andrea Greselin <greselin.andrea <at> gmail.com>

Date: Mon, 1 Apr 2019 21:13:03 UTC

Severity: normal

Found in version 12.1.2

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35074 in the body.
You can then email your comments to 35074 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#35074; Package auctex. (Mon, 01 Apr 2019 21:13:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Andrea Greselin <greselin.andrea <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Mon, 01 Apr 2019 21:13:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andrea Greselin <greselin.andrea <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: 12.1.2; TeX-complete-symbol doesn't work in math mode for
 user-defined command
Date: Mon, 1 Apr 2019 22:55:53 +0200
Hello,

I can't find a way to make AUCTeX complete user-defined commands in math mode.

As an example, in the document below TeX-complete-symbol works outside
of math mode, but if I prepend a dollar sign to the command name it
doesn't complete it, returning `TeX-complete-symbol: Can’t find
completion for "\rnd".`

-------------------------------------------
\documentclass{article}

\newcommand{\rndvar}{X}

\begin{document}

\rnd%      TeX-complete-symbol works here
$\rnd$%    but not here,
$\rnd%     nor here.

\end{document}
-------------------------------------------

I have posted a question on TeX.SE and I refer to the answer at
https://tex.stackexchange.com/a/482631/35903 for a full (and better
formatted) explanation of the faulty behaviour, which is the same as
in my system. Basically, it is `LaTeX-math-list` not being updated
with the name of the new command that appears to cause the issue.

Thank you for maintaining AUCTeX, it's an awesome tool! :-)

Best wishes,
Andrea

Emacs  : GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21)
 of 2017-09-22, modified by Debian
Package: 12.1.2

current state:
==============
(setq
 AUCTeX-date "2019-02-08"
 window-system 'x
 LaTeX-version "2e"
 TeX-style-path '("~/.emacs.d/auctex"
		  "/home/andrea/.emacs.d/elpa/auctex-12.1.2/style"
		  "/home/andrea/.emacs.d/auctex/auto"
		  "/home/andrea/.emacs.d/auctex/style" "auto" "style")
 TeX-auto-save nil
 TeX-parse-self nil
 TeX-master t
 TeX-command-list '(("TeX"
		     "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t"
		     TeX-run-TeX nil
		     (plain-tex-mode ams-tex-mode texinfo-mode) :help
		     "Run plain TeX")
		    ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
		     (latex-mode doctex-mode) :help "Run LaTeX")
		    ("Makeinfo" "makeinfo %(extraopts) %t"
		     TeX-run-compile nil (texinfo-mode) :help
		     "Run Makeinfo with Info output")
		    ("Makeinfo HTML" "makeinfo %(extraopts) --html %t"
		     TeX-run-compile nil (texinfo-mode) :help
		     "Run Makeinfo with HTML output")
		    ("AmSTeX"
		     "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %t"
		     TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
		    ("ConTeXt"
		     "%(cntxcom) --once --texutil %(extraopts) %(execopts)%t"
		     TeX-run-TeX nil (context-mode) :help
		     "Run ConTeXt once")
		    ("ConTeXt Full"
		     "%(cntxcom) %(extraopts) %(execopts)%t"
		     TeX-run-TeX nil (context-mode) :help
		     "Run ConTeXt until completion")
		    ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help
		     "Run BibTeX")
		    ("Biber" "biber %s" TeX-run-Biber nil t :help
		     "Run Biber")
		    ("View" "%V" TeX-run-discard-or-function t t :help
		     "Run Viewer")
		    ("Print" "%p" TeX-run-command t t :help
		     "Print the file")
		    ("Queue" "%q" TeX-run-background nil t :help
		     "View the printer queue" :visible
		     TeX-queue-command)
		    ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t t
		     :help "Generate PostScript file")
		    ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
		     t :help "Convert DVI file to PostScript")
		    ("Dvipdfmx" "dvipdfmx %d" TeX-run-dvipdfmx nil t
		     :help "Convert DVI file to PDF with dvipdfmx")
		    ("Ps2pdf" "ps2pdf %f" TeX-run-ps2pdf nil t :help
		     "Convert PostScript file to PDF")
		    ("Glossaries" "makeglossaries %s" TeX-run-command
		     nil t :help
		     "Run makeglossaries to create glossary file")
		    ("Index" "makeindex %s" TeX-run-index nil t :help
		     "Run makeindex to create index file")
		    ("upMendex" "upmendex %s" TeX-run-index t t :help
		     "Run upmendex to create index file")
		    ("Xindy" "texindy %s" TeX-run-command nil t :help
		     "Run xindy to create index file")
		    ("Check" "lacheck %s" TeX-run-compile nil
		     (latex-mode) :help
		     "Check LaTeX file for correctness")
		    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil
		     (latex-mode) :help
		     "Check LaTeX file for common mistakes")
		    ("Spell" "(TeX-ispell-document \"\")"
		     TeX-run-function nil t :help
		     "Spell-check the document")
		    ("Clean" "TeX-clean" TeX-run-function nil t :help
		     "Delete generated intermediate files")
		    ("Clean All" "(TeX-clean t)" TeX-run-function nil
		     t :help
		     "Delete generated intermediate and output files")
		    ("Other" "" TeX-run-command t t :help
		     "Run an arbitrary command")
		    )
 )




Information forwarded to bug-auctex <at> gnu.org:
bug#35074; Package auctex. (Wed, 03 Apr 2019 12:22:01 GMT) Full text and rfc822 format available.

Message #8 received at 35074 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Andrea Greselin <greselin.andrea <at> gmail.com>
Cc: 35074 <at> debbugs.gnu.org
Subject: Re: bug#35074: 12.1.2;
 TeX-complete-symbol doesn't work in math mode for user-defined command
Date: Wed, 03 Apr 2019 11:55:39 +0200
Andrea Greselin <greselin.andrea <at> gmail.com> writes:

> I can't find a way to make AUCTeX complete user-defined commands in math mode.
>
> As an example, in the document below TeX-complete-symbol works outside
> of math mode, but if I prepend a dollar sign to the command name it
> doesn't complete it, returning `TeX-complete-symbol: Can’t find
> completion for "\rnd".`
>
> -------------------------------------------
> \documentclass{article}
>
> \newcommand{\rndvar}{X}
>
> \begin{document}
>
> \rnd%      TeX-complete-symbol works here
> $\rnd$%    but not here,
> $\rnd%     nor here.
>
> \end{document}
> -------------------------------------------
>
> I have posted a question on TeX.SE and I refer to the answer at
> https://tex.stackexchange.com/a/482631/35903 for a full (and better
> formatted) explanation of the faulty behaviour, which is the same as
> in my system. Basically, it is `LaTeX-math-list` not being updated
> with the name of the new command that appears to cause the issue.

Hi Andrea,

I've answered your question there.  But looking at the bug, here is how
to reproduce it.  Open this file, do `M-x toggle-debug-on-error RET',
eval the setq-form, then put point after `\rnd' and hit `C-M-i':

    \documentclass{article}
    \begin{document}
    \begin{verbatim}
    (setq LaTeX-math-list '((nil "rndvar" nil nil)))
    \end{verbatim}
    $\rnd$
    \end{document}

Emacs does the completion and throws this:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument stringp (if TeX-insert-braces "{}"))
  regexp-quote((if TeX-insert-braces "{}"))
  TeX-complete-symbol()
  funcall-interactively(TeX-complete-symbol)
  call-interactively(TeX-complete-symbol nil nil)
  command-execute(TeX-complete-symbol)
--8<---------------cut here---------------end--------------->8---

The issue is in the function `TeX-complete-symbol' which doesn't handle
functions passed as the fourth element of `TeX-complete-list' The
following patch should fix it:

--8<---------------cut here---------------start------------->8---
diff --git a/tex.el b/tex.el
index 3c3f1769..6cf2e487 100644
--- a/tex.el
+++ b/tex.el
@@ -3109,7 +3109,11 @@ Or alternatively:
     (when entry
       (if (numberp (nth 1 entry))
          (let* ((sub (nth 1 entry))
-                (close (nth 3 entry))
+                (close (if (and (nth 3 entry)
+                                 (listp (nth 3 entry))
+                                 (symbolp (car (nth 3 entry))))
+                            (eval (nth 3 entry))
+                          (nth 3 entry)))
                 (begin (match-beginning sub))
                 (end (match-end sub))
                 (pattern (TeX-match-buffer 0))
--8<---------------cut here---------------end--------------->8---

Can you please try it?  Here the complete function which you can eval
and then run the completion again.

--8<---------------cut here---------------start------------->8---
(defun TeX-complete-symbol ()
  "Perform completion on TeX/LaTeX symbol preceding point."
  (interactive "*")
  (let ((entry (TeX--complete-find-entry)))
    (when entry
      (if (numberp (nth 1 entry))
          (let* ((sub (nth 1 entry))
                 (close (if (and (nth 3 entry)
                                 (listp (nth 3 entry))
                                 (symbolp (car (nth 3 entry))))
                            (eval (nth 3 entry))
                          (nth 3 entry)))
                 (begin (match-beginning sub))
                 (end (match-end sub))
                 (pattern (TeX-match-buffer 0))
                 (symbol (buffer-substring begin end))
                 (list (funcall (nth 2 entry)))
                 (completion (try-completion symbol list))
                 (buf-name "*Completions*"))
            (cond ((eq completion t)
                   (and close
                        (not (looking-at (regexp-quote close)))
                        (insert close))
                   (let ((window (get-buffer-window buf-name)))
                     (when window (delete-window window))))
                  ((null completion)
                   (error "Can't find completion for \"%s\"" pattern))
                  ((not (string-equal symbol completion))
                   (delete-region begin end)
                   (insert completion)
                   (and close
                        (eq (try-completion completion list) t)
                        (not (looking-at (regexp-quote close)))
                        (insert close))
                   (let ((window (get-buffer-window buf-name)))
                     (when window (delete-window window))))
                  (t
                   (if (fboundp 'completion-in-region)
                       (completion-in-region begin end
                                             (all-completions symbol list nil))
                     (message "Making completion list...")
                     (let ((list (all-completions symbol list nil)))
                       (with-output-to-temp-buffer buf-name
                         (display-completion-list list)))
                     (set-window-dedicated-p (get-buffer-window buf-name) 'soft)
                     (message "Making completion list...done")))))
        (funcall (nth 1 entry))))))
--8<---------------cut here---------------end--------------->8---

Best, Arash




Reply sent to Arash Esbati <arash <at> gnu.org>:
You have taken responsibility. (Sun, 07 Apr 2019 10:56:01 GMT) Full text and rfc822 format available.

Notification sent to Andrea Greselin <greselin.andrea <at> gmail.com>:
bug acknowledged by developer. (Sun, 07 Apr 2019 10:56:01 GMT) Full text and rfc822 format available.

Message #13 received at 35074-done <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Andrea Greselin <greselin.andrea <at> gmail.com>
Cc: 35074-done <at> debbugs.gnu.org
Subject: Re: bug#35074: 12.1.2;
 TeX-complete-symbol doesn't work in math mode for user-defined command
Date: Sun, 07 Apr 2019 12:53:50 +0200
Andrea Greselin <greselin.andrea <at> gmail.com> writes:

> thanks Arash, it works exactly as you described and the new function
> fixes the `TeX-complete-symbol: Wrong type argument: stringp, (if
> TeX-insert-braces "{}")` error.

Thanks for checking.  I've pushed this change to AUCTeX repo.

> Still, the command isn't available for completion if I add the
> definition but don't eval the setq-form. I don't understand whether
> you consider this a bug or not, anyway, I find it disorienting that a
> command that is fine for use in math is completed outside of dollar
> signs but not inside them.

I think this behavior is intentional.  I think the idea is to reduce the
number of candidates in math mode in order to make the completion
faster.  But then, AUCTeX has its own way of completion (C-c RET for
macros).  This is probably the reason why `TeX-complete-symbol' is not
in focus for AUCTeX.  Check also the manual for completion[1].

Again, thanks for bringing up this issue.  I'm closing this report.

Best, Arash

Footnotes:
[1]  https://www.gnu.org/software/auctex/manual/auctex.html#Completion




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 05 May 2019 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.