我使用的编辑器会在每行 80 个字符后换行。每当我在行lstinline
尾使用 long 时,编辑器都会继续换行,我就会收到错误消息Package Listings: lstinline ended by EOL.
考虑以下例子:
\documentclass{article}
\usepackage{listings}
\lstset{
breaklines=true,
breakatwhitespace=true,
language=c,
basicstyle=\small\ttfamily,
numbers=left,
numberstyle=\tiny,
frame=tb,
keepspaces=true,
columns=fullflexible,
showstringspaces=false,
}
\begin{document}
This is a text with a long function in \lstinline|void some_func(int
some_argument)|, where the editor automatically adds a second line.
\end{document}
编辑器会自动添加新行,然后void some_func(int
导致出现错误消息。有没有办法将lstlisting
命令扩展到多行?
答案1
我在 中找不到此方法的键值接口listings.sty
,因此这里有一个硬编码方法。您必须更改宏\lst@InlineM
:
\def\lst@InlineM#1{\gdef\lst@inlinechars{%
\lst@Def{`#1}{\lst@DeInit\egroup\global\let\lst@inlinechars\@empty}%
\lst@Def{13}{\lst@DeInit\egroup \global\let\lst@inlinechars\@empty
\PackageError{Listings}{lstinline ended by EOL}\@ehc}}% <--- Error message
\lst@inlinechars}
改为不产生错误的内容。默认行为是结束\lstinline
(以\lst@DeInit\egroup
),然后抛出错误。要使新行表现为空格,您可以执行以下操作:
\def\lst@InlineM#1{\gdef\lst@inlinechars{%
\lst@Def{`#1}{\lst@DeInit\egroup\global\let\lst@inlinechars\@empty}%
\lst@Def{13}{\lst@ProcessSpace}}% <---
\lst@inlinechars}
梅威瑟:
\documentclass{article}
\usepackage{listings}
\lstset{
breaklines=true,
breakatwhitespace=true,
language=c,
basicstyle=\small\ttfamily,
numbers=left,
numberstyle=\tiny,
frame=tb,
keepspaces=true,
columns=fullflexible,
showstringspaces=false,
}
\makeatletter
\def\lst@InlineM#1{\gdef\lst@inlinechars{%
\lst@Def{`#1}{\lst@DeInit\egroup\global\let\lst@inlinechars\@empty}%
\lst@Def{13}{\lst@ProcessSpace}}%
\lst@inlinechars}
\makeatother
\begin{document}
This is a text with a long function in \lstinline|void some_func(int
some_argument)|, where the editor automatically adds a second line.
\end{document}