I have my proper function to run latex, say my-tex. Sometimes one should run latex two times to get references right. A message like below in the echo area appears to tell this. How to identify programmatically the presence of this message in order that I run my-tex two times?

You should run LaTeX again to get references right, {14} pages
  • Perhaps by advising the message function? But I would try to get the information from elsewhere. – JeanPierre Oct 24 '16 at 5:43
  • 1
    You should not be listening to the echo area, but instead be listening to the process running in the background using a process filter. There are already process filters in existence with AUCTex. Unfortunately, that library is so darn complex, you need a forum participant like Giordano to guide you further. I use my own function with start-process that calls latexmk.pl and have my own process filter without using AUCTeX, so for me it would be a lot easier because I have just one filter and I know right were it is. To get a head start, look for the process filters in AUCTeX. – lawlist Oct 24 '16 at 5:44
  • To learn more about process filters, see the related section in the manual: gnu.org/software/emacs/manual/html_node/elisp/… – lawlist Oct 24 '16 at 5:50
  • 1
    I agree with other comments above, it's better not to read the echo area. You may want to define your own sentinel. Take a look to TeX-LaTeX-sentinel. After you define you're own sentinel function, set TeX-sentinel-default-function to the name of that function in LaTeX buffers. – giordano Oct 24 '16 at 10:05

I don't know what you want to accomplish exactly, but as other people pointed out, reading the echo area is not the best strategy. Instead, you probably want to set up a sentinel.

Many commands in AUCTeX have a sentinel associated. For example, the one associated to LaTeX command is TeX-LaTeX-sentinel. You may want to build your own sentinel upon this one. Once you define your sentinel function, you can set it as the default one by setting TeX-sentinel-default-function to the name's symbol of the function in LaTeX buffers (you can use a hook for this).

  • The sentinel itself is not going to help match/catch a process string output of: "You should run LaTeX again to get references right, {14} pages". My assumption, based on the question above, is that the OP may want to run LaTeX again if a similar message is generated by the running process. For that, a process filter will be needed along with a string-match or something similar -- the page length will vary, so a string-equal would not be the best approach. – lawlist Oct 25 '16 at 21:57
  • Of course this solution doesn't catch the string from the echo area, but replaces the function that emits that message. – giordano Oct 26 '16 at 12:50
  • The a new or redefined sentinel does not replace the function that emits the message. A process filter is what catches the message, and it is used in conjunction with a sentinel: gnu.org/software/emacs/manual/html_node/elisp/… A sentinel will only emit strings like: "finished\n"; "deleted\n"; "exited abnormally with code exitcode (core dumped)\n" -- the “core dumped” part is optional, and only appears if the process dumped core; "failed with code fail-code\n"; "signal-description (core dumped)\n". – lawlist Oct 26 '16 at 14:42
  • I'm merely explaining how things work in AUCTeX: the process filter only prepares a static buffer that is afterwards parsed by the sentinel, which then emits warnings to echo area and decides what to do based on what is present in the output buffer. See git.savannah.gnu.org/gitweb/… if you don't believe me. If the OP wants to exploit facilities already present in AUCTeX, then should hack the sentinel, if instead wants to write something from scratch then should write process-filter + sentinel. – giordano Oct 26 '16 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.