Tx · LaTeX & TikZ

How to Fix “Extended mathchar used as mathchar” with mathastext

Published By the 9to5Science editorial team

At a glance

  1. 1. Check math packages

    Look for unicode-math and other packages that change math fonts or symbols alongside mathastext.

  2. 2. Choose one setup

    Use mathastext with traditional math fonts, or use unicode-math for Unicode math fonts; avoid loading both together.

  3. 3. Test a small file

    Compile a minimal document with the same engine, then add packages and font settings back one at a time.

  4. 4. Inspect the log

    Find the first error and the command or package named nearby; later errors may only be consequences.

The XeTeX message “Extended mathchar used as mathchar” is a math-font compatibility error, not usually a spelling mistake in your source. It means that a command or package is handling an extended math character as though it were a traditional TeX math character.

A frequent cause is loading mathastext together with unicode-math, or combining either package with another package that redefines math symbols. These packages control how math characters and fonts are set up, and their assumptions may not fit together. The exact cause depends on the preamble and the first error in the log.

What the message means

Traditional TeX math fonts use a compact math-character representation. XeTeX also supports extended math characters, which can represent Unicode math symbols. The error appears when TeX is asked to use an extended character in a context that expects the traditional form.

mathastext adapts text fonts for use in mathematics in a traditional math setup. unicode-math provides Unicode math-font support and changes how math characters are handled. Since both affect math setup, loading them together is a likely source of conflict. Other math-font or symbol packages can also contribute.

Choose one math-font approach

If you want Unicode math fonts, use unicode-math and do not load mathastext in the same document. This complete example is intended for XeLaTeX:

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\begin{document}
Text in the document, and mathematics: $\alpha + \beta = \gamma$.
\end{document}

fontspec supports system text fonts under XeLaTeX; unicode-math sets up Unicode mathematics. The example uses Latin Modern Math, which is commonly available with TeX distributions. Compile it with XeLaTeX, not pdfLaTeX.

If you specifically need mathastext, use a traditional math setup and remove unicode-math. Start with a small test such as:

\documentclass{article}
\usepackage{mathastext}

\begin{document}
Text and mathematics: $a+b=c$.
\end{document}

Compile this with the same engine as your full document. If it works, add your other packages, font selections, and math declarations back gradually. If it fails even by itself, check that your installed mathastext version supports your TeX engine and consult its package documentation; an outdated installation or a different package interaction may be involved.

Find the conflicting command

  1. Check the preamble. Search for unicode-math, mathastext, and packages that change math fonts, symbols, or alphabets. Remove redundant math-font setup first.
  2. Read the first error. In the .log file, start with the earliest occurrence of the message. Later errors can be knock-on effects.
  3. Reduce the document. Keep the document class and the smallest set of packages that still produces the error. Add removed packages back one at a time.
  4. Check the engine and package versions. Make sure the editor is actually running XeLaTeX and that the relevant packages are up to date. A different engine or stale package installation can make an apparently identical preamble behave differently.

A useful diagnostic is to temporarily comment out mathastext. If the error disappears, the package combination or a command it affects is implicated. That test does not prove mathastext is defective: another package may be supplying the incompatible math character.

Common mistakes

  • Loading both math-font systems. Do not assume that because each package works on its own, they can be combined. Choose the system that matches your document’s font needs.
  • Changing several things at once. Removing multiple packages or changing engines together makes it harder to learn which change fixed the error.
  • Treating every log line as a separate problem. Fix the first error, compile again, and then assess what remains.
  • Using a text-font command as a math-font command. XeLaTeX’s text-font support does not by itself set up Unicode mathematics. Use the math-font package and commands appropriate to the approach you choose.

If a minimal mathastext file works but the full file does not, the relevant problem is usually an interaction in the full preamble. Preserve the first failing version and add components back individually; that will narrow the cause much faster than changing the document’s math expressions at random.

References

  1. The mathastext package documentation
  2. The unicode-math package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.