1

For my lecture notes, I have a big tex file containing \include commands (one for each chapter).

Is there a way to typeset in one go :

  • the whole file: i.e. all the files appearing in the includeonly (below : chapter 2 and 3),
  • and on the other hand, create a separate pdf file for each file appearing in includeonly (here one pdf with just chapter 2, and one pdf with chapter 3).

MWE main file :

\documentclass{scrbook}

\includeonly{
%   file1,
    file2, 
    file3
    }

\begin{document}

\include{file1.tex}
\include{file2.tex}
\include{file3.tex}
\end{document}

file1.tex

\chapter{Chapter 1}

ABCDE

file2.tex

\chapter{Chapter 2}

ABCDE

file3.tex

\chapter{Chapter 3}

ABCDE
3
  • You might consider looking at the subfiles package, though even with it, to produce multiple PDFs, you'd need to run (pdf)(xe)latex multiple times, which is easy enough to do with a script (linux/mac) or batch file (windows).
    – frabjous
    Apr 4, 2022 at 18:44
  • Thanks for this suggestion, but after some tests I'm not sure that the chapter counter be consistent between files (pdf of file2.tex starts with chapter 1).
    – jowe_19
    Apr 4, 2022 at 19:39
  • 1
    In that case, you could consider making the big PDF and then use one of the many tools out there for splitting a PDF into subpdfs. (qpdf, ghostscript, pdftk, pdfjam, stapler, etc.) Probably scriptable.
    – frabjous
    Apr 4, 2022 at 20:06

1 Answer 1

1

As noted in the comment, to generate several pdfs you need to run latex as many times, but which can be automated. Here is an example for Linux'; it looks similar for the Windows shell.

pdflatex main # generate file1.aux, file2.aux, file3.aux
for n in 1 2 3; do # generate main1.pdf, main2.pdf, main3.pdf
   pdflatex "\includeonly{file$n}\input{main}"
   mv main.pdf "main$n.pdf"
done
pdflatex main # generate main.pdf
% main.tex
\documentclass{scrbook}
\usepackage{lipsum}
\begin{document}
\include{file1.tex}
\include{file2.tex}
\include{file3.tex}
\end{document}

% file1.tex
\chapter{One}\lipsum

% file2.tex
\chapter{Two}\lipsum

% file3.tex
\chapter{Three}\lipsum

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .