When is the aux file read and written? The 2019 Stack Overflow Developer Survey Results Are...

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Difference between "generating set" and free product?

Python - Fishing Simulator

Did God make two great lights or did He make the great light two?

Format single node in tikzcd

First use of “packing” as in carrying a gun

How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time

What are these Gizmos at Izaña Atmospheric Research Center in Spain?

How can I define good in a religion that claims no moral authority?

Windows 10: How to Lock (not sleep) laptop on lid close?

Can smartphones with the same camera sensor have different image quality?

University's motivation for having tenure-track positions

How is simplicity better than precision and clarity in prose?

What information about me do stores get via my credit card?

Why is Captain Marvel translated as male in Portugal?

Was credit for the black hole image misattributed?

Does Parliament hold absolute power in the UK?

How to stretch delimiters to envolve matrices inside of a kbordermatrix?

Wall plug outlet change

What aspect of planet Earth must be changed to prevent the industrial revolution?

"... to apply for a visa" or "... and applied for a visa"?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Movie about afterlife I think? Large towers with clothing and food?

How to pronounce 1ターン?



When is the aux file read and written?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How and when is the “aux” file read and processed?Purpose of AtEndDocument{def}calc-package prevents headheight to changeHow do I run bibtex after using the -output-directory flag with pdflatex, when files are included from subdirectories?Read in number of citations from aux fileExecute command stored in aux fileWrite information on aux file when using include to build documentHow to put value{counter} as value to .aux file?Unclean .aux file causes “file ended while scanning use of @newl@bel” error. Why is it not purged?Evaluate pgfkey before reading and writing to file with newfileHow and when is the “aux” file read and processed?Write and read a renamed (or modified) “.aux” fileDefine global commands in aux file












25
















  1. I'd like to know when the aux file is read. I know it happens after the preamble, but does it come before or after the AtBeginDocument hook?



  2. I'd like to know when the aux file (or any other helper file) is actually written. I tried to trace the writing process by placing an undefined command after something should have been written to the aux file, and run pdflatex in interactive mode, like so:



    documentclass{article}
    begin{document}
    section{S}label{s}% write something to the aux file

    foo% unknown command
    end{document}


    but to my surprise the aux file is still empty when pdflatex stops at the error. I guess there is some buffering happening, but how would I resolve the synchronization issue? Say, when foo is command that wants to read from the aux file?












share|improve this question



























    25
















    1. I'd like to know when the aux file is read. I know it happens after the preamble, but does it come before or after the AtBeginDocument hook?



    2. I'd like to know when the aux file (or any other helper file) is actually written. I tried to trace the writing process by placing an undefined command after something should have been written to the aux file, and run pdflatex in interactive mode, like so:



      documentclass{article}
      begin{document}
      section{S}label{s}% write something to the aux file

      foo% unknown command
      end{document}


      but to my surprise the aux file is still empty when pdflatex stops at the error. I guess there is some buffering happening, but how would I resolve the synchronization issue? Say, when foo is command that wants to read from the aux file?












    share|improve this question

























      25












      25








      25


      4







      1. I'd like to know when the aux file is read. I know it happens after the preamble, but does it come before or after the AtBeginDocument hook?



      2. I'd like to know when the aux file (or any other helper file) is actually written. I tried to trace the writing process by placing an undefined command after something should have been written to the aux file, and run pdflatex in interactive mode, like so:



        documentclass{article}
        begin{document}
        section{S}label{s}% write something to the aux file

        foo% unknown command
        end{document}


        but to my surprise the aux file is still empty when pdflatex stops at the error. I guess there is some buffering happening, but how would I resolve the synchronization issue? Say, when foo is command that wants to read from the aux file?












      share|improve this question















      1. I'd like to know when the aux file is read. I know it happens after the preamble, but does it come before or after the AtBeginDocument hook?



      2. I'd like to know when the aux file (or any other helper file) is actually written. I tried to trace the writing process by placing an undefined command after something should have been written to the aux file, and run pdflatex in interactive mode, like so:



        documentclass{article}
        begin{document}
        section{S}label{s}% write something to the aux file

        foo% unknown command
        end{document}


        but to my surprise the aux file is still empty when pdflatex stops at the error. I guess there is some buffering happening, but how would I resolve the synchronization issue? Say, when foo is command that wants to read from the aux file?









      auxiliary-files






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 25 '13 at 9:27









      mafpmafp

      14.6k252100




      14.6k252100






















          1 Answer
          1






          active

          oldest

          votes


















          23














          The .aux file is read as part of the document macro (begin{document}) but before the AtBeginDocument hook is used. (You can check this by inserting some 'test code' into the .aux file and the hook.)



          Writing to the .aux file takes place both 'immediately' and at shipout. The latter is important to get for example the correct page numbers for cross-references, so things like label take place in a delayed fashion, using the protected@write 'wrapper' around the write primitive. Thus for example



          documentclass{article}

          begin{document}
          makeatletter
          immediatewrite@auxout{noexpandfoo}
          protected@write@auxout{}{noexpandbaz}

          end{document}


          only places foo in the .aux file: baz is never written as there is no page shipout. In your example, shipout occurs after foo, so you see nothing in the .aux file at that point although a shipout does occur later.



          Note that TeX keeps the .aux file open until the end of the run, so you cannot be sure that any particular write will appear in the partial .aux file during a run. As such, the only safe time to check on what gets written to the file is after the run completes. In particular, badly-terminated jobs may leave the .aux file in an incomplete state even if the crash occurs after writes 'should' have taken place.






          share|improve this answer


























          • Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

            – mafp
            Jun 25 '13 at 10:30






          • 2





            Because the file is still open for writing. It is closed only at end{document}

            – Ulrike Fischer
            Jun 25 '13 at 10:38






          • 2





            @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

            – Ulrike Fischer
            Jun 25 '13 at 11:26






          • 1





            @frougon I'e made the edit: sorry about the missing argument

            – Joseph Wright
            12 mins ago






          • 1





            @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

            – Joseph Wright
            9 mins ago












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f120973%2fwhen-is-the-aux-file-read-and-written%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          23














          The .aux file is read as part of the document macro (begin{document}) but before the AtBeginDocument hook is used. (You can check this by inserting some 'test code' into the .aux file and the hook.)



          Writing to the .aux file takes place both 'immediately' and at shipout. The latter is important to get for example the correct page numbers for cross-references, so things like label take place in a delayed fashion, using the protected@write 'wrapper' around the write primitive. Thus for example



          documentclass{article}

          begin{document}
          makeatletter
          immediatewrite@auxout{noexpandfoo}
          protected@write@auxout{}{noexpandbaz}

          end{document}


          only places foo in the .aux file: baz is never written as there is no page shipout. In your example, shipout occurs after foo, so you see nothing in the .aux file at that point although a shipout does occur later.



          Note that TeX keeps the .aux file open until the end of the run, so you cannot be sure that any particular write will appear in the partial .aux file during a run. As such, the only safe time to check on what gets written to the file is after the run completes. In particular, badly-terminated jobs may leave the .aux file in an incomplete state even if the crash occurs after writes 'should' have taken place.






          share|improve this answer


























          • Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

            – mafp
            Jun 25 '13 at 10:30






          • 2





            Because the file is still open for writing. It is closed only at end{document}

            – Ulrike Fischer
            Jun 25 '13 at 10:38






          • 2





            @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

            – Ulrike Fischer
            Jun 25 '13 at 11:26






          • 1





            @frougon I'e made the edit: sorry about the missing argument

            – Joseph Wright
            12 mins ago






          • 1





            @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

            – Joseph Wright
            9 mins ago
















          23














          The .aux file is read as part of the document macro (begin{document}) but before the AtBeginDocument hook is used. (You can check this by inserting some 'test code' into the .aux file and the hook.)



          Writing to the .aux file takes place both 'immediately' and at shipout. The latter is important to get for example the correct page numbers for cross-references, so things like label take place in a delayed fashion, using the protected@write 'wrapper' around the write primitive. Thus for example



          documentclass{article}

          begin{document}
          makeatletter
          immediatewrite@auxout{noexpandfoo}
          protected@write@auxout{}{noexpandbaz}

          end{document}


          only places foo in the .aux file: baz is never written as there is no page shipout. In your example, shipout occurs after foo, so you see nothing in the .aux file at that point although a shipout does occur later.



          Note that TeX keeps the .aux file open until the end of the run, so you cannot be sure that any particular write will appear in the partial .aux file during a run. As such, the only safe time to check on what gets written to the file is after the run completes. In particular, badly-terminated jobs may leave the .aux file in an incomplete state even if the crash occurs after writes 'should' have taken place.






          share|improve this answer


























          • Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

            – mafp
            Jun 25 '13 at 10:30






          • 2





            Because the file is still open for writing. It is closed only at end{document}

            – Ulrike Fischer
            Jun 25 '13 at 10:38






          • 2





            @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

            – Ulrike Fischer
            Jun 25 '13 at 11:26






          • 1





            @frougon I'e made the edit: sorry about the missing argument

            – Joseph Wright
            12 mins ago






          • 1





            @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

            – Joseph Wright
            9 mins ago














          23












          23








          23







          The .aux file is read as part of the document macro (begin{document}) but before the AtBeginDocument hook is used. (You can check this by inserting some 'test code' into the .aux file and the hook.)



          Writing to the .aux file takes place both 'immediately' and at shipout. The latter is important to get for example the correct page numbers for cross-references, so things like label take place in a delayed fashion, using the protected@write 'wrapper' around the write primitive. Thus for example



          documentclass{article}

          begin{document}
          makeatletter
          immediatewrite@auxout{noexpandfoo}
          protected@write@auxout{}{noexpandbaz}

          end{document}


          only places foo in the .aux file: baz is never written as there is no page shipout. In your example, shipout occurs after foo, so you see nothing in the .aux file at that point although a shipout does occur later.



          Note that TeX keeps the .aux file open until the end of the run, so you cannot be sure that any particular write will appear in the partial .aux file during a run. As such, the only safe time to check on what gets written to the file is after the run completes. In particular, badly-terminated jobs may leave the .aux file in an incomplete state even if the crash occurs after writes 'should' have taken place.






          share|improve this answer















          The .aux file is read as part of the document macro (begin{document}) but before the AtBeginDocument hook is used. (You can check this by inserting some 'test code' into the .aux file and the hook.)



          Writing to the .aux file takes place both 'immediately' and at shipout. The latter is important to get for example the correct page numbers for cross-references, so things like label take place in a delayed fashion, using the protected@write 'wrapper' around the write primitive. Thus for example



          documentclass{article}

          begin{document}
          makeatletter
          immediatewrite@auxout{noexpandfoo}
          protected@write@auxout{}{noexpandbaz}

          end{document}


          only places foo in the .aux file: baz is never written as there is no page shipout. In your example, shipout occurs after foo, so you see nothing in the .aux file at that point although a shipout does occur later.



          Note that TeX keeps the .aux file open until the end of the run, so you cannot be sure that any particular write will appear in the partial .aux file during a run. As such, the only safe time to check on what gets written to the file is after the run completes. In particular, badly-terminated jobs may leave the .aux file in an incomplete state even if the crash occurs after writes 'should' have taken place.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 12 mins ago

























          answered Jun 25 '13 at 10:07









          Joseph WrightJoseph Wright

          206k23564892




          206k23564892













          • Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

            – mafp
            Jun 25 '13 at 10:30






          • 2





            Because the file is still open for writing. It is closed only at end{document}

            – Ulrike Fischer
            Jun 25 '13 at 10:38






          • 2





            @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

            – Ulrike Fischer
            Jun 25 '13 at 11:26






          • 1





            @frougon I'e made the edit: sorry about the missing argument

            – Joseph Wright
            12 mins ago






          • 1





            @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

            – Joseph Wright
            9 mins ago



















          • Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

            – mafp
            Jun 25 '13 at 10:30






          • 2





            Because the file is still open for writing. It is closed only at end{document}

            – Ulrike Fischer
            Jun 25 '13 at 10:38






          • 2





            @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

            – Ulrike Fischer
            Jun 25 '13 at 11:26






          • 1





            @frougon I'e made the edit: sorry about the missing argument

            – Joseph Wright
            12 mins ago






          • 1





            @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

            – Joseph Wright
            9 mins ago

















          Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

          – mafp
          Jun 25 '13 at 10:30





          Thanks. But even when I do a clearpage after the label, and pdflatex tells me it shipped out the first page before running into the error, I still don't see anything in the aux file. Why?

          – mafp
          Jun 25 '13 at 10:30




          2




          2





          Because the file is still open for writing. It is closed only at end{document}

          – Ulrike Fischer
          Jun 25 '13 at 10:38





          Because the file is still open for writing. It is closed only at end{document}

          – Ulrike Fischer
          Jun 25 '13 at 10:38




          2




          2





          @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

          – Ulrike Fischer
          Jun 25 '13 at 11:26





          @Daniel: The problem bothering @mafp has imho nothing to do with asynchronously output. The file is still open and so its content - even if it belongs to previous pages lurks still around in memory and you don't see it if you open the file. If one would add makeatletterimmediatecloseout@mainaux before the error it would appear.

          – Ulrike Fischer
          Jun 25 '13 at 11:26




          1




          1





          @frougon I'e made the edit: sorry about the missing argument

          – Joseph Wright
          12 mins ago





          @frougon I'e made the edit: sorry about the missing argument

          – Joseph Wright
          12 mins ago




          1




          1





          @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

          – Joseph Wright
          9 mins ago





          @frougon I've kept both arguments as noexpand as the idea is to show as little difference as possible

          – Joseph Wright
          9 mins ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f120973%2fwhen-is-the-aux-file-read-and-written%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Why does my Macbook overheat and use so much CPU and energy when on YouTube?Why do so many insist on using...

          How to prevent page numbers from appearing on glossaries?How to remove a dot and a page number in the...

          Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...