olsak / tex-nutshell

TeX in a Nutshell -- A short document about TeX principles
4 stars 2 forks source link

Inconsistent markup for `\edef` and `\xdef` syntax #3

Closed muzimuzhi closed 1 year ago

muzimuzhi commented 1 year ago

On page 11, TeX in a Nutshell v0.9, the syntax for \edef and \xdef are colored differently than \def and \gdef.

image

https://github.com/olsak/tex-nutshell/blob/2ae3c848c1706c272ff1bcc90b17d85bd75abf7c/tex-nutshell/tex-nutshell.tex#L868-L873

It seems it's cause by wrong position of ; in the markup |...;.

From 0bd3c99428624a2f7da17d28eb286aa800b1cc23 Mon Sep 17 00:00:00 2001
From: Yukai Chou <muzimuzhi@gmail.com>
Date: Sun, 28 May 2023 05:37:09 +0800
Subject: [PATCH] Fix markup for \edef and \xdef syntax

---
 tex-nutshell/tex-nutshell.tex | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tex-nutshell/tex-nutshell.tex b/tex-nutshell/tex-nutshell.tex
index e3f63ed..386a2d4 100644
--- a/tex-nutshell/tex-nutshell.tex
+++ b/tex-nutshell/tex-nutshell.tex
@@ -868,8 +868,8 @@ expanded by the expand processor. The summary of `\def` syntax is:
 \begtt \catcode`\|=13 \catcode`\/=13 \catcode`\<=13 \Blue 
 \def|<control sequence>/<parameters>.{<replacement text>};  % local assignment
 \gdef|<control sequence>/<parameters>.{<replacement text>}; % global assignment
-\edef|<control sequence>/<parameters>.{;<replacement text>} % local assignment
-\xdef|<control sequence>/<parameters>.{;<replacement text>} % global assignment
+\edef|<control sequence>/<parameters>.{<replacement text>}; % local assignment
+\xdef|<control sequence>/<parameters>.{<replacement text>}; % global assignment
 \endtt   

 If you set \i tracingmacros `\tracingmacros=2`, you can see in the log file how the macros are expanded.
-- 
2.40.1
olsak commented 1 year ago

The <replacement text> is blue in \edef and \xdef syntax because these primitives read it fully expanded. On the other hand, the <replacement text> is red in \def and \gdef syntax because these primitives read it not expanded.

muzimuzhi commented 1 year ago

Oh. Then the blue } is also intended?

olsak commented 1 year ago

Yes, it is blue. Try this:

\def\fin{\iffalse{\fi}}

\edef\a{text\fin

\meaning\a

The expand processor is normally working when the <parametere text> is read including closing }.

muzimuzhi commented 1 year ago

Ah the brace hack! Thank you I learnt sth new today.

This also explains why the left braces in syntax for \detokenize, \scantokens, etc., are blue. "TeX performs expansion to find the opening brace of a <general text>."