![新的环境定义,指定默认的 overpic 参数 - 宏扩展和定义问题](https://linux22.com/image/440311/%E6%96%B0%E7%9A%84%E7%8E%AF%E5%A2%83%E5%AE%9A%E4%B9%89%EF%BC%8C%E6%8C%87%E5%AE%9A%E9%BB%98%E8%AE%A4%E7%9A%84%20overpic%20%E5%8F%82%E6%95%B0%20-%20%E5%AE%8F%E6%89%A9%E5%B1%95%E5%92%8C%E5%AE%9A%E4%B9%89%E9%97%AE%E9%A2%98.png)
我正在努力定义一个新环境,其中包含嵌套的overpic
环境,使用我自己的一组默认参数。
我的主要目标只是拥有一个新的环境,如下所示,我可以使用它来代替常规的环境overpic
,以避免重复所有下面编码的参数。
我遇到了无数与扩展和括号(或分组)相关的错误。我首先尝试使用environ
包,如下所示(所有附属宏都是适当定义的长度,保存\figDir
,它是包含相关图像的目录的路径;这些显示在该问题的下一个块中):
\NewEnviron{logoOverpic}[1]{%
\begin{overpic}[width=\linewidth, height=\seqLogoHeight, trim=\leftTrimLogo \botTrimLogo \rightTrimLogo \topTrimLogo, clip]{\figDir/#1}
\BODY%
\end{overpic}%
}{}
\newcommand{\addSeqLogoLabel}[2]{
\setcounter{putVPos}{44}
\put (17, \value{putVPos}) {
\fontsize{14pt}{18pt}\selectfont
%
% use fill colour as border as well, to get correct border-less size
\Large\textsf{#1}\hspace*{4pt}\fboxsep0pt\fcolorbox{#2}{#2}{\phantom{X}}
}
}
其用法示例如下:
\begin{logoOverpic}{logoMA0466_1}
\addSeqLogoLabel{\TFBS{CEBPB}~MA0466.1}{orange}
\end{logoOverpic}
我之前得到的错误形式是:“\Gread@parse@vp 的参数有一个额外的}。”
我一直试图(徒劳地)解决这个问题,方法是应用相关答案。
我在这方面的努力显然很差,因为它们只会加剧我所犯的错误。我尝试了以下方法,尽管我意识到它根本不正确:
\NewEnviron{logoOverpic}[1]{%
\begingroup\edef\x{\endgroup\noexpand%
\begin{overpic}[width=\linewidth, height=\seqLogoHeight, trim=\leftTrimLogo \botTrimLogo \rightTrimLogo \topTrimLogo, clip]{\figDir/#1}}\x%
\BODY%
\end{overpic}%
}{}
我现在收到如下三个错误:
"Runaway argument?
main.tex, 396
clip,\@nil ,\XKV@usepresetkeys {}{presett}\let \CurrentOption \@empty \ETC.
! Paragraph ended before \Gread@parse@vp was complete.
<to be read again>
\par
l.396 \end{logoOverpic}
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
Extra }, or forgotten \endgroup.
main.tex, 396
<recently read> }
l.396 \end{logoOverpic}
I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.
Runaway argument?
main.tex, 441
\env@nil \end {logoOverpic} \label {fig:0.3:JASPAR_CEBPB} \end {subfi\ETC.
! Paragraph ended before \Gread@parse@vp was complete.
<to be read again>
\par
l.441
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
LaTeX Error: Not in outer par mode.
我将非常感激任何人能提供的建议!
目前,我不提供 MWE。我承认这会给我提供帮助带来更多困难,对此造成的不便,我深表歉意。
如果有人愿意提供建议,我将不胜感激。如果在一定时间内没有合适的建议,我将努力撰写一份合适的 MWE。
答案1
您使用 时遇到问题trim=
,因为长度之间没有留空格。您可以使用\newenviroment
。
\documentclass{article}
\usepackage{overpic}
\newlength\seqLogoHeight
\newlength\leftTrimLogo
\newlength\botTrimLogo
\newlength\rightTrimLogo
\newlength\topTrimLogo
\setlength{\seqLogoHeight}{2cm}
\newenvironment{logoOverpic}[2][]
{\begin{overpic}[
width=\linewidth,
height=\seqLogoHeight,
trim={\leftTrimLogo} {\botTrimLogo} {\rightTrimLogo} {\topTrimLogo},
clip,
#1 % additional keys
]{#2}% it would be \figDir/#1 for you
}
{\end{overpic}}
\begin{document}
\noindent% no overfull box
\begin{logoOverpic}{example-image}
\end{logoOverpic}
\setlength{\rightTrimLogo}{4cm}
\noindent
\begin{logoOverpic}[width=4cm]{example-image}
\end{logoOverpic}
\end{document}