In order to learn better about handling dynamic arguments and "blocks" like what you pass to a command/environment, I would like to try to write a wrapper function around \NewDocumentEnvironment
and \NewDocumentCommand
that does pretty much exactly what they do. However I would like the API to be:
\myenvironment{foo}{<args>}{startblock}{endblock}
\mycommand{foo}{<args>}{block}
i.e. even though the API is \NewDocumentCommand{\foo}
with the backslash \foo
, I would like to make it foo
.
Here is the MWE for the system:
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\begin{document}
\NewDocumentCommand{\mycommand}{mmm} {
\NewDocumentCommand{#1}{#2}{#3}
}
\mycommand{myenvironment}{mmmO{}} {
\NewDocumentEnvironment{#1}{#2}{#3}{#4}
}
\myenvironment{foo}{m}{
\typeout{#1}
}{}
\begin{foo}{abc}
\end{foo}
\end{document}
The things I am not sure about are:
- Passing through the arguments like
\NewDocumentEnvironment{#1}{#2}{#3}{#4}
- Handling "blocks", since all I've ever dealt with in passing arguments is simple one-liners/strings/key-val pairs.
- How to handle the
foo
to\foo
transformation when passing through.
Wondering how to get this to work using the above definitions for \myenvironment
and \mycommand
:
\begin{foo}{abc}
\end{foo}
\ExplSyntaxOn
if you're usingxparse
macros alone\ExplSyntaxOn
.