[Tex/LaTex] TeXStudio does not recognize \colon

texstudio

What is the file to load the command \colon to be recognized (as a known command) by TeXStudio? If I add it to the personal command it works but I guess that this command comes from some package.

ps: I'm talking about highlighting unknown commands.

ps2: I tried grep colon *.cwl on my .config/texstudio folder and I found

mathabx.cwl:\coloneq#Sm
mathabx.cwl:\eqcolon#Sm
mathtools.cwl:\vcentcolon#S
mathtools.cwl:\ordinarycolon#S
mathtools.cwl:\MT_activate_colon#S
mathtools.cwl:\MT_active_colon_true#S

that is, no \colon command.

Best Answer

The macro \colon is defined in plain.tex as a punctuation mark (: is a relation symbol in math mode)

\mathchardef\colon="603A

and redefined by amsmath.

Unfortunately, TeXstudio doesn’t recognize the command even if the amsmath.cwl completion file is selected.

But we can create our own .cwl file. On Windows, custom .cwl files are stored and recognized by TeXstudio in %appdata%\texstudio\completion\user. In Linux in ~/.config/texstudio/completion/user. (more information in 4.13.4 cwl file placement)

Create your own .cwl file, I named it custom.cwl. One line suffices:

\colon#m

Notes:

  • m declares it as a math mode command, the use of \colon in text mode will still give you the unrecognized highlighting.
  • S, as I understand it, gives you recognizing (i.e. correct highlighting) but not completion.

After saving the file custom.cwl start TeXstudio go to the “Options” menu and open the “Configure TeXstudio” dialog. In the “Completion” tab select custom.cwl and apply your changes (“OK”).

Code

\documentclass{article}
\begin{document}
$a:b$\par
$a{:}b$ \par
$a\mathrel{:}b$ \par
$a{:\,}b$ \par% \colon
$a\colon b$ \par
a \colon b
\end{document}

Screenshots

auto-completion \colon is highlightet correct