可选参数内的可选参数的控制序列必须用括号“隐藏”使用该abntex2cite
包来处理我的引用时,我经常想要写:
\begin{teor}[{\cite[p.~42]{johndoe1999}}]
$2+2=4$.
\end{teor}
但这并不管用;我需要写:
\begin{teor}[\leavevmode{\cite[p.~42]{johndoe1999}}]
$2+2=4$.
\end{teor}
相反。
\cite
和\citeonline
在这方面表现完全相同。此外\leavevmode
,\strut
或只是一个空格/行尾也可以工作(除了空格看起来很奇怪/丑陋)。也就是说,LaTeX 需要在括号之间的引用宏之前开始一行。我认为这可能是因为宏\cite
和\citeonline
必须以 开头\leavevmode
,但事实并非如此;然而,来源显示, ISabntex2cite
的第一行\citeonline
\leavevmode
!
我的问题是:
- 为什么虽然以 开头,但
\leavevmode
在 之前\citeonline
(或)还需要有 another 呢?\cite
\citeonline
\leavevmode
- 有没有办法重新定义
\cite
,\citeonline
这样我就不需要在括号引用宏之前添加空格/\strut
/ 了?\leavevmode
(展示我所描述的内容的文件)
内容sample.tex
:
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{teor}{Teorema}
\newcommand*{\page}[1]{p.~#1}
\usepackage[alf]{abntex2cite}
\begin{document}
Regular ``external'' citation according to the ABNT (Brazilian) standard:
\cite{johndoe1999}.
Regular ``inline'' citation according to the ABNT (Brazilian) standard:
\citeonline{johndoe1999}.
So far, so good; no extra braces needed.
Whithin the optional argument of an environment, however,
extra braces are needed:
\begin{teor}[This works
{\cite[\page{25}]{johndoe1999}}%<-- notice the extra braces!
]
Notice the extra braces in the optional argument.
\end{teor}
\begin{teor}[Also works
{\citeonline[\page{25}]{johndoe1999}}%<-- notice the extra braces!
]
Notice the extra braces in the optional argument.
\end{teor}
And the next one works, but it requires
(besides the extra braces)
something to start a line before \verb|\cite| or \verb|\citeonline|:
it can be a space, a \verb|\strut| or \verb|\leavevmode|.
I think that's annoying and error-prone;
is there another way?
\begin{teor}[% avoid extraneous space here
\leavevmode{\citeonline[\page{25}]{johndoe1999}}%<-- \leavevmode + extra braces!
]
This one requires both
extra braces AND ``something to start a line''
in the optional argument.
\end{teor}
\bibliography{bibfile}
% this is how a chapter of a book is supposed to look in the ABNT style...
\end{document}
% -- the following won't compile!
% erase the previous 2 macros to generate errors
\begin{teor}[% lacks \leavevmode AND extra braces
\citeonline[\page{25}]{johndoe1999}%
]
\fbox{content}
\end{teor}
\begin{teor}[% lacks extra braces: {\citeonline...}
\leavevmode\citeonline[\page{25}]{johndoe1999}%
]
\fbox{content}
\end{teor}
\begin{teor}[% lacks \leavevmode (or \strut)
{\citeonline[\page{25}]{johndoe1999}}%
]
\fbox{content}
\end{teor}
\bibliography{bibfile}
\end{document}
内容bibfile.bib
:
% Encoding: UTF-8
@InCollection{johndoe1999,
author = {Doe, John},
booktitle = {Handbook of Foobar},
publisher = {Barbaz},
title = {Interesting chapter},
year = {1999},
address = {Earth},
editor = {{Mc}Editor, Editor},
pages = {283--342},
}
答案1
问题显然是由于ntheorem
:如果我删除它,问题就会消失。
如果你真的需要它(就我个人而言,我不会使用它),我可以提出一个解决方法:
\begin{filecontents*}{\jobname.bib}
@InCollection{johndoe1999,
author = {Doe, John},
booktitle = {Handbook of Foobar},
publisher = {Barbaz},
title = {Interesting chapter},
year = {1999},
address = {Earth},
editor = {{Mc}Editor, Editor},
pages = {283--342},
}
\end{filecontents*}
\documentclass{article}
\usepackage[alf]{abntex2cite}
\usepackage{ntheorem}
\newtheorem{teor}{Teorema}
\ExplSyntaxOn
\NewDocumentCommand{\fixtheorem}{m}
{
\cs_set_eq:cc { #1@fixed } { #1 }
\cs_set_eq:cc { end#1@fixed } { end#1 }
\RenewDocumentEnvironment{#1}{o}
{
\IfNoValueTF{##1}{\use:c{#1@fixed}}{\use:c{#1@fixed}[\exp_not:n{##1}]}
}
{
\use:c{end#1@fixed}
}
}
\ExplSyntaxOff
\fixtheorem{teor}
\newcommand*{\page}[1]{p.~#1}
\begin{document}
Regular ``external'' citation according to the ABNT (Brazilian) standard:
\cite{johndoe1999}.
Regular ``inline'' citation according to the ABNT (Brazilian) standard:
\citeonline{johndoe1999}.
So far, so good; no extra braces needed.
Whithin the optional argument of an environment, however,
extra braces are needed:
\begin{teor}[This works {\cite[\page{25}]{johndoe1999}}]
Notice the extra braces in the optional argument.
\end{teor}
\begin{teor}[Also works {\citeonline[\page{25}]{johndoe1999}}]
Notice the extra braces in the optional argument.
\end{teor}
And the next one works, but it requires
(besides the extra braces)
something to start a line before \verb|\cite| or \verb|\citeonline|:
it can be a space, a \verb|\strut| or \verb|\leavevmode|.
I think that's annoying and error-prone;
is there another way?
\begin{teor}[{\cite[\page{25}]{johndoe1999}}]
This one requires both extra braces AND ``something to start a line''
in the optional argument.
\end{teor}
\begin{teor}[{\citeonline[\page{25}]{johndoe1999}}]
This one requires both extra braces AND ``something to start a line''
in the optional argument.
\end{teor}
\bibliography{\jobname}
\end{document}
对原来的teor
进行重命名,并定义teor@fixed
一个更为强大的环境,同时保护可选参数免受不合时宜的扩展的影响。teor
ntheorem
这还有一个小优点,你甚至可以省略内部括号和
\begin{teor}[\cite[\page{25}]{johndoe1999}]
会工作。