1

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}
AndréC
  • 24,137
  • 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
  • @AndréC well starting from the version of your document that I put in my answer, it works in pdftex,luatex,xetex, if your real document needs colour you need to add \usepackage{color} and it will again work in all three. If you need to use \directlua then it only works in luatex. What other answer can be given? – David Carlisle Apr 28 '18 at 18:00
  • how can you have a preamble for "every conceivable document" ? you just need the packages that are used in a specific document. – David Carlisle Apr 28 '18 at 18:06
  • @DavidCarlisle For example, it would be nice to make a kind of Wiki where everyone could complete the preamble of an imaginary document when he knows that one package is forbidden or that another is mandatory. – AndréC Apr 28 '18 at 18:07
  • honestly I can not guess what you mean. the minimal preamble is empty \documentclass{article}\begin{document} hello world\end{document} works correctly in all three engines. i only needed to add babel, tikz and fontenc because your example document used French and tikz. – David Carlisle Apr 28 '18 at 18:09
  • @DavidCarlisle I'm sorry to misspoke, I use an automatic translator. https://www.deepl.com/translator My question is to create a preamble that works with the maximum number of CTAN packages and the maximum number of LaTeX engines. And thus to complete the preamble when an incompatibility is known between a package and a LaTeX engine. – AndréC Apr 28 '18 at 18:14
  • that is not feasible, there are literally thousands of packages on ctan so a preamble that worked with the maximum number of a packages would require literally thousands of \usepackage{zzz} just in case the document used a command from that package????? – David Carlisle Apr 28 '18 at 18:16
  • @DavidCarlisle Ok, precisely, as this is materially impossible, would it be possible to answer this question little by little as we get to know each other? For example, by allowing users to modify the preamble of the imaginary document of the question according to their knowledge of the packages and engines they use. – AndréC Apr 28 '18 at 18:22
  • there is nothing that can be said in general, you just need to add packages that define the commands that are used in the document, what else can be said? If someone wants to add \usepackage{lmodern} to get latin modern and someone else wants to add \usepackage{times} to get times, then you have to decide who wins but that is a social not a technical question and unrelated to "working in all tex engines" which is the title of your question. – David Carlisle Apr 28 '18 at 18:30
  • André, it seems you are a beginner and have misunderstood how LaTeX works. You should read an introduction before thinking about different engines. Yes, packages can interact, but there is no general rule of thumb in which way. If you are using a template that confuses you, get rid of it. – Johannes_B Apr 29 '18 at 05:16
  • @Johannes_B I have read a lot of documentation about LaTeX and TeX and it is true that I have translation difficulties. I use an automatic translator deepl.com/translator . I find that the LaTeX system is complicated and according to the documents, there is sometimes contradictory or obsolete information. So, today, which document would you advise me to read? – AndréC Apr 29 '18 at 05:23
  • 1
    texdoc lshort on the command line. There might even be a recent introduction in your native language. – Johannes_B Apr 29 '18 at 05:25

1 Answers1

4

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}
quark67
  • 4,166
David Carlisle
  • 757,742
  • 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
  • How about \ifdefined\Umathcar...\fi? I don't think anybody uses non-eTeX engines these days. – Henri Menke Apr 29 '18 at 01:07
  • @DavidCarlisle I use MikTeX and updated it yesterday. Can I delete the inputenc call now? – AndréC Apr 29 '18 at 05:13
  • Interesting premise. I shall do some testing. – thymaro Apr 29 '18 at 05:35
  • 1
    @AndréC yes (but not if you need to share the document with people using older installations) – David Carlisle Apr 29 '18 at 08:04
  • @HenriMenke yes that's a matter of the internal wiring in my brain, not the reality of which engines people have access to. – David Carlisle Apr 29 '18 at 08:05