« first day (4898 days earlier)      last day (29 days later) » 

user581918
1:20 AM
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?
 
9:47 AM
@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 \regex_replace_all:neN ?
@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 sorry too much information to hold in my head, you'd need to make a small example (better in the Q&A site where code formatting is easier)
 
user581918
11:26 AM
@DavidCarlisle Alright. I leave.
 
@Cattleya but don't over-use l3regex, it's impressive that it works but it's scarily slow
 
11:40 AM
@DavidCarlisle It all would have been better of, written in lisp.
 
11:51 AM
@mickep (replace-regexp-in-string "tex" "emacs lisp" "tex is good")
 
@DavidCarlisle Quick and simple
 
 
2 hours later…
1:23 PM
@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.
 
2:11 PM
@UlrichDiez \expanded is available in pdftex, etex and ptex as well
 
 
1 hour later…
3:34 PM
Please can anyone have a look at tex.stackexchange.com/q/712156/963
 
 
5 hours later…
user581918
8:47 PM
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.
 
9:31 PM
\documentclass{article}

\begin{document}
\ExplSyntaxOn
\tl_set:Nn\l_tmpa_tl { aaba }
\regex_replace_all:nnN { \G a } { <!> } \l_tmpa_tl

\show\l_tmpa_tl

\ExplSyntaxOf
\end{document}
@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....
23
Q: When is \G useful application in a regex?

JimI 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...

 
user581918
@DavidCarlisle So \G says that a is only a match in case there is no non-match right before it?
 
@Cattleya yes like ^
 
user581918
@DavidCarlisle Afaik ^ says it is a mach only if it is at the start of the entire string whose matches are to be found.
 
@Cattleya yes and \G is the same but applying to the string after you have processed any earlier matches
 
9:49 PM
@Cattleya Afaik \G says that a is a match only in case there is no non-match somewhere before it.
 
user581918
10:09 PM
@UlrichDiez In How to substitute placeholders in string with arguments? you have \regex_replace_all:nnN {(\G|[^\cP\#])(\cP\#)(\d+)([\cO\/]?)}... Why does it make sense to combine \G with | ?
 
cfr
11:01 PM
@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?
 
11:12 PM
@DavidCarlisle ^^ squiggles
 
@cfr well they don't really, not explictly
@UlrikeFischer yes JF posted to texhax the other day:-) Fraktur would be rather clustered towards the bottom of that graph
 
@DavidCarlisle left or right of the bottom?
 
@UlrikeFischer left:-)
@cfr note the future tense:
%    A check should perhaps be built in to ensure that the (text)
%    margin width does not get too small!
@cfr it makes no sense at all
\documentclass[a5paper]{article}
\usepackage{graphicx}% force paper size
\begin{document}
\typeout{\the\marginparwidth}

% usletter 65pt
% a4paper 57pt
% a5paper 3pt
\noindent X\dotfill X\marginpar{\noindent\rlap{!}\dotfill\llap{!}\mbox{}}
\end{document}
@cfr look here on classes.dtx
    \addtolength\marginparwidth {-0.4in}
    \addtolength\marginparwidth {-.4in}
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
 
11:41 PM
@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."
 
@cfr was that way in 2001 web.archive.org/web/20011004092209/http://www.ctan.org/… I'll see if I can find an older version
 
@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... ;-)
 

« first day (4898 days earlier)      last day (29 days later) »