Trouble with math fonts in XeLaTeX

552 Views Asked by At

I want to use the "Gentium Plus" font for writing mathematical work (in math mode). Added \usepackage{fontspec} and \usepackage{unicode-math}.

When compiling XeLaTeX it gives an error:

   ! Package unicode-math Error: No main maths font has been set up yet.
   (unicode-math) If you simply want ‘the default’, use:
   (unicode-math)\setmathfont{latinmodern-math.otf}

and writes math using "Latin Modern Math".

How can I force the use of "Gentium Plus" for math and completely prohibit the transition to the default font (it would be better to have ▯ instead of symbols)?

Template:

\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}

\usepackage{fontspec}
\setmainfont{Gentium Plus}

\usepackage{amsmath, amssymb, amsthm, thmtools, unicode-math}
\setmathfont{Gentium Plus}

\begin{document}

\title{Mathematical text}

\section{Section name}

Lorem ipsum

\[
\alpha + \beta = \gamma + \delta.
\]

\end{document}
1

There are 1 best solutions below

0
On BEST ANSWER

How can I force the use of "Gentium Plus" for math and completely prohibit the transition to the default font (it would be better to have ▯ instead of symbols)?

There does not seem to be a Gentium Plus math font available. You won't get happy with writing math if you don't have any symbols etc.


Some alternatives:

mathastext

You could use the mathastext package to use letters and numbers from the normal text font in math mode:

% !TeX TS-program = xelatex

\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}

\usepackage{amsmath, amssymb, amsthm, thmtools}
\usepackage[no-math]{fontspec} 
\setmainfont{Gentium Plus} 

\usepackage[italic]{mathastext}

\begin{document}

\title{Mathematical text}

\section{Section name}

Lorem ipsum2

abcxyz \itshape abxzyx2

\[
abcxyz2 \alpha + \beta = \gamma + \delta.
\]

\end{document}

enter image description here

mathspec

You could use the mathspec package to load Gentium Plus for letters and digits:

% !TeX TS-program = xelatex

\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}

\usepackage{amsmath, amssymb, amsthm, thmtools}
\usepackage[no-math]{fontspec} 
\setmainfont{Gentium Plus} 
\usepackage{mathspec} 
\setmathfont(Digits,Latin,Greek){Gentium Plus}
\begin{document}

\title{Mathematical text}

\section{Section name}

Lorem ipsum2

abcxyz \itshape abxzyx2

\[
abcxyz2 \alpha + \beta = \gamma + \delta.
\]

\end{document}

enter image description here

Combine with an actual math font

Instead of the Frankenstein approaches above, you could also pair your font with a real math font, e.g. XCharter might work well with it and you'll get matching symbols etc.

% !TeX TS-program = xelatex

\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}

\usepackage{amsmath, amssymb, amsthm, thmtools}
\usepackage[no-math]{fontspec} 
\setmainfont{Gentium Plus} 

\usepackage[no-text,Scale=0.93]{xcharter-otf}

\title{Mathematical text}

\begin{document}

\section{Section name}

Lorem ipsum2

abcxyz \itshape abxzyx2

\[
abcxyz2 \sum \int \alpha + \beta = \gamma + \delta.
\]

\end{document}

enter image description here