TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

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.

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:


$\pi = \seqsplit{%
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} 

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:

    #1\hspace{0pt plus 1pt}\let\next\@bignumber

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.




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


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-

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