[metapost] luamplib + textext + empty string = bug ?

Toby Thurston thurston at eml.cc
Wed Sep 15 22:31:42 CEST 2021


Here is another possible small bug in the otherwise excellent `luamplib` implementation of Metapost.  Consider this minimal program:

prologues := 3;
outputtemplate := "%j%c.%{outputformat}";
beginfig(1);
    label(mpversion, origin);
    label("", 10 up);
endfig;
end.

This compiles without error and produces a tiny eps file saying "2.00" and gives this log

This is MetaPost, version 2.00 (TeX Live 2021) (kpathsea version 6.3.3)  15 SEP 2021 21:14
**bug.mp
(/usr/local/texlive/2021/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2021/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./bug.mp [1{psfonts.map}<cmr10
.pfb>] )
1 output file written: bug1.eps

If I wrap this up in luamplib like this

\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
beginfig(1);
    label(mpversion, origin);
    label("", 10 up);
endfig;
\end{mplibcode}
\end{document}

it also compiles without error and produces a tiny PDF saying "2.00".   But if I add the textext option like this:

\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    label(mpversion, origin);
    label("", 10 up);
endfig;
\end{mplibcode}
\end{document}

Then it fails with an error, no output it produced, and I see this in the log

...texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:22: bad argument #2 
to 'format' (no value)
stack traceback:
[C]: in function 'string.format'
...texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:22: in upvalue 'war
n'
...texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:257: in upvalue 're
porterror'
...texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:313: in function <.
..texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:309>
(...tail calls...)
...texlive/2021/texmf-dist/tex/luatex/luamplib/luamplib.lua:656: in field 'proc
ess_mplibcode'
[\directlua]:1: in main chunk.
<inserted text> BAD

Obviously I can avoid the error by *not* using an empty string, but since it works with plain MP it was a bit surprising that the textext option trips over it.   The original use case was an if ... else ... fi block in a loop where I only wanted a label for some values of the loop variable.

-  In luamplib, I get the same error if I put   TEX("")   or  textext("").
-  In plain MP with input TEX there is no error with  TEX("")


thanks and best wishes, Toby Thurston
   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/metapost/attachments/20210915/ed4fbcff/attachment.html>


More information about the metapost mailing list.