[texhax] re: grouping
moheb missaghi
moheb1333 at comcast.net
Tue Mar 29 04:54:55 CEST 2005
Hi Ross,
Thanks for detailed reply. I gathered choosing } in ifnum0=`} had something
to do with matching parens for example in emacs. My problem was with
grouping such as for example in the following c snippet:
int a()
{
printf("something");
{ /* open paren */
}
int b()
{
printf("something else");
} /* close paren */
}
where the open brace in a cannot be closed with close brace in b (you get a
compiler error). Unless there is a call of b in a such as:
int a()
{
printf("something");
{
b()
}
and somehow tex keeps track of unmatched braces across calls. Is that the
case?
Since you are obviously knowledgeable in tex here are 2 more questions:
1. It appears that spaces are gobbled such as:
\ifdim \dimen@ >\z@
again in tabularx. So \ifdim\diment@>\z@ is the same?
2. Why does \show have problem with variables with @ in them? For example:
\show\@empty
gives:
*\show\@empty
> \@=macro:
->\spacefactor \@m .
<*> \show\@
empty
or am I missing something?
Thanks again,
Moheb
----- Original Message -----
From: "Ross Moore" <ross at ics.mq.edu.au>
To: "moheb missaghi" <moheb1333 at comcast.net>
Cc: <texhax at tug.org>
Sent: Sunday, March 27, 2005 9:07 PM
Subject: Re: [texhax] grouping
> Hello Moheb,
>
> On 28/03/2005, at 12:27 PM, moheb missaghi wrote:
>
>> Hi,
>>
>> I am reading tabularx.sty as a means to learn how to write packages. Not
>> that it really matters for what I want to do but as a matter of curiosity
>> I don't understand the grouping opened by:
>>
>> {\ifnum0=`}\fi
>>
>> in tabularx (tabularx.sty) and apparently closes by:
>>
>> \ifnum0=`{\fi}%
>>
>> in TX at endtabularx. How can a grouping go across 2 different macros and
>> what does it mean?
>
> A grouping can certainly go across different macros.
>
> Most LaTeX environments start with something that puts a
> \begingroup
> and finishes with something else that puts the corresponding
> \endgroup
>
> You can also use \bgroup and \egroup to do the same
> kind of thing.
>
> It's very common to use these, as when the grouping closes,
> then the expansion values of any temporary macros revert
> to what they were before entering the grouping.
> This is important for scoping the values of variables and
> pointers, and for memory-management.
>
>
> This looks to me like a fancy trick to include a {
>> {\ifnum0=`}\fi
>
> while keeping {..} balanced for an editor, while
> also keeping the \ifnum ... balanced with a \fi .
>
> That is, the group opens, but \ifnum returns \iffalse
> so the grouping does not close right away.
>
> Rather, when later we encounter the corresponding
>> \ifnum0=`{\fi}%
>
> then the closing bracket is found.
>
> This could probably have been done much more easily using
> first a \bgroup , then close it later with \egroup .
>
>
> However, this package was generated using docstrip .
> I've seen this style used there quite a lot.
> Perhaps it meshes better with the need to use the
> same source document for multiple purposes.
> So there could be a good reason for this apparently
> cryptic way to start and finish groupings.
>
>
> See if you can find tabularx.dtx on your system,
> or get it from CTAN.
> Maybe the context there will shed further light
> on this question, and help you to learn how these
> packages are constructed.
>
>
>
>>
>> Thx,
>
> Hope this helps,
>
> Ross Moore
>
>
>>
>> Moheb
>> _______________________________________________
>> TeX FAQ: http://www.tex.ac.uk/faq
>> TeX newsgroup: http://groups.google.com/groups?group=comp.text.tex
>> 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
> ------------------------------------------------------------------------
> Ross Moore ross at maths.mq.edu.au
> Mathematics Department office: E7A-419
> Macquarie University tel: +61 +2 9850 8955
> Sydney, Australia fax: +61 +2 9850 8114
> ------------------------------------------------------------------------
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> TeX newsgroup: http://groups.google.com/groups?group=comp.text.tex
> 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
More information about the texhax
mailing list