# Using \crefformat with cleveref causes spurious chktex warnings

Cleveref has a useful feature in \crefformat where an equation can be referred to, for instance, an inequality. This adds an extra square-bracket argument to the \label command. For example:

\crefformat{inequality}{inequality~(#2#1#3)}

$$S \leq 2. \label[inequality]{eqn:bell}$$


However, when using chktex for syntax validation there are two spurious syntax warnings. First, it points to the closing square bracket on the \label line saying

Solo ]' found.

and secondly, on the final line of the document it says

Number of [' doesn’t match the number of ']'.

I do not simply want to turn these warnings off as I believe there is some underlying explanation for these warnings.

Create a file called something like mychktexrc somewhere, containing

WipeArg
{
\label:[]{} \ref:{} \eqref:{} \vref:{} \pageref:{} \index:[]{}
\cite:[][]{} \nocite:{}
\input:{} \verbatiminput:[]{} \listinginput:[]{}{}
\verbatimtabinput:[]{} \include:{} \includeonly:{}
\bibitem:[]{}
\cline:{} \cmidrule:[](){}
\href:{}{}
# Cleveref -- there are many others that could be here as well...
\cref:*{} \cpageref:*{} \crefrange:*{}{} \cpagerefrange:*{}{}
\Cref:*{} \Cpageref:*{} \Crefrange:*{}{} \Cpagerefrange:*{}{}
# natbib
\citet:*[][]{} \citep:*[][]{} \citealt:*{} \citealp:*[]{} \citeauthor:*{}
\Citet:*[][]{} \Citep:*[][]{} \Citealt:*{} \Citealp:*[]{} \Citeauthor:{}
\citetext:{} \citeyear:*{} \citeyearpar:{}
# tipa which uses "
\textipa:{}
}


which is the same entry as in the default chktexrc file, but with \label marked to accept an optional argument.

Then running

chktex -l mychktexrc filename


you shouldn't get any error message.

The argument for the -l command line option should have the path for the created file.

• I created a new file ´~/.chktexrc´ with the contents specified. In order to get the vim syntastic plugin to use this rc file I added the following to my .vimrc: let g:syntastic_tex_chktex_args = ("-l \"".\$HOME."\\.chktexrc\"") – Jonathan Jogenfors Jul 16 '17 at 23:06