On 1/6/2023 3:05 AM, Rik Kabel via ntg-context wrote:

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?

just remove the #* in the example i sent,

\starttexdefinition tolerant protected BD #=#=

Hans


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