[metapost] Beginners question

Patrick Gundlach patrick at gundla.ch
Tue Sep 12 19:44:45 CEST 2023



> Am 12.09.2023 um 18:48 schrieb Laurence.Finston at gmx.net:
> 
>> I have my own routine that typesets a text and gets back a hbox with the text.
> 
> I don't quite understand this.  What language is your routine in and where is it used?  MetaPost has no concept of hboxes (or vboxes for that matter).


This is the software: https://github.com/speedata/publisher/ 

It is based on LuaTeX and I use mplib similar to luamplib (https://github.com/lualatex/luamplib), but without the \backslashes stuff.

I run metapost and collect the objects and paths returned by mplib.execute() and from that I create whatsits/pdf_literal nodes with the PDF instructions. The fonts are rendered by a different sub system (also LuaTeX) and returned as glyph nodes. These are packed in a hbox and also added to the node list which is then passed to tex.shipout().

So my task is to have a macro in metapost which calls the typesetter to return a box and use these dimensions for the metapost picture. When rendering, I need to inject the hbox with the text at the right place (both of these parts work fine).

Mow my problem is (was) the metapost macro part. 

I came up with a user interface (a macro) such as this:

draw mytext( "my text to be output", "Meta Pro", "regular");

but I thought it would be nicer to have a macro like this:

draw "my text to be output" infont "Meta Pro" withstyle "regular";

(I've implemented the first one but failed for the second one)

Aditya has provided another suggestion which seems to be the 'ConTeXt style' with flexible key value pairs which also looks good. And I still need to understand why the implementation from Taco fails with my code, but this is on my todo list.


So, I have most of the parts running and they are working fine, I am still struggling with the correct usage of the def/vardef/primarydef etc. macros from metapost. But I am on my way to learn these.


> "The MFbook" lesen schadet nicht. (Reading "The MFbook" won't do you any harm.)


Das werde ich machen (I will do so).

Thanks 
  Patrick





More information about the metapost mailing list.