[Tex/LaTex] TeXstudio chemfig commands marked as unrecognized

chemfigsyntax highlightingtexstudio

I included the chemfig package to draw chemical stuff in LaTex.
But the commands aren't recognized by TeXstudio. I even added the package to the autocompletion list in the settings to get recognized in every document but that doesn't help either.

The commands are red like following:

Looks like:

The file compiles as it should, so everything works except the recognition of the chemfig commands.

Best Answer

Short answer:

It's not in the .cwl file for some reason, you're gonna have to add it in manually. (I think(!) that's the only alternative. I'm happy to be proven wrong..)

Long answer:

The Why: Autocompletion and recognition of commands by TeXstudio is controlled by the .cwl file, which can be found in your local directory. For Windows, it's in:


The .cwl file autogenerated by TeXstudio looks like this:

cwl file for chemfig

The commands in the .cwl file are in the format: <command>[#classification], so note that there are no \setatomsep, \schemestart, \chemfig etc. commands in here, so that's why they are unrecognized.

Also note that the classification are #S which means that they will not appear in the autocompleter tab when typing the command in TeXstudio.

The How:

Like I said in the short answer, you're probably gonna have to add the commands in manually if you don't want to see the 'warnings' by TeXstudio about unrecognised commands.

See my other answer here to find out how. But I have here something you can copy-paste for a quick fix. You just need to add this into your chemfig.cwl file and restart your TeXstudio to see its effect. You will need to activate chemfig.cwl in the options -> completion tab from within TeXstudio as well.

\setatomsep{sep dist}#n
\schemestart{your scheme}#n

Note: I chose to use #n classification here so you will see it in the autocompleter.

Proof that it works:

proof :)

The Hack: Of course, there is always the less desirable, but still effective solution of just plain ignoring it. :p

You can simply turn off syntax highlighting for a wrong/unrecognized command by TeXstudio, by right-clicking on the background colour box to reset it to 'no colour'.

turn off syntax highlighting

Related Question