[Tugindia] Wrapping long numbers

CV Radhakrishnan cvr at river-valley.org
Thu Mar 15 15:58:24 CET 2007


> Hello,

> How could I 'wrap' a long number (> 120 digits) into multiple 
> lines without having to insert spaces manually ? I have to typeset 
> a lot of numbers like this.

Here is a quick and dirty solution:

\breaklonglines takes two arguments, first is the number of digits 
after which you want to insert a space and second is your long 
number.

\documentclass{article}

\begin{document}
\makeatletter

\def\breaklongline#1#2{%
     \@tempcnta=0%
     \edef\@tmp{#1}%
     \@tfor\@breakchar:=#2\do{%
      \advance\@tempcnta1
      \@breakchar\ifnum\@tempcnta=\@tmp
        \relax\space\@tempcnta=0\fi}%
      }

\makeatother

\parindent=0pt
\parskip=12pt

\breaklongline{10}
{12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}

\breaklongline{20}
{12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}

\breaklongline{30}
{12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}

\breaklongline{40}
{12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}

\end{document}


-- 
Radhakrishnan


More information about the tugindia mailing list