Re: Uppercasing the first character of an expanded macro arg?



On Feb 4, 3:27 am, Hans Meine <me...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Alan Ristow wrote:


Nevertheless, I wanted to hear the answer from some TeX gurus whether and
why \lowercase and \uppercase are not accompanied by \capitalize.

[...]

Wouldn't the expansion triggered by \expandafter in
\expandafter\capitalize\prettyref{eq:foo}
expand \prettyref{eq:foo} as far as possible?

No. According to the TeXbook: the second token following \expandafter
is expanded (meaning: replaced with its replacement text) and then
the
first token following expandafter is processed.
\expandafter\capitalize\prettyref{eq:foo}
produces
\capitalize \@prettyref eq:foo:
You can trigger more expansion with
\expandafter\expandafter\expandafter\capitalize\prettyref{eq:foo}
which produces
\expandafter\capitalize\@prettyref eq:foo:
which then produces
\capitalize \expandafter \ifx \csname pr@eq\endcsname \relax
\PackageWarning {prettyref}{Reference format eq\space undefined}%
\ref {eq:foo}\else \csname pr@eq\endcsname {eq:foo}\fi
which would attempt to run \capitalize on \expandafter. If you define
\capitalize to mean \expandafter\capitalizea you can expand away that
\expandafter but now you encounter \ifx, etc., etc.

There are cases where expansion proceeds as far as possible:
- in the replacement text of \edef or \xdef
- inside \csname ...\endcsname
- inside \write constructs
- inside \special{...}
There are also cases where expansion proceeds until some
unexpandable token appears, mainly in numeric assignments.

An trick recently discussed in c.t.t was \romannumeral 0\stuff
This will expand \stuff as far as necessary looking for more
digits. If it finds digits it continues expanding. When finally an
unexpandable nondigit appears, it produces the lowercase
roman numeral of the number. If no nonzero digits appear,
it produces nothing (except the tokens of the expansion
that remain).

Thus
\expandafter\capitalize\romannumeral 0\prettyref{eq:foo}
if like an infinity of \expandafters, but here is what it actually
produces:
\capitalize \protect \textup {(\ref {eq:foo})}\fi
and it tries to capitalize \protect (=\relax). This is
where arbitrary numbers of \expandafter's would stop,
because \relax is unexpandable.

This whole idea is doomed from the start (for
anything except the most simple macros).

Can adding more \expandafter really help? (Yes, I tried, though being
sceptical, but up to 13 made no difference.)

The number has to a power of two minus one, and it will
expand the number of times equal to the power.
So 1, 3, 7, 15, 31, etc. will expand 1, 2, 3, 4, 5, etc. times

This is because in
\expandafter\expandafter\expandafter\x\y
the first expands the third, which expands \y, then
the second remains to expand the first token of the
expansion of \y. To expand three levels, you have to
interleave 4 \expandafter among the 3 (7 total), then
8 among the 7, etc.


Dan
.



Relevant Pages

  • Re: OT. Crying about Gas $$$
    ... Because of the limitations in the refinement procedure, a refinery can at ... A Chevron spokesman said the expansion of the Pascagoula refinery would ... Aruba, Valero's refinery is being expanded by 35,000 b/d to 275,000 ... arguing that it would be more economically sensible to expand ...
    (alt.autos.toyota)
  • Re: OT. Crying about Gas $$$
    ... Because of the limitations in the refinement procedure, a refinery can at ... A Chevron spokesman said the expansion of the Pascagoula refinery would ... Aruba, Valero's refinery is being expanded by 35,000 b/d to 275,000 ... arguing that it would be more economically sensible to expand ...
    (alt.autos.toyota)
  • Re: How to check in an expandable way if a token is expandable?
    ... \noexpand\TOKEN is interpreted "as if its meaning were ... | sequences that are expanded whenever expansion has not ... TeX does _not_ expand control sequences ... | when it looks at the two tokens. ...
    (comp.text.tex)
  • Re: Dynamical Systems and Expansion-Contraction
    ... expansion, and speeds of expansion in each direction. ... outside in its program as well as a "picture" of an inside even though ... The decision of how to expand would seem to depend on what the point ... and we could isolate "symmety" as ...
    (sci.physics)
  • NEW FUNCTION - DYNAMIC VOLUME EXPANSION
    ... NEW FUNCTION - DYNAMIC VOLUME EXPANSION ... This support allows a customer to ... before attempting to expand a volume. ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)