5

What would be the correct way to execute commands conditionally in LaTeX?

Here is the problem I am having. I have a book_pdf.tex where I wish to define the style of the book as it would look in a PDF. Then I have book_epub.tex where I wish to define the style of the book as it would look in an EPUB format.

Then I also have chapter1.tex, chapter2.tex, etc. In each of these chapters I have to do micro adjustments for each format. So I am thinking that I need to define a variable in either ebook_pdf.tex (something like var pdf = true in pseudosyntax), and then in chapter1.tex, I want to check if it's the pdf template that is used (something like if pdf then insert \newline). Or if it's the epub format, then I want to define epub variable and do stuff like if epub then \begin{lstlistings}[basicstyle=\smaller] else insert \begin{lstlistings}[basicstyle=\small].

Any ideas how to accomplish this?

1 Answers1

5

Define your own document class with an optional argument, eg for myClass.cls:

\newif\ifEPUB\EPUBfalse
\DeclareOption{EPUB}{\EPUBtrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions\relax
\LoadClass{book}
\RequirePackage{...}
...

in your document you can use:

\documentclass[EPUB,11pt,a4paper,...]{myClass}
\usepackage{...}
...
\begin{document}
...
\ifEPUB
  ...
\else
  ...
\fi
...
\end{document}