# Inline listing for LaTeX code: language definition fails

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}

-

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}

-
Thanks, works like a charm! – Marius Hofert Jan 17 '13 at 9:27