Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
I don't think you need any packages. Are you using this in math mode? –  Peter Grill Oct 29 '12 at 23:53
    
@PeterGrill, sorry. Probably I'm confusing you guys. My question is about unknown commands by the editor not by LaTeX. Everything is fine with the compilation. –  Sigur Oct 29 '12 at 23:57
    
Ok, then perhaps this is a duplicate of TeXStudio doesn't recognize some commands. –  Peter Grill Oct 30 '12 at 0:20
    
I found that topic, but it does not consider the command \colon. I am not able to find this command. –  Sigur Oct 30 '12 at 0:23
1  
You could just add \colon#S to a custom .cwl file. (It is defined in plain.tex: \mathchardef\colon="603A % colon as a punctuation mark and is redefined by amsmath.) –  Qrrbrbirlbel Oct 30 '12 at 3:56
show 2 more comments

2 Answers

up vote 5 down vote accepted
+50

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 my Windows 7 installation, custom .cwl files are stored and recognized by TeXstudio in %APPDATA%\texstudio\.

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

share|improve this answer
    
    
How do you create a .cwl file though? I tried creating in in TXS and one in with a text editor and neither worked when I dragged it into ~/.config/texstudio (for Mac). –  AlanH May 8 '13 at 18:32
    
Have you activated the .cwl file in the Options menu/Completion tab (see last paragraph of Notes section of this answer)? –  Qrrbrbirlbel May 8 '13 at 18:37
    
All I see under Options is "Load Profile", "Save Profile", "Save Current Settings", "Define Current Document as Master Document", and "Automatically Restore Session at Next Start". When you create the .cwl file, are you typing \colon#m in TXS or some other application? (I should note that I'm on a Mac.) –  AlanH May 8 '13 at 18:48
    
It doesn’t matter where you type it, just be sure it is a normal text file (and it is probably better to not use UTF8). Sorry, the correct route is Options, Configure TeXstudio, Completion tab (as in my answer above). –  Qrrbrbirlbel May 8 '13 at 18:58
show 4 more comments

\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.

share|improve this answer
    
So should I try it with other commands or is there a bug the ability to create any sort of custom command? –  AlanH May 8 '13 at 19:59
    
@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 8 '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. –  AlanH May 8 '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 8 '13 at 20:19
    
@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 8 '13 at 20:22
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.