According to TeXbook TeX does preprocess files of .tex-input line per line (converting all characters of the line to TeX's internal character-representation-scheme (ASCII or Unicode), truncating sequences of space-characters at ends of lines, appending a character specified by \endlinechar).

So questions arise:

  1. What is the maximum amount of characters per line in .tex-input files?
  2. How does TeX behave when encountering at reading-time a line that is too long?

You can use TeX for writing external text files.

  1. How does TeX behave when attempting to write a line to external text file that is too long/that has more characters than TeX can place into a single line of an external text file?

The \write-primitive always writes an entire line to external text-file.

  1. Are there means for
    • just beginning a new line of an external text-file?
    • appending characters to the current line of an external text-file?
  • I'm not sure there is a limit. I certainly have a line of over 1300 characters in one file in my thesis (a \caption, including cross-references, equations, \label and a lot of edits highlighted using the changes package; I tend to write one sentence per line)
    – Chris H
    Jun 15, 2021 at 9:47
  • Given @David's answer below, I feel like I wasn't even trying
    – Chris H
    Jun 15, 2021 at 9:49
  • 1
    @ChrisH my test file had 400000 z followed by \bye Jun 15, 2021 at 9:51
  • I am not sure I understand all your \write questions, you can write a newline by writing the \newlinechar (^^J in laTeX) try \typeout{aaa^^Jbbb} Jun 15, 2021 at 10:03
  • While 200000 is the nominal limit, with 199990 characters in a line you still get the error, and running pdflatex on a file starting with 199989 times the letter z, I get an ! Emergency stop error for some reason... Jun 15, 2021 at 10:30

1 Answer 1


This is system dependent and with web2c implementations user-settable.

texlive 2021 texmf.cnf has

% Buffer size.  TeX uses the buffer to contain input lines, but macro
% expansion works by writing material into the buffer and reparsing the
% line.  As a consequence, certain constructs require the buffer to be
% very large, even though most documents can be handled with a small value.
buf_size = 200000

If you exceed this you get:

$ pdftex aa408
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdftex)
 restricted \write18 enabled.
entering extended mode
(./aa408.tex! Unable to read an entire line---bufsize=200000.
Please increase buf_size in texmf.cnf.

TeX has no mechanism to append to a file.

  • Thanks for answering. As to "TeX has no mechanism to append to a file." The question is not about appending to a file but about appending to a line as could, e.g., be done with Pascal's write-procedure which - unlike writeln - does not finish the line. Jun 15, 2021 at 10:25
  • What happens if you have accumulated tokens for writing in an amount where the resulting amount of characters to be written to external file has more characters than TeX's \write can write into a single line? Jun 15, 2021 at 10:28
  • 1
    Is "macro expansion works by writing material into the buffer and reparsing the line" actually true? Doesn't TeX just start reading from a token list?
    – texdr.aft
    Jun 15, 2021 at 21:13
  • 1
    @texdr.aft normally yes but I seem to think that comment is right and there are constructs where tex borrows the input buffer, a couple of quick examples failed to show this howerever, and it's a bit late at night to start reading tex.web:-) Jun 15, 2021 at 23:00
  • 2
    @texdr.aft ah \input triggers this if you have \input file followed by z to say column 199980 then if file.tex is just x it all works but make it 20 x then you get the unable to read entire line error even though neither file has a line that long Jun 15, 2021 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .