Aside from ConTeXt, it is also possible to include OpenType fonts in MetaPost labels if you use MetaPost through Lua(La)TeX.
As it was noted in the comments, thanks to Dohyun Kim the btex … etex
flags are now recognized by luamplib
, but in the recents versions it goes much further than that: luamplib
now also includes a textext
function that is pretty much the same as its namesake in MetaFun/ConTeXt.
Like the btex … etex
flags, textext()
(which takes a string of characters as argument) uses by default the fonts of the current Lua(La)TeX document, OpenType or not, to typeset the labels. But it has two big advantages on the btex … etex
flags:
- it allows the treatment of variables in labels; see Metapost label based on variable value;
- if you issue the
\mplibtextextlabel{enable}
instruction in the preamble, it is enough to give the string itself as argument to the label
commands; textext
is called to typeset it, but in the background. Very handy if you have a great bunch of labels to typeset!
So the following program:
\documentclass[12pt]{scrartcl}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
label(textext("Pythagorean addition: $a^2+b^2 = c^2$."), origin);
endfig;
\end{mplibcode}
\end{document}
gives exactly the same result as this:
\documentclass[12pt]{scrartcl}
\usepackage{unicode-math}
\setmainfont{XITS}
\setmathfont{XITS Math}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
label("Pythagorean addition: $a^2+b^2 = c^2$.", origin);
endfig;
\end{mplibcode}
\end{document}
Either way you get 12pt-sized OpenType text and math fonts from XITS (which are themselves adaptation of the STIX fonts) in the label:
btex
...etex
commands available in luamplib. I’m not sure if it’s in the pretest already but it’s worth a try.