我正在编写一种biblatex
扩展另一个第三方样式的样式。我需要的是,\DeclareCiteCommand
这样\justcite
打印参考书目时就不会考虑它的引用,而只有当作者不再使用任何其他引用命令(例如)引用它时才会考虑\cite
。解决方案不应该要求在\printbibliography
命令中设置选项,也不应该在条目中设置特殊属性.bib
,这意味着所有实现都应该在我的样式文件中。
\DeclareBibliographyCategory{refcite}
\AtEveryCitekey{%
\ifcsstring{blx@delimcontext}{justcite}{}{%
\addtocategory{refcite}{\thefield{entrykey}}}}
\newbibmacro*{justcite}{%
\DeclareFieldAlias{bibhyperref}{noformat}%
\usebibmacro{cite}}
\DeclareCiteCommand{\justcite}
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{justcite}}
{}
{\usebibmacro{postnote}}
\DeclareMultiCiteCommand{\justcites}
{\justcite}
{\setunit{\multicitedelim}}
但这样作者就需要category
在\printbibliography
命令中明确设置选项:
\printbibliography[category=refcite]
我还发现了一些有关refsection
s 的信息,但我不确定我应该如何实现它以及这对我有何帮助。
也许我可以直接在我的样式文件中为命令设置默认选项\printbibliography
,但我没有找到有关这种方法的任何文档或实现。
我怎样才能实现这个目标?
以下代码是我当前拥有的 MWE:
\documentclass{article}
\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}
\DeclareBibliographyCategory{refcite}
\AtEveryCitekey{%
\ifcsstring{blx@delimcontext}{justcite}{}{%
\addtocategory{refcite}{\thefield{entrykey}}}}
\newbibmacro*{justcite}{%
\DeclareFieldAlias{bibhyperref}{noformat}%
\usebibmacro{cite}}
\DeclareCiteCommand{\justcite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{justcite}}
{}
{\usebibmacro{postnote}}
\DeclareMultiCiteCommand{\justcites}[\mkbibparens]
{\justcite}
{\setunit{\multicitedelim}}
\addbibresource{biblatex-examples.bib}
\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.
But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.
\printbibliography[category=refcite]
\end{document}
它生成以下文档,其中是预期结果:
请注意,glashow
未列出参考文献,因为它仅被命令引用\justcite
。
再次,问题在于作者必须category
在\printbibliography
命令中明确设置选项。但是,当引用条目在参考文献中列出时,引用的处理方式对作者来说应该是隐含的,即,这种过滤应该直接在我的样式文件中实现。
根据 MWE,这意味着作者应该有以下内容:
\documentclass{article}
\usepackage[style=my-style]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}
\addbibresource{biblatex-examples.bib}
\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.
But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.
\printbibliography
\end{document}
并且此代码应该生成相同的文档。
我还相信一定有一种更通用的方法来解决这个问题,而不需要下面的代码片段:
\AtEveryCitekey{%
\ifcsstring{blx@delimcontext}{justcite}{}{%
\addtocategory{refcite}{\thefield{entrykey}}}}
对我来说这似乎也是一种解决方法。
顺便说一下,MWE 使用了biblatex
我想要扩展的样式,该包名为biblatex-abnt
。
答案1
也许我可以直接在我的样式文件中为命令设置默认选项
\printbibliography
,但我没有找到有关这种方法的任何文档或实现。
\DeclarePrintbibliographyDefaults
是您要查找的命令。它不需要密钥category
,但它确实需要filter
密钥,所以我们只需要定义一个仅匹配refcite
类别的过滤器。
\documentclass{article}
\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}
\DeclareBibliographyCategory{refcite}
\AtEveryCitekey{%
\ifcsstring{blx@delimcontext}{justcite}{}{%
\addtocategory{refcite}{\thefield{entrykey}}}}
\newbibmacro*{justcite}{%
\DeclareFieldAlias{bibhyperref}{noformat}%
\usebibmacro{cite}}
\DeclareCiteCommand{\justcite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{justcite}}
{}
{\usebibmacro{postnote}}
\DeclareMultiCiteCommand{\justcites}[\mkbibparens]
{\justcite}
{\setunit{\multicitedelim}}
%%% BEGIN ADDED %%%
\defbibfilter{refcite}{category=refcite}
\DeclarePrintbibliographyDefaults{filter=refcite}
%%% END ADDED %%%
\addbibresource{biblatex-examples.bib}
\begin{document}
This sentence wants to list the reference of its citation because it is important \cite{aksin}.
But not this sentence \justcite{aksin,glashow}. However, once \verb|aksin| was cited above with \verb|\cite|, it appears in the references below.
\printbibliography % No [category=refcite] needed
\end{document}
我还相信一定有一种更通用的方法来解决这个问题,而不需要下面的代码片段:
\AtEveryCitekey{% \ifcsstring{blx@delimcontext}{justcite}{}{% \addtocategory{refcite}{\thefield{entrykey}}}}
对我来说这似乎也是一种解决方法。
\AtEveryCitekey
我们可以使用和 书目来确定该条目是否应包含在书目中,而不是定义新的书目类别
check
。但是我们无法设置check
和
\DeclarePrintbibliographyDefaults
,因此我们需要侵入私有 BibLaTeX 宏来执行此操作。
\documentclass{article}
\pagestyle{empty}
\usepackage[style=abnt]{biblatex}
\usepackage[citecolor=red, colorlinks]{hyperref}
\makeatletter
\def\bbx@printentry@yes{%
\global\cslet{bbx@printentry@key@\abx@field@entrykey}\@empty%
}
\def\bbx@printentry@no{%
\ifcsdef{bbx@printentry@key@\abx@field@entrykey}{}{%
\global\cslet{bbx@printentry@key@\abx@field@entrykey}\bbx@printentry@no@aux%
}%
}
\let\bbx@printentry@this=\bbx@printentry@yes
\AtEveryCitekey{%
\bbx@printentry@this%
}
\newrobustcmd{\justcite}[2][cite]{%
\let\bbx@printentry@this=\bbx@printentry@no
\csname#1\endcsname{#2}%
\let\bbx@printentry@this=\bbx@printentry@yes
}
%%% The proper way:
%
% \def\bbx@printentry@no@aux{%
% \skipentry%
% }
%
% \defbibcheck{nojustcite}{%
% \csname bbx@printentry@key@\abx@field@entrykey\endcsname%
% }
%
%%% [...]
%
% \printbibliography[check=nojustcite]
%%% The hacky way:
\def\bbx@printentry@no@aux{%
\toggletrue{blx@skipentry}%
}
\def\blx@bibcheck{%
\csname bbx@printentry@key@\abx@field@entrykey\endcsname%
}
\makeatother
\addbibresource{biblatex-examples.bib}
\begin{document}
This sentence wants to list the reference of its citation because it is
important \cite{aksin}.
But not this sentence \justcite{aksin,glashow}. However, once
\verb|aksin| was cited above with \verb|\cite|, it appears in the
references below.
We can also use other citation commands like
\justcite[citetitle]{glashow} or \justcite[Citeauthor]{aksin}.
\printbibliography
\end{document}