ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Thangalin <thangalin@gmail.com>
To: Hans Hagen <j.hagen@xs4all.nl>
Cc: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Pass string into text background graphic
Date: Sat, 12 Aug 2023 10:19:51 -0700	[thread overview]
Message-ID: <CAANrE7oizcfTprsUv3-+axnkR0g2EcUC+zjNT2XjV8ovsxXjrQ@mail.gmail.com> (raw)
In-Reply-To: <550cf663-274f-106c-e930-03fb0b092643@xs4all.nl>


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

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:

\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}

{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

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

[-- Attachment #2: concurrent.pdf --]
[-- Type: application/pdf, Size: 33096 bytes --]

[-- Attachment #3: Type: text/plain, Size: 495 bytes --]

___________________________________________________________________________________
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	other threads:[~2023-08-12 17:22 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 [this message]
2023-08-12 20:04     ` Hans Hagen via ntg-context
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=CAANrE7oizcfTprsUv3-+axnkR0g2EcUC+zjNT2XjV8ovsxXjrQ@mail.gmail.com \
    --to=thangalin@gmail.com \
    --cc=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.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).