Hello! Is there a possibility to invert \unexpanded within \edef or \expanded? I.e. to have things expanded that are wrapped between \undexpanded{ and the matching } while having things not expanded that are not wrapped between \undexpanded{ and a matching }?
user581918
With l3regex's \regex_replace_all:nnN {⟨regular expression⟩}{⟨replacement⟩}⟨tl var⟩ - is it possible to apply some expansion to the tokens that form a ⟨replacement⟩ so that in the ⟨tl var⟩ with each replacement, instead of inserting the tokens that form a replacement, the result of applying some expansion to that replacement is inserted?
@Cattleya change ....\unexpanded{...}... to \foo{...}\bar{...}\foo{...} then define \foo as \unexpanded and \bar as \expanded and put it all in edef or \expanded
1 hour later…
user581918
11:12 AM
@DavidCarlisle When I write the ⟨balanced text⟩ of \edef/the ⟨general text⟩ of \expanded by hand, then I can do this easily. But I can't do this easily when the tokens forming that ⟨balanced text⟩/⟨balanced text⟩ are the result of carrying out another control sequence which would need whatsoever complicated post-processing for obtaining this and where some of the tokens which need to be separated into chunks of \boo{...}\bar{...}\fo{...}\bar{...}... are burried inside nested curly braces.
@Cattleya well if the \unexpanded are inside macros you are probaly doomed but if they are at the top level you just need to recursively apply \def\xxx#1\unexpanded#2{\foo{#1}\bar{#2}} don't you?
@Cattleya I suspect we need the full context: usually \unexpanded is there for a reason
user581918
@DavidCarlisle This would expand the ⟨replacement⟩ before having \regex_replace_all:nnN act on the ⟨tl var⟩. Assume the ⟨replacement⟩ is a call to a macro whose arguments come from submatches of some of the ⟨regular expression⟩'s capture-groups and in ⟨tl var⟩ you need each of these macro-calls with arguments expanded...
user581918
At first i assumed one could have a regular expression split matches and non-matches into brace-groups trailet by \expanded/\unexpanded and apply \edef or \expanded to the resulting value of the ⟨tl var⟩, but that doesn't work out in cases where due to brace-nesting matches occur inside surrounding brace groups that belong to non-matches.
@Cattleya Probably you can do two \regex_replace_all:nnN: The first one for having prepended \noexpand to each token of the token-list variable , the second one for doing the replacements you actually want, but taking into account that some \noexpand are already there. Then you can apply \edef or \expanded.
Expansion-control can be included into the replacements of the second \regex_replace_all:nnN by means of things like \romannumeral, stuff of expl3's l3expan and probably macros like \expandtimes that in the past were posted to TeX - LaTeX StackExchange and can be found by searching TeX - LaTeX StackExchange.
There is also the LaTeX 2e macro \ExpandArgs and the LuaTeX/XeTeX-primitive \expanded and the e-TeX-primitive \unexpanded.
What is this \G-thingie in l3regex about? interface3.pdf says it is the start of the current match and that \regex_count:nnN { \G a } { aaba } \l_tmpa_int yields 2. Every match has a start and is the current match at some time. So this seems kind of pointless. There are three matches, each of them being the current match at some time and having a start, so that should yield 3 which it doesn't.
@Cattleya @Cattleya ^^^ the first two a match. the third one doesn't. the first a matches then you start looking again from that point and the second a matches` then you start looking from that point and the last a does not match.
@Cattleya that's what it does, I can't say I can think of a case when it's useful but....
I am not clear on the use/need of the \G operator.
I read in the perldoc:
You use the \G anchor to start the next match on the same string where
the last match left off.
I don't really understand this statement. When we use \g we usually move to the character after the last match anyway...
@DavidCarlisle Do you know why article and report set \marginparwidth to 3pt for a5paper? I know that being single-sided makes a difference, but book uses 51pt and surely double-sided doesn't make that much difference?
why that line twice with one spurious 0 if that was intended why not just subtract .8in, looks like a cut and paste error to me, I suppose I should look if it's always been there, we can probably blame @UlrikeFischer
@Cattleya It makes sene because #⟨digit sequence⟩ shall be replaced by the token-list-item only in case there is no other # before it which is the case in case there either is a non-parameter-character before it or there is no non-match before it as there either is nothing between it and the previous match or it is the leftmost thing of the string.
So let's correct my statement "Afaik \G says that a is a match only in case there is no non-match somewhere before it." should be: "Afaik \G says that a is a match in case either it is the leftmost thing of the string or there is no non-match somewhere before it and the previous match."
@Cattleya One more correction: "Afaik \G says that a is a match in case either it is the leftmost thing of the string or there is no non-match somewhere between it and the previous match."
user581918
@UlrichDiez Thank you. I need to think about it. I wanted to learn TeX/LaTeX and now I find myself learning regex... ;-)