From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: [NTG-context] Re: Pass string into text background graphic
Date: Sat, 12 Aug 2023 22:04:47 +0200 [thread overview]
Message-ID: <b3d9ac7f-3f84-663e-9903-bc92ce220099@freedom.nl> (raw)
In-Reply-To: <CAANrE7oizcfTprsUv3-+axnkR0g2EcUC+zjNT2XjV8ovsxXjrQ@mail.gmail.com>
On 8/12/2023 7:19 PM, Thangalin wrote:
> Thanks Hans.
>
> The \newinteger approach would always increment the value, regardless of
> conditionals within the MetaPost code (i.e., it was like legend :=
> "\ConcurrentTextGet" would always invoke the macro just be referencing the
> MPgraphic and nothing would prevent its execution). This meant that the Get
> indexes would not correspond to the Set indexes. Switching to \definenumber
> resolved the issue. There were a few other oddities, such as the "Get"
> counter incrementing twice. Here's the code:
you could remove the \localcontrolled around the advance
> \definenumber[ConcurrentTextSetCounter][prefix=no]
> \definenumber[ConcurrentTextGetCounter][prefix=no]
>
> \setnumber[ConcurrentTextSetCounter][0]
> \setnumber[ConcurrentTextGetCounter][0]
>
> % Map each label as global key/value pairs.
> \def\ConcurrentTextSet#1{%
> \incrementnumber[ConcurrentTextSetCounter]%
> \setxvariable
> {concurrent}
> {text:\rawcountervalue[ConcurrentTextSetCounter]}
> {#1}}
>
> % Account for the counter incrementing twice and the index being 1-based.
> \def\ConcurrentTextGet{%
> \incrementnumber[ConcurrentTextGetCounter]%
> \getvariable
> {concurrent}
why twice ? you only have to typeset the text once, right?
> {text:\number\numexpr1+\rawcountervalue[ConcurrentTextGetCounter]/2\relax}}
>
> \startuseMPgraphic{GraphicConcurrent}
> numeric index;
> index := 1;
>
> % Differentiate between new text blocks and those crossing pages.
> if (multikind[ index ] = "single") or (multikind[ index ] = "first"):
> string legend;
> legend := "\ConcurrentTextGet";
>
> % For new text blocks, write the title.
> picture p;
> p := textext.rt( legend )
> shifted ulcorner multipars[ index ]
> shifted (1cm, 0);
>
> % Draw the horizontal rule only for the initial text block.
> draw
> ulcorner multipars[ index ] shifted (1mm + xpart lrcorner p, 0) --
> urcorner multipars[ index ];
>
> % Draw the vertical rule for the initial text block.
> draw
> llcorner multipars[ index ] --
> ulcorner multipars[ index ] --
> ulcorner multipars[ index ] shifted (9mm, 0);
>
> draw p;
> else:
> % Draw only the vertical rule only when crossing page boundaries.
> draw
> llcorner multipars[ index ] --
> ulcorner multipars[ index ];
> fi
> \stopuseMPgraphic
>
> \definetextbackground[TextConcurrentFrame][
> mp=GraphicConcurrent,
> frame=off,
> topoffset=1em,
> leftoffset=1em,
> before=\blank[2*big],
> after=\blank,
> location=paragraph,
> ]
>
> \startsetups concurrent:before
> \ConcurrentTextSet{%
> % Be sure to format "a.m." and other special phrases.
> \expandafter\TextReplacement{%
> \xmlatt{\getvariable{div}{concurrent}}{data-title}%
> }
> }
> \startTextConcurrentFrame
> \stopsetups
>
> \startsetups concurrent:after
> \stopTextConcurrentFrame
> \stopsetups
>
> \definestartstop[concurrent][
> before=\directsetup{concurrent:before},
> after=\directsetup{concurrent:after}
> ]
>
> This allows for typesetting a wider range of pandoc-style Markdown
> annotations, such as:
>
> ::: {.concurrent title="Terminal Berth 5, 3:17 a.m."}
> text goes here
> :::
>
> With these changes, the titles now only appear at the start of the
> demarcated text, in any combination of "concurrent" annotation instances
> spanning any number of pages.
>
> Much appreciated.
>
> Cheers!
> P.S.
> The following line requires KeenWrite themes:
>
> \expandafter\TextReplacement{ ... }
>
> For details, see:
>
> -
> https://github.com/DaveJarvis/keenwrite-themes/blob/main/xhtml/xml-blocks.tex
> -
> https://github.com/DaveJarvis/keenwrite-themes/blob/main/boschet/replace.tex
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
>
> maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage : https://www.pragma-ade.nl / http://context.aanhet.net
> archive : https://bitbucket.org/phg/context-mirror/commits/
> wiki : https://contextgarden.net
> ___________________________________________________________________________________
--
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2023-08-12 20:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 19:57 [NTG-context] " Thangalin
2023-08-11 21:53 ` [NTG-context] " Hans Hagen
2023-08-12 17:19 ` Thangalin
2023-08-12 20:04 ` Hans Hagen via ntg-context [this message]
2023-08-13 19:33 ` Thangalin
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=b3d9ac7f-3f84-663e-9903-bc92ce220099@freedom.nl \
--to=ntg-context@ntg.nl \
--cc=j.hagen@freedom.nl \
/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).