我正在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}