Re: Feature request: Access to MP variable values from TeX/LaTeX?
Esger Renkema via metapost <[email protected]> Thu, 23 Oct 2025 23:05:21 +0200
| Newsgroups | gmane.comp.tex.metapost |
|---|---|
| Message-ID | <sp5ywtw6ctvbykywmbee374vthxhf5opsz6g5kfla6aqjq6wuo@dqooa27hvl37> |
>Currently `luamplib` sets the values `\MPwidth` and `\MPheight` after
>each figure is processed to provide information about the bounding box,
>but would it be possible to get access to the value of other variables
>that MP has calculated?
I do not know if luamplib grants it, but if you have access to the
internal (in lua) metapost instance, you can use the mplib.get_numeric()
function that is mentioned on page 242 of the luatex manual.
>The `tkz-elements` package provides `\tkzUseLua` that lets you get at
>a Lua value, so maybe there is a generic Lua way of doing this?
Here is an example with minim-mp:
-----------------------------------------------
\documentclass{article}
\usepackage{minim-mp}
\def\MPvalue#1{\directlua {
local mp = require 'minim-mp'
local mpi = mp.instances[\the\mpi].instance
tex.sprint(mplib.get_numeric(mpi, '#1'))}}
\newmetapostinstance \mpi
\begin{document}
\runmetapost \mpi { n = 42; }
The value of n is \MPvalue{n}.
\end{document}
-----------------------------------------------
--
http://tug.org/metapost/