3

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}
Philippe
  • 139

1 Answers1

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!

Keks Dose
  • 30,892