如何自动拆分列表中的长数字?重新定义 \lst@lettertrue 不起作用。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\lstset{
breaklines=true
}
\makeatletter
\def\lst@lettertrue{\let\lst@ifletter\iffalse}
\makeatother
\begin{document}
\begin{lstlisting}
5646534535677654567453241456765467863576465467345675856382436457687534678665425769888843222222222587
\end{lstlisting}
\end{document}
答案1
您可以使用literate
一对一替换所有数字(作为参考,请参阅我如何格式化所有数字listings
?):
\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{
breaklines=true,
}
\begin{document}
\begin{lstlisting}
5646534535677654567453241456765467863576465467345675856382436457687534678665425769888843222222222587
\end{lstlisting}
\lstset{% Literate one-to-one mapping of numerals
literate={0}{0}{1}%
{1}{1}{1}%
{2}{2}{1}%
{3}{3}{1}%
{4}{4}{1}%
{5}{5}{1}%
{6}{6}{1}%
{7}{7}{1}%
{8}{8}{1}%
{9}{9}{1}%
}
\begin{lstlisting}
5646534535677654567453241456765467863576465467345675856382436457687534678665425769888843222222222587
\end{lstlisting}
\end{document}
当然,这可能会破坏您不想破坏的常规数字。但是,我不确定这是否会成为一个问题。