From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/116811 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rik Kabel via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: \autoinsertedspace fails Date: Thu, 5 Jan 2023 21:05:23 -0500 Message-ID: References: <86830236-f8d8-cbdd-ff24-d14f9a35f90e@rik.users.panix.com> <44990e16-0a82-ee19-abed-8b588ac42b8d@rik.users.panix.com> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3626148056786589928==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10334"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.6.1 Cc: Rik Kabel To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 06 03:06:04 2023 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pDc7Q-0002V5-EK for gctc-ntg-context-518@m.gmane-mx.org; Fri, 06 Jan 2023 03:06:04 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D50A33803FD; Fri, 6 Jan 2023 03:05:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wsgrehZS2Bof; Fri, 6 Jan 2023 03:05:31 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 40195380469; Fri, 6 Jan 2023 03:05:31 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 92460380468 for ; Fri, 6 Jan 2023 03:05:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d16GDecIqSlj for ; Fri, 6 Jan 2023 03:05:27 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=166.84.1.89; helo=mailbackend.panix.com; envelope-from=context@rik.users.panix.com; receiver= Original-Received: from mailbackend.panix.com (mailbackend.panix.com [166.84.1.89]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 1BCAC3803FD for ; Fri, 6 Jan 2023 03:05:26 +0100 (CET) Original-Received: from [192.168.1.106] (cpe-69-204-136-231.nycap.res.rr.com [69.204.136.231]) by mailbackend.panix.com (Postfix) with ESMTPSA id 4Np69x1XP0z3mdw for ; Thu, 5 Jan 2023 21:05:25 -0500 (EST) Content-Language: en-US In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:116811 Archived-At: This is a multi-part message in MIME format. --===============3626148056786589928== Content-Type: multipart/alternative; boundary="------------YuPnZE0A4EdqQR5x543ZA78T" Content-Language: en-US This is a multi-part message in MIME format. --------------YuPnZE0A4EdqQR5x543ZA78T Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------YuPnZE0A4EdqQR5x543ZA78T Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit


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


--------------YuPnZE0A4EdqQR5x543ZA78T-- --===============3626148056786589928== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cHM6Ly93d3cubnRnLm5sL21haWxtYW4v bGlzdGluZm8vbnRnLWNvbnRleHQKd2VicGFnZSAgOiBodHRwczovL3d3dy5wcmFnbWEtYWRlLm5s IC8gaHR0cDovL2NvbnRleHQuYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHBzOi8vYml0YnVja2V0 Lm9yZy9waGcvY29udGV4dC1taXJyb3IvY29tbWl0cy8Kd2lraSAgICAgOiBodHRwczovL2NvbnRl eHRnYXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============3626148056786589928==--