Is there some facility in the LaTeX3 kernel to modify existing commands like etoolbox's \preto \appto and \patchcmd do?


No. The expl3 language is useful for both programming with existing LaTeX2e code and creating new code, and so there are some facilities which are '2e-facing'. However, patching existing commands is not an area we wish to encourage: it is much better if interfaces are provided for altering code flows, etc. Patching for LaTeX2e can as you note be achieved using etoolbox, whilst it should not be used for expl3 code at all (rather discussions should be undertaken to provide appropriate interfaces).

Note that \preto and appto are more-or-less the same at \tl_put_left:Nn and \tl_put_right:Nn, but there are no equivalents of \pretocmd/\apptocmd.

  • I tried to \tl_put_left:Nn \existingmacro { \new \directives } without success. Am I right to assume they only work on initialized token lists and not for arbitrary macros? – XZS Sep 10 '15 at 12:46
  • @XZS As the name says, it's adding to the left of an existing token list (macro): the 'all vars must be declared' position is pretty clear in expl3. – Joseph Wright Sep 10 '15 at 12:58
  • 1
    @JosephWright (off-topic question): it seems LaTeX3 parlance often refers to token lists which are not the same as the token list registers or variables from TeX. Am I wrong, and if not isn't it a bit confusing ? – user4686 Sep 10 '15 at 13:10
  • 1
    @jfbu I guess I should have put tl var in the above comment: we use tl var to refer to a TeX macro used as a storage bin. We don't use toks (token list registers) at all in expl3 (well, there are a few internal places but we don't expose them). The point thus is from an expl3 point of view there is no need to discuss toks at all. – Joseph Wright Sep 10 '15 at 13:24
  • @JosephWright thanks for the explanation, good to know. Is this some remnant of Lamport's LaTeX spirit ? – user4686 Sep 10 '15 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.