[metapost] Beginners question

Laurence.Finston at gmx.net Laurence.Finston at gmx.net
Tue Sep 12 20:23:54 CEST 2023


> draw_command --> string_expression with_infont_optional withstyle_optional

That should be:  draw_command --> DRAW string_expression with_infont_optional withstyle_optional

Someone must be interfering with my messages today.

> Gesendet: Dienstag, 12. September 2023 um 20:20 Uhr
> Von: Laurence.Finston at gmx.net
> An: Kein Empfänger
> Cc: "Metapost List" <metapost at tug.org>
> Betreff: Re: [metapost] Beginners question
>
> > Also known as the commutative and associative laws of arithmetic,
> 
> Or something.
> 
> > Gesendet: Dienstag, 12. September 2023 um 20:18 Uhr
> > Von: Laurence.Finston at gmx.net
> > An: "Metapost List" <metapost at tug.org>
> > Betreff: Aw: Re: [metapost] Beginners question
> >
> > > 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 primary, secondary, tertiary, expression structure is for the purpose of establishing the priority of operations.  For example, it performs the magic that causes multiplications to be performed before additions in an expression like this:
> >
> > 2 * 3 + 4 * 5.  Also known as the commutative and associative laws of arithmetic, as all other victims of the New Math will tell you.
> >
> > Knuth, of course, hand-coded the parser for MF in machine code, thinly disguised as Pascal.  A parser generator such as Bison provides other means for setting the priority of operations.  I used Bison for 3DLDF, but imitated Knuth's rules of syntax as closely as possible, using the primary, secondary, etc., structure for the rules.  When running the program with the --bison-trace option, with enables debugging, it can be fascinating to watch how the rules are matched.  I learned a lot by implementing the parser this way.
> >
> > > draw "my text to be output" infont "Meta Pro" withstyle "regular";
> >
> > The syntax for this in Backus-Naur format would be something like this (primitives in all capitals):
> >
> > draw_command --> string_expression with_infont_optional withstyle_optional
> >
> > with_infont_optional --> (Empty) | WITH_INFONT string_expression
> >
> > withstyle_optional --> (Empty) | WITHSTYLE string_expression
> >
> > I've implemented more rules like this than you can shake a stick at.
> >
> > > Gesendet: Dienstag, 12. September 2023 um 19:44 Uhr
> > > Von: "Patrick Gundlach" <patrick at gundla.ch>
> > > An: metapost at tug.org
> > > Betreff: Re: [metapost] Beginners question
> > >
> > >
> > >
> > > > 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
> > >
> > >
> > >
> > > --
> > > http://tug.org/metapost/
> > >
> 
> --
> http://tug.org/metapost/
>



More information about the metapost mailing list.