[Tugindia] Wrapping long numbers

David Kastrup dak at gnu.org
Thu Mar 15 21:52:14 CET 2007


David Kastrup <dak at gnu.org> writes:

> "Alok G. Singh" <alokgs at yahoo.co.uk> writes:
>
>> 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.
>
> In the preamble:
>
> \newenvironment{wrappednumbers}
> {\count0=`\9 \loop \ifnum\count0>`\0
>   \uccode`\~=\count0\uccode`\!=\count0
>   \lowercase{\def~{!\penalty0}}
>   \catcode\count0=\active
>   \repeat
>   \uccode`\~=0 \uccode`\!=0}{}

Oops.  That comes from not testing code.  Amusing how many things can
go wrong at once.  Here is something that works:

\documentclass[a4paper]{article}
\newenvironment{wrappednumbers}
{\count0=`\0 \loop \ifnum\count0<`\:
  \uccode`\~=\count0\uccode`\!=\count0
  \uppercase{\def~{!\penalty0 }}
  \catcode\count0=\active
  \advance\count0 1
  \repeat
  \uccode`\~=0 \uccode`\!=0 }{}
\begin{document}
\begin{wrappednumbers}
3.141592653589793238462643383279502884197169399375105820974944592307816%
40628620899862803482534211706798214808651328230664709384460955058223172%
5359408128481117450284102701938521105559644622948954930382
\end{wrappednumbers}
\end{document}

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>


More information about the tugindia mailing list