6

I have a few documents that result in a lot of warnings because I've been using $...$ instead of \(...\) and a few other tiny details.

How can I automatically fix these chktex warnings? vscode provides a "quick fix" but I would need to manually apply in each case.

Update:

I was wondering if there is some command line tool (or similar) that can automatically fix these warnings. vscode can fix warnings one by one automatically, but that is too time consuming.

Update2:

Here is the code:

\documentclass{article} 
\begin{document}
$1+1=2$
\end{document}

Here is the minimum command line that vscode executes:

chktex -wall example.tex 

and the output:

ChkTeX v1.7.6 - Copyright 1995-96 Jens T. Berger Thielemann. 
Compiled with POSIX extended regex support. 
Warning 46 in example.tex line 3: Use \( ... \) instead of $ ... $.
$1+1=2$
^^^^^^^                       
No errors printed; One warning printed; No user suppressed warnings; No line suppressed warnings. 
See the manual for how to suppress some or all of these warnings/errors.
4
  • Please provide a minimum working example of a LaTeX document that the $-related warning messages. For sure, on MacTeX2018, passing \documentclass{article} \begin{document} $1+1=2$ \end{document} thru chktex does not generate any $-related warning messages.
    – Mico
    Feb 2, 2019 at 20:34
  • 6
    there is nothing wrong with using $ but if you want to change to \( any text editor should allow you to replace $...$ by \(...\) using regular expression search.replace Feb 2, 2019 at 20:34
  • 1
    There's also debuck by Loop Space, which performs this replacement. Feb 2, 2019 at 23:35
  • 1
    Just FYI, I don't recommend running with -wall, there are some weird warnings that almost no-one would actually want, such as warning about comments. This warning (about $) is off by default because it's not as important as others. That said, ChkTeX doesn't provide automatic fixing. Feb 13, 2019 at 3:31

2 Answers 2

7

You can accomplish this in vscode by doing a find-replace with a regex:

Press Ctrl + Shift + h (or use the menu bar Edit > Replace in Files)
In the search field enter this regex:
\$([^$]+)\$
Make sure the "Use Regular Expression" button is checked (Alt + r)
In the replace field enter:
\($1\)
files to include:
*.tex

Click the "Replace All" button (Ctrl + Alt + Enter)
and watch the magic happen

1
  • 1
    Just as a note, for those that are using $$a$$ instead of \[a\], you should replace \$\$([^$]+)\$\$ with \[$1\] first. Mar 9 at 6:43
6

This message is number 46 warning of ChkTex,just append -n46 to construct the compile command, which means ignoring the number 46 warning. As illustrated below(It's an option in VSCode extensions setting).VSCode Extensions SettingMore detail in the document of ChkTex ChkTex.dvi

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.