1

I write course material for my students. Every chapter is in a different file. Some chapters are used in several classes, but in a different order. Say:

  • ClassA.tex

    • including chapter-foo.tex as chapter 1
    • including chapter-bar.tex as chapter 2
    • including chapter-xyz.tex as chapter 3
  • ClassB.tex

    • including chapter-abc.tex as chapter 1
    • including chapter-foo.tex as chapter 2
    • including chapter-bar.tex as chapter 3

Now, whenever I compile ClassA.tex or ClassB.tex, three AUX files are generated and all is fine. However, if I add a fourth chapter to class A's document and -- in order to save time -- use \includeonly so that the first three chapters can be skipped during compilation, this will get me wrong cross-references, if the last complete run has been done with ClassB.tex.

I am looking for a way to add some prefix to the AUX file's names, e.g. compiling chapter-foo.tex from ClassA.tex would use (and create, if necessary) a-chapter-foo.aux, wheres compiling it from ClassB.tex would use b-chapter-foo.aux.

  • I don't know of any package offering this and one would imho have to change quite a number of internal commands (and e.g. check side-effects on bibtex). What you could do is to use an intermediary layer: a b-chapter-foo.tex which contains only the line \input{chapter-foo}. – Ulrike Fischer Aug 11 '17 at 8:43
  • Indeed, a very simple way of achieving exactly what I want. Thank you very much. If you make it an answer, I'll accept. – Philipp Imhof Aug 11 '17 at 8:53
3

The name of the auxiliary files of files included by \ínclude are used in the internal command \@include only. Patching the two occurrences of #1.aux solves the issue. The following patch prefixes #1.aux with the job name of the main document \jobname. It belongs to the preamble of the main files (ClassA.tex and ClassB.tex).

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@include}{\@input{#1.aux}}{\@input{\jobname-#1.aux}}{}{%
  \errmessage{First patch of \noexpand\@include failed.}%
}
\patchcmd{\@include}{\@partaux #1.aux}{\@partaux\jobname-#1.aux}{}{%
  \errmessage{Second patch of \noexpand\@include failed.}%
}
\makeatother

Then, the auxiliary files for chapter-???.tex are no longer chapter-???.tex but Class?-chapter-???.tex (the single question mark is A or B and the question mark triple is abc, bar, foo, or xyz).

2

I don't know of any package offering this and one would imho have to change quite a number of internal commands (and e.g. check side-effects on bibtex) to get it.

What you could do is to use an intermediary layer: create a b-chapter-foo.tex which contains only the line \input{chapter-foo}.

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.