1

Overleaf generates following warning message for tex files: unexpected $ after open inline math \(.

Is it possible to catch this warning message in AUCTex as well?

Example would be: \( ... $ ... \)

\(a_{s}$ and $h_{d}\)
       ^
       |___ unexpected $ after open inline math \(`

Note that when you try to type $ in between \( \) auctex does not allow and gives Math mode started with ‘\(’ cannot be closed with dollar warning message. But if you just paste \( $ \) into the buffer it does not give any warning message.

alper
  • 1,238
  • 11
  • 30

2 Answers2

1

AUCTeX doesn't have a code parser which checks your code all the time. The case where you get the warning message Math mode started with ‘\(’ cannot be closed with dollar is due to the function TeX-insert-dollar which is invoked when you insert a $.

If you want on-the-fly syntax checking then I suggest you take a look at tools like flymake and/or flycheck.

Arash Esbati
  • 1,795
  • 1
  • 8
  • 13
  • Should I configure `flycheck` for this? I think it is on but it does not detect this – alper Oct 21 '22 at 12:40
  • @alper - Can't tell since I haven't `flycheck` installed. I briefly tried `lacheck` as a linter with AUCTeX which recognizes the issue and `chktex` which doesn't. So it seems it's a `chktex` issue. – Arash Esbati Oct 21 '22 at 17:52
  • Interesting how can I enable `lacheck`? Should I open a issue at https://tex.stackexchange.com/questions/tagged/chktex ? – alper Oct 21 '22 at 19:31
  • @alper - If you have the binary `lacheck` installed, you can try it in your .tex file with `C-c C-c Check RET` (or from the `Command` menu) and get a buffer with the results. – Arash Esbati Oct 22 '22 at 13:06
  • `C-c C-c` returns `TeX-command-master`on my end – alper Oct 22 '22 at 16:12
  • @alper - I don't understand you last comment; `C-c C-c` runs `TeX-command-master` and then you can choose a command. Try `TAB` in the minibuffer to get a list of candidates. Or choose one from the `Command` menu. – Arash Esbati Oct 23 '22 at 10:48
  • Ah sorry it was different key binding on my end: `flycheck-select-checker (C-c ! s)` – alper Oct 23 '22 at 10:52
1

Interesting how can I enable lacheck?

How can you afford NOT to read the AucTeX manual? Make it a habit to read the manual when you are relying on some tool very heavily

Check for syntax errors in tex buffers using lacheck and flymake

Check for syntax errors in tex buffers using lacheck and flymake

(info "(auctex) Checking")

https://emacsdocs.org/docs/auctex/Checking

File: auctex.info, Node: Checking, Next: Control, Prev: Debugging, Up: Processing

4.4 Checking for problems

Running TeX or LaTeX will only find regular errors in the document, not examples of bad style. Furthermore, description of the errors may often be confusing. The utilities lacheck and chktex can be used to find style errors, such as forgetting to escape the space after an abbreviation or using ... instead of \ldots and other similar problems. You start lacheck with C-c C-c Check <RET> and chktex with C-c C-c ChkTeX <RET>. The result will be a list of errors in the *compilation* buffer. You can go through the errors with C-x \`` (next-error`, note (emacs)Compilation::), which will move point to the location of the next error.

Alternatively, you may want in-buffer notation. AUCTeX provides support for this using the Flymake package in Emacs 26 or newer (note (Flymake)Using Flymake:: for details). To enable, call M-x flymake-mode <RET> in the buffer or enable it in all buffers by adding this to your init file:

(add-hook `LaTeX-mode-hook #`flymake-mode) 

Note that AUCTeX currently only provides support for using chktex as the flymake backend.

Each of the two utilities lacheck and chktex will find some errors the other doesnot, but chktex is more configurable, allowing you to create your own errors. You may need to install the programs before using them.

You can get lacheck from URL:https://www.ctan.org/pkg/lacheck and chktex from URL:https://www.ctan.org/pkg/chktex. TeX Live contains both.

~$ apt-cache show lacheck

Package: lacheck Version: 1.26-17 Installed-Size: 76 Maintainer: Davide G. M. Salvetti salve@debian.org Architecture: amd64 Replaces: auctex (<< 9.7l-1) Depends: libc6 (>= 2.14) Recommends: texlive-latex-base Suggests: auctex Breaks: auctex (<< 9.7l-1) Description-en:

Simple syntax checker for LaTeX

LaCheck is a simple syntax checker for LaTex that is based on a single-pass lexical scanner. This makes clear that there are a lot of LaTeX problems this program cannot find, although it will find most simple mistakes. Complex macro packages may, however, make it completely unusable. . This program was bundled with AUCTeX once upon a time and is best known from there.


~$ apt-cache show chktex

Package: chktex Version: 1.7.6-5 Installed-Size: 225 Maintainer: Thorsten Alteholz debian@alteholz.de Architecture: amd64 Depends: libc6 (>= 2.33), libpcre2-posix3 (>= 10.34), libtinfo6 (>= 6) Description-en:

Finds typographic errors in LaTeX

ChkTeX finds typographic errors in LaTeX documents:

  • Supports over 40 warnings.

  • Supports \input command; both TeX and LaTeX version. Actually includes the files. TEXINPUTS''-equivalent search path.

  • Intelligent warning/error handling. The user may promote/mute warnings to suit his preferences. You may also mute warnings in the header of a file; thus killing much unwanted garbage.

  • Supports both LaTeX 2.09 and LaTeX2e.

  • Flexible output handling. Has some predefined formats and lets the user specify his own format. Uses a printf() similar syntax. lacheck compatible mode included for interfacing with the AUC-TeX Emacs mode.