# Automatic line breaks of long numbers in listings

How can I automatically break long numbers in a listing? Redefining \lst@lettertrue doesn't work.

\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}


You can use a literate one-to-one replacement of all numerals (as reference, see How can I format all numbers in 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}


Of course, this may break regular numerals that you don't want to break as well. However, I'm not sure whether this might be an issue.

• Thx, this does the trick! – user4811 Jan 9 '14 at 13:08