[NTG-context] \autoinsertedspace fails
Hans Hagen
j.hagen at xs4all.nl
Fri Jan 6 08:53:22 CET 2023
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
-----------------------------------------------------------------
More information about the ntg-context
mailing list