GNU bug report logs - #48144
13.0.11; TeX-run-format signals error in sentinel

Previous Next

Package: auctex;

Reported by: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Date: Sat, 1 May 2021 16:16:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 13.0.11

Done: Ikumi Keita <ikumi <at> ikumi.que.jp>

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 48144 in the body.
You can then email your comments to 48144 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#48144; Package auctex. (Sat, 01 May 2021 16:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Basil L. Contovounesios" <contovob <at> tcd.ie>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Sat, 01 May 2021 16:16:02 GMT) Full text and rfc822 format available.

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

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: bug-auctex <at> gnu.org
Subject: 13.0.11; TeX-run-format signals error in sentinel
Date: Sat, 01 May 2021 17:15:26 +0100
I was experimenting with configuring latexmk as best I could in
TeX-command-list when I noticed an inconsistency between TeX-run-format
and its sentinel.  Here's a recipe to illustrate what I mean:

0. emacs -Q
1. M-x package-initialize RET
2. (progn
     (setq debug-on-error t)
     (add-hook 'LaTeX-mode-hook
               (lambda () (setq TeX-command-default "Latexmk")))
     (with-eval-after-load 'tex
       (push '("Latexmk"
               "latexmk%(file-line-error) %(extraopts)%(mode) %t"
               TeX-run-format nil (latex-mode))
             TeX-command-list)))
3. C-x C-e
4. C-x C-f /tmp/helloworld.tex RET
5. M-x auto-insert RET RET article RET RET RET
6. \helloworld
7. C-c C-c y RET

  Debugger entered--Lisp error: (wrong-type-argument stringp nil)
    intern(nil)
    TeX-TeX-sentinel-check(#<process Latexmk> "Latexmk")
    TeX-TeX-sentinel(#<process Latexmk> "Latexmk")
    TeX-command-sentinel(#<process Latexmk> "exited abnormally with code 12\n")

AFAICT, this is because TeX-run-format uses TeX-TeX-sentinel, which
calls TeX-TeX-sentinel-check, which expects TeX-error-report-switches to
have been initialised by TeX-run-TeX, but we're not using TeX-run-TeX!

I'm not sure whether the TeX-error-report-switches initialisation should
be moved to TeX-run-format, or TeX-TeX-sentinel-check should guard
against an uninitialised TeX-error-report-switches.

Are my assumptions about or use of TeX-run-format wrong?  E.g., should I
just be using TeX-run-command for this purpose instead?

---

Some off-topic justification for how I ended up here:

I tried using a sentinel that is as close to TeX-run-TeX as possible,
whilst avoiding the false positive output parsing about cross-references
and the like in TeX-LaTeX-sentinel, which latexmk already handles.
TeX-run-format seems to fit a nice middle-ground between TeX-run-TeX and
TeX-run-command.

I also tried TeX-command-run-all instead of latexmk, but AFAICT the
former doesn't handle as many scenarios as the latter, such as running
Biber as needed.

Since neither TeX-run-format nor TeX-run-command runs
TeX-after-compilation-finished-functions, I've ended up with the
following custom sentinel for latexmk:

  (defun blc-latexmk-sentinel (proc _msg)
    "Run `TeX-after-compilation-finished-functions' on PROC success."
    (when (and (eq (process-status proc) 'exit)
               (zerop (process-exit-status proc)))
      (defvar TeX-command-buffer)
      (run-hook-with-args 'TeX-after-compilation-finished-functions
                          (with-current-buffer TeX-command-buffer
                            (expand-file-name
                             (TeX-active-master (TeX-output-extension)))))))

  (defun blc-TeX-run-latexmk (&rest args)
    "Like `TeX-run-format', but also run TeX compilation hooks."
    (let ((proc (apply #'TeX-run-format args)))
      (add-function :after (process-sentinel proc) #'blc-latexmk-sentinel)
      proc))

Please let me know if any of this runs afoul of AUCTeX's design, or if
there's a better way to integrate latexmk or call a hook on successful
compilation.  [I read through all of the relevant AUCTeX mailing list
discussions I could find, and I'm undecided about the auctex-latexmk
package on MELPA, which uses old-style function advice.]

Thanks,

-- 
Basil

Emacs  : GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars)
 of 2021-05-01
Package: 13.0.11

current state:
==============
(setq
 AUCTeX-date "2021-04-28"
 window-system 'x
 LaTeX-version "2e"
 TeX-style-path '("~/.emacs.d/auctex"
		  "/home/blc/.emacs.d/elpa/auctex-13.0.11.0.20210428.195438/style"
		  "/home/blc/.emacs.d/auctex/auto" "/home/blc/.emacs.d/auctex/style" "auto" "style")
 TeX-auto-save nil
 TeX-parse-self nil
 TeX-master t
 TeX-command-list '(("Latexmk" "latexmk%(file-line-error) %(extraopts)%(mode) %t" TeX-run-format nil
		     (latex-mode))
		    ("TeX"
		     "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %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) %(o-dir) %t" TeX-run-compile nil
		     (texinfo-mode) :help "Run Makeinfo with Info output")
		    ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" TeX-run-compile nil
		     (texinfo-mode) :help "Run Makeinfo with HTML output")
		    ("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %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 %(O?aux)" TeX-run-BibTeX nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode context-mode)
		     :help "Run BibTeX")
		    ("Biber" "biber %s %(output-dir)" TeX-run-Biber nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :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
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Generate PostScript file")
		    ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Convert DVI file to PostScript")
		    ("Dvipdfmx" "dvipdfmx %d -o %(O?pdf)" TeX-run-dvipdfmx nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Convert DVI file to PDF with dvipdfmx")
		    ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Convert PostScript file to PDF")
		    ("Glossaries" "makeglossaries %(O?aux)" TeX-run-command nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Run makeglossaries to create glossary\n     file")
		    ("Index" "makeindex %(O?idx)" TeX-run-index nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Run makeindex to create index file")
		    ("upMendex" "upmendex %(O?idx)" TeX-run-index t
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :help
		     "Run upmendex to create index file")
		    ("Xindy" "texindy %s" TeX-run-command nil
		     (plain-tex-mode latex-mode doctex-mode ams-tex-mode texinfo-mode) :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#48144; Package auctex. (Wed, 05 May 2021 07:56:01 GMT) Full text and rfc822 format available.

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

From: Arash Esbati <arash <at> gnu.org>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 48144 <at> debbugs.gnu.org
Subject: Re: bug#48144: 13.0.11; TeX-run-format signals error in sentinel
Date: Wed, 05 May 2021 09:54:55 +0200
Hi Basil,

"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:

> I was experimenting with configuring latexmk as best I could in
> TeX-command-list when I noticed an inconsistency between TeX-run-format
> and its sentinel.  Here's a recipe to illustrate what I mean:
>
> 0. emacs -Q
> 1. M-x package-initialize RET
> 2. (progn
>      (setq debug-on-error t)
>      (add-hook 'LaTeX-mode-hook
>                (lambda () (setq TeX-command-default "Latexmk")))
>      (with-eval-after-load 'tex
>        (push '("Latexmk"
>                "latexmk%(file-line-error) %(extraopts)%(mode) %t"
>                TeX-run-format nil (latex-mode))
>              TeX-command-list)))
> 3. C-x C-e
> 4. C-x C-f /tmp/helloworld.tex RET
> 5. M-x auto-insert RET RET article RET RET RET
> 6. \helloworld
> 7. C-c C-c y RET
>
>   Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>     intern(nil)
>     TeX-TeX-sentinel-check(#<process Latexmk> "Latexmk")
>     TeX-TeX-sentinel(#<process Latexmk> "Latexmk")
>     TeX-command-sentinel(#<process Latexmk> "exited abnormally with code 12\n")
>
> AFAICT, this is because TeX-run-format uses TeX-TeX-sentinel, which
> calls TeX-TeX-sentinel-check, which expects TeX-error-report-switches to
> have been initialised by TeX-run-TeX, but we're not using TeX-run-TeX!
>
> I'm not sure whether the TeX-error-report-switches initialisation should
> be moved to TeX-run-format, or TeX-TeX-sentinel-check should guard
> against an uninitialised TeX-error-report-switches.
>
> Are my assumptions about or use of TeX-run-format wrong?  E.g., should I
> just be using TeX-run-command for this purpose instead?

I'm not familiar with Latexmk, but I think you want to use `TeX-run-TeX'
instead of `TeX-run-format'.  Can you please try it with something like
this:

(with-eval-after-load 'tex
  (add-to-list 'TeX-command-list
	       '("Latexmk"
		 "latexmk%(file-line-error) %(extraopts)%(mode) %t"
		 TeX-run-TeX nil (latex-mode))))

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#48144; Package auctex. (Wed, 05 May 2021 12:39:02 GMT) Full text and rfc822 format available.

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

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Arash Esbati <arash <at> gnu.org>
Cc: 48144 <at> debbugs.gnu.org
Subject: Re: bug#48144: 13.0.11; TeX-run-format signals error in sentinel
Date: Wed, 05 May 2021 13:38:39 +0100
Arash Esbati <arash <at> gnu.org> writes:

> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>
>> I was experimenting with configuring latexmk as best I could in
>> TeX-command-list when I noticed an inconsistency between TeX-run-format
>> and its sentinel.  Here's a recipe to illustrate what I mean:
>>
>> 0. emacs -Q
>> 1. M-x package-initialize RET
>> 2. (progn
>>      (setq debug-on-error t)
>>      (add-hook 'LaTeX-mode-hook
>>                (lambda () (setq TeX-command-default "Latexmk")))
>>      (with-eval-after-load 'tex
>>        (push '("Latexmk"
>>                "latexmk%(file-line-error) %(extraopts)%(mode) %t"
>>                TeX-run-format nil (latex-mode))
>>              TeX-command-list)))
>> 3. C-x C-e
>> 4. C-x C-f /tmp/helloworld.tex RET
>> 5. M-x auto-insert RET RET article RET RET RET
>> 6. \helloworld
>> 7. C-c C-c y RET
>>
>>   Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>>     intern(nil)
>>     TeX-TeX-sentinel-check(#<process Latexmk> "Latexmk")
>>     TeX-TeX-sentinel(#<process Latexmk> "Latexmk")
>>     TeX-command-sentinel(#<process Latexmk> "exited abnormally with code 12\n")
>>
>> AFAICT, this is because TeX-run-format uses TeX-TeX-sentinel, which
>> calls TeX-TeX-sentinel-check, which expects TeX-error-report-switches to
>> have been initialised by TeX-run-TeX, but we're not using TeX-run-TeX!
>>
>> I'm not sure whether the TeX-error-report-switches initialisation should
>> be moved to TeX-run-format, or TeX-TeX-sentinel-check should guard
>> against an uninitialised TeX-error-report-switches.
>>
>> Are my assumptions about or use of TeX-run-format wrong?  E.g., should I
>> just be using TeX-run-command for this purpose instead?
>
> I'm not familiar with Latexmk, but I think you want to use `TeX-run-TeX'
> instead of `TeX-run-format'.  Can you please try it with something like
> this:
>
> (with-eval-after-load 'tex
>   (add-to-list 'TeX-command-list
> 	       '("Latexmk"
> 		 "latexmk%(file-line-error) %(extraopts)%(mode) %t"
> 		 TeX-run-TeX nil (latex-mode))))

Thanks for the suggestion, but this doesn't address the OP.

Ideally TeX-run-TeX would indeed be the most appropriate function, but
it is not practical with latexmk because the sentinel of TeX-run-TeX
unconditionally picks up all the errors and warnings from all the runs
that latexmk invokes, rather than just from the last (successful) run.
This means that TeX-run-TeX never sets the next command to "View".
TeX-run-TeX also does not recognise the output of latexmk when there is
nothing to do for the current file.

The bug report is about the inconsistency between TeX-run-format and its
sentinel TeX-TeX-sentinel.  In some cases the latter expects
TeX-error-report-switches to be initialised, but TeX-run-format never
does this.  IMO if TeX-TeX-sentinel is going to be used with
TeX-run-format then it should not assume that its process was started by
TeX-run-TeX.  Unless I'm missing something?

[ BTW since submitting the OP I have indeed resorted to using the
  auctex-latexmk package, which seems to work reliably well.  ]

Thanks,

-- 
Basil




Information forwarded to bug-auctex <at> gnu.org:
bug#48144; Package auctex. (Thu, 06 May 2021 11:34:02 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: Arash Esbati <arash <at> gnu.org>, 48144 <at> debbugs.gnu.org
Subject: Re: bug#48144: 13.0.11; TeX-run-format signals error in sentinel
Date: Thu, 06 May 2021 20:33:10 +0900
[Message part 1 (text/plain, inline)]
Hi Basil, thanks for your report.

>>>>> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>>> AFAICT, this is because TeX-run-format uses TeX-TeX-sentinel, which
>>> calls TeX-TeX-sentinel-check, which expects TeX-error-report-switches to
>>> have been initialised by TeX-run-TeX, but we're not using TeX-run-TeX!

I agree with your analysis. I made a tentative fix as attachment, which
moves initialization of `TeX-error-report-switches' into
`TeX-format-run'. Could you test whether it works on your side?

> The bug report is about the inconsistency between TeX-run-format and its
> sentinel TeX-TeX-sentinel.  In some cases the latter expects
> TeX-error-report-switches to be initialised, but TeX-run-format never
> does this.  IMO if TeX-TeX-sentinel is going to be used with
> TeX-run-format then it should not assume that its process was started by
> TeX-run-TeX.  Unless I'm missing something?

I think this is a AUCTeX bug. `TeX-run-format' is a valid choice for
"How" item of `TeX-command-list' according to its defcustom. However,
current implementation of `TeX-run-format' doesn't achieve its job as
your analysis shows.

>>> I'm not sure whether the TeX-error-report-switches initialisation should
>>> be moved to TeX-run-format, or TeX-TeX-sentinel-check should guard
>>> against an uninitialised TeX-error-report-switches.

Actually, it isn't clear, at least for me, which is the proper fix. :-)
It's very difficult to determine what the proper behavior of
`TeX-run-format' and `TeX-run-TeX' should be, from the relevant doc
stirngs:
,----
| (defun TeX-run-format (name command file)
|   "Create a process for NAME using COMMAND to format FILE with TeX."
`----
,----
| (defun TeX-run-TeX (name command file)
|   "Create a process for NAME using COMMAND to format FILE with TeX."
`----
,----
| (defcustom TeX-command-list
|   [...]
| TeX-run-format: As `TeX-run-command', but assume the output is created
| by a TeX macro package.  Return the process object.
| 
| TeX-run-TeX: For TeX output.
`----
Actually (again), not all the TeX-run-* series are maintained well. The
ones which are seldom used sometimes have nonsense implementation:
https://lists.gnu.org/archive/html/auctex-devel/2017-05/msg00014.html

Regards,
Ikumi Keita

[diff (text/x-diff, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#48144; Package auctex. (Thu, 06 May 2021 12:10:02 GMT) Full text and rfc822 format available.

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

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Arash Esbati <arash <at> gnu.org>, 48144 <at> debbugs.gnu.org
Subject: Re: bug#48144: 13.0.11; TeX-run-format signals error in sentinel
Date: Thu, 06 May 2021 13:09:21 +0100
tags 48144 + patch
quit

Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> I agree with your analysis. I made a tentative fix as attachment, which
> moves initialization of `TeX-error-report-switches' into
> `TeX-format-run'. Could you test whether it works on your side?

It works well here, thank you!

> Actually (again), not all the TeX-run-* series are maintained well. The
> ones which are seldom used sometimes have nonsense implementation:
> https://lists.gnu.org/archive/html/auctex-devel/2017-05/msg00014.html

:)

-- 
Basil




Added tag(s) patch. Request was from "Basil L. Contovounesios" <contovob <at> tcd.ie> to control <at> debbugs.gnu.org. (Thu, 06 May 2021 12:10:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#48144; Package auctex. (Thu, 06 May 2021 13:04:01 GMT) Full text and rfc822 format available.

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

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: Arash Esbati <arash <at> gnu.org>, 48144 <at> debbugs.gnu.org
Subject: Re: bug#48144: 13.0.11; TeX-run-format signals error in sentinel
Date: Thu, 06 May 2021 22:03:17 +0900
>>>>> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>> I agree with your analysis. I made a tentative fix as attachment, which
>> moves initialization of `TeX-error-report-switches' into
>> `TeX-format-run'. Could you test whether it works on your side?

> It works well here, thank you!

Thanks for confirmation, pushed to the git repo.

Bye,
Ikumi Keita




Added tag(s) fixed. Request was from Ikumi Keita <ikumi <at> ikumi.que.jp> to control <at> debbugs.gnu.org. (Thu, 06 May 2021 13:05:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 48144 <at> debbugs.gnu.org and "Basil L. Contovounesios" <contovob <at> tcd.ie> Request was from Ikumi Keita <ikumi <at> ikumi.que.jp> to control <at> debbugs.gnu.org. (Thu, 06 May 2021 13:05:02 GMT) Full text and rfc822 format available.

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

This bug report was last modified 2 years and 325 days ago.

Previous Next


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