# Is there a common preamble for all TeX engines?

I know that there is the iftex package that allows you to do specific actions depending on whether the engine used is PDFLaTeX, XeLaTeX or LuaLaTeX.

I also know that LuaLaTex forbids using the inputenc package and requires fontspec. I do not know the forbidden and the prerequisites for others.

How to fulfill the conditions of the iftex package for these three engines with the packages: tikz, tcolorbox, babel, amsmath, amsfonts, amssymb and with the others ?

For example, how to fill the preamble of this ECM so that it is common to all LaTeX engines, or if this is impossible to maximum LaTeX engines?

Edit I am not asking the question for this document, but for every conceivable document. I put the ECM below because I know I'm going to be asked to put one, so I put the one there whose only use is to have a preamble.

\documentclass[11pt]{article}
\usepackage{iftex}
%\usepackage{tikz}
%\usepackage{amsmath, amsfonts, amssymb,mathrsfs}
%\usepackage[margin=1cm]{geometry}
%\usepackage[french]{babel}
%\ifLuaTeX
%\usepackage{fontspec}
%\else
%⟨material not for LuaT E X⟩
%\fi

%\ifXeTeX
%⟨material for XeT E X⟩
%\else
%⟨material not for XeT E X⟩
%\fi
%
%\ifPDFTeX
%⟨material for PDFT E X⟩
%\else
%⟨material not for PDFT E X⟩
%\fi

\begin{document}

Bien sûr, il s'agit d'écrire aussi avec des accents français et des formules mathématiques comme $2\times3^2=18$

Left of picture\begin{tikzpicture}
\draw[use as bounding box] (2,0) rectangle (3,1);
\draw (1,0) -- (4,.75);
\end{tikzpicture}right of picture

\end{document}

• Export some document to LaTeX with pandoc (with the -s option) and check the preamble of the output. – Fran Apr 28 '18 at 17:26
• your question is not at all clear your document only needs \usepackage{tikz} and would work with current pdflatex xelatex and lualatex – David Carlisle Apr 28 '18 at 17:29
• lualatex doesn't require spec (and doesn't forbid inputenc, it just ignores that) – David Carlisle Apr 28 '18 at 17:31
• @DavidCarlisle I am not asking the question for this document, but for every conceivable document. I put this ECM because I know I'm going to be asked to put one, so I put the one there whose only use is to have a preamble. – AndréC Apr 28 '18 at 17:51
• texdoc lshort on the command line. There might even be a recent introduction in your native language. – Johannes_B Apr 29 '18 at 5:25

The following document works without error in pdflatex, xelatex and lualatex:

\documentclass[11pt]{article}

\usepackage[french]{babel}
\usepackage{tikz}

\begin{document}

Bien sûr, il s'agit d'écrire aussi avec des accents français.

Left of picture\begin{tikzpicture}
\draw[use as bounding box] (2,0) rectangle (3,1);
\draw (1,0) -- (4,.75);
\end{tikzpicture}right of picture

\end{document}


If your latex is older than the 2018-04-01 release then you need to add:

\usepackage[utf8]{inputenc}


for pdftex, which generates a warning in lualatex and xelatex that it does nothing, but that was by design, so that you could use that form in portable documents.

Ideally for pdftex you would add:

\usepackage[T1]{fontenc}


rather than add an extra package just for testing I would tend to do:

\ifx\Umathchar\undefined
\usepackage[T1]{fontenc}
\fi


so that fontenc is not used in xetex and luatex, so final document is:

\documentclass[11pt]{article}

\usepackage[french]{babel}

\ifx\Umathchar\undefined
\usepackage[T1]{fontenc}
\fi

\usepackage{tikz}

\begin{document}

Bien sûr, il s'agit d'écrire aussi avec des accents français.

Left of picture\begin{tikzpicture}
\draw[use as bounding box] (2,0) rectangle (3,1);
\draw (1,0) -- (4,.75);
\end{tikzpicture}right of picture

\end{document}

• Questions : 1) We do not need anymore lmodern for pdflatex and fontspec for xe/lua ? 2) Is the order babel then fontenc important ? – Kpym Apr 28 '18 at 17:49
• @Kpym you never needed lmodern for pdflatex (of course, you have lots of choices of which font to use, and latin modern is one) you haven't needed fontspec in xe/lua since the release at the start of 2017 (or was it 2016, I forget:-) babel and fontenc can usually be loaded in either order, although some languages such as Greek expect fontenc first as they need special encodings – David Carlisle Apr 28 '18 at 18:04
• My question about lmodern was not clear : does pdflatex now use by default a non bitmap font ? This was not the case before, I think. – Kpym Apr 28 '18 at 19:34
• @Kpym classic tex never uses the font at all it just loads the font metrics (tfm) and pdftex only loads the actual fonts at the end while working as the driver effectively. so it uses bitmap fonts or not depending on the mappings set. The default distributions have used type1 (scalable) versions of the default computer modern fonts for at least 10 years, possibly longer – David Carlisle Apr 28 '18 at 19:38
• @AndréC yes (but not if you need to share the document with people using older installations) – David Carlisle Apr 29 '18 at 8:04