6

I have a very long source file. I would like to prepare from this source two PDF files:

  1. PDF contains all of the source file

  2. PDF containing only a few, marked earlier parts of the source file.

How I should mark source file and how prepare main file in LateX, to achieve point 2?

Ama
  • 61

1 Answers1

3

In your long TeX input file (your source), use \ifsecret ... \fi to sandwich the secret parts that you want to either include or exclude. The common parts will always be included so don't sandwich them.

% filename.tex
\documentclass[preview,border=12pt]{standalone}
\newif\ifsecret
\begin{document}
common 1

\ifsecret
I have a top secret message here.
\fi

common 2
\end{document}

Make a batch file as follows.

pdflatex -jobname=secret-included "\AtBeginDocument{\secrettrue} \input{filename}"
pdflatex -jobname=secret-excluded "\AtBeginDocument{\secretfalse} \input{filename}"

The following simulates your problem.

% compile with pdflatex -shell-escape

\documentclass[preview,border=12pt]{standalone}
\usepackage{filecontents}

\begin{filecontents*}{filename.tex}
\documentclass[preview,border=12pt]{standalone}
\newif\ifsecret
\begin{document}
common 1

\ifsecret
I have a top secret message here.
\fi

common 2
\end{document}
\end{filecontents*}

\usepackage{graphicx}
\begin{document}
\immediate\write18{\unexpanded{pdflatex -jobname=secret-included "\AtBeginDocument{\secrettrue} \input{filename}"}}
\immediate\write18{\unexpanded{pdflatex -jobname=secret-excluded "\AtBeginDocument{\secretfalse} \input{filename}"}}
Done, secret-included.pdf and secret-excluded.pdf have been generated!

\fbox{\includegraphics[width=.5\linewidth]{secret-included}}%
\fbox{\includegraphics[width=.5\linewidth]{secret-excluded}}
\end{document}

enter image description here