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.

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

share|improve this question

1 Answer 1

up vote 24 down vote accepted

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.

share|improve this answer
1  
Is there a Plain TeX command to write in the log file and in the terminal? –  Paul Gaborit Aug 30 '12 at 17:19
2  
What's the difference between \wlog, \typeout, and \message? –  lpdbw Aug 30 '12 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 1 hour ago
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 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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