[Tex/LaTex] Commands not recognized and missing $ error message

errorstabularxtexstudio

I have an equation and added a legend beneath it to explain the variables (the syntax is copied from another duscussion here somewhere). MWE below:

\documentclass[a4paper,oneside,abstracton]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}                     %Schriftsatz Dokument
\usepackage[english]{babel}                  %ngerman for German
\usepackage{csquotes}                        %[babel,quotes=english]
\usepackage{caption}
\addto\captionsenglish{\renewcommand{\contentsname}{Table of Contents}}
\usepackage{array}
\usepackage{tabularx}                    %more customisable tables (used also for eq legend)
\newenvironment{conditions*}
{\par\vspace{\abovedisplayskip}\noindent\tabularx{\columnwidth}{>{$}l<{$} @{\ : } >{\raggedright\arraybackslash}X}}{\endtabularx\par\vspace{\belowdisplayskip}}

\begin{document}
\begin{conditions*}
    N\textsubscript{*}  &\hspace{0.5cm} the total number of collected object photons during the exposure time\\
    n\textsubscript{pix}   &\hspace{0.5cm} number of pixels that are taken into account for \\
    n\textsubscript{B}   &\hspace{0.5cm} speed of light\\
    N\textsubscript{S}   &\hspace{0.5cm} \\
    N\textsubscript{D}   &\hspace{0.5cm} \\
    N\textsubscript{R}   &\hspace{0.5cm} \\
    G   &\hspace{0.5cm} \\
    $\sigma$\textsubscript{f}   &\hspace{0.5cm} 
\end{conditions*}
\end{document}

TeXStudio marks the following syntax in red and when moving over it tells me that the command is not recognized. How can I make it recognize the command?
In the newenvironment-preamble definition the following \tabularx and a line farther \endtabularx

Inside the document and the condition environment I have the following: The & signs are marked red and cursor-over it tells me that "tabular command outside tabular env". Moreover, I get the error message for this condition environment Missing $ inserted. \end{conditions*} . I don't see why.

Best Answer

The first column is already declared in math mode with >{$} and <{$}, so what you have in the last row is, after all substitutions

$ $\sigma$\textsubscript{f} $

which causes \sigma to be outside of math mode. So just omit $.

You shouldn't use \textsubscript. Here's a better version that avoids specifying \hspace{0.5cm} every time.

\documentclass[a4paper,oneside,abstracton]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}                     %Schriftsatz Dokument
\usepackage[english]{babel}                  %ngerman for German
\usepackage{csquotes}                        %[babel,quotes=english]
\usepackage{caption}
\addto\captionsenglish{\renewcommand{\contentsname}{Table of Contents}}
\usepackage{array}
\usepackage{tabularx}                    %more customisable tables (used also for eq legend)
\newenvironment{conditions*}
 {\par\nopagebreak
  \vspace{\abovedisplayskip}
  \noindent
  \tabularx{\columnwidth}{
    >{$}l<{$}
    @{\ :\hspace{0.5cm}}
    >{\raggedright\arraybackslash}X
  }
 }
 {\endtabularx\par\vspace{\belowdisplayskip}}

\begin{document}
\begin{conditions*}
N_{*}               & the total number of collected object photons during the exposure time \\
n_{\mathrm{pix}}    & number of pixels that are taken into account for \\
n_{\mathrm{B}}      & speed of light\\
N_{\mathrm{S}}      & \\
N_{\mathrm{D}}      & \\
N_{\mathrm{R}}      & \\
G                   & \\
\sigma_{\mathrm{f}} &
\end{conditions*}
\end{document}

enter image description here

Related Question