11

I am using pdflatex in Texmaker (implements TeXLive). Using the default font, the numerator text of the following fractions are aligned to a common baseline:

$$\frac{\partial x}{\partial t} \frac{\partial y}{\partial t} \frac{\partial z_j}{\partial t}$$

default font with aligned numerators

However, using the newpxmath package results in the numerators becoming misaligned:

\documentclass{article}
\usepackage{newpxmath}
\begin{document}
$$\frac{\partial x}{\partial t} \frac{\partial y}{\partial t} \frac{\partial z_j}{\partial t}$$
\end{document}

newpx font with misaligned numerators

I would like to use New PX for math, but align the numerators as in the default font. I could use \vphantom{...} to force the numerators to have the same height, but is there a more elegant way to do this?

  • 1
    The “aligned at baseline” for default Computer Modern fonts is by accident. If you try \frac{\partial z_{j_j}}{\partial t} the numerator would be shifted upward too. – Ruixi Zhang Sep 20 '19 at 15:02
  • Aha, that's interesting! So the behaviour in the example is because Palatino has longer "tails" under letters than Computer Modern, and this forces LaTeX to shift them upwards in more situations? Maybe the best solution would be to define a "blfrac" function, that inserts something like \vphantom{A^A j_j} automatically. [EDIT: I would be happy to accept this as an answer btw, if it's the most LaTeX-onic way of doing it - would you like to post it, for the points? :-) ] – palatinouser1 Sep 20 '19 at 15:14
  • I am exploring other alternatives. You are correct that Palatino has longer descender since it is based on calligraphy. But the downside is that it can look uneven (the \partial x and \partial y are not on the same baseline either). I would say this is due to the (not-so-well) design of newpxmath, so I think we can play with font dimensions here… – Ruixi Zhang Sep 20 '19 at 15:24
13

Newer and simpler solution

Since v1.401 of newpxmath (released on October 2, 2019, now available in both MiKTeX and TeX Live), the package offers a new option fracspacing that “modifies fontdimens 8 and 11 of the symbol font to values more appropriate to the newpx fonts”.

\documentclass{article}

% New package option since 2019/10/02 update
\usepackage[fracspacing]{newpxmath}[2019/10/02]

\usepackage{mathtools}% for \clap
\newcommand*\drawbaseline{%
  \clap{\rule{80pt}{0.4pt}}%
}

\begin{document}
\[
\begin{gathered}
x,y\drawbaseline,z\\
\frac{\partial x}{\partial t} \frac{\partial y\drawbaseline}{\partial t} \frac{\partial z_j}{\partial t} \frac{\partial z_{j_j}}{\partial t}\\
\frac{\partial x}{\partial t} \frac{\partial y}{\partial t} \frac{\partial z_j}{\partial t} \frac{\partial z_{j_j}}{\partial t}\\
\end{gathered}
\]
\end{document}

The output looks very similar to the one in the old answer below. The parameters are refined from the very crude 0.8.


Old and depreciated answer

The design of Palatino contains long descenders. When a math font is based Palatino, the various math font dimensions should be chosen to avoid unevenness, as much as possible.

There are many font dimensions governing the positions of numerator and denominator in a fraction. We can change two of them in newpxmath which are the most relevant.

newpxmath-modified

\documentclass{article}
\usepackage{newpxmath}

% Code modified from lmsnpxsy.fd
\makeatletter
\expandafter\ifx\csname npxmath@scaled\endcsname\relax
  \let\npxmath@@scaled\@empty%
\else
  \edef\npxmath@@scaled{s*[\csname npxmath@scaled\endcsname]}%
\fi
\DeclareFontFamily{LMS}{npxsy}{\providecommand {\setSYdimens}{}\setSYdimens\skewchar \font =120}
\DeclareFontShape{LMS}{npxsy}{m}{n}{%
  <-> \npxmath@@scaled zplsy
}{%
  \fontdimen 8\font=0.8\fontdimen6\font % was 0.677 of a quad
  \fontdimen11\font=0.8\fontdimen6\font % was 0.686 of a quad
}
\makeatother

\usepackage{mathtools}% for \clap
\newcommand*\drawbaseline{%
  \clap{\rule{80pt}{0.4pt}}%
}

\begin{document}
\[
\begin{gathered}
x,y\drawbaseline,z\\
\frac{\partial x}{\partial t} \frac{\partial y\drawbaseline}{\partial t} \frac{\partial z_j}{\partial t} \frac{\partial z_{j_j}}{\partial t}\\
\frac{\partial x}{\partial t} \frac{\partial y}{\partial t} \frac{\partial z_j}{\partial t} \frac{\partial z_{j_j}}{\partial t}\\
\end{gathered}
\]
\end{document}

Modifying font dimensions gives the most consistent look for all your fractions, but this requires your own aesthetic judgement.

Here, I changed the numerator raising dimension from 0.677 to 0.8 to give more room for long descender. I also changed the denominator dropping dimension from 0.686 to 0.8 for more even spacing both above and below the fraction bar.

  • Thank you for this great answer. This is very useful to know - your description of the raising and dropping parameters is very helpful. I didn't know that these font parameters could be tweaked, so knowing about this approach will help if I run into similar problems with newpxmath too. Thanks again! – palatinouser1 Sep 20 '19 at 16:27
  • 1
    @palatinouser1 The above code could be simplified to \def\setSYdimens{...} but this turns out revealing a hidden bug in newpxmath. If weren’t for your question I would not notice this bug: Changing dimensions in the symbol font also changes dimensions in the extensible font. I will send an email to the maintainer to report this bug. – Ruixi Zhang Sep 20 '19 at 16:40
  • Very nice answer! – Oleg Lobachev Sep 20 '19 at 19:43

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.