# Shifting underbrace with lualatex and unicode-math

Compiling this example:

\documentclass{scrartcl}

\usepackage{mathtools}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}

\begin{document}
\begin{equation*}
\symcal{L}_{\text{QED}} =
- \underbrace{\frac{1}{4} F_{\mu\nu} F^{\mu\nu}}_\text{Photon}
+ \underbrace{\bar{\psi} (i \gamma^\mu\partial_\mu - m) \psi}_\text{Dirac}
- \underbrace{eQ\bar{\psi} \gamma_\mu \psi A^\mu}_\text{WW}
\end{equation*}
\end{document}


using lualatex from TeXLive 2016, the second \underbrace is shifted to the left. This only seems to happen when the first thing in the \underbrace is \bar.

Even adding something ridiculous like \hphantom{} resolves the issue.

Only \underbrace{\bar{\psi} (i \gamma^\mu\partial_\mu - m) \psi}_\text{Dirac}:

Adding an \hphantom{} before \bar

A “more minimal” example, to be compiled with luatex

\input ifluatex.sty
\ifluatex
\fi

\font\mf="[latinmodern-math.otf]"
\textfont1=\mf \scriptfont1=\mf \scriptscriptfont1=\mf
\protected\def\underbrace#1{%
\mathop{\Umathaccent bottom 7 1 "023DF\relax {#1}}\limits
}
\protected\def\hat{\Umathaccent fixed 7 1 "00302\relax}

$\underbrace{z+w}_y$\qquad$\underbrace{\hat{z}+w}_{y}$

\bye


If compiled with xetex, the output is

Changing the math font to xits-math.otf doesn't change the situation. With Asana-Math.otf the output is different:

• This also happens with other accents such as \hat... it should be reported as a bug. – Andrew Swann Aug 8 '16 at 8:42
• it's enough to use {} not sure yet whether it's a problem in unicode-math or luatex (it's not mathtools, you get the same if you use $ and just load amstex for \text – David Carlisle Aug 8 '16 at 8:44 • It is unicode-math under lualatex that is the problem. Minimal example: \documentclass{article} \usepackage{unicode-math} \begin{document} \begin{displaymath} \underbrace{ABCDEFGH}_P + \underbrace{\bar a IJKLMNOP}_D \end{displaymath} \end{document}. Under XeLaTeX it is fine. – Andrew Swann Aug 8 '16 at 9:46 • @HenriMenke Indeed LuaLaTeX without unicode-math works fine. – Andrew Swann Aug 8 '16 at 10:31 • The problem still seems to exist in TeX Live 2017. Bug report for unicode-math: github.com/wspr/unicode-math/issues/391 – Socob Oct 23 '17 at 9:59 ## 1 Answer As a temporary workaround, you could add the empty brace group proposed by David Carlisle in the definition of the over- and underbraces. \documentclass{article} \usepackage{amstext} \usepackage{unicode-math} \ExplSyntaxOn \cs_set:Nn \__um_set_math_overunder:Nnnn { \cs_gset_protected_nopar:Npx #1 ##1 { \mathop { \__um_accent:nnn {#2} {#3} {#4} {{}{##1}} } % see the empty braces? \limits } } \ExplSyntaxOff \begin{document} \[ \symcal{L}_{\text{QED}} = - \underbrace{\frac{1}{4} F_{\mu\nu} F^{\mu\nu}}_\text{Photon} + \underbrace{\bar{\psi} (i \gamma^\mu\partial_\mu - m) \psi}_\text{Dirac} - \underbrace{eQ\bar{\psi} \gamma_\mu \psi A^\mu}_\text{WW}$
\end{document}


• Better: \__um_accent:nnn {#2} {#3} {#4} {{}{##1}}, so the empty group will not interfere with the spacing at the beginning of the argument (for instance, if it's an operator). – egreg Aug 8 '16 at 10:33