[texhax] Can't use \d (dot below) with \edef

Wenlin Institute wenlin at wenlin.com
Wed Jun 20 22:52:28 CEST 2007


On Jun 19, 2007, at 3:51 AM, Oleg Katsitadze wrote:

> On Mon, Jun 18, 2007 at 02:59:26PM -0700, Wenlin Institute wrote:
>> \edef\test{\d{u}}\bye
>
> Why are you using \edef?

I'm copying \firstmark or \botmark or \splitbotmark, which  
subsequently changes. I need to save the current value before it  
changes.

>   Generally it is not a good idea to fully
> expand arbitrary macros.  If you have to use \d inside some other
> \edef'd macro, add \noexpand in front of \d:
>
>   \edef\test{...\noexpand\d{u}...}

Thank you, I'll give that a try. In the meantime, I found a  
workaround which was to redefine \d without \halign:

\def\d#1{\leavevmode\setbox0=\hbox{#1}\dimen0=\wd0\setbox0=\hbox{.} 
\advance\dimen0 by -\wd0
	\hbox{#1\raise-0.5ex\hbox to 0pt{\hss.\kern.5\dimen0}}}%

(It doesn't do italic correction but I can't actually see the  
difference.)

Thank you also for your explanations -- I suspected it had to do with  
##.

Best wishes,

Tom

>
> The reason for the failure is obscure, but if you are curious:  \d
> calls \o at lign; \o at lign calls \oalign.  When TeX was parsing \oalign,
> it saw ## and converted it into a single token #.  When the
> replacement text of \oalign is substituted back into the body of \d,
> TeX sees this _single_ # and expects it to be followed either by
> another # (which would become literal #) or by a number (which would
> be replaced by an argument of \d).  TeX sees neither, therefore it
> complains.
>
> Here is a minimal example to illustrate the problem (or maybe confuse
> you even more :).  \tracingall provides useful debugging info.
>
> First, run this:
>
> --------------------%<--------------------
> \tracingall
> \def\b#1{\halign{##\cr#1\cr}}% ## become #
> \edef\a#1{#1\b{b}}
> \a{a}
> \bye
> -------------------->%--------------------
>
> TeX complains as before.  Now we put four #'s in \b:
>
> --------------------%<--------------------
> \tracingall
> \def\b#1{\halign{####\cr#1\cr}}% #### become ##
> \edef\a#1{#1\b{b}}
> \a{a}
> \bye
> -------------------->%--------------------
>
> Works, but now we can't use \b directly, because it contains two #'s
> in \halign's preamble.  Now try this:
>
> --------------------%<--------------------
> \tracingall
> \def\b#1{\halign{##1\cr#1\cr}}% ##1 become #1
> \edef\a#1{#1\b{b}}
> \a{a}
> \bye
> -------------------->%--------------------
>
> Definition of \a passes, but TeX complains about the missing # in
> \halign's preamble when we try to use \a.
>
> HTH,
> Oleg
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: http://tug.org/mailman/listinfo/ 
> texhax
> Human mailing list managers: postmaster at tug.org
>


文林 Wenlin Institute, Inc.        Software for Learning Chinese
E-mail: wenlin at wenlin.com     Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)
☯







More information about the texhax mailing list