2

The example below was an accepted means for dealing with fonts, loading polyglossia versus babel, etc., before the 2016 changes to fontspec:

\usepackage{ifxetex}
\usepackage{ifluatex}
\ifxetex%                               uses fontspec
  \usepackage{fontspec}%                check package docs
  \defaultfontfeatures{Mapping=tex-text}
  \usepackage{xunicode}%                check if outmoded
  \usepackage{xltxtra}%                 check if outmoded
\else
  \ifluatex%                            also uses fontspec
    \usepackage{fontspec}%              check package docs
    \defaultfontfeatures{Ligatures=TeX}
  \else%                                traditional NFSS
    \usepackage[utf8]{inputenc}
    \usepackage[TS1,T1]{fontenc}
  \fi
\fi

So should one attempt to test for pre-2016 versions anymore? Should one just drop xunicode and xltxtra (given the fontspec doc reference to euenc)? Should {Ligatures=TeX} replace {Mapping=tex-text} since they are functionally equivalent?

My goal is to provide a generic framework for making a (relatively) engine-agnostic document. I may fold in language support into this example. I have other structures that test for xetex, pdftex, luatex in pdf or dvi mode, and regular tex dvi mode.

3
  • As an addendum, the minimal test for loading TikZ appears to be: \usepackage{ifxetex} \usepackage{ifpdf} \ifxetex \usepackage{tikz}\else \ifpdf\usepackage{tikz}\fi \fi Commented Mar 16, 2017 at 20:34
  • what??? why not simply \usepackage{tikz} why wrap it in tests? (it works with at least latex, pdflatex, xetex, luatex. what other engines are you testing for?) Commented Mar 16, 2017 at 21:17
  • I had the Windows-based dvi reader that comes with TeX Live totally crash when using tikz and dvi. In Ubuntu everything functions, albeit with unexpected results with my diagrams. Commented Mar 17, 2017 at 0:45

1 Answer 1

5

you haven't (for a long time, not just last year) needed to load xunicode, xltxtra,

or specify the tex mapping (which is the default since 2014) so all you need is

\ifx\Umathchardef\undefined
    \usepackage[utf8]{inputenc}
    \usepackage[TS1,T1]{fontenc}
\else
     \usepackage{fontspec}
\fi
4
  • Okay this is handy and upon testing, it works a treat. I have used the e-tex '\ifdefined\Umathchar ... \fi' before, but since some templates in certain popular TeX editors still load these other packages, I was confused as to the general state of affairs. This approach also works to choose babel or polyglossia. Commented Mar 16, 2017 at 20:16
  • This way also ensures better handling of traditional TeX ligatures, e.g., \'a, than the example in my question. Using that example will cause traditional ligatures not to work properly in some macros using, e.g., \uppercase. This solution fixes that issue. Commented Mar 16, 2017 at 22:36
  • @CharlesP.Schaum sorry I can't guess what you mean by that comment. \uppercase shouldn't be used in latex documents anyway (certainly not for uppercasing natural language text) \MakeTextUppercase is the latex command and works with \'{a} etc (which doesn't use the tex ligature mechanism) Commented Mar 16, 2017 at 22:39
  • Thanks for the tip. I was capping the first letter of an argument within a macro via \uppercase. When using what I posted, where the first letter was a tex ligature, it worked under latex and pdflatex, but not xelatex and lualatex. With your solution it works under all cases. But I will move to a latex-based solution. Commented Mar 17, 2017 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .