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
___________________________________________________________________________________

Reply via email to