Why Does Unicode-math And Mathastext Interact Badly?
Introduction
When working with mathematical equations in LaTeX, two popular packages are often used: unicode-math
and mathastext
. While both packages are designed to improve the typesetting of mathematical expressions, they can sometimes interact badly with each other. In this article, we will explore the reasons behind this interaction and provide some solutions to mitigate the issues.
What is unicode-math?
unicode-math
is a package that allows users to typeset mathematical expressions using Unicode characters. It provides a wide range of mathematical fonts, including STIX, Asana Math, and TeX Gyre Termes Math. The package also supports various mathematical operators, such as integrals, derivatives, and summations.
What is mathastext?
mathastext
is a package that allows users to typeset mathematical expressions using the same font as the surrounding text. This means that mathematical expressions are typeset in the same font as the rest of the document, rather than using a separate mathematical font. The package also provides some additional features, such as the ability to typeset mathematical expressions in a sans-serif font.
The Problem
When unicode-math
and mathastext
are used together, they can interact badly. The problem arises because unicode-math
is designed to work with mathematical fonts, while mathastext
is designed to work with text fonts. When unicode-math
is used with mathastext
, the mathematical fonts are not properly loaded, leading to a range of issues, including:
- Incorrect font loading: The mathematical fonts are not loaded correctly, leading to a range of issues, including incorrect font sizes and styles.
- Mathematical expressions not typeset correctly: Mathematical expressions are not typeset correctly, leading to a range of issues, including incorrect spacing and alignment.
- Error messages: The package can produce error messages, such as "Undefined control sequence" or "Missing number, treated as zero".
Why does this happen?
The reason why unicode-math
and mathastext
interact badly is because of the way they are designed to work. unicode-math
is designed to work with mathematical fonts, while mathastext
is designed to work with text fonts. When unicode-math
is used with mathastext
, the mathematical fonts are not properly loaded, leading to a range of issues.
Solutions
There are several solutions to mitigate the issues caused by the interaction between unicode-math
and mathastext
. These include:
- Using a different mathematical font: Instead of using
unicode-math
, users can use a different mathematical font, such asmathpazo
ornewpxmath
. - Disabling mathastext: Users can disable
mathastext
by adding the line\usepackage[nofonts]{mathastext}
to their document. - Using a different package: Users can use a different package, such as
amsmath
ormathtools
, which do not interact badly withunicode-math
.
Example Code
Here is an example of how to use unicode-math
and mathastext
together:
\documentclass{article}
\usepackage{tikz}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{TeX Gyre Termes Math}
\setsansfont{Arial}
\usepackage[subdued, italic]{mathastext}
\begin{document}
This is a mathematical expression: $\int_{0}^{1} x^2 dx$
\end{document}
However, this code will produce a range of issues, including incorrect font loading and mathematical expressions not typeset correctly.
Conclusion
In conclusion, unicode-math
and mathastext
can interact badly when used together. The problem arises because unicode-math
is designed to work with mathematical fonts, while mathastext
is designed to work with text fonts. There are several solutions to mitigate the issues, including using a different mathematical font, disabling mathastext
, or using a different package.
M(N)WE
Here is a M(N)WE (Minimal (Non-)Working Example) that demonstrates the issues caused by the interaction between unicode-math
and mathastext
:
\documentclass{article}
\usepackage{tikz}
\usepackage{unicode-math}
\setmainfont{Times New Roman}
\setmathfont{TeX Gyre Termes Math}
\setsansfont{Arial}
\usepackage[subdued, italic]{mathastext}
\begin{document}
This is a mathematical expression: $\int_{0}^{1} x^2 dx$
\end{document}
This code will produce a range of issues, including incorrect font loading and mathematical expressions not typeset correctly.
Fonts
- Times New Roman: A serif font that is commonly used in documents.
- TeX Gyre Termes Math: A mathematical font that is designed to work with
unicode-math
. - Arial: A sans-serif font that is commonly used in documents.
Fontspec
- Fontspec: A package that allows users to specify fonts in LaTeX documents.
Unicode Math
- Unicode Math: A package that allows users to typeset mathematical expressions using Unicode characters.
Sans Serif
- Sans Serif: A font style that is characterized by the absence of serifs.
Mathastext
- Mathastext: A package that allows users to typeset mathematical expressions using the same font as the surrounding text.
Q&A: unicode-math and mathastext Interaction Issues =====================================================
Q: What is the main reason why unicode-math and mathastext interact badly?
A: The main reason why unicode-math
and mathastext
interact badly is because unicode-math
is designed to work with mathematical fonts, while mathastext
is designed to work with text fonts. When unicode-math
is used with mathastext
, the mathematical fonts are not properly loaded, leading to a range of issues.
Q: What are some common issues that arise when using unicode-math and mathastext together?
A: Some common issues that arise when using unicode-math
and mathastext
together include:
- Incorrect font loading: The mathematical fonts are not loaded correctly, leading to a range of issues, including incorrect font sizes and styles.
- Mathematical expressions not typeset correctly: Mathematical expressions are not typeset correctly, leading to a range of issues, including incorrect spacing and alignment.
- Error messages: The package can produce error messages, such as "Undefined control sequence" or "Missing number, treated as zero".
Q: How can I fix the issues caused by the interaction between unicode-math and mathastext?
A: There are several solutions to mitigate the issues caused by the interaction between unicode-math
and mathastext
. These include:
- Using a different mathematical font: Instead of using
unicode-math
, users can use a different mathematical font, such asmathpazo
ornewpxmath
. - Disabling mathastext: Users can disable
mathastext
by adding the line\usepackage[nofonts]{mathastext}
to their document. - Using a different package: Users can use a different package, such as
amsmath
ormathtools
, which do not interact badly withunicode-math
.
Q: What are some alternative packages that I can use instead of unicode-math and mathastext?
A: Some alternative packages that you can use instead of unicode-math
and mathastext
include:
- amsmath: A package that provides a wide range of mathematical commands and environments.
- mathtools: A package that provides a wide range of mathematical commands and environments, including support for Unicode characters.
- mathpazo: A package that provides a mathematical font that is designed to work with the Palatino font.
- newpxmath: A package that provides a mathematical font that is designed to work with the New Century Schoolbook font.
Q: How can I troubleshoot issues caused by the interaction between unicode-math and mathastext?
A: To troubleshoot issues caused by the interaction between unicode-math
and mathastext
, you can try the following:
- Check the error messages: Check the error messages produced by the package to see if they provide any clues about the issue.
- Try disabling mathastext: Try disabling
mathastext
by adding the line\usepackage[nofonts]{mathastext}
to your document. - Try using a different mathematical font: Try using a different mathematical font, such as
mathpazo
ornewpxmath
. - Try using a different package: Try using a different package, such as
amsmath
ormathtools
.
Q: Can I use unicode-math and mathastext together in a document?
A: While it is technically possible to use unicode-math
and mathastext
together in a document, it is not recommended. The interaction between the two packages can cause a range of issues, including incorrect font loading and mathematical expressions not typeset correctly.
Q: What are some best practices for using unicode-math and mathastext?
A: Some best practices for using unicode-math
and mathastext
include:
- Use a different mathematical font: Instead of using
unicode-math
, use a different mathematical font, such asmathpazo
ornewpxmath
. - Disable mathastext: Disable
mathastext
by adding the line\usepackage[nofonts]{mathastext}
to your document. - Use a different package: Use a different package, such as
amsmath
ormathtools
, which do not interact badly withunicode-math
.
Q: Can I use unicode-math and mathastext together in a specific font?
A: While it is technically possible to use unicode-math
and mathastext
together in a specific font, it is not recommended. The interaction between the two packages can cause a range of issues, including incorrect font loading and mathematical expressions not typeset correctly.
Q: What are some common fonts that I can use with unicode-math and mathastext?
A: Some common fonts that you can use with unicode-math
and mathastext
include:
- Times New Roman: A serif font that is commonly used in documents.
- TeX Gyre Termes Math: A mathematical font that is designed to work with
unicode-math
. - Arial: A sans-serif font that is commonly used in documents.
Q: Can I use unicode-math and mathastext together in a specific document class?
A: While it is technically possible to use unicode-math
and mathastext
together in a specific document class, it is not recommended. The interaction between the two packages can cause a range of issues, including incorrect font loading and mathematical expressions not typeset correctly.
Q: What are some common document classes that I can use with unicode-math and mathastext?
A: Some common document classes that you can use with unicode-math
and mathastext
include:
- article: A document class that is commonly used for articles and other short documents.
- report: A document class that is commonly used for reports and other long documents.
- book: A document class that is commonly used for books and other long documents.