![键盘命令和环境之间的交互不好?](https://linux22.com/image/268373/%E9%94%AE%E7%9B%98%E5%91%BD%E4%BB%A4%E5%92%8C%E7%8E%AF%E5%A2%83%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BA%A4%E4%BA%92%E4%B8%8D%E5%A5%BD%EF%BC%9F.png)
我怀疑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}