# Unicode-math: How to get a nice function restriction (despite shorter delimiters and lower subscript baseline)?

I'm using function restriction notation like here, but after switching to XeLaTeX with unicode-math I noticed that it looks slightly odd. Here's a minimal working example

\documentclass{minimal}
\usepackage{unicode-math}
\begin{document}
$\left. \frac{dy}{dx} \right\vert_{x=5} \quad \left. y \right\vert_{x=5}$
\end{document}


Here's the output with unicode-math:

and here it is without unicode-math:

Apparently with unicode-math delimiters are shorter and the baseline of subscripts is lower.

Ideally I would like the bottom of the vertical bar to extend to the baseline of the subscript, and at the same time keep the automatic scaling of the delimiter wrt. the expression on the left of it.

How could I achieve this?

In case it's relevant: I'll be using texgyrepagella-math font.

• Some of this is font-related, and some of it can be adjusted by looking at font dimensions... unfortunately I don't have a good interface to them, yet! Feb 5, 2018 at 14:11
• Side note: Don't use the minimal documentclass :) Feb 5, 2018 at 14:43
• @PhelypeOleinik thanks, I didn't know. But I checked and it doesn't seem to make much of a difference in the output in this case. Feb 5, 2018 at 15:32
• @Michael No, it doesn't make a difference in this case. Just a question of good practice :) Feb 5, 2018 at 15:38

In case anyone is interested, this is the hack I came up with myself, combining things from this and this answer:

\documentclass{article}

\newcommand{\restr}[2]{%
\mathchoice{%
\restriction{#1}{#2}{\displaystyle}%
}{%
\restriction{#1}{#2}{\textstyle}%
}{%
\restriction{#1}{#2}{\scriptstyle}%
}{%
\restriction{#1}{#2}{\scriptscriptstyle}%
}%
}

\newlength{\totbarheight}
\newlength{\bardepth}

\newcommand{\restriction}[3]{%
\settodepth{\bardepth}{$$#3 #1$$} %
\settoheight{\totbarheight}{$$#3 #1$$}%
\addtolength{\totbarheight}{1ex}% make it somewhat higher
\addtolength{\bardepth}{0.7ex}% make it extend somewhat further down
{#1 %
\rule[-\bardepth]{0ex}{\totbarheight} %invisible rule to force the next \vrule to be bigger
\mkern 2mu \vrule width 0.14ex \mkern 2.5mu}
{\addtolength{\bardepth}{-0.2ex}%make shorter to lift the baseline of the subscript
$$\restr{\frac{dy}{dx}}{x=2} 5\restr{y}{x=a}$$
$\restr{\frac{dy}{dx}}{x=2} 5\restr{y}{x=a}$