键盘命令和环境之间的交互不好?

键盘命令和环境之间的交互不好?

我怀疑keycommandenviron软件包无法很好地协同工作,因为以下代码会出错。有人能解释一下发生了什么吗?

\documentclass{article}

\usepackage{environ}
\usepackage{keycommand}
\usepackage{graphicx}

% Turn scalebox into an environment
\NewEnviron{scaleboxenv}[1]{%
  \scalebox{#1}{\BODY}%
}

% An environment with a named argument
\newkeyenvironment{scaled}[scale=1]{%
  % My real code does some more stuff here
  \begin{scaleboxenv}{\commandkey{scale}}
}{%
  \end{scaleboxenv}
}

\begin{document}

\begin{scaled}[scale=0.7]
Hello
\end{scaled}

\end{document}

答案1

这与keycommandLaTeX 发现\begin{scaleboxenv}需要时 \end{scaleboxenv},但它没有这样做,因为它发现了\end{scaled},从而引发错误。

\documentclass{article}

\usepackage{environ}
\usepackage{keycommand}
\usepackage{graphicx}

% Turn scalebox into an environment
\NewEnviron{scaleboxenv}[1]{%
  \scalebox{#1}{\BODY}%
}

% An environment with a named argument
\newkeyenvironment{scaled}[scale=1]{%
  % My real code does some more stuff here
  \scaleboxenv{\commandkey{scale}}
}{%
  \endscaleboxenv
}

\begin{document}

\begin{scaled}[scale=0.7]
Hello
\end{scaled}

\end{document}

您确定要使用 吗keycommand

这是一个keycommand免费environ版本。

\documentclass{article}
\usepackage{graphicx}
%\usepackage{keyval} % already loaded by graphicx

\makeatletter
\newsavebox{\wickscalebox}
\newenvironment{scaled}[1][]
 {%
  % My real code does some more stuff here
  \setkeys{wickscale}{#1}%
  \begin{lrbox}{\wickscalebox}%
 }
 {%
  \end{lrbox}%
  \scalebox{\wick@scale}{\usebox{\wickscalebox}}%
 }
\define@key{wickscale}{scale}{\def\wick@scale{#1}}
\makeatother


\begin{document}

\begin{scaled}[scale=0.7]
Hello
\end{scaled}

\end{document}

相关内容