When I use the mathpartir package, Tex Studio does not seem to identify that mathpar
is a math environment, and highlights all my math mode commands in red. When I hover the mouse over them, it says "math command outside math env"
The document still compiles just fine, without producing any errors. But all those red backgrounds make it harder to read the rules. Is there some way for me to tell Tex Studio that mathpar is a math environment, so those warnings can go away?
I tried checking the "mathpartir.cwl" checkbox inside Configure TexStudio -> Completion, as suggested in this other answer but it made no difference.
By the way, here is the test file I used, in a format that can be copy and pasted:
\documentclass{article}
\usepackage{mathpartir}
\begin{document}
\begin{mathpar}
\inferrule
{\Gamma \vdash e_1 : A \rightarrow B \\
\Gamma \vdash e_2 : A }
{\Gamma \vdash (e_1 \; e_2) : B }
\end{mathpar}
\end{document}
Best Answer
The "math command outside of math env" warning is related to Tex Studio's autocompletion feature. Tex Studio identifies which commands are declared by each package you require, and highlights it in red if the command is mispelled, or used inside the wrong kind of environment. Tex Studio identifies the commands by parsing the
sty
files, using some clever heuristics. It works most of the time, but sometimes it doesn't get it 100% correct. For example, in mathpartir's case, Tex Studio failed to identify that\begin{mathpar}
command opens a math environment.To fix this, we can manually edit the completion information, which is stored in cwl files. Find
mathpartir.cwl
, and add a\math
classification in the line corresponding to the mathpar environment.Before:
After: