On 26/08/2015 5:10 a.m., Joseph Wright wrote: > On 26/08/2015 12:34, Bruno Le Floch wrote: >> Thank you for the responses. I was remiss. I didn't make it clear that >> looking inside braced groups was not the concern, rather to replace (or >> remove) a list of tokens that might include braced groups. I've been >> reworking the code of a package that turns latex expressions into >> expressions that can be digested by l3fp. In fact, this particular issue >> has now been reworked away, but the problem had been to remove a varying >> expression, e.g. \sqrt{123} or \frac{1-x}{1+x}, from the initial >> segment of a formula. Rescanning { and } to "other" allowed me to use >> \tl_remove:Nn successfully. Although I can think of other means of doing >> this, they seem cumbersome by comparison. >> >> Andrew >> \tl_set:No \l_result_tl { \use_none:nn \sqrt{123} + 123 } >> >> could be a better approach in many cases, no? >> >> Bruno I hadn't thought of the \use_none:... functions. (There is much of expl3 which is *not* at my fingertips.) Thank you, and I see that they can absorb up to 9 tokens. > I'm not quite clear if the outcome needs to be that the calculation > remains the same :-) For the simple case of 'drop the \sqrt', presumably > some wrapper is needed > > \cs_new_protected:Npn \my_calc:n #1 > { > \tl_set:Nn \l__my_tl {#1} > \tl_replace_all:Nnn \l__my_tl { \sqrt } { \use_none:n } > % Further replacements > \tl_set:Nx \l__my_tl { \l__my_tl } > } > > I'd though probably go for something like > > \cs_new_protected:Npn \my_calc:n #1 > { > \group_begin: > \cs_set:Npn \sqrt ##1 { sqrt( ##1 ) } > % Further replacements > \fp_set:Nn \l__my_fp {#1} > \exp_args:NNNV \group_end: > \fp_set:Nn \l__my_fp \l__my_fp > } > > i.e. set up the various TeX commands to convert expandably into their fp > equivalents, then set an fp before 'smuggling' the result out the group. > > Depending on the exact spec these approaches could be combined: for > example \frac{1-x}{1+x} clearly has to go, which might be done with > > \cs_set_eq:NN \frac \use_none:nn > > in the second approach or > > \tl_replace_all:Nnn \l__my_tl { \frace} { \use_none:nn } > > in the first. > > The key point is none of this needs rescanning :-) > > Joseph OK, at first glance I was a bit overwhelmed but having had a little time to see what you are doing, this is helpful. Dare I continue the theme? For instance I have used rescanning of ( and ) to "group begin" and "group end" to obtain the parenthesised arguments of functions "at one gulp", e.g. \max(<variable number of terms>) or the parenthesised part (the inner sum) of \sum_{k=0}^{\infty}\frac{(-1)^{k}}{2^{k+1}}\left(\sum_{n=0}^{k}(-1)^{n}\binom{k}{n}\frac{1}{(k-n)!}\right) (= 1/e). Finally, in arguing against changing catcodes you are assuming a greater knowledge of TeX than I possess. There must be a reason for this deprecation. The great joy of discovering expl3 was that it made TeX programming available to someone familiar with basic (or even, dare I say it, line-numbered BASIC) programming concepts but with only a meagre knowledge of TeX. (So, for instance, I wonder why you use \cs_new_protected:Npn above rather than \cs_new:Npn or \cs_new_nopar:Npn. Interfaces3.pdf is thin on such matters.) Andrew LyX Document --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus