[Tex/LaTex] Brackets and parenthesis from different fonts in unicode-math

bracketsunicode-math

I am using the unicode-math package to use letters from the body font in math typesetting. The font I am using (Arno Pro) works quite well for this, because it includes a full Greek alphabet on top of the Latin one, but it is not a math font. For characters not included in the font, I am using XITS Math as fallback.

However, some punctuation characters (such as a comma, parenthesis, square brackets and curly brackets) differ significantly between the fonts, so I took those from the body font as well. This works great for the smallest bracket size, but the font does not support the auto-scaling for brackets. Is it possible to instruct unicode-math to use brackets (and parentheses and curly brackets) from one font for the small size, and fall back to an other font for other sizes?

I can switch between fonts like so:

% Use XITS Math for    [     ]     (     )     {     }
\setmathfont[range={"005B,"005D,"0028,"0029,"007B,"007D}]{XITS Math}

% Use Arno Pro for     [     ]     (     )     {     }
\setmathfont[range={"005B,"005D,"0028,"0029,"007B,"007D}]{Arno Pro}

Defining these as new commands makes it slightly easier to handle multiple fonts, but switching does not work in math mode, and even if it did, it would still require manually selecting the correct font for different brackets and parentheses. Does unicode-math offer a way to use one font for the bigger brackets, and an other for the normal size?

An other workaround I found, is to use a proper math font in math mode, for all characters, but set the small brackets using the text font (via \text{\{}). This is a nicer solution, but it still not as nice as I had hoped. Also, this might impact spacing around the bracket.

Best Answer

Attacking the problem from a completely different angle... if your font does not support auto-scaling of brackets etc., are you open to the scalerel package which has a \scaleleftright[]{}{}{} command for mimicking the scale-to-size feature I think you are seeking? In the case of scalerel, it takes the base character and scales it directly to match the height of the target object. But here's the trick: the optional argument is a width limiter, to prevent the scaled object from getting too wide. In this example, I set that argument to 2ex, so that no matter how big the character is scaled, it never gets wider than 2ex.

Alternatively, there is \stretchleftright command which does a vertical stretch, but in that case, it has an aspect-ratio limiter as the optional argument, so that the aspect ratio of the stretched symbol never exceeds the amount given in the optional argument.

In all cases, the auto-scaled object is based on the original font symbol.

\documentclass{article}
\usepackage{scalerel}
\parskip 2ex
\begin{document}
\(
\scaleleftright[2ex]{[}{ x^2}{]}
\scaleleftright[2ex]{(}{ x^2}{)}
\scaleleftright[2ex]{\{}{ x^2}{\}}
\)

\(
\scaleleftright[2ex]{[}{%
\begin{array}{c}%
 x^2\\
y^2\\
\end{array}}{]}
\scaleleftright[2ex]{(}{%
\begin{array}{c}%
 x^2\\
y^2\\
\end{array}}{)}
\scaleleftright[2ex]{\{}{%
\begin{array}{c}%
 x^2\\
y^2\\
\end{array}}{\}}
\)

\(
\scaleleftright[2ex]{[}{%
\begin{array}{c}%
 x^2\\
y^2\\
z^2\\
\end{array}}{]}
\scaleleftright[2ex]{(}{%
\begin{array}{c}%
 x^2\\
y^2\\
z^2\\
\end{array}}{)}
\scaleleftright[2ex]{\{}{%
\begin{array}{c}%
 x^2\\
y^2\\
z^2\\
\end{array}}{\}}
\)

\end{document}

enter image description here

Just for comparison, below I use the \stretchleftright command, rather than the \scaleleftright

enter image description here

Related Question