仅在其中一个分割书目中抑制 biblatex 字段?

仅在其中一个分割书目中抑制 biblatex 字段?

我知道\clearfield\clearlist等等(参见是否可以在 biblatex 中抑制 bibtex .bbl 中的特定字段?)——但我真的不确定如何在这种情况下应用它:

假设您有一个拆分的参考书目(即,在一个文档中多次调用\printbibliography)。您如何过滤参考书目项目中的特定字段 - 但只能在一个参考书目中(即,只能在一次调用 中\printbibliography)?

例如,在下面的 MWE 中(使用 编译pdflatex test.tex && biber test && pdflatex test.tex && pdflatex test.tex),假设我想过滤urldate(即urldate未排版)仅有的在第一个参考书目中 - 但对于第二个,应该恢复原始/默认行为(即urldate排版)。我该怎么做?

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{ctan,
  title        = {CTAN},
  date         = 2006,
  url          = {http://www.ctan.org},
  subtitle     = {The Comprehensive TeX Archive Network},
  urldate      = {2006-10-01},
  label        = {CTAN},
  langid       = {english},
  langidopts   = {variant=american},
}
@misc{google,
  title        = {Google},
  date         = 2007,
  url          = {http://www.google.com},
  urldate      = {2007-10-01},
}
@misc{hotmail,
  title        = {Hotmail},
  date         = 2008,
  url          = {http://www.hotmail.com},
  urldate      = {2008-10-01},
}
@misc{yahoo,
  title        = {Yahoo},
  date         = 2009,
  url          = {http://www.yahoo.com},
  urldate      = {2009-10-01},
}
@misc{aol,
  title        = {AOL},
  date         = 2010,
  url          = {http://www.aol.com},
  urldate      = {2010-10-01},
}
@misc{altavista,
  title        = {AltaVista},
  date         = 2011,
  url          = {http://www.altavista.com},
  urldate      = {2011-10-01},
}
\end{filecontents*}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,defernumbers=true,style=ieee]{biblatex}
\bibliography{\jobname}

\begin{document}

\section{Section 1}
\begin{refsection}

Citing some stuff here: first \cite{ctan}, then \cite{google}, and finally \cite{hotmail}.

\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]

\end{refsection}

\section{Section 2}
\begin{refsection}

Citing some stuff here: first \cite{yahoo}, then \cite{aol}, and finally \cite{altavista}.

\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]

\end{refsection}

\end{document}

输出:

测试.png

答案1

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\newbool{clearurl}

\AtEveryBibitem{%
 \ifbool{clearurl}
  {%
   \clearfield{urlday}%
   \clearfield{urlmonth}%
   \clearfield{urlyear}%
  }{}%
  }

\begin{document}

Citing some stuff here: first \cite{ctan}

\booltrue{clearurl}
\printbibliography


\boolfalse{clearurl}
\printbibliography
\end{document}

输出:

测试.png

答案2

我们可以为此定义一个新命令:(\AtEveryBibitemNextBibOnly多好的名字),它结合了\AtEveryBibitem和的优点\AtNextBibliography

\makeatletter
\newrobustcmd*{\AtEveryBibitemNextBibOnly}{%
  \ifundef\blx@hook@bibitem@save
    {\global\let\blx@hook@bibitem@save\blx@hook@bibitem
     \preto\blx@endbibliography{\global\let\blx@hook@bibitem\blx@hook@bibitem@save
                                \global\undef\blx@hook@bibitem@save}}
    {}%
  \gappto\blx@hook@bibitem}
\makeatother

本质上,它保存了所做事情的当前定义\AtEveryBibitem并将您输入的所有代码附加到,但下一个参考书目之后将恢复的\AtEveryBibitem旧定义。\AtEveryBibitem

因此,您通过添加的所有代码\AtEveryBibitemNextBibOnly都会针对下一个参考书目中的每个项目执行(并且仅在下一个参考书目中执行)。

在我们的例子中我们只需要

\AtEveryBibitemNextBibOnly{\clearfield{urlyear}}

就在我们想要抑制的参考书目之前urldate

平均能量损失

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,defernumbers=true,style=ieee]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\newrobustcmd*{\AtEveryBibitemNextBibOnly}{%
  \ifundef\blx@hook@bibitem@save
    {\global\let\blx@hook@bibitem@save\blx@hook@bibitem
     \preto\blx@endbibliography{\global\let\blx@hook@bibitem\blx@hook@bibitem@save
                                \global\undef\blx@hook@bibitem@save}}
    {}%
  \gappto\blx@hook@bibitem}
\makeatother

\begin{document}
\section{Section 1}
\begin{refsection}
Citing some stuff here: first \cite{ctan}, then \cite{markey}.
\AtEveryBibitemNextBibOnly{\clearfield{urlyear}}
\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]
\end{refsection}

\section{Section 2}
\begin{refsection}
Citing some stuff here: first \cite{ctan}, then \cite{markey}.
\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]
\end{refsection}
\end{document}

在此处输入图片描述

相关内容