lualatex / luamplib

generic TeX package - including MetaPost code in LuaTeX documents
http://ctan.org/pkg/luamplib
14 stars 11 forks source link

Separate \everymplib and \everyendmplib for different instances #102

Closed jemmybutton closed 2 years ago

jemmybutton commented 2 years ago

Currently global \everymplib and \everyendmplib are used with MetaPost code in all MetaPost instances. However, it is desirable to be able to have separate \everymplib and \everyendmplib for each MetaPost instance. At first glance, syntax like this, with an optional argument for instance name, like in the LaTeX environment, seems appropriate:

\everymplib[instanceName]{...}
\everyendmplib[instanceName]{...}

However, the implementation of \everymplib and \everyendmplib unlike that of the LaTeX mplibcode environment, employs plain TeX \def which makes it more difficult to add an optional argument. So it may make sense to keep plain TeX code intact and add multiple instance support in \everymplib and \everyendmplib for LaTeX separately somehow.

dohyunkim commented 2 years ago

I'm wondering whether #103 is a solution to your issue. Please let me know. When it turns out to be usable, then a new version will be released.

jemmybutton commented 2 years ago

Thank you! It works perfectly! The only thing I see which may be more convenient to have working differently is that now, afaiu, you have to set \everymplib and \everyendmplib for every instance, while in many cases it may not be necessary and setting them once without indicating a particular instance would be more straightforward. It seems like changing these lines like so:

  local everymplib    = luamplib.everymplib[instancename] or luamplib.everymplib[""]
  local everyendmplib = luamplib.everyendmplib[instancename] or luamplib.everyendmplib[""]

does just that.

dohyunkim commented 2 years ago

Yes. That seems to be reasonable. Just committed #104.

jemmybutton commented 2 years ago

Thank you so much!