Generalexpl3 meta macro

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

expl3 meta macro

Post by erwann »

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?

Code: Select all

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn

\cs_new:Npn
	\impl #1
		{
			(#1)
		}

\cs_new:Npn \metamacro #1 {
	\NewDocumentCommand {\cs:w #1 \cs_end: } 
%		{
			{ m }
			{
				\impl{#1}
			}
%		}
}

\metamacro{baz}

\ExplSyntaxOff

\begin{document}

\baz % Expected: (baz)

\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 4186 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

expl3 meta macro

Post by cgnieder »

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:

Code: Select all

\documentclass{article}
\usepackage{xparse}
 
\ExplSyntaxOn
\cs_new:Npn \ewann_impl:n #1 { (#1) }
 
\cs_new_protected:Npn \ewann_metamacro:n #1
  {
    \exp_args:Nc \NewDocumentCommand {#1} {}
      { \ewann_impl:n {#1} }
  }

\NewDocumentCommand \metamacro {m}
  { \ewann_metamacro:n {#1} }
\ExplSyntaxOff
 
\begin{document}

\metamacro{baz}

\baz % Expected: (baz)
 
\end{document}
site moderator & package author
Post Reply