3

I would like to define a command which produces inline LaTeX listings via the package listings. However, the language definition for LaTeX contains [] which seems to be the cause of the error:

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{listings}

\newcommand*{\Lcode}{\lstinline[language=[LaTeX]TeX]}% does not work
%\newcommand*{\Lcode}{\lstinline}% works

\begin{document}
   If you like LaTeX, you write \Lcode|\LaTeX| which gives \LaTeX
\end{document}
5

You need braces for optional arguments in optional arguments:

\documentclass{scrartcl}

\usepackage[american]{babel}
\usepackage{listings}

\newcommand*{\Lcode}{\lstinline[{language=[LaTeX]TeX}]}% works, too
% \newcommand*{\Lcode}{\lstinline} % works

\begin{document}
   If you like LaTeX, you write \Lcode|\LaTeX| which gives \LaTeX
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.