6

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.

Sigur
  • 37,330

2 Answers2

7

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

Qrrbrbirlbel
  • 119,821
2

\colon is made known to TeXStudio in latex-mathsymbols.cwl, which, as a pre-customized .cwl file, is not directly accessible to the end user, since it is in the compiled program files. (Found through googling colon site:http://svn.code.sf.net/p/texstudio/code/trunk/completion/; also see Where does TeXstudio store the .cwl files for hyperref and xspace?)

For some reason, all commands from that file are recognized, i.e. suggested as autocompletion and not marked as unknown commands, except for \colon and \lnot. This seems to be a bug to me. I reported it as bug #728 \colon and \lnot from latex-mathsymbols.cwl aren’t recognized.

doncherry
  • 54,637
  • So should I try it with other commands or is there a bug the ability to create any sort of custom command? – TheRealFakeNews May 08 '13 at 19:59
  • 1
    @AlanH In the long run, I expect this bug to be fixed in one of the next releases of TXS, so you won’t have to worry about \colon anymore. If I understand your question correctly as asking if personal/customized .cwl files are broken in general, the answer is no. I just added \colon#m to my personal .cwl file, restarted TXS, and it is recognized just fine. – doncherry May 08 '13 at 20:05
  • so you were able to get \colon to show in the autocompletion? If so, then I must have done something wrong... Btw, I don't care so much about \colon, I was just trying to follow the example posted by Qrrbrbirlbel. – TheRealFakeNews May 08 '13 at 20:06
  • In my case, I created my personal cwl file with the same name as my package sty where I defined my personal command. So, only when I load my package TeXstudio suggest the command. The cwl file contains only the command (in my case, \alert{arg}). Nothing more at the end of line. – Sigur May 08 '13 at 20:19
  • 1
    @Sigur Depending on how complex the macro definitions in your personal .sty file are, TXS will automatically recognize the macros. (Not sure if it has to be in the texmf tree as well, this was the case when it worked for me.) However, custom .cwl definitons might be more precise and complete, e.g. in providing an autocomplete entry for a command with and without an optional macro. – doncherry May 08 '13 at 20:22
  • Re bug report: For me, \colon is not recognized with SVN 3661 but it is with SVN 3883 (and then even without latex-mathsymbols.cwl activated which I can’t remember being in the list of .cwl files). – Qrrbrbirlbel May 08 '13 at 20:32
  • @Qrrbrbirlbel So TXS 2.5.2 isn’t equals TXS 2.5.2? (I’m on SVN 3661.) – doncherry May 08 '13 at 20:36
  • @doncherry At their download page the file contains already 260 but the GUI says 2.5.2. – Qrrbrbirlbel May 08 '13 at 21:15
  • @Qrrbrbirlbel: With the 'download page' link, you are pointing to the SVN snapshots these are no official releases, but just reflect the state of the project during development. They are for testing and for users, who want to have the cutting edge stuff without compiling themselves. However, the SVN snapshots are less well tested and use on your own risk. – Tim Hoffmann May 13 '13 at 18:03
  • @doncherry: Yes and no. There is only one official release of 2.5.2. However, there may be multiple SVN snapshots which all carry the same version number (e.g. 2.5.2). Admittedly, naming is not always consistent with the SVN snapshots. – Tim Hoffmann May 13 '13 at 18:08