How to run some commands for XeLaTeX only?
To call some commands when running xelatex on a file, I use an old trick that was quite useful when I wanted to run commands for pdflatex, and not for plain latex: I check that a given primitive is present or not, and if it is, do XeLaTeX stuff, else just do normal things:
\newif\ifxelatex \ifx\XeTeXglyph\undefined \xelatexfalse \else \xelatextrue \fi % You can now use \ifxelatex to execute XeLaTeX-specific stuff \ifxelatex \usepackage[french]{polyglossia} \usepackage{xltxtra} \setmainfont[Mapping=tex-text]{Times New Roman} \else \usepackage{babel} \usepackage[utf8]{inputenc} \usepackage{times} \usepackage[T1]{fontenc} \fi
The trick here is the check whether the \XeTeXglyph
primitive is present; if it is, the file is being XeLaTeX’ed, otherwise it’s probably PDFLaTeX’ed, or even LaTeX’ed, or whatever. The same can be achieved by importing the ifxetex
package, which provides a ifxetex
command.
Strangely enough, when defining french
as a documentclass
option, it doesn’t automatically get passed to polyglossia
, as I’d expect it, as it does for PDFLaTeX – almost made me believe for a while that polyglossia was broken for the French language, when it was just not getting the option.