2

I'll go direct to the point: I'm using Haskell to calculate the numbers that I want, these numbers always have some millions of digits (usually more than 15 million digits) and I'm throwing them into separately ".txt" files. How can I get the number from the file and use it with text formatting and etc? Basically it's use what is inside the file (one line only with the huge number, no extra lines)

  • Welcome to TeX.SX! Why don't you post a minimal working example (MWE) with a "small" (one thousand digits?) number to clarify what do you want? For example, placing the digits in a matrix, filling up page after pages of them, using some structure on the pages... – Rmano Jun 23 '16 at 14:01
  • 1
    By the way... http://math.stackexchange.com/questions/1104660/patterns-in-pi-in-contact :-) – Rmano Jun 23 '16 at 14:04
  • if your file only holds that number, you could add it to your document using \input{number.txt}. – Runar Jun 23 '16 at 14:04
  • do you have extra constraints such as wanting to put in grouping separator in threes starting from the wrong end, or do you just want a string of digits allowing breaking anywhere? – David Carlisle Jun 23 '16 at 14:04
  • @runartrollet unless you have quite a wide page, that many digits is likely to make an overfull line unless you add some breakpoints.... – David Carlisle Jun 23 '16 at 14:19
  • well it's just a number, I think since latex has an "auto" line breaker if a line is too long shouldn't it work with just the \input as said by @runartrollet ? i will try it in 2 hours because i'm at university right now – Iago Sousa Jun 23 '16 at 14:43
  • no use in using input{} directly, as made very clear by egreg and David Carlisle. I'll leave this one to them and the other big boys around here. – Runar Jun 23 '16 at 14:51
  • Can I ask why? Typical font sizes results in approx 5000 characters per page. 15 million digits means you will have 3000 pages for one number. Is you goal to run a stress test of the pdftex engine? – Willie Wong Jun 23 '16 at 14:54
  • Not at all, i explained it in another comment in the other answer – Iago Sousa Jun 23 '16 at 14:56
  • If you know the fontsize at which you are going to be printing, and since you are using monospace, you can compute the exact number of characters you can fit on each line. Programmatically it seems a lot easier to get either your original Haskell program or even a simple perl script to insert a line break every so-many characters, than to rely on the TeX engine to do this... – Willie Wong Jun 23 '16 at 15:00

2 Answers2

3

enter image description here

num.txt a one line list of digits and

\documentclass{article}

\makeatletter
\def\fooinput#1{\begingroup
\everyeof{\stopfooinput\endgroup}%
\expandafter\xfooinput\@@input#1\relax}
\def\xfooinput#1{#1\penalty\z@\xfooinput}
\def\stopfooinput#1#2#3{}
\makeatother
\begin{document}

\fooinput{num.txt}

\end{document}
David Carlisle
  • 757,742
  • Hoping that the big number doesn't overflow memory due to the gigantic paragraph being typeset. – egreg Jun 23 '16 at 14:30
  • By the way, the buffer size should be increased. A 1MiB file causes TeX capacity exceeded, sorry [main memory size=5000000] – egreg Jun 23 '16 at 14:39
  • @egreg yes I suppose I could throw in a par every n characters.... – David Carlisle Jun 23 '16 at 14:39
  • The 1MiB file compiles with buf_size=20000000 extra_mem_top=10000000 pdflatex bignum, creating 331 completely useless pages. ;-) – egreg Jun 23 '16 at 14:41
  • My .txt files have from 20MB to 30MB in size – Iago Sousa Jun 23 '16 at 14:45
  • @IagoSousa And what's the purpose of printing them? – egreg Jun 23 '16 at 14:53
  • Well i'm just a crazy guy who loves those big numbers that have a reason for being big, like large prime numbers or the nth term of a sequence and things like that, me and more 2 friends of mine we enjoy it so much that we're gonna print them, and i need to put them into a small monospace font into a pdf and send to print, LaTeX is the best option that i have to that – Iago Sousa Jun 23 '16 at 14:55
  • @IagoSousa There are several Unix tools for massaging big files and making them into well manageable chunks. – egreg Jun 23 '16 at 14:57
  • @IagoSousa I could adjust it to print each line as a paragraph then memory consumption would be much less, – David Carlisle Jun 23 '16 at 14:57
  • 2
    @egreg rm for example? – David Carlisle Jun 23 '16 at 14:58
  • i'm uploading one of the files to my drive, cool thing about it is that this 22million number was generated in less than 5 seconds but needed more than a minute to actually open the txt file – Iago Sousa Jun 23 '16 at 15:01
  • For what egreg meant: see http://unix.stackexchange.com/questions/60219/is-there-a-command-line-tool-to-insert-line-breaks-into-a-long-string – Willie Wong Jun 23 '16 at 15:03
  • https://drive.google.com/open?id=0B8bzOYSM9MS5MVktbjJUR3dmQXc – Iago Sousa Jun 23 '16 at 15:04
3

OFF TOPIC ANSWER

I really doubt LaTeX is the best tool. For example, off the top of my mind:

  1. install a2ps (in Debian/Ubuntu you have a package with the same name);

  2. run

    a2ps -o lalla.ps -4 bignumber.txt
    
  3. it will say

    [bignumber.txt (plain): 22 pages on 6 sheets]
    [Total: 22 pages on 6 sheets] saved into the file `lalla.ps'
    [1375 lines wrapped]
    
  4. enjoy your crime against trees ;-)

Useless heap of paper

This is four logical pages per sheet, but you can play with the options to have more compact or bigger fonts or whatever. man a2ps is your friend.

After that you can use ps2pdf kind of filter to convert it to PDF.

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • 1
    i got it [primo.txt (plain): 4296 pages on 1074 sheets] [Total: 4296 pages on 1074 sheets] saved into the file `lalla.ps' [279232 lines wrapped] – Iago Sousa Jun 23 '16 at 18:55