lualatex / luamplib

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

About infont, textext and luamplib: a suggestion #35

Closed franckpastor closed 10 years ago

franckpastor commented 10 years ago

Hello,

Currently, each time I use luamplib for my MetaPost drawing, I use the textext macro inspired from its ConTeXt namesake that you recently introduced to typeset labels. I think it's one of the most useful features of this package. In fact, I'm using it so frequently that I would like not having to "write" it. To be more precise: one of the handy features of the latexmp package (by Jens-Uwe Morawski) I load each time I have to use standalone MetaPost, is to replace the infont operator by the textext macro. Quoting the latexmp manual:

If one uses a string in the METAPOST label macro then this string will be converted in a picture using the `infont` operator. The typesetting capablities of `infont` are very limited, thus it makes sense to replace it with `textext`. `latexMP` provides an alternative version of the internal METAPOST macro `thelabel`. Compared to the original macro it uses `textext` instead of infont to typeset strings. The `thelabel` replacement provided by latexMP has to be activated using `textextlabel=enable` in `setupLaTeXMP`. Now the string can be given to label directly without to use `textext` anymore.

So, if I write in the preamble of a MetaPost file setupLaTeXMP(textextlabel=enable);, writing label("my text", (a, b)) thereafter is exactly the same as label(textext("my text"), (a, b)), which saves a non-negligible amount of typing.

It seems that ConTeXt has a similar behavior when MetaPost code is run into it: quoting the Metafun manual, page 42:

When you run inside CONTEXT (as we do here) there is no difference between `infont` and the TEX methods. This is because we overload the `infont` operator and also pass its content to TEX. Both `infont` and `btex` use the macro textext which is intercepted and redirects the task to TEX. This happens in the current run so there is no need to pass extra information about fonts.

I personally think it would be a very good thing if luamplib proposed something like that. For example, something like \mplibtextextlabel{enable} (latexmp-like) which would allow the user to replace the infont operator by the textext macro. Is it reasonable to think so, or would there be problems I didn't think of if this feature was to be implemented?

Many thanks for having read this,

Franck Pastor

franckpastor commented 10 years ago

An useful link I was not able to insert into the previous message (my current browser is not supported by github and so the Edit button is not activated): the latexmp manual.

dohyunkim commented 10 years ago

I just have pushed a new version.

The stategy I have chosen is more aggressive than that of latexmp but similar to context. While latexmp redefines thelabel macro only, context and luamplib redefine infont operator, a primitive of metapost. So, with \mplibtextextlabel{enable}, even the string tokens in, say, boxit.mybox("my box"); will also be typeset by TeX.

There's some drawback however: be careful about char ... infont ... syntax. For instance, draw char 1 infont defaultfont will raise a TeX error. Currently I have no general solution to this issue.

franckpastor commented 10 years ago

I've downloaded and installed the 2.6.0 version of luamplib, and \mplibtextextlabel seems to work fine. Again, thanks for having implemented this.

I've read that \fontsize has been redefined as well. Is this redefinition related to \mplibtextextlabel?

dohyunkim commented 10 years ago

@franckpastor Yes, there's a close relation. Without fontsize redefinition, a code as follows will raise a metapost error:

picture pic; pic:= "A" infont "cmr10";
draw origin--(fontsize fontpart pic, 0);

As infont operator is now the same as textext, pic here does not have fontpart. So the latter returns empty string only, and fontsize fails to find a tfm font.

franckpastor commented 10 years ago

OK! Didn't know about that. One last question. In the updated doc's part concerning \mplibtextextlabel, it is said: "To typeset string labels with current TEX font, assign empty string to defaultfont, that is defaultfont:=””;." Why must we do that? I thought that the default font always was the current TeX font with luamplib?

franckpastor commented 10 years ago

To be more precise: like the btex … etex flags, the textext() function selects (as it should) the current TeX font as default font for the picture. Since the point of \mplibtextextlabel{enable} is to replace infont by textext(), I would expect that each string given thereafter as argument to labelling commands (label, thelabel, etc.) would be also typesetted automatically with the current TeX font, without having to specify defaultfont:="";. I'm probably missing something, but what?

dohyunkim commented 10 years ago

@franckpastor I will think on it today. Currently I am inclined to adopting your suggestion. It's quite easy: just removing if ... fi part in the code redefining infont operator.

dohyunkim commented 10 years ago

@franckpastor Adopted your suggestion and just pushed revised code. When \mplibtextextlabel is enabled, every text label will be typeset with current TeX font.

franckpastor commented 10 years ago

Perfect! It was the right thing to do, we can be sure of that.