1

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.

  • 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 – Charles P. Schaum Mar 16 '17 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?) – David Carlisle Mar 16 '17 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. – Charles P. Schaum Mar 17 '17 at 0:45
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
  • 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. – Charles P. Schaum Mar 16 '17 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. – Charles P. Schaum Mar 16 '17 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) – David Carlisle Mar 16 '17 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. – Charles P. Schaum Mar 17 '17 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.