LaTeX forum ⇒ Generalexpl3 meta macro Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
erwann
Posts: 72
Joined: Thu Aug 25, 2016 2:24 am

expl3 meta macro

Postby erwann » Thu Mar 01, 2018 3:12 am

I'd like to create a macro for creating external macros that conform to a template. Cld someone pls make a suggestion? Perhaps '\exp_args:Nc' somewhere?


  1. \documentclass{article}
  2. \usepackage{xparse}
  3.  
  4. \ExplSyntaxOn
  5.  
  6. \cs_new:Npn
  7. \impl #1
  8. {
  9. (#1)
  10. }
  11.  
  12. \cs_new:Npn \metamacro #1 {
  13. \NewDocumentCommand {\cs:w #1 \cs_end: }
  14. % {
  15. { m }
  16. {
  17. \impl{#1}
  18. }
  19. % }
  20. }
  21.  
  22. \metamacro{baz}
  23.  
  24. \ExplSyntaxOff
  25.  
  26. \begin{document}
  27.  
  28. \baz % Expected: (baz)
  29.  
  30. \end{document}
Attachments
Screen Shot 2018-02-28 at 8.09.30 PM.png
Screen Shot 2018-02-28 at 8.09.30 PM.png (26.33 KiB) Viewed 1027 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Tags:

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Mar 01, 2018 11:44 am

The first argument to \NewDocumentCommand can only be one command sequence token and not – like in your case – an instruction to build one. This means you have to build the command sequence token before passing it to \NewDocumentCommand.

Also you are not following expl3 guidelines and naming conventions. Here is a working suggestion:

  1. \documentclass{article}
  2. \usepackage{xparse}
  3.  
  4. \ExplSyntaxOn
  5. \cs_new:Npn \ewann_impl:n #1 { (#1) }
  6.  
  7. \cs_new_protected:Npn \ewann_metamacro:n #1
  8. {
  9. \exp_args:Nc \NewDocumentCommand {#1} {}
  10. { \ewann_impl:n {#1} }
  11. }
  12.  
  13. \NewDocumentCommand \metamacro {m}
  14. { \ewann_metamacro:n {#1} }
  15. \ExplSyntaxOff
  16.  
  17. \begin{document}
  18.  
  19. \metamacro{baz}
  20.  
  21. \baz % Expected: (baz)
  22.  
  23. \end{document}
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim


Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 13 guests