ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Rik Kabel via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Rik Kabel <ConTeXt@rik.users.panix.com>
Subject: Re: \autoinsertedspace fails
Date: Thu, 5 Jan 2023 21:05:23 -0500	[thread overview]
Message-ID: <d7f26fd1-9258-b27d-f987-e2f8730a9f0e@rik.users.panix.com> (raw)
In-Reply-To: <b42be28f-c3fb-7df3-f0fa-8fc69221da4f@freedom.nl>


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


On 2023-01-05 04:35, Hans Hagen via ntg-context wrote:
> On 1/5/2023 4:21 AM, Rik Kabel via ntg-context wrote:

     [ snipped by rik]

> Here is a more lmtx-ish variant:
>
> \starttexdefinition tolerant protected BD #=#*#=
>    \removeunwantedspaces
>    \space % insert a space
>    (
>    \ifparameter#2\or
>        #1|–|#2
>    \orelse\ifparameter#1\or
>        #1–
>    \else
>        {\red I NEED A DATE OR DATES!}
>    \fi
>    )
>    \autoinsertedspace
> \stoptexdefinition
>
> Hans

Thank you for that. This works for me with \optionalspace, but fails in 
some cases with \autoinsertedspace.

I have now re-read lowlevel-macros.pdf and have a better understanding 
of what I read when first I approached it; I still have a way to go.

/Tolerant/ removes the need for /dodoubleempty/ and friends and the 
two-step /macro/ and /doMacro/ dance. There was a small advantage to the 
two-step, however. I had two separate macros, BD and BDNP (no parens), 
as shown.

The old code in full was:

    %-------------------- Birth and death dates -----------------------%
    % Ferdinand de Saussure\BD{1857}{1913}
    % Noam Chomsky \BD{1928}
    %
    % Perhaps this could be tied to an acronym-like database so that the
    %   dates are printed only once per person.
    % \removeunwantedspaces allows this to directly follow, or follow
    %   after whitespace, the associated name: Name\BD{1}{2} or
    %   Name \BD{1}{2}.
    % Using the compound indication (|–|) allows hyphenation after the
    %   endash. Omitting it and using a bare endash inhibits hyphenation
    %   ‘twixt the endash and the paren.
    % By default, add parens around the dates. If none are needed due to
    %   the context, use \BDNP.
    %
    \newif\ifBDParen
    \starttexdefinition unexpanded BD
       \BDParentrue
       \dodoublegroupempty
       \doBD
    \stoptexdefinition
    \starttexdefinition unexpanded BDNP
       \BDParenfalse
       \dodoublegroupempty
       \doBD
    \stoptexdefinition
    \starttexdefinition doBD #1#2
        \removeunwantedspaces\
        \ifBDParen(\fi
        \ifsecondargument
            #1|–|#2
        \else\iffirstargument
            #1–
        \else
            {\red I NEED A DATE OR DATES!}
        \fi\fi
        \ifBDParen)\fi
        \autoinsertedspace
    \stoptexdefinition

Both call the same doBD, but they set a flag (newif) to control 
insertion or not of the parens. While there is no performance benefit 
compared to having two fully separate macros, there is a maintenance 
benefit in having only one place, doBD, to make changes should they be 
required.

Can you suggest a way to do this under the new one-step scheme, or am I 
over-thinking this?

Finally, is there any reason to go back to previously written and 
properly functioning macros and convert them to the LMTX-only syntax? It 
does imply committing to LMTX-only (or

-- 
Rik


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

[-- Attachment #2: Type: text/plain, Size: 496 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-01-06  2:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30  0:12 Rik Kabel via ntg-context
2023-01-04 22:10 ` Rik Kabel via ntg-context
2023-01-04 23:45   ` Hans Hagen via ntg-context
2023-01-05  3:21     ` Rik Kabel via ntg-context
2023-01-05  7:38       ` Hans Hagen via ntg-context
2023-01-05  9:35       ` Hans Hagen via ntg-context
2023-01-06  2:05         ` Rik Kabel via ntg-context [this message]
2023-01-06  7:53           ` Hans Hagen via ntg-context

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=d7f26fd1-9258-b27d-f987-e2f8730a9f0e@rik.users.panix.com \
    --to=ntg-context@ntg.nl \
    --cc=ConTeXt@rik.users.panix.com \
    /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).