Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a batch file that will compile the same input file with 3 compilers one after another as shown below. This mechanism is used to see the file size of the resulting PDF (before and after compression) generated by each compiler.

rem ============= LaTeX =============
latex %1
dvips %1
ps2pdf %1.ps
rename %1.pdf %1-LaTeX.pdf
copy %1-LaTeX.pdf %1-LaTeX-Compressed.pdf
compress %1-LaTeX-Compressed.pdf
cleanup %1


rem ============= PdfLaTeX =============
pdflatex %1
rename %1.pdf %1-PdfLaTeX.pdf
copy %1-PdfLaTeX.pdf %1-PdfLaTeX-Compressed.pdf
compress %1-PdfLaTeX-Compressed.pdf
cleanup %1


rem ============= XeLaTeX =============
xelatex %1
rename %1.pdf %1-XeLaTeX.pdf
copy %1-XeLaTeX.pdf %1-XeLaTeX-Compressed.pdf
compress %1-XeLaTeX-Compressed.pdf
cleanup %1

The problem occurs when the input file cannot be compiled with a certain compiler. If the input file, for example, contains PSTricks code then the pdflatex must skip the compilation and just produces a PDF output with a warning message "Compilation has been interrupted.". Another example is that an input file imports PDF image that cannot be compiled with latex.

I need something like the followings:

Case 1

\documentclass{article}
\usepackage{ifxetex}

\ifxetex
  \begin{document}

    \end{document}
\fi

\iflatex
    \begin{document}

    \end{document}
\fi

\ifpdflatex
    \begin{document}

    \end{document}
\fi

Case 2

\documentclass{article}
\usepackage{ifxetex}

\iflatex
    \begin{document}

    \end{document}
\fi


\ifpdflatexorxelatex
    \begin{document}

    \end{document}
\fi

How to control the PDF output based on the compiler being used?

share|improve this question
    
Those parts should contain the "escape" text for blocking compilation in case a wrong compiler is used? –  egreg Mar 13 '12 at 16:45
    
@egreg: Yes. For example when compiling PSTricks code, the XeLaTeX and PDFLaTeX conditional block must produce a PDF output with a warning message. –  Who is crazy first Mar 13 '12 at 16:49

1 Answer 1

up vote 6 down vote accepted

First Case

A document containing PSTricks code that must be run either with latex+dvips+ps2pdf or xelatex but not with pdflatex:

\documentclass{article}

\newcommand{\INTERRUPT}{\shipout\hbox{Compilation interrupted}\stop}

\usepackage{etoolbox,ifpdf,ifxetex}
\ifboolexpr{ bool {pdf} } {\INTERRUPT} {}

\begin{document}

text

\end{document}

For only with pdflatex, swap the {} and {\INTERRUPT}.

Second Case

A document that must be compiled either with latex+dvips+ps2pdf or pdflatex, but not with xelatex:

\documentclass{article}

\newcommand{\INTERRUPT}{\shipout\hbox{Compilation interrupted}\stop}

\usepackage{etoolbox,ifxetex}
\ifboolexpr{ bool {xetex} } {\INTERRUPT} {}

\begin{document}

text

\end{document}

For only with xelatex, swap the {} and {\INTERRUPT}.

Third Case

A document that must be compiled either with pdflatex or xelatex, but not with latex+dvips+ps2pdf:

\documentclass{article}

\newcommand{\INTERRUPT}{\shipout\hbox{Compilation interrupted}\stop}

\usepackage{etoolbox,ifxetex}
\ifboolexpr{ bool {pdf} or bool {xetex} } {} {\INTERRUPT}

\begin{document}

text

\end{document}

For only with latex+dvips+ps2pdf, swap the {} and {\INTERRUPT}.

When the compiler doesn't pass the test, the low level \shipout operation will produce a PDF (or DVI) and \stop will end the run.

share|improve this answer
1  
@DamienWalters There are more if you consider also luatex. :) But with the powerful boolean expression manager of etoolbox it's just playing with the operators not, and and or. –  egreg Mar 13 '12 at 17:39
    
Of course. By the way, is it possible to enclose document environment in \ifboolexpr? –  Who is crazy first Mar 13 '12 at 17:42
    
@DamienWalters I wouldn't use it, but it's possible; after all you want only a valid file for later processing. One might think to improve \INTERRUPT to show the reason for the failure. Is it worth the trouble? –  egreg Mar 13 '12 at 17:46
    
What's the problem with any engine? auto-pst-pdf exists. –  Martin Schröder Mar 14 '12 at 17:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.