12

In source2e (specifically ltfiles.dtx) under \document, the following definition is given:

34 \if@filesw
35 \immediate\openout\@mainaux\jobname.aux
36 \immediate\write\@mainaux{\relax}%
37 \fi

In plain English: the first line of the aux file begins with \relax.

For what purpose does the \relax serve?

  • I think this answer is close to what you are looking for : tex.stackexchange.com/a/285803/120578 – koleygr Oct 30 '17 at 9:39
  • 1
    My feeling is that it is done in order to catch as soon as possible an error about impossibility to write in the file. – egreg Oct 30 '17 at 10:02
  • 1
    @egreg Is that not already the purpose of \if@filesw? – Jonathan Komar Oct 30 '17 at 10:03
  • 1
    @JonathanKomar No, that's just controls inside of TeX if writing is enabled. The conditional returns false when \nofiles is issued and no writing to the auxiliary files is performed to begin with. I was referring to interaction with the operating system. – egreg Oct 30 '17 at 10:04
  • 1
    Later in the same file, uses the same method to define \include... I tried to remove that line and played around to find different behavior (with permissions and other things) but didn't found anything useful. Just adding the idea for more anyone experienced that may find something useful. – koleygr Oct 30 '17 at 11:11
16

LaTeX has always done that (and it's not really documented why) however I think it has two purposes.

  • As egreg mentioned in comments it means that if the operating system does not allow file writing at that point you get an error at the start of the document not at some unpredictable place later where latex needs the aux file.

  • By writing something you ensure that the file is never empty, even if there are no cross references in the document. This is useful for debugging (for example it means that you can detect a "first run" on the basis that there is no content in the aux file).

  • 2
    I think the second point is important, because if you use \openin on an empty file \ifeof is already true. So \IfFileExists{\jobname.aux}{true}{false} on an empty file would result in false. BTW: (Re)storing 0 byte files is sometimes problematic too (but this shouldn't be a problem for aux-files). – Schweinebacke Oct 30 '17 at 10:56

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.