3

This is kind of a follow up question of Make mathfont respect the surrounding family.

For my main text (\rmfamily) I want to use Palatino and for \sffamily Arev. The math fonts should also respect this. And it nearly works, but the following example code has two issues:

  1. Uppercase greek letters don’t work in sans. How can I fix that?
  2. How can I select the other v from Araev, ssince the one selected is nearly indistinguishable from \nu. When I try \DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71} it affects all math fonts and also has no bold version.

Code

\documentclass{book}

\usepackage[scaled=1.15]{newpxtext}
\usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}
\usepackage{letltxmacro}

\renewcommand{\sfdefault}{fav}

\DeclareMathVersion{arev}

\SetSymbolFont {operators}    {arev} {OT1} {zavm}  {m} {n}
\SetSymbolFont {letters}      {arev} {OML} {zavm}  {m} {it}
\SetSymbolFont {lettersA}     {arev} {OT1} {zavm}  {m} {n} % <-- breaks some symbols
\SetSymbolFont {symbols}      {arev} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it}
\SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n}
\SetMathAlphabet {\mathtt} {arev} {T1}  {fvm}  {m} {n}

% ander Form für v
\DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it}
%\DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71}% affects \rmfamily too, and doesnt have bold version

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators}    {arevbold} {OT1} {zavm}  {b} {n}
\SetSymbolFont {letters}      {arevbold} {OML} {zavm}  {b} {it}
\SetSymbolFont {lettersA}     {arevbold} {OT1} {zavm}  {b} {n} % <-- breaks some symbols
\SetSymbolFont {symbols}      {arevbold} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathit}    {arevbold} {OT1} {zavm}  {b} {it}
\SetMathAlphabet {\mathbf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathtt}    {arevbold} {T1}  {fvm}   {b} {n}


\newif\IfInSansMode
\LetLtxMacro\oldsf\sffamily
\renewcommand*{\sffamily}{\oldsf\mathversion{arev}\InSansModetrue}
\LetLtxMacro\oldbf\bfseries
\renewcommand*{\bfseries}{\oldbf\IfInSansMode\mathversion{arevbold}\else\mathversion{bold}\fi\relax}
\LetLtxMacro\oldnorm\normalfont
\renewcommand*{\normalfont}{\oldnorm\InSansModefalse\mathversion{normal}}
\LetLtxMacro\oldrm\rmfamily
\renewcommand*{\rmfamily}{\oldrm\InSansModefalse\mathversion{normal}}

\newcommand{\TestText}{%
   $v \nu$

   $abcdefghijklmnopqrstuvwxyz$

   $ABCDEFGHIJKLMNOPQRSTUVWXYZ$

   $\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

   $\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

   $\int(1-2\cdot 10^{-5}) = \sum_i^\infty\sin x_i + a$
}

\begin{document}
\TestText

\bigskip
\bfseries
\TestText

\bigskip
\sffamily\mdseries
\TestText

\bigskip
\bfseries
\TestText

\end{document}

PS: I have to use pdflatex

Tobi
  • 56,353

2 Answers2

4

There's actually a lot of work involved, because newpxmath assigns Greek upright letters to the lettersA symbol font and changes several locations for symbols.

\documentclass{book}
\usepackage{iftex}

\usepackage[scaled=1.15]{newpxtext} \usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}

\iftutex \defaultfontfeatures{Ligatures=TeX} \setsansfont{DejaVu Sans} \else \renewcommand{\sfdefault}{fav} \fi

\DeclareMathVersion{arev}

\SetSymbolFont {operators} {arev} {OT1} {zavm} {m} {n} \SetSymbolFont {letters} {arev} {OML} {zavm} {m} {it} \SetSymbolFont {lettersA} {arev} {OT1} {zavm} {m} {n} % <-- added \SetSymbolFont {symbols} {arev} {OMS} {zavm} {m} {n} \SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n} \SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it} \SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n} \SetMathAlphabet {\mathtt} {arev} {T1} {fvm} {m} {n}

% ander Form für v \DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it} % affects \rmfamily too, and doesn't have bold version %\DeclareMathSymbol{v}{\mathalpha}{extraitalic}{71}

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators} {arevbold} {OT1} {zavm} {b} {n} \SetSymbolFont {letters} {arevbold} {OML} {zavm} {b} {it} \SetSymbolFont {lettersA} {arevbold} {OT1} {zavm} {b} {n} % <-- added \SetSymbolFont {symbols} {arevbold} {OMS} {zavm} {m} {n} \SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm} {arevbold} {OT1} {zavm} {b} {n} \SetMathAlphabet {\mathit} {arevbold} {OT1} {zavm} {b} {it} \SetMathAlphabet {\mathbf} {arevbold} {OT1} {zavm} {b} {n} \SetMathAlphabet {\mathtt} {arevbold} {T1} {fvm} {b} {n}

\newif\IfInSansMode \mathchardef\normalplus="202B \mathchardef\newpxplus="22CF \mathchardef\normallparen=16424 \mathchardef\newpxlparen=\mathcode( \def\normallparencode{164608 } \edef\newpxlparencode{\the\delcode( } % other similar commands \newcommand{\choosemathversion}[1]{% \mathversion{#1}% \symbolfixes{#1}% } \newcommand{\symbolfixes}[1]{\csname makesymbolfixes#1\endcsname} \newcommand{\makesymbolfixesnormal}{% \mathcode+=\newpxplus \mathcode(=\newpxlparen \delcode(=\newpxlparencode\relax % other similar fixes } \newcommand{\makesymbolfixesarev}{% \mathcode+=\normalplus \mathcode(=\normallparen \delcode(=\normallparencode\relax % other similar fixes } \newcommand{\makesymbolfixesarevbold}{\makesymbolfixesarev}

\AddToHook{cmd/normalfont/after}{% \choosemathversion{normal}\InSansModefalse } \AddToHook{cmd/sffamily/after}{% \choosemathversion{arev}\InSansModetrue } \AddToHook{cmd/bfseries/after}{% \IfInSansMode \choosemathversion{arevbold}% \else \choosemathversion{bold}% \fi }

\begin{document}

Some text $v\nu$ with a v.

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip \bfseries

Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip \sffamily\mdseries

Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\bigskip \bfseries Some text $v\nu$ with a v.

$v\nu$

$abcdefghijklmnopqrstuvwxyz$

$ABCDEFGHIJKLMNOPQRSTUVWXYZ$

$\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

$\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

$\sin^2\alpha+\cos^2\alpha=1$

\end{document}

The “lot of work” refers to what has to be added to those lists of commands in order to change output encodings back and forth.

How to discover what codes to switch? You'll be warned about missing characters.

enter image description here

egreg
  • 1,121,712
  • Thanks! That solves my issue no. 1. Any ideas vor issue no. 2 (changing v shape in sans only)? – Tobi Aug 06 '16 at 07:55
  • @Tobi That's more work, I'll give a look later – egreg Aug 06 '16 at 08:43
  • Mille grazie:-) – Tobi Aug 06 '16 at 10:46
  • I tried to add your solution to my real document now but it breaks parens and some other symbols. See the updated MWE in my question. – Tobi Aug 08 '16 at 15:26
  • @Tobi I'm afraid there are several differences in encodings. – egreg Aug 08 '16 at 16:47
  • Damn … I guess that means there’s no solution?! Or can I “remap” on of the two fonts? I came to the same issue when trying to fix my second problem: I can declare v in a way that only arevaffect it but then palatino uses the sam slot in which it has a G instead of a v due to the different encodings … – Tobi Aug 08 '16 at 17:36
  • @Tobi I'm trying, but it's quite a mess. – egreg Aug 08 '16 at 17:38
  • Hm … has this to be done letter by letter? In that case it would be enough to have the \Delta (and the alternative v). As far as I can tell at the moment no other uppercase greek letters are in use. – Tobi Aug 08 '16 at 17:42
  • Hi … I found a solution for the greek uppercase letters myself (see my own answer below). I have no idea why this works, but it seems to do the trick. – Tobi Aug 08 '16 at 18:31
  • Yea :-D I also found a solution for my second problem. It works but I don’t know if it has any consequences I can’t think of at the moment. I would really appreciate if you could review my solution :-) – Tobi Aug 08 '16 at 19:12
  • @egreg Is it possible to fix the same by using XeLaTeX? – MadyYuvi Jul 03 '23 at 06:57
  • @MadyYuvi It's not difficult to support XeLaTeX. The hard part is finding all symbols that change positions. – egreg Jul 03 '23 at 08:39
  • @egreg Sorry, I meant that for the arabic and alpha numerals from the sans font and the Greek can come from any of the standard fonts, i.e., like \mathversion{sans}, sorry for my poor English – MadyYuvi Jul 03 '23 at 09:12
  • @MadyYuvi That's a completely different topic. – egreg Jul 03 '23 at 09:43
  • @egreg Thanks, will raise a separate question, and really thanks for your prompt reply – MadyYuvi Jul 03 '23 at 09:49
0

I found a solution myself:

  1. Uppercase greek: Using the original \DeclareMathSymbol{\Gamma}{\mathalpha}{operators}{"00} etc. from source2e.pdf (p. 224) the uppercase greek letters are taken from the right fonts for roman and sans version.
  2. v vs. \nu: Make vactive in mathe mode and define it to use the italic v of the text font with \text{\textit{v}}.

enter image description here

\documentclass{book}

\usepackage[scaled=1.15]{newpxtext}
\usepackage[varg,scaled=1.15,cmintegrals]{newpxmath}
\usepackage{letltxmacro}

\renewcommand{\sfdefault}{fav}

\DeclareMathSymbol{\Gamma}{\mathalpha}{operators}{"00}
\DeclareMathSymbol{\Delta}{\mathalpha}{operators}{"01}
\DeclareMathSymbol{\Theta}{\mathalpha}{operators}{"02}
\DeclareMathSymbol{\Lambda}{\mathalpha}{operators}{"03}
\DeclareMathSymbol{\Xi}{\mathalpha}{operators}{"04}
\DeclareMathSymbol{\Pi}{\mathalpha}{operators}{"05}
\DeclareMathSymbol{\Sigma}{\mathalpha}{operators}{"06}
\DeclareMathSymbol{\Upsilon}{\mathalpha}{operators}{"07}
\DeclareMathSymbol{\Phi}{\mathalpha}{operators}{"08}
\DeclareMathSymbol{\Psi}{\mathalpha}{operators}{"09}
\DeclareMathSymbol{\Omega}{\mathalpha}{operators}{"0A}

\DeclareMathSymbol{\intop}{\mathop}{largesymbols}{"52}
\DeclareMathSymbol{\ointop}{\mathop}{largesymbols}{"48}

\DeclareMathAlphabet {\mathsfbf} {OT1} {zavm}  {b} {n}

\DeclareMathDelimiter{(}{\mathopen} {operators}{"28}{largesymbols}{"00}
\DeclareMathDelimiter{)}{\mathclose}{operators}{"29}{largesymbols}{"01}

\DeclareMathVersion{arev}

\SetSymbolFont {operators}    {arev} {OT1} {zavm}  {m} {n}
\SetSymbolFont {letters}      {arev} {OML} {zavm}  {m} {it}
\SetSymbolFont {symbols}      {arev} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arev} {OMX} {mdbch} {m} {n}

\SetMathAlphabet {\mathrm} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathsf} {arev} {OT1} {zavm} {m} {n}
\SetMathAlphabet {\mathit} {arev} {OT1} {zavm} {m} {it}
\SetMathAlphabet {\mathbf} {arev} {OT1} {zavm} {b} {n}
\SetMathAlphabet {\mathtt} {arev} {T1}  {fvm}  {m} {n}

\DeclareMathVersion{arevbold}

\SetSymbolFont {operators}    {arevbold} {OT1} {zavm}  {b} {n}
\SetSymbolFont {letters}      {arevbold} {OML} {zavm}  {b} {it}
\SetSymbolFont {symbols}      {arevbold} {OMS} {zavm}  {m} {n}
\SetSymbolFont {largesymbols} {arevbold} {OMX} {mdbch} {b} {n}

\SetMathAlphabet {\mathrm}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathsf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathsfbf}  {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathit}    {arevbold} {OT1} {zavm}  {b} {it}
\SetMathAlphabet {\mathbf}    {arevbold} {OT1} {zavm}  {b} {n}
\SetMathAlphabet {\mathtt}    {arevbold} {T1}  {fvm}   {b} {n}

\newif\IfInSansMode

\let\oldsf\sffamily
\renewcommand*{\sffamily}{\oldsf\mathversion{arev}\InSansModetrue}

\let\oldbf\bfseries
\renewcommand*{\bfseries}{\oldbf\IfInSansMode\mathversion{arevbold}\else\mathversion{bold}\fi\relax}

\let\oldnorm\normalfont
\renewcommand*{\normalfont}{\oldnorm\InSansModefalse\mathversion{normal}}

\let\oldrm\rmfamily
\renewcommand*{\rmfamily}{\oldrm\InSansModefalse\mathversion{normal}}

\DeclareSymbolFont{extraitalic}{U}{zavm}{m}{it}
\SetSymbolFont{extraitalic}{arevbold} {OML} {zavm}  {b} {it}
\DeclareMathSymbol{\VarV}{\mathalpha}{extraitalic}{71}
\DeclareSymbolFont{extraitalicbold}{U}{zavm}{b}{it}
\DeclareMathSymbol{\VarVBold}{\mathalpha}{extraitalicbold}{71}
\DeclareMathSymbol{\NormalV}{\mathalpha}{letters}{`v}

\mathcode`\v="8000
{\catcode`\v=\active
\gdef v{\mathalpha{\text{\textit{\char`v}}}}}

\newcommand{\TestText}{%
   $v \nu$

%   $abcdefghijklmnopqrstuvwxyz$

%   $ABCDEFGHIJKLMNOPQRSTUVWXYZ$

%   $\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\omega\psi\chi\varphi\phi\upsilon$

   $\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega$

%   $\int(1-2\cdot 10^{-5}) = \sum_i^\infty\sin x_i + a$
}

\begin{document}
\TestText

\bigskip
\bfseries
\TestText

\bigskip
\sffamily\mdseries
\TestText

\bigskip
\bfseries
\TestText

\end{document}
Tobi
  • 56,353