我想定义一个通过包生成内联 LaTeX 列表的命令
listings
。但是,LaTeX 的语言定义包含以下内容[]
,这似乎是导致错误的原因:
\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}
答案1
您需要在可选参数中使用括号来表示可选参数:
\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}