Open thruston opened 8 years ago
Thanks for the report. Commit #64 is an attempt to address the issue. I'll upload to ctan after several days of testing.
Since luamplib v2.20 (TeX Live 2019), which was a huge internal change from the previous version, the example code shown above does not work anymore. I am currently trying to tackle the issue once again, but no success yet. So let me suggest another solution:
\documentclass{article}
\usepackage{luamplib}
\newbox\mympbox
\setbox\mympbox\hbox{%
\begin{mplibcode}
beginfig(1);
draw unitsquare scaled 4 withcolor .67 red;
endfig;
\end{mplibcode}}
\def\redbox{\ensuremath{\mathop{\copy\mympbox}}}
\begin{document}
% same as MWE
\end{document}
Now that beginfig(1)
has been processed in advance by \setbox...\hbox
, beginfig(3)
does not contain nested beginfig(1)
any more.
thanks for the work around -- and glad to know you are still trying to tackle the issue.
With recent version of luamplib, independent mplib instances can coexist with each other, running side by side.
So, just adding an mplibcode instance name, say [nested]
as follows, in the \redbox
definition seems to solve the issue.
diff --git a/bug63ori.tex b/bug63.tex
index 1423e12..222a249 100644
--- a/bug63ori.tex
+++ b/bug63.tex
@@ -1,6 +1,6 @@
\documentclass{article}
\usepackage{luamplib}
-\newcommand{\redbox}{\ensuremath{\mathop{\begin{mplibcode}beginfig(1);draw unitsquare
+\newcommand{\redbox}{\ensuremath{\mathop{\begin{mplibcode}[nested]beginfig(1);draw unitsquare
scaled 4 withcolor .67 red;endfig;\end{mplibcode}}}}
\begin{document}
\noindent
yes, looks good to me too. Many thanks.
With just released version 2.34.1, which will be distributed via TeX Live tomorrow, we can obtain the same result very efficiently.
\begingroup
\setbox0=\hbox{%
\begin{mplibcode}
beginfig(1);
draw unitsquare scaled 4
asgroup "" withgroupname "redbox"
withcolor .67red;
endfig;
\end{mplibcode}%
}
\endgroup
\newcommand{\redbox}{\ensuremath{\mathop{\usemplibgroup{redbox}}}}
Of course, box 0 will be discarded after endgroup
. But, as the transparency group object redbox
has already been written to PDF, it can be referred to even after the endgroup
.
Even if the redbox is used hundreds times, PDF file size will remain quite small. Rather than replicating the same drawing code hundreds times, usemplibgroup
will write to the PDF only the reference to the same PDF object.
I'm trying to use luamplib to define a new symbol, and it works ok in normal math formulas, but I've run into a problem when I try to use it in a formula inside a label in another
mplibcode
environment. Here's my example that shows the problem.In the last math display the whole mplibcode picture is being replaced by the symbol.