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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 '14 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.