![以编程方式创建新的文档环境](https://linux22.com/image/445231/%E4%BB%A5%E7%BC%96%E7%A8%8B%E6%96%B9%E5%BC%8F%E5%88%9B%E5%BB%BA%E6%96%B0%E7%9A%84%E6%96%87%E6%A1%A3%E7%8E%AF%E5%A2%83.png)
我想以编程方式创建一个新\NewDocumentEnvironment
环境,使用一个简单的命令来创建新的环境(有点像如何使用\newtheorem
创建一种新类型的环境)。
但是,我不确定该怎么做。我应该使用某种类型的expandafter
, \csname
... 吗?
平均能量损失
\documentclass[]{article}
\usepackage{xparse}
%% Environment generic but too verbose to use. (I need the +b)
\NewDocumentEnvironment{myenv}{O{}m+b}{
Foo (#1) Bar (#2) Baz (#3) Bise}{}
%% Create a command to create new environment to fix the options of the verbose env.
\NewDocumentCommand\newEnv{O{}mm}{
\NewDocumentEnvironment{#1}{O{}+b}{
\begin{myenv}[##1]{#2}
##3
\end{myenv}
}{}
}
%% Use it to create a new environment
\newEnv[dolphin]{myDolpinEnv}{I am a dolphin.}
\begin{document}
\begin{myenv}[I'm optional]{I'm mandatory}
I'm inside.
\end{myenv}
\begin{myDolpinEnv}[blue dolphin]
Psiooouu!
\end{myDolpinEnv}
\end{document}
答案1
好的,我找到了解决方案,我在原来的环境中犯了一些拼写错误。
\documentclass[]{article}
\usepackage{xparse}
%% Environment generic but too verbose to use. (I need the +b)
\NewDocumentEnvironment{myenv}{O{}m+b}{
Foo (#1) Bar (#2) Baz (#3) Bise}{}
%% Create a command to create new environment to fix the options of the verbose env.
\NewDocumentCommand\newEnv{O{}mm}{
\NewDocumentEnvironment{#2}{O{}+b}{
\begin{myenv}[#1,##1]{#3}
##2
\end{myenv}
}{}
}
%% Use it to create a new environment
\newEnv[dolphin]{myDolpinEnv}{I am a dolphin.}
\begin{document}
\begin{myenv}[I'm optional]{I'm mandatory}
I'm inside.
\end{myenv}
\begin{myDolpinEnv}[blue dolphin]
Psiooouu!
\end{myDolpinEnv}
\end{document}