1

Often I have to create two documents with the same content but different layout: one version to print and another as a digital document. Therefore some small changes have to be made like other margins, page numbering, document settings from oneside --> twoside etc.

Up till now, I compile the document two times to get both the documents right. It would be much easier if I could just define two pagestyles (let's say print and display) and automatically run the compilation two times (one time with each pagestyle) so I get the two different pdf-files I need.

I have been reading some similar threads on this already, but couldn't make anything out of it. Could someone please help me out?

The code I use to define the layout for the printed document is:

\documentclass[10 pt, a4paper, twoside, openright]{book}
\usepackage{fancyhdr}
\usepackage{geometry}

\geometry{vmargin=2.5cm, inner=3cm, outer=2cm, headheight=11pt}             
\pagestyle{fancy}    
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[RE]{\small\nouppercase{\textbf{\textit{\leftmark}}}}
\fancyhead[LO]{\small\nouppercase{\textit{\rightmark}}}
\fancyfoot[LE,RO]{\thepage}

The display version uses this layout settings:

\documentclass[10 pt, a4paper, oneside, openany]{book}
\usepackage{fancyhdr}
\usepackage{geometry}

\geometry{margin=2.5cm, headheight=11pt}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[R]{\small\nouppercase{\textbf{\textit{\leftmark}}}}
\fancyfoot[R]{\thepage}
  • 1
    You cannot do that with LaTeX. But you can have a make file, or bat-file, that runs LaTeX multiple times with different flags. You would just have to push a button once. – Johannes_B May 15 '18 at 12:09
  • @Johannes_B See my answer! – Keks Dose May 15 '18 at 16:28
  • I think the closest concept is this one. But I don't get to make it work for my case... tex.stackexchange.com/questions/5228/… – Philippe May 15 '18 at 20:28
  • @Keks Just as I said, no single run. – Johannes_B May 16 '18 at 0:12
1

Use two different engines, pdfLaTeX and LuaLaTeX

Use two different engines, pdfLaTeX and LuaLaTeX, and the package ifluatex.

Untested code:

\documentclass...
all the packages you need for both variants.

\ifluatex
code for the digital version
\usepackage{fontenc}
\setmainfont...

\else
code for the printed version
\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}...

\fi
\begin{document}

So you just have to compile once, rename the PDF, change the engine, compile second time. Usually I even change the typeface between printed and digital version, because on screen some fonts are better to read than in the printed version.

Once in a while I even need three version, namely a simplified one for producing a html-document using tex4ht. The engine htlatex loads tex4ht and we can use that to make another fork:

\newif\ifhtlatex
\@ifpackageloaded{tex4ht}{%

Don't forget to rename the first PDF, but I'm quite sure, there is a way to automate that as well. Hope that helps!

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.