3

I'm running into an issue when using boxes in subscripts with unicode-math loaded.

I drafted the following MWE from my package actuarialsymbol. [Command \qx below puts subscripts on both sides of a symbol; the subscripts should be bottom aligned.]

\documentclass{article}
 \usepackage{unicode-math}

 \makeatletter
 \def\qx[#1]#2{
   \fboxsep=0pt % for debugging purposes
   \setbox\@ne\hbox{$\scriptstyle{#1}$}
   \setbox\thr@@\hbox{$\scriptstyle{#2}$}
   \ifdim \ht\@ne>\ht\thr@@
     \ht\thr@@=\ht\@ne
   \else
     \ht\@ne=\ht\thr@@
   \fi
   \vphantom{q}\sb{\fbox{\box\@ne}}%
   q\sb{\fbox{\box\thr@@}}%
 }
 \makeatother

\begin{document}

$\qx[t]{x}$

\end{document}

When compiling with xetex, the t and x on either side of q are at different heights:

enter image description here

Commenting out unicode-math, the subscripts are at the same height, as I would expect and as it works with pdftex:

enter image description here

Adding \the\ht\thr@@ or \the\ht\@ne before symbol building solves the positioning issue (but is clearly not a viable solution). Removing the call to \vphantom also solves the positioning issue.

I see in the documentation of unicode-math that there is some treatment of subscripts in unicode-math with xetex, but I'm honestly at lost as to what I might be doing wrong or how I should fix the issue.

Placement of subscripts using unicode-math. Is it XeTeX bug? seems closely related to my issue, but alas nothing there helped.

3

I can see the different shift when \vphantom is used. Curiously it disappears if one explictly choose \textstyle inside the \vphantom. It looks like another variant of the problem of leaking mathstyles and imho is probably a xetex problem and not unicode math.

\documentclass{article}
 \usepackage{unicode-math}


\makeatletter
 \def\qx[#1]#2{
   \fboxsep=0pt % for debugging purposes
   \setbox\@ne\hbox{$\scriptstyle{#1}$}
   \setbox\thr@@\hbox{$\scriptstyle{#2}$}
   \ifdim \ht\@ne>\ht\thr@@
     \ht\thr@@=\ht\@ne
   \else
     \ht\@ne=\ht\thr@@
   \fi
   \vphantom{q}\sb{\fbox{\box\@ne}}%
   q\sb{\fbox{\box\thr@@}}%
 }
\makeatother
\usepackage{tikz}
\begin{document}



\tikz[overlay]\draw[red] (0,-2.47003pt)--++(10cm,-2.47003pt);
$\vphantom{\textstyle q}\sb{t} q\sb{t}$

\tikz[overlay]\draw[red] (0,-2.47003pt)--++(10cm,-2.47003pt);
$\vphantom{q}\sb{t} q\sb{t}$

\tikz[overlay]\draw[red] (0,-2.47003pt)--++(10cm,-2.47003pt);
$\qx[t]{x}$


\makeatletter
 \def\qx[#1]#2{
   \fboxsep=0pt % for debugging purposes
   \setbox\@ne\hbox{$\scriptstyle{#1}$}
   \setbox\thr@@\hbox{$\scriptstyle{#2}$}
   \ifdim \ht\@ne>\ht\thr@@
     \ht\thr@@=\ht\@ne
   \else
     \ht\@ne=\ht\thr@@
   \fi
   \vphantom{\textstyle q}\sb{\fbox{\box\@ne}}%
   q\sb{\fbox{\box\thr@@}}%
 }
\makeatother

\tikz[overlay]\draw[red] (0,-2.47003pt)--++(10cm,-2.47003pt);
$\qx[t]{x}$



\end{document}

enter image description here

  • Adding \textstyle inside \vphantom in the macro seems like an entirely satisfactory solution. I can confirm it solves the issue. – Vincent Goulet Jun 14 '17 at 15:30
  • The following question is related: tex.stackexchange.com/questions/296177/…. It looks as if the problem was in part resolved in tl2017 but not completly. – Ulrike Fischer Jun 14 '17 at 15:55
  • Interestingly, I also notice that, say, $p_x$ and $p_x^2$ have their subscript at the same height with xetex and unicode-math. Probably related to the bug you link to, although I get this behaviour with TL 2017. – Vincent Goulet Jun 14 '17 at 18:53
  • It depends on the height/size of the subscript. "t" is a problem, "x" not. And I think that the bug has been only partially resolved. – Ulrike Fischer Jun 14 '17 at 21:44
1

I can't confirm the issue:

\documentclass{article}
\usepackage{ifxetex}
\ifxetex
  \usepackage{unicode-math}
\else
  \usepackage{lmodern}
\fi

\makeatletter
\def\qx[#1]#2{%
  \begingroup
  \sbox\z@{$\scriptstyle{#1}$}%
  \sbox\tw@{$\scriptstyle{#2}$}%
  \ifdim \ht\z@>\ht\tw@
    \ht\tw@=\ht\z@
  \else
    \ht\z@=\ht\tw@
  \fi
  \vphantom{q}\sb{\box\z@}%
  q\sb{\box\tw@}%
  \endgroup
}
\makeatother
\newcommand{\debugrule}{%
  \leavevmode
  \rlap{%
    \sbox0{$q_x$}\sbox2{$q$}%
    \dimen0=\dp0 \ifdim\dp2>\dp0 \dimen=\dp2\fi
    \vrule depth \dimen0 height \dimexpr0.1pt-\dimen0\relax width 2cm}%
}

\begin{document}

\debugrule$q_tq_x\qx[t]{x}$

\debugrule$\vphantom{q}_{q}q_x\qx[q]{x}$

\debugrule$\vphantom{q}_{t}q_x\qx[t]{x}$

\end{document}

The compilation with XeLaTeX yields

enter image description here

where the misalignment only appears when \vphantom{q}_t is used without the adjustment to the height.

  • I'm not sure why you mention not being able to confirm the issue: using your preamble, \debugrule$\qx[t]{x}$ yields a misaligned symbol. Actually, \debugrule$\qx[t]{x}$\qx[t]{x} even yields a misaligned first symbol... and correct second one. – Vincent Goulet Jun 13 '17 at 17:10
  • @VincentGoulet That's what I get. Maybe an issue due to outdated software? – egreg Jun 13 '17 at 17:19
  • @VincentGoulet I mean: I do get the misalignment with \fbox, but, as you see from the picture, there is good alignment without it. – egreg Jun 13 '17 at 17:43
  • Perhaps I'm being picky, but I would consider something like the first symbol of your third example as misaligned, if ever so slightly. I tested this on TL 2016 and 2017. – Vincent Goulet Jun 13 '17 at 18:34
  • @VincentGoulet That doesn't use \qx, as pointed out in the final paragraph. – egreg Jun 13 '17 at 19:06

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.