1

I noticed the space between \frac{}{} changes depending on where it shows up in the expression.

And also depending on font used. Why does this happen? It does not look very good.

Here is an example, using default font

enter image description here

The first case, the space is the same between the numerator and the dash, and the numerator and the dash. In the second case, the space is not the same. It is the same expression in both cases.

The code for the above is

\documentclass[11pt, notitlepage]{article}
\usepackage{amsmath}
\usepackage[mathit=sym,bold-style=ISO]{unicode-math}        
\begin{document}

\[
y \left(x \right) = -\left(\int \frac{\sin \left(x \right) g \left(x \right)}{x^{\frac{3}{2}}}d x \right) \cos \left(x \right)
\]

\[
y \left(x \right) = \frac{-\left(\int \frac{\sin \left(x \right) g \left(x \right)}{x^{\frac{3}{2}}}d x \right) \cos \left(x \right)}{\sqrt{x}}
\]

\end{document}

Things get a little worst, when I use the following font. Now there is too much wasted space between the numerator and the dash. The space is not the same between the dash.

enter image description here

The code for the above is

\documentclass[11pt, notitlepage]{article}
\usepackage{amsmath}

\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}[Scale=MatchLowercase]
\usepackage{Baskervaldx} %changed to thisbelow
\setmainfont{Baskervaldx}[
  UprightFont=*-Reg,
  ItalicFont=*-Ita,
  BoldFont=*-Bol,
  BoldItalicFont=*-BolIta,
]

\begin{document}

\[
y \left(x \right) = -\left(\int \frac{\sin \left(x \right) g \left(x \right)}{x^{\frac{3}{2}}}d x \right) \cos \left(x \right)
\]

\[
y \left(x \right) = \frac{-\left(\int \frac{\sin \left(x \right) g \left(x \right)}{x^{\frac{3}{2}}}d x \right) \cos \left(x \right)}{\sqrt{x}}
\]

\end{document}

In both cases, the exponent font size could be made little smaller actually. It seems to be be the same size as the letter itself it is being raised to this exponent.

Is there a font that does this right? Keeping the same space all the time?

TL 2020

8
  • 2
    Just out of curiosity: Why do you write \left(x \right) everywhere? (x) is not only simpler, it also prevents the spacing mess that occurs with \left(x \right)...
    – Mico
    Nov 28, 2020 at 18:27
  • @Mico Sorry, forgot to mention this is auto-generated code. CAS always generate \left( .. \right). I add \usepackage{mleftright} \mleftright in my preamble to fix the spacing around ( ). But for the purpose of this question, I did not add this as it makes no difference to the fraction spacing issue I am asking about and wanted to keep MWE as simple as possible.
    – Nasser
    Nov 28, 2020 at 18:31
  • 1
    In TeX you got the four different styles for maths, \displaystyle, \textstyle, \scriptstyle, and \scriptscriptstyle. In both cases your exponents are in \scripscriptstyle, but the base is once in \textstyle, and once in \scriptstyle. You can alter the sizes of the different styles by using \DeclareMathSizes.
    – Skillmon
    Nov 28, 2020 at 21:50
  • I would have used x^{3/2} \frac always looks bad in exponents or subscripts. Nov 28, 2020 at 22:42
  • @JohnKormylo thanks for the suggestion,. I tried xfrac instead of frac, but I do not like the output. Here is MWE..
    – Nasser
    Nov 28, 2020 at 23:52

1 Answer 1

2

(posting this answer so that the posting may be considered as having an "official answer")

Some preliminary comments and observations:

  • In a displayed equation, the default math style is \displaystyle.

  • When TeX is in display-style math mode, \int generates the "large" size of the integral symbol, and \frac employs textstyle for the contents of the numerator and denominator. Letters and other symbols have the same size in display and text style; the main difference between the two styles lies in the size of "variable-size symbols" such as \sum, \prod, and \int.

  • When TeX is in text-style math mode, \int generates the "regular" size of the integral symbol, and \frac employs \scriptstyle for the contents of the numerator and denominator. In \scriptstyle, letters and symbols are 30% smaller than in \textstyle.

Armed with these pieces of knowledge, we can explain the output of your sample code.

  • In the first case (also shown in the first line below), \displaystyle is in effect; hence, a "large" integral symbols is generated, and the numerator and denominator terms are typeset in text style.

  • In the second case (also shown in the second line below), the code of the first example occurs in the numerator of a \frac expression; hence, text style is in effect. Therefore, the "regular" size of the integral symbol will be produced, and the numerator and denominator of the "inner" \frac term will be typeset in \scriptstyle.

  • To force the contents of the numerator of the "outer" \frac term to be typeset in \displaystyle rather than in \textstyle, it suffices to insert the directive \displaystyle at the start of the numerator term; see the third row below.

Aside: In the following code, I've replaced x^{\frac{3}{2}} with x^{3/2} in order not to make the denominator term needlessly (and distractingly) large.

enter image description here

\documentclass[11pt]{article}
\usepackage{amsmath} % for 'align*' environment

\usepackage[mathit=sym,bold-style=ISO]{unicode-math}
\setmainfont{Baskervaldx}[
    UprightFont   = *-Reg,
    ItalicFont    = *-Ita,
    BoldFont      = *-Bol,
    BoldItalicFont= *-BolIta]
\setmathfont{Asana Math}[Scale=MatchLowercase]

\newcommand\blurb{-\left( \int \frac{\sin(x)\,g(x)}{x^{3/2}}\,dx \right) \cos x}

\begin{document}
\begin{align*}
y (x) &= \blurb                  \\[1.5ex]
z (x) &= \frac{\blurb}{\sqrt{x}} \\
      &= \frac{\displaystyle\blurb}{\sqrt{x}}
\end{align*}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .