lualatex / luamplib

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

Featurerequest: \inputmpcode #107

Open Reissner opened 1 year ago

Reissner commented 1 year ago

The idea is stolen from latex package 'listings': it provides a command \lstinputlisting{...}, which allows to read in a file containing the listing. So the file can be run and printed in parallel.

I would suggest to complement the environment mplibcode with the command \inputmcode reading in an mp file and executing it. That way one could avoid mixing tex and mp in a single file. I have highlighter in my editor which get confused, if i to not separate the two languages.

dohyunkim commented 1 year ago

Why don't you use TeX's expansion functionality.

\newcommand*\inputmpcode[1]{\begin{mplibcode}input #1.mp\end{mplibcode}}
...
\inputmpcode{mympfile}

The above definition at first line can go into luamplib.cfg as well.

Reissner commented 1 year ago

as such a good idea... but i feel i prefer a standardized way to do it. If I depend on a config, it is not portable. When I send a file to someone with just standard texlive with luamplib installed, it should work without config.

but just to test luamplib.cfg: shall it be in the package directory?

dohyunkim commented 1 year ago

as such a good idea... but i feel i prefer a standardized way to do it. If I depend on a config, it is not portable. When I send a file to someone with just standard texlive with luamplib installed, it should work without config.

Then the definition can go into .tex file.

but just to test luamplib.cfg: shall it be in the package directory?

Anywhere lualatex can read it is OK. In this respect, it is not different from other .tex or .sty files. The local directory is also OK, as a matter of course.

Reissner commented 1 year ago

I think, one shall in general avoid pollution the local directory with files. Also, an installation shall be plain to keep reproducibility. The best alternative if you don't follow my suggestion is writing the command into the tex file.

I think that the authors of the listings package added the according command was a good decision. I think it would be frequently used and avoids for the user to write the definition over and over into a tex file. Realization is very simple.