I want to write some things to the log file. What is the best practice for this? Is it \message{} or \typeout{} or what?

1 Answer 1


The Plain TeX command \wlog is available also in LaTeX

\wlog{This will be written in the log file}

The macro \wlog expands to \immediate\write-1, and by rule the argument will be written out only in the log file and won't appear in the terminal.

When \write is followed by a number between 0 and 15 (included), the write operation is made on the output stream with that number if open at the time the write is performed (immediately or when the output routine is in action, according whether \immediate precedes \write or not). If the output stream is not open or the number is non negative, the argument to \write is written on the terminal and in the log file. Conversely, when the number is negative the argument is written only in the log file.

Exception: in most TeX distribution, \write18 passes the argument to the operating system, provided shell escape is enabled (possibly in restricted mode, see the manual of TeX Live or MiKTeX).

The LaTeX command \typeout does \immediate\write\@unused, so it writes the argument both to the terminal and to the log file. There is no predefined command of this kind in Plain TeX. Indeed \typeout also gives \protect a suitable meaning for coping with fragile commands in the argument. The \@unused stream is permanently unassigned to a file.

Also \message writes both in the terminal and the log file, but it doesn't force a new line, which instead is done by \write when the output is directed to the log file.

  • 1
    Is there a Plain TeX command to write in the log file and in the terminal? Aug 30, 2012 at 17:19
  • 4
    What's the difference between \wlog, \typeout, and \message?
    – lpdbw
    Aug 30, 2012 at 19:09
  • One difference I noted is that \typeout writes a newline while the others don't. (cc @lpdbw) I failed to output any amount of "formatting" whitespace to the log. :(
    – Raphael
    Nov 28, 2014 at 17:15
  • 1
    @Raphael A \write that ends up in the log file because the number is negative (\wlog) or the output stream is not open (\typeout) will always be printed on a new line. This is not the case of \message. In LaTeX you can use ^^J to force a line break, so \message[^^JText^^J} will be on a line by itself.
    – egreg
    Nov 28, 2014 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.