6

Before an emerging of a Unicode-based XeLaTeX and LuaLaTeX there was pdfLaTeX which directly could output to a pdf-format. For the convenience of a typeset of mathematics, the amsmath package was mainly used.

But after emerging of the Unicode-based engines, there also appear such package like unicode-math (also, lualatex-math for fixing some troubles). And now there are questions and problems of how or in what order to use these packages, because sometimes we encounter conflicts between them (mainly with mathtools), as evidenced by numerous questions here in tex.se.

Aslo, for example, if one use lualatex, it is possible to use either amsmath or the unicode-math package, or both (it's not uncommon).

Compare Lualatex + amsmath:

% !TeX program = lualatex
% !TeX encoding = utf8

\documentclass[]{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
    I = \alpha\oint\limits_L f(x) dx, \quad \text{an Integral}
\end{equation}

\end{document}

OR Lualatex + unicode-math:

% !TeX program = lualatex
% !TeX encoding = utf8

\documentclass[]{article}
\usepackage{unicode-math}

\begin{document}

\begin{equation}
    I = \alpha\oint\limits_L f(x) dx, \quad \text{an Integral}
\end{equation}

\end{document}

Summarizing, is is needed an brief instructions on how and what order you need to call mathematical packages for use with Unicode-based XeLaTeX and LuaLaTeX engines.

2 Answers 2

4

As David Carlisle said, amsmath works with all font packages. It’s so ubiquitous, I’m not aware of any that are incompatible with it. Many newer packages want to modify how amsmath works, and amsmath does not deign to change itself for them, so it is very rare for any package to need to be loaded before amsmath. (Except document classes, which expect to come first.) I often load mathtools, which loads amsmath and adds some fixes and extensions, rather than amsmath.

The unicode-math package loads amsmath, but if you want to load amsmath with any options, or to load mathtools, load them before unicode-math.

Other math symbol packages are compatible with unicode-math, in the sense that they don’t cause errors, but unicode-math will override other symbols with the same name at the end of the preamble. Therefore, if you wanted to load unicode-math but change any individual symbol to its definition in some legacy package, you would need to copy and paste the relevant commands from the legacy package, wrapping the symbol definition in \AtBeginDocument.

If you want to use modern fonts for text and legacy (8-bit) fonts for math, load fontspec. Loading fontspec will change your fonts for \mathrm and a few other things, and if you load fontspec after amsmath, it will also change the fonts for a few more like \text and log-like operators. To turn this behavior off, give fontspec the option no-math. The unicode-math package loads fontspec, and can pass options to it. It is possible to load fontspec explicitly, and then unicode-math, if you need to resolve a clash between packages that load fontspec with different options.

You can load mathastext after setting up your text font (which can be 8-bit or modern) and your legacy math fonts. This will use the main font for letters in math mode, too. You can also set up unicode-math to do that, but it takes more effort.

Finally, you can use mathspec in XeTeX to load modern text fonts as math alphabets, along with legacy math fonts. This supports a few more use cases than fontspec and mathastext, such as using a modern font other than the main text font for math letters, or setting a sans-serif math alphabet.

8

unicode-math and and amsmath are not really related, the first is primarily about font setup and the latter is about defining macros for math layout structures and is more or less independent of the fonts used.

If typesetting mathematics using OpenType math fonts, it is recommended that you load both (load amsmath first). In fact the development version (v0.8p) loads amsmath automatically so just loading unicode-math will be enough in future.

For both lualatex and xelatex the default setup is to use OpenType fonts for text but classic 8bit tfm font metrics for type 1 fonts for math. For that setup it is recommended just to load amsmath.

4
  • @MarcelKrüger not the released version yet though, I'll add a note.... Jan 2, 2020 at 16:00
  • Is amsmath soon to be loaded automatically? Will that not break packages like nath?
    – Gaussler
    Jul 8, 2021 at 7:23
  • @Gaussler is nath incompatible with amsmath? why? Jul 8, 2021 at 7:26
  • Ah, I stand corrected. I seem to have gotten the wrong impression somehow. This is the second time in a row I get beaten by the English. ;-)
    – Gaussler
    Jul 8, 2021 at 7:49

You must log in to answer this question.

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