ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Emanuel Han via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Emanuel Han <emanuel@labonneheure.ch>
Subject: [NTG-context] Re: Working with layer sets with Metapost
Date: Sat, 17 Feb 2024 11:03:48 +0100	[thread overview]
Message-ID: <2D427F57-AC95-4A2C-92A2-AE3E047DBEA0@getmailspring.com> (raw)
In-Reply-To: <CAHy-LL-QUSeXWNM4V_9LB5zGPqVeWwV2M07Jk-vbG4s-eW05xw@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 9323 bytes --]

I think I could solve all the problems. Attached the finalized working example. I created the https://wiki.contextgarden.net/MetaPost#Layer_sets_as_individual_pages entry with it. Feel free to modify.

Cheers
Emanuel

On Feb. 16 2024, at 7:56 am, Mikael Sundqvist <mickep@gmail.com> wrote:
> Hi,
>
> not sure I get what you are missing. But you can try
> setbounds currentpicture to (fullsquare scaled 200) ;
> in base. And then do
> \dorecurse{5}{
> \startTEXpage[offset=1DK]
> \useMPgraphic{layerset#1}
> \stopTEXpage
> }
>
> if that is the looping you are after.
> /Mikael
> On Fri, Feb 16, 2024 at 6:54 AM Emanuel Han via ntg-context
> <ntg-context@ntg.nl> wrote:
> >
> > Resp. the solution should be such that each generated PDF page has the same dimension, the same background colour and a page number and the metapost content on each page has the same scaling factor.
> >
> > On Feb. 15 2024, at 11:10 pm, Emanuel Han via ntg-context <ntg-context@ntg.nl> wrote:
> >
> > Dear Mikael,
> >
> > I actually need to keep the \dorecurse mechanism of the mwe (from line 44 on), because I need the "setbounds currentpicture to TheFrame" and also because I need page numbering inside the MPpage, as done with draw textext(decimal(currentime)).
> >
> > So, how can I use the \useMPgraphic{layerset1} etc. inside the \dorecurse, assuming I name my layersets "layerset1", "layerset2", "layerset3" etc.?
> >
> > Emanuel
> >
> > On Feb. 15 2024, at 10:07 pm, Emanuel Han via ntg-context <ntg-context@ntg.nl> wrote:
> >
> > Dear Mikael,
> > thanks a lot!
> > this seems to be the solution! And it looks beatiful enough to me 😄
> > I'll try to port all my layers to this new method and see if I run into new problems again 😅
> >
> > Emanuel
> >
> >
> > On Feb. 15 2024, at 8:19 am, Mikael Sundqvist <mickep@gmail.com> wrote:
> >
> > Hi
> >
> > On Thu, Feb 15, 2024 at 1:03 AM Emanuel Han via ntg-context
> > <ntg-context@ntg.nl> wrote:
> > >
> > > Dear list,
> > >
> > > the attached .tex file is the minimal working example we discussed today in the online meeting.
> > >
> > > I realized that the approach of looping through k of p[k] is not fitting my needs, because it's not flexible enough.
> > >
> > > I need another approach, one which works with layer sets.
> > >
> > > I would stop using p as an array, because with the layer sets approach we don't have a fixed order of the layers.
> > >
> > > So the definition of the layers would be something like
> > >
> > > picture layerA;
> > > layerA:=image(
> > > label("Word 1", z1);
> > > );
> > >
> > > picture layerW;
> > > layerW:=image(
> > > label("Mot 2", z2);
> > > );
> > >
> > > picture layerM;
> > > layerM:=image(
> > > label("Parola 3", z3);
> > > );
> > >
> > > picture layerC;
> > > layerC:=image(
> > > label("Wort 4", z3+z1);
> > > );
> > >
> > > picture layerY;
> > > layerY:=image(
> > > label("Nummer 5", z2+z3);
> > > );
> > >
> > > picture layerU;
> > > layerU:=image(
> > > label("number 6", z2+z1);
> > > );
> > >
> > > After that, I would define layer sets and layer subsets. This will be done manually for each layer set and each layer subset.
> > > I don't know the proper syntax to do that. Let's assume we could use a variable type called "myset".
> > >
> > > myset layersubsetGamma;
> > > layersubsetGamma:={layerU,layerM};
> > >
> > > In my logic, the layers will be drawn in the order of their appearance within the {}. In the example, drawn content of layerM might cover drawn content of layerU.
> > >
> > > Contrary to a layer subset, each layer set will result in a PDF page, and thus the layer sets are related to each other by an inner order. That's why I would use an array variable here with [].
> > >
> > > I don't know how to append a set. In the following example, I assumed there would be a function myappend(<initial set>, <the things what the initial set should be appended with>)
> > >
> > > myset layerset[];
> > > layerset1 := {layerW,layerA};
> > > layerset2 := myappend{layerset1, layerY};
> > > layerset3 := myappend{layerset2, layersubsetGamma};
> > > layerset4 := myappend{layerset2, layerU};
> > > layerset5 := myappend{layerset4, layersubsetGamma};
> > >
> > > Finally, I would need each layerset[k] typeset on its own pdf page. And of course on each page k, only the layers which appear in the definition of the layerset[k] should be drawn on top of each other in the order as they appear in that definition.
> > >
> > > I'm very curious to hear your suggestions.
> > >
> >
> > Not beautiful, perhaps, but maybe something like this could work? I
> > think there is no way out of doing some manual work to tell what you
> > want included on each page.
> >
> > \startuseMPgraphic{base}
> > z1 = origin ;
> > z2 = (10,50) ;
> > z3 = (40,30) ;
> >
> > picture layerA;
> > layerA:=image(
> > label("Word 1", z1);
> > );
> >
> > picture layerW;
> > layerW:=image(
> > label("Mot 2", z2);
> > );
> >
> > picture layerM;
> > layerM:=image(
> > label("Parola 3", z3);
> > );
> >
> > picture layerC;
> > layerC:=image(
> > label("Wort 4", z3+z1);
> > );
> >
> > picture layerY;
> > layerY:=image(
> > label("Nummer 5", z2+z3);
> > );
> >
> > picture layerU;
> > layerU:=image(
> > label("number 6", z2+z1);
> > );
> > \stopuseMPgraphic
> >
> > \startuseMPgraphic{Gamma}
> > draw layerU ;
> > draw layerM ;
> > \stopuseMPgraphic
> >
> > \startuseMPgraphic{layerset1}
> > \includeMPgraphic{base}
> > draw layerW ;
> > draw layerA ;
> > \stopuseMPgraphic
> >
> > \startuseMPgraphic{layerset2}
> > \includeMPgraphic{layerset1} ;
> > draw layerY ;
> > \stopuseMPgraphic
> >
> > \startuseMPgraphic{layerset3}
> > \includeMPgraphic{layerset2} ;
> > \includeMPgraphic{Gamma} ;
> > \stopuseMPgraphic
> >
> >
> > \startuseMPgraphic{layerset4}
> > \includeMPgraphic{layerset2} ;
> > draw layerU ;
> > \stopuseMPgraphic
> >
> > \startuseMPgraphic{layerset5}
> > \includeMPgraphic{layerset4} ;
> > \includeMPgraphic{Gamma} ;
> > \stopuseMPgraphic
> >
> > \starttext
> >
> > \startTEXpage[offset=1DK]
> > \useMPgraphic{layerset1}
> > \stopTEXpage
> >
> > \startTEXpage[offset=1DK]
> > \useMPgraphic{layerset2}
> > \stopTEXpage
> >
> > \startTEXpage[offset=1DK]
> > \useMPgraphic{layerset3}
> > \stopTEXpage
> >
> > \startTEXpage[offset=1DK]
> > \useMPgraphic{layerset4}
> > \stopTEXpage
> >
> > \startTEXpage[offset=1DK]
> > \useMPgraphic{layerset5}
> > \stopTEXpage
> >
> > \stoptext
> >
> > /Mikael
> > ___________________________________________________________________________________
> > If your question is of interest to others as well, please add an entry to the Wiki!
> >
> > maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> > archive : https://github.com/contextgarden/context
> > wiki : https://wiki.contextgarden.net
> > ___________________________________________________________________________________
> >
> > ___________________________________________________________________________________
> > If your question is of interest to others as well, please add an entry to the Wiki!
> >
> > maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> > archive : https://github.com/contextgarden/context
> > wiki : https://wiki.contextgarden.net
> > ___________________________________________________________________________________
> >
> > ___________________________________________________________________________________
> > If your question is of interest to others as well, please add an entry to the Wiki!
> >
> > maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> > archive : https://github.com/contextgarden/context
> > wiki : https://wiki.contextgarden.net
> > ___________________________________________________________________________________
> >
> > ___________________________________________________________________________________
> > If your question is of interest to others as well, please add an entry to the Wiki!
> >
> > maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> > webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> > archive : https://github.com/contextgarden/context
> > wiki : https://wiki.contextgarden.net
> > ___________________________________________________________________________________
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive : https://github.com/contextgarden/context
> wiki : https://wiki.contextgarden.net
> ___________________________________________________________________________________
>


[-- Attachment #1.2: Type: text/html, Size: 12285 bytes --]

[-- Attachment #2: layer_sets.md --]
[-- Type: application/octet-stream, Size: 3093 bytes --]

The following ConTeXt code example can be used to create a series of layered Metapost graphics and generate multiple pages with different combinations of these layers. Each page represents a different composition of the defined layers. Use cases are when you need to compose manually your layer sets. 

#### Base or Invisible Layer
The code begins by defining a base or invisible layer called "base" using the `\startuseMPgraphic` command. In this layer, various components are defined, such as paths, colors, and coordinates. These components will be used to draw the images in subsequent layers, but they're not drawn yet, thus this layer is "invisible".

#### Layer Definitions
After defining the base layer, several other layers are defined using the `\startuseMPgraphic` command. Each layer is given a unique name, in our example the names are such as "layerA" "layerW" or "layerM". These layers are created as images using the `picture` environment. Each image consists of drawn elements. In our example, the elements are filled squares with a specific color and a label.

#### Finishing Layer
The purpose of the finishing layer in our ConTeXt code is to add the final touches to the drawn layers and to clip the graphic to the same frame. It also includes the addition of page numbering to each page with the help of a Metapost variable, in our case "mypagenumber". We need this method because apparently, it is not possible to use the ConTeXt page numbering on a Metapost page. The finishing layer needs to be applied after drawing all the other layers.

#### Layer Sets
The before defined layers can be "set" (selected and combined) manually together, to become a layer set. They are layered on top of each other according to the order of appearance. The last layer is put on top of (and might cover) the previous one. 
Some subgroups or intermediate results of our "setting" or "putting together" will be reused again during the process. Selected intermediate results will be shown as such on individual pages, like a photo documentation of your setting procedure. Other intermediate results will be reused without ever being shown on an individual page. To be spared from doing such steps over and over again, they are stored, either as layersetpage plus a number, as a mere layerset, or as a layer subset.

All of them are defined using the `\startuseMPgraphic` command. Each of them includes a specific set of the previously defined layers (or if you want, also drawn elements, as the "special!" label in layersetpage4). The layersets which are shown as a page are numbered, starting from one.

#### Drawing the Pages
Finally, the code uses a loop to draw each layerset page onto its own page using the `\dorecurse` command. The loop iterates from 1 to a manually defined number, and for each iteration, it uses the `\useMPgraphic` command to draw the corresponding layersetpage, to which it is also passing the Metapost variable "mypagenumber".

The resulting output is a series of pages, each displaying a different selection and combination of the defined layers.

[-- Attachment #3: layer_sets.pdf --]
[-- Type: application/pdf, Size: 11970 bytes --]

[-- Attachment #4: layer_sets.tex --]
[-- Type: application/x-tex, Size: 4797 bytes --]

[-- Attachment #5: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2024-02-17 10:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 23:54 [NTG-context] " Emanuel Han via ntg-context
2024-02-15  7:19 ` [NTG-context] " Mikael Sundqvist
2024-02-15 21:07   ` Emanuel Han via ntg-context
2024-02-15 22:10     ` Emanuel Han via ntg-context
2024-02-16  5:52       ` Emanuel Han via ntg-context
2024-02-16  6:56         ` Mikael Sundqvist
2024-02-17 10:03           ` Emanuel Han via ntg-context [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2D427F57-AC95-4A2C-92A2-AE3E047DBEA0@getmailspring.com \
    --to=ntg-context@ntg.nl \
    --cc=emanuel@labonneheure.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).