My first approach to solve this would be simply to turn on the metafun
format provided by luamplib
, like this:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibsetformat{metafun}
\begin{mplibcode}
beginfig(1);
picture p;
p := outlinetext("BEST") scaled 10;
for i within p:
j := j + 1;
drawarrow pathpart i;
endfor;
endfig;
\end{mplibcode}
\end{document}
The metafun
format provides an outlinetext
macro, but unfortunately in my copy of TexLive 2023 it does not work. If I compile the above document with lualatex
, I get these error messages (and no output):
mplib warning: error in script: [string "mp.mf _outline_text(1,[===[BEST]===],[===[]===..."]:1: attempt to call a nil value (field 'mf_outline_text')
mplib warning: error in script: [string "mp.mf_get_outline_text(1)"]:1: attempt to call a nil value (field 'mf_get_outline_text')
So a second approach would be to define my own outlinetext
macro. The Context implementation is rather complex and deals properly with kerning and vertical movement and so on, but it is not too hard to make a version that ignores all these complexities and works ok for simple cases.
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
vardef outlinetext(expr s) =
save c, g, x; string c; picture g; numeric x;
image(
for i = 1 upto length s:
c := substring (i-1, i) of s;
g := glyph ASCII c of defaultfont scaled 1/64;
x := xpart lrcorner currentpicture;
for item within g:
draw pathpart item shifted (x, 0);
endfor
endfor
)
enddef;
beginfig(1);
% defaultfont := "pplri8r"; % <- uncomment to try another font
ahangle := 30;
picture p; p = outlinetext("BESTA&?") scaled 10;
for item within p:
drawarrow pathpart item;
endfor;
endfig;
\end{mplibcode}
\end{document}
Compile this with lualatex
to get a PDF that looks like this:
glyph
works as advertised. It is no different in LuaLaTeX than pdfLaTeX or LaTeX (or the TeX equivalents). To say it doesn't work under LuaLaTeX just seems misleading. Having read one of your answers, I think you rather want it to work without needing to runmpost
, but that was far from obvious when reading your question here. I learnt something playing withglyph
, but I would never have posted it!glyph
not working in LuaLaTeX, now that I check the example from MP manual:glyph "Dcaron" of "ec-lmr10" scaled .2
, it works, I just couldn't get any of the examples where the glyph comes from a picture (e.g.btex $\sum_{x=0}^{10}x^2$ etex
) to work and wrongly assumed that the problem is inglyph
.