我怀疑keycommand
和environ
软件包无法很好地协同工作,因为以下代码会出错。有人能解释一下发生了什么吗?
\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
这与keycommand
LaTeX 发现\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}