# newcommand wrapping lstinline does not work inside table

I like to have consistent documents and I like to make some decisions on formatting after I finished writing the document. I use my own placeholder LaTeX commands to wrap some words or expressions. For example, I'd like to use a command called \Shortcut to wrap \lstinline with a suitable style parameter. (whether I'll use \lstinline in the end does not matter, I may change that to \textcolor or whatever). Until now my approach simply worked. But it does not work in a tabular environment. How can I make it work? Here is my MWE:

\documentclass{book}

\usepackage{tabularx}
\usepackage{listings}
\usepackage{xcolor}

\lstdefinestyle{inlcode}{
language=C,
identifierstyle=\color{blue!75!black}
}
\newcommand\Shortcut{\lstinline[style=inlcode]}

\begin{document}
\Shortcut{test}            % <--- works

\begin{tabular}[t]{cc}
1 & 2 \\
\Shortcut{one} & two   % <--- doesn't work
\end{tabular}
\end{document}


I have changed the definition of your custom command to allow for the use of an argument.


\documentclass{book}

\usepackage{tabularx}
\usepackage{listings}
\usepackage{xcolor}

\lstdefinestyle{inlcode}{
language=C,
identifierstyle=\color{blue!75!black}
}
\newcommand{\Shortcut}[1]{\lstinline[style=inlcode]{#1}}

\begin{document}
\Shortcut{test}

\begin{tabular}[t]{cc}
1 & 2 \\
\Shortcut{one} & two
\end{tabular}

\end{document}

• Could you add an explanation of why the version without an explicit argument doesn't work in tabulars? – siracusa Jun 27 '19 at 22:57
• Lstinline is a verbatim like command. By using an argument you freeze the catcodes and actually break it. – Ulrike Fischer Jun 28 '19 at 6:00