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
  • I don't really understand what you're trying to do. Your code appears to be trying to set an opentype font as the 'main maths font' and not one from PSNFSS. In addition, TeX Gyre Termes doesn't support Greek. – cfr Jul 24 '18 at 22:13
  • @DavidCarlisle Definitely agree on that point. – cfr Jul 24 '18 at 22:14
  • @DavidCarlisle. If T1 encoding only works with pdfLaTeX, how can someone use accents and get the font customization features of XeLaTex at the same time? – Al-Motasem Aldaoudeyeh Jul 24 '18 at 22:16
  • @cfr. My code is just a sample. I tried to replace TeX Gyre Termes with something like ptm but it did not work. – Al-Motasem Aldaoudeyeh Jul 24 '18 at 22:19
  • There's no problem using accents with XeLaTeX. You certainly don't need T1 for that - you are using a unicode encoding, which had slots for all the accented characters you could ever want (and many you never will). – cfr Jul 24 '18 at 22:24
  • The thing is, why are you trying to use mathspec if you want to use a PSNFSS font for maths? Just use a traditional configuration for maths and then load fontspec with nomath if you want to use opentype fonts for text mode. – cfr Jul 24 '18 at 22:25
  • if you use T1 with xetex then all hyphenation will be incorrect as xelatex does not load hyphenation tables for 8bit fonts. unicode forms as used by xetex of course support accents. – David Carlisle Jul 24 '18 at 22:28
  • Then what kind of encoding would work well if I want to use XeLaTeX and be able to change math fonts? – Al-Motasem Aldaoudeyeh Jul 24 '18 at 22:31
  • for text fonts the only encoding to use with xetex is the default TU encoding. for math fonts you have a choice of unicode-math which will usie unicode math fonts or use classic math fonts or a kind of half-way which is mathspec which uses classic 8bit math fonts except using the unicode text fonts for math alphabets. – David Carlisle Jul 24 '18 at 22:46
  • by coincidence this just became available https://www.youtube.com/watch?v=L0MfY6EkiKc – David Carlisle Jul 24 '18 at 22:48
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Mar 12 '19 at 10:01

2 Answers2

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}
  • 8-bit fonts are like archaeology, like writing on paper instead of electronic. ASCII does not allow copy-paste to retain the semantic meaning of the symbols, e.g. all the alphabets in the Mathematical Alphanumeric Symbols unicode block. The author of the package mathastext says: "it is extremely far from being able to define a math font, as it applies basically only to a subset of the 32-127 ascii range, and in particular it does not know how to use a given Unicode font simultaneously for Latin and Greek letters. Again the user is strongly advised to look at mathspec and unicode-math." – Cicada Dec 15 '19 at 06:04
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.

Davislor
  • 44,045