我正在文档中使用该listings
包。为了简化\lstinline
命令的使用,我创建了一个新命令,如下所示:
\newcommand{\lstcs}[1]{\lstinline[language=[Sharp]C,breaklines=false]#1}
我也尝试过:
\newcommand{\lstcs}[1]{\lstinline[language=[Sharp]C,breaklines=false]{#1}}
显然,我使用此命令来内联列出 C# 代码。这是我的示例文档,我在其中收到完全相同的错误消息:
\documentclass{scrreprt}
\usepackage{listings}
\newcommand{\lstcs}[1]{\lstinline[language=[Sharp]C,breaklines=false]#1}
\begin{document}
This is \lstcs{CSharpCode()}.
\end{document}
错误信息如下:
Runaway argument?
CSharpCode().
./test.tex:8: Paragraph ended before \lstKV@OptArg@@ was complete.
<to be read again>
\par
l.8
?
[1{/usr/local/texlive/2012/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./test.aux) )
(\end occurred inside a group at level 1)
### simple group (level 1) entered at line 7 ({)
### bottom level
(\end occurred when \ifx on line 7 was incomplete)
(\end occurred when \ifx on line 7 was incomplete)
(\end occurred when \ifx on line 7 was incomplete)
(\end occurred when \ifx on line 7 was incomplete)
(\end occurred when \ifx on line 7 was incomplete) </usr/local/texlive/2012/texm
f-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on test.pdf (1 page, 11039 bytes).
SyncTeX written on test.synctex.gz.
Transcript written on test.log.
我对 LaTeX 还很陌生,以前没有用过\newcommand
,所以我猜问题就出在这里。
我希望你可以帮助我!
谢谢——克里斯
答案1
]
当它看到结束符时会感到困惑,Sharp
所以你需要用一对额外的括号将其括起来。还需要另一对括号#1
\documentclass{scrreprt}
\usepackage{listings}
\newcommand{\lstcs}[1]{\lstinline[language={[Sharp]C},breaklines=false]{#1}}
\begin{document}
This is \lstcs{CSharpCode()}.
\end{document}