6

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"

enter image description here

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}
hugomg
  • 1,071

2 Answers2

3

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:

\begin{mathparpagebreakable}#S
\begin{mathpar}#S

After:

\begin{mathparpagebreakable}#S\math
\begin{mathpar}#S\math
hugomg
  • 1,071
  • 1
    Interesting. One post, two answers ;). I remember something about \math while editing my own .sty files and creating their respectives .cwl files. I just couldn't imagine it would be the case for this package. – FHZ Mar 03 '20 at 01:05
2

Go to Options -> Configure TeXstudio and then to the left menu Syntax Highlighting. Right click the central column of the option latexSyntaxMistake of the section LaTeX checking, or change the color.

enter image description here

This is the result.

enter image description here

However, I would recommend to find the respective .cwl file. TeXstudio stores the users .cwl file at %AppData%\Roaming\texstudio\completion\user (Where are cwl files stored?). Use this option if you install it manually.

FHZ
  • 3,939
  • 1
    Thanks! I managed to fix the problem by editing the cwl file, using the information you linked. – hugomg Mar 03 '20 at 01:00