Timeline for Does a package exist for programmatically (incrementally) constructing a macro?
Current License: CC BY-SA 4.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 26, 2022 at 18:00 | history | tweeted | twitter.com/StackTeX/status/1563224805603934209 | ||
| Aug 26, 2022 at 0:21 | comment | added | user202729 |
A bit odd many people don't see the usefulness of this, while it's used in e.g. expl3 source code e.g. in \__regex_replacement_put:n to allow "appending" e.g. unbalanced { or } to a "token list". They think other people don't want to write complex macros?
|
|
| Aug 26, 2022 at 0:11 | comment | added | user202729 |
I kind of covered this (tricks to handle unbalanced token list in TeX, by putting something that x-expands to the desired token list) in tex.stackexchange.com/a/638453/250119, but maybe also see other answers under there. But "appending" a \ does require manipulating the whole thing as a string and \scantokens the result, it may be a better idea to learn how tokens work in TeX and manipulate the input as a token list directly instead of a string. ■ Side note, \tl_put_right:Nn in a loop has quadratic time complexity, use \tl_build_put_right:Nn etc. for performance.
|
|
| Aug 25, 2022 at 22:44 | answer | added | jps | timeline score: 3 | |
| Aug 25, 2022 at 21:11 | answer | added | Ulrich Diez | timeline score: 2 | |
| Aug 25, 2022 at 19:41 | comment | added | Ulrich Diez |
You use the phrase "macro under construction". You say you want \AddCharToMacro{c} to append the special character "command ('\')" to the macro under construction. The characters in a .tex-input-file are taken for instructions to append tokens to the token stream. These might be explicit character tokens or control sequence token. Expansion takes place after tokenization. What shall "macro under construction" be? A set of tokens? Then there is no special \ . A set of character which can be retokenized via \scantokens? Then there is no expansion at the time of adding things to the buffer.
|
|
| Aug 25, 2022 at 19:33 | answer | added | wipet | timeline score: 5 | |
| Aug 25, 2022 at 7:17 | comment | added | Joseph Wright♦ | So many assignments :( | |
| Aug 25, 2022 at 3:14 | history | became hot network question | |||
| Aug 25, 2022 at 2:40 | comment | added | Daniel Diniz |
it might be worthy learning the hook system of the latest few releases of the LaTeX kernel. I've found myself replacing 5 or 6 uses of etoolbox's \pretocmd-and-friends with \AddToHook
|
|
| Aug 24, 2022 at 23:12 | vote | accept | COTO | ||
| Aug 24, 2022 at 21:49 | answer | added | Marijn | timeline score: 4 | |
| Aug 24, 2022 at 21:44 | answer | added | egreg | timeline score: 6 | |
| Aug 24, 2022 at 19:24 | comment | added | Ulrike Fischer |
there is no need to "build" a macro. You can simply append e.g. with \tl_put_right:Nn
|
|
| Aug 24, 2022 at 19:10 | history | asked | COTO | CC BY-SA 4.0 |