# Problem between auto-pst-pdf and \ifPDFTex

I would like to build a document which can compile with LaTex, pdfLaTeX or xeLateX.

But on the code below you can see that it doesn't compile with LaTeX : the trouble seems to come from the \ifPDFTeX because with the \ifpdf from the ifpdf package there is no problem. No problem with xelatex and pdflatex.

The trouble is with auto-pst-pdf and \ifPDFTeX

What's wrong ???

Thanks

\documentclass[a4paper,11pt]{article}

\usepackage{iftex}

\ifXeTeX
\usepackage[tuenc]{fontspec}
\usepackage{xunicode} %à charger après fontspec
\else
\usepackage[utf8]{inputenc} %pour linux
\usepackage[T1]{fontenc} %lettres accentuées %problème de flou en .pdf mais pas avec cm-super
\fi

%This does not work :
\ifXeTeX\else\ifPDFTeX\usepackage{auto-pst-pdf}\fi\fi

%This works :
%\usepackage{ifpdf}
%\ifXeTeX\else\ifpdf\usepackage{auto-pst-pdf}\fi\fi

\usepackage{pstricks-add}

\begin{document}

Essai

\begin{pspicture}(0,0)(4,4)
\psline(0,0)(4,4)
\end{pspicture}

\end{document}


And the log :

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode

<recently read> \fi

l.14 ...\else\ifPDFTeX\usepackage{auto-pst-pdf}\fi
\fi
! Extra \fi.
l.14 ...se\ifPDFTeX\usepackage{auto-pst-pdf}\fi\fi


EDIT 1 : new problem with this example :

When compiling with pdflatex, some material is putted on a second page and the word "essai" comes two times.

\documentclass[a4paper,11pt]{article}

\usepackage{iftex,ifpdf}

\ifXeTeX
\usepackage[tuenc]{fontspec}
\else
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\fi

%Some material put on a 2nde page  :
\ifpdf\usepackage{auto-pst-pdf}\fi

%Works normalty with this :
%\usepackage{auto-pst-pdf}

\usepackage{pstricks-add}

\begin{document}

Essai

\begin{pspicture}(0,0)(4,4)
\psline(0,0)(4,4)
\end{pspicture}

\end{document}


EDIT 2 : And same problem here when not using ifpdf :

\documentclass[a4paper,11pt]{article}

%without this no problem ...
\newif\ifpdf
\ifx\pdfoutput\undefined
\pdffalse % we are not running PDFLaTeX
\else
\pdfoutput=1 % we are running PDFLaTeX
\pdftrue
\fi
%%%%%%%%%%%%%

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

%\usepackage{auto-pst-pdf}
\usepackage{pst-pdf}

\usepackage{pstricks-add}

\begin{document}

Essai

\begin{pspicture}(0,0)(4,4)
\psline(0,0)(4,4)
\end{pspicture}

\end{document}

• \ifpdf tests the output mode, \ifPDFtex the engine, so the second is true for pdflatex and latex. – Ulrike Fischer Oct 17 '16 at 19:22
• unrelated but do you need xunicode? one of the benefits of the new tuenc support is that it greatly reduces the number of packages that get pulled in (xunicode being one of them) – David Carlisle Oct 17 '16 at 19:33
• @UlrikeFischer : Thank you. I understand now. Il will use ifpdf. But i have a new problem. I will edit the code above to post a example. – Oli Oct 18 '16 at 6:10
• @DavidCarlisle : I've copy/paste some code found to try xelatex ... and tuenc was give to me in another post (to use cm-unicode). I will try without xunicode. Another question : is the package "unicode-math" needed anymore with 'tuenc' or not ? – Oli Oct 18 '16 at 6:10
• @Oli Your definition of \ifpdf is wrong. What Ulrike suggested is \usepackage{ifpdf}, which provides the correct \ifpdf conditional. – egreg Oct 19 '16 at 17:20

## 2 Answers

This works for xelatex, pdflatex and latex

\documentclass[a4paper,11pt]{article}
\usepackage{iftex,ifpdf}

\ifXeTeX
\usepackage{fontspec}
\else
\ifpdf
\typeout{==== pdflatex ===}%
\usepackage{auto-pst-pdf}
\else
\usepackage{auto-pst-pdf}
\pagestyle{empty}
\fi
\usepackage[utf8]{inputenc} %pour linux
\usepackage[T1]{fontenc}
\fi
\usepackage{pstricks-add}
\begin{document}

Essai

\begin{pspicture}(0,0)(4,4)
\psline(0,0)(4,4)
\end{pspicture}

\end{document}

• Sorry for the late answer. It works with LaTeX and XeLaTeX but it doesn't work with PdfLaTeX. I've put all the files here : ovh.to/MkwJ3ac. Any ideas ? – Oli Oct 31 '16 at 10:47
• Links doesn't work. Here is the pdf output : cjoint.com/c/FJFk2U3HNc3 And the log : cjoint.com/c/FJFk3LsYhV3 – Oli Oct 31 '16 at 10:56
• The \pagestyle{empty} was missing, see edited answer – user2478 Oct 31 '16 at 18:44
• Thank's for your answer. But always a problem : the word 'essai' is printed two times. Pdf : cjoint.com/c/FJFtlz06FX3 Log : cjoint.com/c/FJFtl7xtiY3 – Oli Oct 31 '16 at 19:10
• Ah, I see. We also need for that case the auto-pst-pdf. See edited answer. – user2478 Oct 31 '16 at 19:13

I don't know why, but \usepackage{geometry} solves the problem. This example now works with LaTeX and pdfLaTeX too.

\documentclass[a4paper,11pt]{article}

\usepackage{ifpdf}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

%solution to the problem :
\usepackage{geometry}

%\ifpdf %not necessary with geometry
\usepackage{auto-pst-pdf}
%\fi

\usepackage{pstricks-add}

\begin{document}

Essai

\begin{pspicture}(0,0)(4,4)
\psline(0,0)(4,4)
\end{pspicture}

\end{document}

• It's because geometry loads ifpdf by itself and for some reason the error is not raised. But I wouldn't call this a solution. – egreg Oct 19 '16 at 17:30
• Yes but I loaded ifpdf too, and before geometry ... So "geometry" really do something else. – Oli Oct 19 '16 at 20:51