1

The declaration \DeclareMathAlphabet{cmd}{encoding}{family}{series}{shape} works to create a new command whose argument would be a font as specified in the declaration. PSNFSS distribution families work with it.

However, I want to get a simple way to declare global math fonts using the following code

\usepackage[]{mathspec}

        \newcommand{\mainmathfont}{TeX Gyre Termes}
        \setmathsfont(Latin)[]{\mainmathfont}
        \setmathsfont(Greek)[]{\mainmathfont}
        \setmathsfont(Digits)[]{\mainmathfont}

But it looks like it works only for TeX Gyre, Courier, and Computer Modern font families. How can I modify the commands above to globally customize math fonts?

Here is my source code

\documentclass[]{book}
\usepackage[T1]{fontenc}

\usepackage{amsmath}
\usepackage{amssymb, amsfonts}


\DeclareMathAlphabet{\mathsf}{OT1}{pzc}{m}{n}

\usepackage[]{mathspec}

        \newcommand{\mainmathfont}{TeX Gyre Termes}
        \setmathsfont(Latin)[]{\mainmathfont}
        \setmathsfont(Greek)[]{\mainmathfont}
        \setmathsfont(Digits)[]{\mainmathfont}

\begin{document}


\begin{equation}
    \sum\limits_{i=1}^{\left[ \frac{n}{2} \right]}{\left(\substack{{x_{i, i+1}^{i^{2}}} \\ \\ {\left[ \frac{i+3}{3} \right]}}\right)}
    \frac{\sqrt{\mu(i)^{\frac{3}{2}}\left( i^{2} - 1 \right)}}{\sqrt[3]{\rho(i)-2} + \sqrt[3]{\rho(i)-1}} \Omega
\end{equation}

\[
\int_{\mathcal{D}} | \overline{\partial u} |^{2}
\Phi_{0}(z) e^{\alpha |z|^2}
\geq c_{4} \alpha \int_{\mathcal{D}} |u|^{2}\Phi_{0}
e^{\alpha |z|^{2}}
+ c_{5} \delta^{-2} \int_{A} |u|^{2}
\Phi_{0} e^{\alpha |z|^{2}}
\]

$\alpha \medspace \beta \medspace \gamma \medspace \delta \medspace \epsilon \medspace \varepsilon \medspace \zeta \medspace \eta \medspace \theta \medspace \vartheta \medspace \iota \medspace \kappa \medspace \lambda \medspace \mu \medspace \nu \medspace \xi \medspace \pi \medspace \sigma \medspace \varsigma \tau \medspace \upsilon \medspace \phi \medspace \varphi \medspace \chi \medspace \psi \medspace \omega \medspace \Delta \medspace \Xi \medspace \Phi \medspace \Omega \medspace \Psi$

$[1], \thinspace [2], \thinspace [3], \thinspace [4], \thinspace [5], \thinspace [6], \thinspace [7], \thinspace [8], \thinspace [9]$

\begin{equation}
    \mathbf{A} =
        \begin{pmatrix}
            \dfrac{\varphi \cdot X_{n, 1}} {\varphi_{1} \times
                \varepsilon_{1}} & (x + \varepsilon_{2})^{2}
            & \cdots & (x + \varepsilon_{n - 1})^{n - 1}
            & (x + \varepsilon_{n})^{n}\\[10pt]
            \dfrac{\varphi \cdot X_{n, 1}} {\varphi_{2} \times
                \varepsilon_{1}} & \dfrac{\varphi \cdot X_{n, 2}}
            {\varphi_{2} \times \varepsilon_{2}} & \cdots &
            (x + \varepsilon_{n - 1})^{n - 1}
            & (x + \varepsilon_{n})^{n}\\
            \hdotsfor{5}\\
            \dfrac{\varphi \cdot X_{n, 1}} {\varphi_{n} \times
                \varepsilon_{1}} & \dfrac{\varphi \cdot X_{n, 2}}
            {\varphi_{n} \times \varepsilon_{2}} & \cdots
            & \dfrac{\varphi \cdot X_{n, n - 1}} {\varphi_{n}
                \times \varepsilon_{n - 1}} &
            \dfrac{\varphi\cdot X_{n, n}}
            {\varphi_{n} \times \varepsilon_{n}}
        \end{pmatrix}
    + \mathbf{I}_{n}
\end{equation}

\begin{equation}
I = I_{ ph } -  
\overbrace{
    I_{ rs }
    \biggl[
    \mathrm{exp} \biggl(
    \frac{V + I R_{s}}{a \thinspace V_{t}}
    \biggl) - 1   
    \biggl]
    % overbrace title
}^{ I_{d} }
-
\overbrace{
    \frac{V + I R_{s}}{R_{p}}
    % overbrace title
}^{I_{p}}
%
\label{eq:I_PV_m}
\end{equation}



\begin{equation}
P_{e, \thinspace WT} =
    \left \{
        %
        \begin{aligned}
            %
            & 0  &   & v_{w} \thinspace < \thinspace v_{ci} 
            \\
            & P_{GCR} (v_{w}) \quad   & v_{ci} \thinspace \leq \thinspace &  v_{w} \thinspace \leq v_{r} 
            \\
            & P_{r, \thinspace WT}   & v_{r} \thinspace \leq \thinspace  &  v_{w} \thinspace \leq v_{co}
            \\
            & 0  &   & v_{w} > \thinspace v_{co}
            %
        \end{aligned}
    %
    \right.
%
\label{eq:WTPSC}
\end{equation} 

\begin{equation}
%
    \begin{aligned}
        %
        PMSE_{av} &= \frac{Mean \ Square \ Error}{Average \ of \ Estimations} \times 100\%
        \\
        & = \frac{ \displaystyle
            \frac{1}{n} \sum \limits_{i=1}^{n} {(x_{i}-y_{i})^2}
        }
        { \displaystyle
            \sum\limits_{i=1}^{n} {y_{i}}
        } \times 100\%  
        %
    \end{aligned}
%
\label{eq:PMSE_av}
\end{equation}

\begin{equation}
  • mathspec is for unicode tex (xetex or luatex) but your document is using T1 encoding which only makes sense if using an 8-bit tex such as pdftex. – David Carlisle Jul 24 '18 at 21:51
  • It seems that the command is being ignored because I cannot see any difference whether it is there or not, but I used to put it when I was using pdftex. – Al-Motasem Aldaoudeyeh Jul 24 '18 at 21:56
  • math for 8bit tex requires multiple fonts in custom tex-specific encodings, each with 127 or 256 characters per font. math for unicode tex can use a single font with thousands of characters. the mechanisms and fonts used have almost nothing in common. – David Carlisle Jul 24 '18 at 22:05
  • @DavidCarlisle Although the single-font trick is usually unicode-math rather than mathspec, isn't it? Of course, mathspec still expects unicode fonts, but wouldn't you usually use it to combine stuff from multiple fonts? – cfr Jul 24 '18 at 22:09
  • @cfr with mathspec yes but basically any document that starts \usepackage[T1]{fontenc} is unusable with xetex and probably will do the wrong thing in luatex, so I'm trying to find out what the actual use case is, this seems to be an X-Y question that's starting from the wrong point – David Carlisle Jul 24 '18 at 22:12
2

Short Answer

Usemathastext package under the following constraints:

  1. load mathastext after loading all math font related packages
  2. if you are using fontspec package then you must load it with the no-math option

\MTDeclareVersion[<ltsh>]{<name>}{<enc>}{<fam>}{<ser>}{<sh>}

This command declares the type of certain 'math version'

<ltsh>: shape of letters and small Greeks

<name>: name of the math font type being declared

<enc>: the needed encoding

<fam>: font family

<ser>: series type of the font

<sh>: shape of digits and capital Greeks

and

\MTversion*{<name>}

This command allows for the use of math version whose name is given in the mandatory argument.

  • Example

\MTDeclareVersion[it]{AvantGarde}{T1}{pag}{m}{n} and \MTversion*{AvantGarde} give the math equation shown here

enter image description here

The equation above is shown only for reference.

Long Answer

mathastext package changes fonts used in math mode to virtually any font that can be used in text mode. Loading mathastext, as shown in its documentation, sets up a bigger size for subscripts hence. Using defaultmathsizes helps retain the default subscript sizes

  • Important mathastext options:

subdued: allows mathastext to activate only by enabling math versions. Use this option along with defaultmathsizes to get displayed math to be almost as if mathastext had not been loaded

disables mathastextification for \mathxx commands and enables them only after explicit \MTversion commands

IMPORTANT: if this option is enabled, it is highly recommended to explicitly set up and use a math version. Otherwise, unexpected results may appear in the font.

italic: specifies if math letters are italic by default (this does not affect greek letters unless LGRgreek is loaded and subdued is not)

symbolgreek: uses bold and upright Adobe Postscript Greek letters (it does not work if LGRgreek or subdued are active)

eulergreek: uses Greek letters from Euler font (it does not work if LGRgreek or subdued are active)

LGRgreek: uses bold and upright greek letter Adobe Postscript greek letters (it does not work if LGRgreek or subdued are active)

itgreek and upgreek: specifies whether small letter Greeks are in italic or upright shape

itGreek and upGreek: specifies whether capital letter Greeks are in italic or upright shape

symbolmisc: replaces older symbols with newer ones of better looks (e.x., thicker)

Compare the new ones

enter image description here

with the old ones

enter image description here

Also symbolmisc defines four new symbols

enter image description here

which can be accessed with $\shortiff \longto \inftypsy \proptopsy$

symbolre: redefines \re and \im to a better look

Compare the new ones

enter image description here

with the old ones

enter image description here

It also provides the \DotTriangle symbol

enter image description here

  • Bold and italic styling commands mathastext commands

\mathnormalbold{<exp>}: provides a bold font for its argument IMPORTANT: it is better to use this command instead of \bm since \mathnormalbold provides direct access to the bold version of \mathnormal and it is slightly more compact

enter image description here

\MTmathoperatorsdonotobeymathxx, \MTnonlettersdonotobeymathxx, and \MTeasynonlettersdonotobeymathxx

\MTmathoperatorsdonotobeymathxx: specifies that math operators (such as sin) will not obey math \mathbf or \mathit

\MTnonlettersdonotobeymathxx: specifies that math non-letters (! ? , : ; + - = ( ) [ ] < >) will not obey \mathbf or \mathit (default)

\MTeasynonlettersdonotobeymathxx: specifies that math easy nonletters (. / | \ # $ % &) do not obey \mathbf or \mathit

\MTmathoperatorsobeymathxx, \MTnonlettersdonotobeymathxx, and \MTeasynonlettersobeymathxx

\MTmathoperatorsobeymathxx: specifies that math operators (such as sin) will obey math \mathbf or \mathit (default)

\MTnonlettersobeymathxx: specifies that math non-letters (! ? , : ; + - = ( ) [ ] < >) will obey \mathbf or \mathit (when not used as delimiters with \left or \right) % Important: this option may give raise to some compatibility issues with other packages

\MTeasynonlettersobeymathxx: specifies that math easy non-letters (. / | \ # $ % &) will obey \mathbf or \mathit (default)

Compare the default options:

enter image description here

with the non-default ones:

enter image description here

\begin{align}
&\mathbf{\sin\left(x+y\right) = \left<\right> \cos(z-t)} / >
\\
&\mathbf{! \medspace ? \medspace , \medspace : \medspace ; \medspace + \medspace - \medspace = \medspace ( \medspace ) [ \medspace ] \medspace < \medspace >}
\\
& \mathbf{. \medspace / \medspace | \medspace \backslash \medspace \# \medspace \$ \medspace \% \medspace \&}
\end{align}


\MTmathoperatorsdonotobeymathxx

\MTnonlettersobeymathxx

\MTeasynonlettersdonotobeymathxx

\vspace{-1.5\baselineskip}


\begin{align}
&\mathbf{\sin\left(x+y\right) = \left<\right> \cos(z-t)} / >
\\
&\mathbf{! \medspace ? \medspace , \medspace : \medspace ; \medspace + \medspace - \medspace = \medspace ( \medspace ) [ \medspace ] \medspace < \medspace >}
\\
& \mathbf{. \medspace / \medspace | \medspace \backslash \medspace \# \medspace \$ \medspace \% \medspace \&}
\end{align}
1

To use a psnfss font as the math font, load the relevant package, for example, newtxmath or newpxmath. You might need to use a package option to load only the math font. Then either load a text package of your choice, setting fontenc appropriately, or \usepackage[no-math]{fontspec}.

You would load mathspec in order to set your math letters to an OpenType font, for example, AMS Euler but with italic letters from Palatino and digits from the text font. (Like with eulerpx, but using OpenType fonts.) You would use an OpenType or TrueType font with \setmathsfont, and not set fontenc.

Another option allowing you to use legacy text fonts in math mode is mathastext. The isomath package also has a comprehensive selection of font families as package options. As David Carslisle brings up in the comments, hyphenation might not work properly in xetex if you stick to NFSS text fonts.

However, my personal recommendation (Which some regulars with higher scores disagree with!) is to use unicode-math when you can, and legacy encodings only when you have to.

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.