3

Following Make mathfont respect the surrounding family I’m trying to set up my document to use Platino and Arev for math depending on text context too. Unfornutalty it gives me the wrong parenthesis in math mode, when Arev is in use:

enter image description here

The problem seems to affect only the normal sized parenthesis; brackets and braces work fine, as well as bigger parenthesis.

How can I set up the right parens?

Code:

\documentclass{book}

\usepackage{parskip}

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

\usepackage{siunitx}
   \sisetup{detect-all}

\renewcommand{\sfdefault}{fav}

\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}

\newif\IfInSansMode
\LetLtxMacro\oldsf\sffamily
\renewcommand*{\sffamily}{\oldsf\mathversion{arev}\InSansModetrue}
\LetLtxMacro\oldrm\rmfamily
\renewcommand*{\rmfamily}{\oldrm\InSansModefalse\mathversion{normal}}

\newcommand{\TestText}{%
   $\{[(a+b)]\} = \left(\frac{c-d}{e+f}\right)$ (Text-Mode)
}

\begin{document}
\TestText

\sffamily
\TestText
\end{document}
Tobi
  • 56,353

2 Answers2

3

newtxmath redefines the delimiters:

\DeclareMathDelimiter{(}{\mathopen}{lettersA}{125}{largesymbols}{0}
\DeclareMathDelimiter{)}{\mathclose}{lettersA}{126}{largesymbols}{1}

so your changes in the operator/letter font don't affect them.

You can reset them but only globally as \DeclareMathDelimiter can be used only in the preamble. If you want to use the parentheses from the text font, you can try \SetSymbolFont {operators} {arev} {T1} {fav} {m} {n}.

\documentclass{book}

\usepackage{parskip}

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

\renewcommand{\sfdefault}{fav}

\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}

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

\begin{document}

\sffamily 
$\bigg ((a+b)$ (Text-mode)

\mathversion{arev}
$\bigg ((a+b)$ (Text-mode)
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
2

The arev math fonts use the standard LaTeX math codes, but newpxmath changes a few of them.

I acted on the parentheses, you may want to add other codes in a similar fashion. I also used xpatch to simplify patching \rmfamily and \sffamily.

\documentclass{book}

% store the necessary standard codes
\edef\latexmathcodelparen{\the\mathcode`(\relax}
\edef\latexdelcodelparen{\the\delcode`(\relax}
\edef\latexmathcoderparen{\the\mathcode`)\relax}
\edef\latexdelcoderparen{\the\delcode`)\relax}

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

\usepackage{siunitx}
   \sisetup{detect-all}

\renewcommand{\sfdefault}{fav}

% store the codes from newpxmath
\edef\pxmathcodelparen{\the\mathcode`(\relax}
\edef\pxmathcoderparen{\the\mathcode`)\relax}
\edef\pxdelcodelparen{\the\delcode`(\relax}
\edef\pxdelcoderparen{\the\delcode`)\relax}

\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 {\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}

\newif\IfInSansMode
\xapptocmd\sffamily{%
  \mathversion{arev}%
  \InSansModetrue
  % restore the standard codes
  \mathcode`(=\latexmathcodelparen
  \mathcode`)=\latexmathcoderparen
  \delcode`(=\latexdelcodelparen
  \delcode`)=\latexdelcoderparen
}{}{}
\xapptocmd\rmfamily{%
  \InSansModefalse
  \mathversion{normal}%
  % restore the newpxmath codes
  \mathcode`(=\pxmathcodelparen
  \mathcode`)=\pxmathcoderparen
  \delcode`(=\pxmathcodelparen
  \delcode`)=\pxmathcoderparen
}{}{}

\newcommand{\TestText}{%
   $\{[(a+b)]\} = \left(\frac{c-d}{e+f}\right)$ (Text-Mode)
}

\begin{document}
\TestText

\sffamily
\TestText
\end{document}

enter image description here

This is a check document

\documentclass{article}
\usepackage{arevtext,arevmath}
\begin{document}

$\{[(a+b)]\} = \left(\frac{c-d}{e+f}\right)$ (Text-Mode)

\end{document}

enter image description here

egreg
  • 1,121,712
  • What’s the difference to Ulrikes answer? I mean is on of them more robust or are they just different solutions? – Tobi Aug 08 '16 at 18:09
  • @Tobi It's quite different. Ulrike is changing the codes also for the normal math version, so the parentheses are different from the usual newpxmath ones. – egreg Aug 08 '16 at 19:11
  • But the (optical) result seems to be the same, wo which solution should I prefer? – Tobi Aug 08 '16 at 19:12
  • @Tobi That's up to you. My solution can be generalized also for other characters you need to modify. – egreg Aug 08 '16 at 19:13
  • I see … I think I use Ulrikes version since it’s shorter :-) – Tobi Aug 08 '16 at 20:18