Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
Thanks, works like a charm! –  Marius Hofert Jan 17 '13 at 9:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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