GeneralDouble/partial compilation, create two files at once

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
guigui
Posts: 3
Joined: Tue May 06, 2014 4:40 pm

Double/partial compilation, create two files at once

Post by guigui »

Hello all,

Here is how my so complicated document looks like :

Code: Select all

\documentclass[a4paper,11pt]{article}

\begin{document}

Long part I

Long part II

\end{document}
I would like to "double/partial" compile this document such that :

- be created a .dvi or .pdf file that contains only part I.
- be created another .dvi or .pdf file that contains both part I and II.
- this process is fast, cause I will compile several times.

Anyone has any idea how to manage that ?
I precise that I use Kile on Linux, which lets me set up custom terminal-like compile commands.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Double/partial compilation, create two files at once

Post by kaiserkarl13 »

Here's one way: put each part in a different file, then include, then use \includeonly to limit it to one. Here's a shell script that does it:

Code: Select all

#! /bin/sh

runBibTeX=true
outfile=`mktemp LongPartI_XXXXXXXX`
sed 's/\(\\begin{document}\)/\\includeonly{guiguiLongPartI}\1/' guigui.tex > \
    $outfile
pdflatex $outfile
$runBibTeX && bibtex $outfile
pdflatex $outfile
$runBibTeX && pdflatex $outfile
mv ${outfile}.pdf LongPartI.pdf
rm ${outfile}*

pdflatex guigui.tex
$runBibTeX && bibtex guigui.aux
pdflatex guigui.tex
$runBibTeX && pdflatex guigui.tex
Here's the file guigui.tex:

Code: Select all

\documentclass[a4paper,11pt]{article}
\begin{document}
\include{guiguiLongPartI}
\include{guiguiLongPartII}
\end{document}
guigui
Posts: 3
Joined: Tue May 06, 2014 4:40 pm

Re: Double/partial compilation, create two files at once

Post by guigui »

Thanks for your help kaiserkarl13.

This works pretty well, even though I dont understand everything !

Now isn't there a way not to use \include ? I'd like to avoid having to put my part I and II in different files, it screws up my organization.
Something like telling latex to compile :
1) only one part of the file, delimited by labels or such.
2) the whole file


If this is not possible, let me ask how to modify the .sh file if I want to :
- totally remove bibtex from it, I'll never have any biblio.
- compile via latex->dvips->pspdf
- have the two created filenames be as follows, considering that the main .tex document is docname.tex :
* file that contains only part I is docname_partI.pdf
* file that contains both parts is docname.pdf

Again, thanks for any help.
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Double/partial compilation, create two files at once

Post by kaiserkarl13 »

You could try using the ifthen package, and then using sed in the shell script to change your variable from true to false in the temporary file.
If this is not possible, let me ask how to modify the .sh file if I want to :
- totally remove bibtex from it, I'll never have any biblio.
- compile via latex->dvips->pspdf
- have the two created filenames be as follows, considering that the main .tex document is docname.tex :
* file that contains only part I is docname_partI.pdf
* file that contains both parts is docname.pdf
To remove BibTeX processing, change the "true" to "false" and it should avoid BibTeX. To use latex->dvips->ps2pdf (the last is what I assume you meant?), change it as follows (also answers third part):

Code: Select all

#! /bin/sh

runBibTeX=false
outfile=`mktemp LongPartI_XXXXXXXX`
sed 's/\(\\begin{document}\)/\\includeonly{guiguiLongPartI}\1/' docname.tex > \
    $outfile
latex $outfile
$runBibTeX && bibtex $outfile
latex $outfile
$runBibTeX && latex $outfile
dvips $outfile
ps2pdf $outfile docname_PartI.pdf
rm ${outfile}*

latex docname.tex
$runBibTeX && bibtex docname.aux
latex docname.tex
$runBibTeX && latex docname.tex
dvips docname
ps2pdf docname.ps docname.pdf
guigui
Posts: 3
Joined: Tue May 06, 2014 4:40 pm

Re: Double/partial compilation, create two files at once

Post by guigui »

Thanks a lot Karl,

That new .sh file works like a charm. I'll also dig the ifthen part.
Post Reply