4

I'm using TeXstudio as editor because I think it provides the best features among other software I tried (namely Kile and TeXworks), especially about highlighting, autocompletion and spell checking. It correctly recognizes all the commands and environments I use, even those I have declared myself in the preamble with \newcommand.

However I've got some lines like these

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norma}{\lVert}{\rVert}

which TeXstudio doesn't recognize as valid commands and therefore highlights them in red throughout the text to mark them as bad LaTeX commands.

Anyway if I add them manually in the TeXstudio advanced highlighting option page and restart the program everything is fine and the bad red highlightings disappear.

However, is there a way to make TeXstudio aware of these new commands automatically or do I have to manually specify all of them in the options?

Edit: furthermore simply adding \norma as a new command in the options makes TeXstudio not aware that this is a new command that can be autocompleted: if I type \norma and then type { TeXstudio substitutes my typing with \normalcolor{}, which is not what I want!

2

After the help of @Torbjørn I came up with this workaround.

  1. Create a mydefinition.cwl file and place it in the %APPDATA%/texstudio folder (I'm using Windows, don't know where it should go in other operative systems).
  2. Add the \DeclarePairedDelimiter{cmd}{left_delim}{right_delim}#md line in the .cwl file.
  3. In TeXstudio Options -> Completion check the box of mydefinition.cwl that appeared in the list.

This fixed the problem for me: I get the correct autocompletion for my \abs and \norma commands!

Now a little explaination: as far as I could learn (but if anyone has further information please let me know!), the problem comes from TeXstudio .cwl files, which are not yet complete. There are some packages with some commands which haven't been added to the autocompletion files of TeXstudio yet. The TeXstudio team is working for improving this.

0

This is kind of a hacky workaround, but it is less tedious and it worked for me: make a \newcommand with the same name, but make sure LaTeX doesn't read it. To do this, place a line like

\iffalse
\newcommand{\abs}{abcdef}
\fi

in the preamble. The highlighting should work without affecting the document output. (Note: This does not however fix autocompletion.)

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.