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.

Possible Duplicate:
Wrapping long lines that contain no spaces

I'm writing a report (in LaTeX) in cryptology and I have to work with very large numbers. I want those big numbers to be on multi-lines, I mean when I write my big number, and after compiling, LaTeX puts this big number on a single line, but we can only read the beginning of this number. How to print the big number on multi-lines automatically ? Is there a tag to use or something else? Thanks

share|improve this question

migrated from stackoverflow.com Mar 16 '11 at 22:18

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Hendrik Vogt, lockstep, Joseph Wright Mar 17 '11 at 9:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3  
tex.stackexchange.com –  nightcracker Mar 16 '11 at 20:26

4 Answers 4

There's a very nice package for this, seqsplit designed originally for DNA/RNA sequences, but eminently usable for your purposes too. From the documentation:

\documentclass{article}
\usepackage{seqsplit}
\begin{document}

$\pi = \seqsplit{%
3.
1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164
0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 5058223172
5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 4428810975
6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 4543266482
1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 9171536436
7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 5759591953
0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 8912279381
8301194912 9833673362 4406566430 8602139494 6395224737 1907021798 6094370277
0539217176 2931767523 8467481846 7669405132 0005681271 4526356082 7785771342
7577896091 7363717872 1468440901 2249534301 4654958537 1050792279 6892589235} 
\ldots$
\end{document}

enter image description here

share|improve this answer
    
Nice. It basically does the same as what my macro does, but has the advantage that it also works in math mode. –  Michael Ummels Mar 17 '11 at 0:15
    
@Michael To get your solution to work in mathmode you could replace the \- with \ifmmode\allowbreak\else\hspace{0pt plus 1pt}\fi BUT that makes the first line of the sequence overlap by one character. I haven't thought much how to fix that. –  Alan Munn Mar 17 '11 at 0:39

I've written a small macro that automatically inserts \- after each digit of a given number, as proposed by hlovdal:

\makeatletter
\def\@bignumber#1#2{%
  \ifx#2\end
    #1\let\next\@gobble
  \else
    #1\hspace{0pt plus 1pt}\let\next\@bignumber
  \fi
  \next#2}
\newcommand{\bignumber}[1]{\@bignumber#1\end}
\makeatother

With this definition, you can write \bignumber{123456....}, which should print the number and perform suitable linebreaks automatically.

Edit: Replaced \- by \hspace{0pt plus 1pt}. This omits the hyphen at the end of a line and avoids overfull hboxes.

share|improve this answer

You can insert manual "word split markers" (not sure if this is the correct latex term), e.g. \- after every single digit, then latex will be able to split the number where ever needed. Maybe it is possible to make a latex macro to do this, but I do not know enough latex to do this, so I will use the commandline instead.

Example

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{xltxtra}

\begin{document}

$\pi \approx \frac{22}{7} = NUMBER\ldots$

\end{document}

Running the command

echo "scale=200; 22/7" | bc -l | tr -d '\012\\' | sed 's/\(.\)/\1\\-/g' | xclip -i

and then pasting in the clipboard content replacing NUMBER above gives the following output:

π ≈ 22/7 = 3.1428571428571428571428571428571428571428571428571428571428571-
428571428571428571428571428571428571428571428571428571428571428571428571428-
5714285714285714285714285714285714285714285714285714285714285714...

The command to add \- after every single digit is sed 's/\(.\)/\1\\-/g'.

share|improve this answer

You could just use \newline or its alias \\ within the number to force a linebreak.

share|improve this answer
1  
This is not a good way to split numbers: firstly, you need to break lines by hand which could involve a lot of recompiling, and secondly, what happens when you need to change margins, paper size, font, font size or other metrics? Underfull/overfull hboxes everywhere, I suspect. –  Richard Terrett Mar 17 '11 at 1:51