[tex-eplain] Putting two \definexref together

Oleg Katsitadze olegkat at gmail.com
Sun Sep 9 22:35:54 CEST 2007


On Fri, Sep 07, 2007 at 05:31:09PM -0500, Karl Berry wrote:
> I can imagine it theoretically being used to read the aux file in a
> group.

Yeah, that makes sense, but looking at xeplain.tex, I see many places
where \readauxfile is internally used inside a group, so if we make
non-global label definitions, the whole idea will be defeated and the
user will always have to call \readauxfile explicitly.

Anyway, I realized that the fix is trivial, after all -- we just put
the \csname...\endcsname inside another group, so only that group will
have to retain the global definition of the label (see the attached
patch).  Very nice :).

> I wonder what LaTeX does.

AFAICT, it reads the .aux file inside a group as well, just like the
current btxmac.tex.

Cheers,
Oleg
-------------- next part --------------
Index: xeplain.tex
===================================================================
RCS file: /cvsroot/eplain/eplain/xeplain.tex,v
retrieving revision 1.44
diff -u -p -r1.44 xeplain.tex
--- xeplain.tex	7 Sep 2007 20:59:42 -0000	1.44
+++ xeplain.tex	9 Sep 2007 20:09:02 -0000
@@ -1638,26 +1638,37 @@
 % label class CLASS to be DEFINITION.
 % 
 \def\@definelabel#1{% #2 and #3 will be read later.
-  % Warn if we see that another label with the same name has been
-  % defined.  Remember, we are called when the aux file is being read,
-  % which means that no labels have been defined yet except the ones
-  % which come earlier in this aux file.
-  \expandafter\ifx\csname\xrlabel{#1}\endcsname \relax
-    \let\next\@definelabel at nocheck
-  \else
-    \let\next\@definelabel at warn
-  \fi
-  % Define the control sequences or warn.
-  \next{#1}%
+  % The following group will keep the save stack from overflowing:
+  % We are reading the .aux file inside a group.  For undefined
+  % commands, \csname...\endcsname makes them equivalent to \relax
+  % locally in that group; when we globally redefine them, TeX enters
+  % the definitions on the save stack, once for each label.  When done
+  % in the topmost group, this can overflow stack of any size, given
+  % sufficient number of label definitions.  So, we put these
+  % \csname...\endcsname's inside another group, to pop the stack for
+  % every label.
+  \begingroup % Will be ended in \@definelabel at nocheck.
+    % Warn if we see that another label with the same name has been
+    % defined.  Remember, we are called when the aux file is being read,
+    % which means that no labels have been defined yet except the ones
+    % which come earlier in this aux file.
+    \expandafter\ifx\csname\xrlabel{#1}\endcsname \relax
+      \expandafter\@definelabel at nocheck
+    \else
+      \expandafter\@definelabel at warn
+    \fi
+    % Define the control sequences or warn.
+    {#1}%
 }%
 % Define a label without checking for redefinitions.
 \def\@definelabel at nocheck#1#2#3{%
-  % Define the control sequence.
-  \expandafter\gdef\csname\xrlabel{#1}\endcsname{#2}%
-  %
-  % Remember what kind of label this is, so \ref will know what to do.
-%  \global\setproperty{\xrlabel{#1}}{class}{#3}%
-  \setpropertyglobal{\xrlabel{#1}}{class}{#3}%
+    % Define the control sequence.
+    \expandafter\gdef\csname\xrlabel{#1}\endcsname{#2}%
+    %
+    % Remember what kind of label this is, so \ref will know what to do.
+%    \global\setproperty{\xrlabel{#1}}{class}{#3}%
+    \setpropertyglobal{\xrlabel{#1}}{class}{#3}%
+  \endgroup % From \@definelabel.
 }%
 % Warn and then redefine a label.
 \def\@definelabel at warn#1#2#3{%
@@ -1946,7 +1957,8 @@
   % Define hyperlink destination.
   \hldest at impl{eq}{\hl at eqlabel}%
   % Define the LABEL omitting redefinition check.
-  \@definelabel at nocheck{#1}{#2}{eq}%
+  \begingroup % \@definelabel at nocheck will end this group.
+    \@definelabel at nocheck{#1}{#2}{eq}%
 }%
 % 
 % \eqdef{LABEL} defines LABEL, with \eqdefn, then prints it.  We allow
Index: btxmac.tex
===================================================================
RCS file: /cvsroot/eplain/eplain/btxmac.tex,v
retrieving revision 1.3
diff -u -p -r1.3 btxmac.tex
--- btxmac.tex	19 Aug 2005 18:04:32 -0000	1.3
+++ btxmac.tex	9 Sep 2007 20:09:02 -0000
@@ -1,6 +1,6 @@
 %% @texfile{
 %%   author = "Karl Berry and Oren Patashnik",
-%%   version = "0.99k-18aug05",
+%%   version = "0.99k-09sep07",
 %%   date = "19 August 2005",
 %%   filename = "btxmac.tex",
 %%   address = "tex-eplain at tug.org",
@@ -513,7 +513,16 @@
 % the \@citedef, we define \@citelabel{#1}, where #1 is the user's
 % label.
 %
-\def\@citedef#1#2{\expandafter\gdef\csname\@citelabel{#1}\endcsname{#2}}%
+% The group around the def will keep the save stack from overflowing:
+% We are reading the .aux file inside a group.  For undefined
+% commands, \csname...\endcsname makes them equivalent to \relax
+% locally in that group; when we globally redefine them, TeX enters
+% the definitions on the save stack, once for each label.  When done
+% in the topmost group, this can overflow stack of any size, given
+% sufficient number of label definitions.  So, we put these
+% \csname...\endcsname's inside another group, to pop the stack for
+% every label.
+\def\@citedef#1#2{{\expandafter\gdef\csname\@citelabel{#1}\endcsname{#2}}}%
 %
 %
 % Reading the .bbl file also produces the typeset bibliography.  Please
Index: Makefile
===================================================================
RCS file: /cvsroot/eplain/eplain/Makefile,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile
--- Makefile	7 Sep 2007 20:59:42 -0000	1.18
+++ Makefile	9 Sep 2007 20:09:02 -0000
@@ -1,6 +1,6 @@
 # Makefile for Eplain.  This file is public domain.
 
-VERSION     = 3.1.91
+VERSION     = 3.1.92
 DIST_NAME   = eplain-$(VERSION)
 
 # Categories of the files in the source tree.


More information about the tex-eplain mailing list