Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can use a literate one-to-one replacement of all numerals (as reference, see How can I format all numbers in listings?):

enter image description here

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

share|improve this answer
    
Thx, this does the trick! –  user4811 Jan 9 at 13:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.