I'd like to define some tables as commands (MWE) in an external .tex file,
because there are a lot of settings for them. This external file gets included in the main document by the \input{}
command. Using my pre-defined commands is no problem. TeXStudio is able to compile the main document and also gives an output. The problem is, that TeXStudio doesn't recognize the \hline
command and the &
separator for tables inside my self-defined table (the editor says there are table commands outside of table environment). Also, if only the main document is opened in the editor (without the myTemplate file),
the \mytable{}
and \lb
commands I defined in the external document are not recognized.
Is there a way to make this red highlighting disappear
without simply deactivating the syntax-highlighting? I got some help from here: TeXStudio doesn't recognize some commands, because I've had the same Problem with other commands before. Though, These commands were from packages I got from ctan, so no self-defined commands.
I'm not sure if this problem is reproducable for you, but here is a MWE:
\documentclass[]{scrartcl}
\input{myTemplate.tex}
\begin{document}
\mytable{
%% \hline A & B & C & D & E \\ \hline
a & b1 \lb b2 \lb b3 & c1 \lb c2 \lb c3 & d & e \\ \hline
& & & & \\ \hline
& & & & \\ \hline
}
\end{document}
And the myTemplate file:
\usepackage{tabularx}
\usepackage{here}
\usepackage{array}
\usepackage[table]{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcommand{\mytable}[1]{%
\begin{center}
\rowcolors{1}{white}{pink}
\begin{tabular}{| M{.2\textwidth} | M{.15\textwidth} | M{.1\textwidth} | M{.2\textwidth} | M{.2\textwidth} | M{.15\textwidth}|} \hline
A & B & C & D & E \\ \hline
#1
\end{tabular}
\end{center}%
}
\newcommand{\lb}{\linebreak}
Best Answer
It's not possible to selectively switch of parts of the syntax checking. It's also not possible to make the parser accept table-like behavior in arguments.
However, you could define your own table environment:
in a custom .cwl declare that environment to be tabular-like:
and use it in your document: