[NTG-context] \autoinsertedspace fails
Rik Kabel
ConTeXt at rik.users.panix.com
Fri Jan 6 03:05:23 CET 2023
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20230105/69226532/attachment.htm>
More information about the ntg-context
mailing list