Re: Mathmode.pdf and braket.sty
- From: Morten Høgholm <morten.hoegholm@xxxxxxxxx>
- Date: Wed, 26 Oct 2005 21:29:40 -0500
On Tue, 25 Oct 2005 14:43:51 -0500, Jonathan Fine <jfine@xxxxxxxxx> wrote:
We can optimise this a bit more, at least when processing a large number of items.
% not tested, but hope that all errors are only (?) typos \def\new@for@loop #1#2#3,{% \def#1{#3}% \ifx\@nnil#1% \new@for@loop@exit % cunning \fi replacement trick goes here \fi #2% \new@for@loop #1{#2}% } \def\new@for@loop@exit #1 \new@for@loop #2#3{\fi}
Small typo here although with more suitable catcode settings for coding it wouldn't be (at least, what I find suitable for coding :-).
The exit function is good. I have added it but in a way that is less cunning and perhaps a little more general.
The thing is that different loop types will contain different code where one effectively would have to design a special exit function for each one. What I did instead was adding an extra stop marker at the end of the internal rearrangement and then simply gobble everything up to that one. The advantage (besides working for all these loop constructs) is that this will then also be the same function people can use for breaking a loop if a certain item was found. Since some functions might very well return the result of such a test *after* exiting the underlying \if...\fi structure, I found it better to not let it first gobble and then re-insert a \fi. After all, I would rather tell people to insert an \expandafter once in a while rather than having to add some obscure code like \iftrue\break@this@loop\fi.
% Generic quark like thingies that belong elsewhere
\def\q@nil{\q@nil}
\def\q@stop{\q@stop}
\long\def\@gobble@to@q@stop #1\q@stop{}% for comma lists:
\let\new@for@break \@gobble@to@q@stop
\def\new@for#1#2#3{%
\new@for@loop#1{#3}#2,\q@nil,\q@stop
}
\def\new@for@loop#1#2#3,{%
\def#1{#3}%
\ifx\q@nil#1%
\expandafter\new@for@break
\fi
#2\new@for@loop#1{#2}%
}And if we are willing to forbid loop nesting, we can avoid having to shuffle tokens about (this is something that irritates me when writing expandable list processing macros).
Such shuffling is a performance hit.
True. However people tend to use nested loops (I know I have seen it) so that is a severe restriction. It is not something I'd want to do for the loop that assigns a tmp-var as the one(s) we have discussed in this (now wildly OT) thread.
But I've shown you these two tricks, just in case you're interested.
I'm always interested in tricks... -- Morten .
- References:
- Mathmode.pdf and braket.sty
- From: Dan
- Re: Mathmode.pdf and braket.sty
- From: Dan
- Re: Mathmode.pdf and braket.sty
- From: Dan
- Re: Mathmode.pdf and braket.sty
- From: Heiko Oberdiek
- Re: Mathmode.pdf and braket.sty
- From: Dan
- Re: Mathmode.pdf and braket.sty
- From: Morten Høgholm
- Re: Mathmode.pdf and braket.sty
- From: Jonathan Fine
- Re: Mathmode.pdf and braket.sty
- From: Morten Høgholm
- Re: Mathmode.pdf and braket.sty
- From: Jonathan Fine
- Mathmode.pdf and braket.sty
- Prev by Date: Re: subfigure question
- Next by Date: Re: Figures in .ps and .eps for MikTex
- Previous by thread: Re: Mathmode.pdf and braket.sty
- Next by thread: Re: Mathmode.pdf and braket.sty
- Index(es):
Relevant Pages
|
Loading