使用循环定义 bibchecks

使用循环定义 bibchecks

我正在尝试为我的参考书目创建按年份分类的子类别(使用 biblatex)。我发现我可以使用 defbibcheck 按年份进行检查,如下所示:

\defbibcheck{2013}{
  \iffieldint{origyear}
    {\ifnumequal{\thefield{origyear}}{2013}
      {}
      {\skipentry}
    }
    {\iffieldint{2013}
      {\ifnumequal{\thefield{year}}{2013}
       {}
       {\skipentry}
    }
    {\skipentry}
   }
}       

但是因为年份太多,我并不想每年都有一份副本。我想我可以像这样\foreach从包中使用:pgffor

\foreach \year in {2012,2013}{%
 \defbibcheck{\year}{
  \iffieldint{origyear}
    {\ifnumequal{\thefield{origyear}}{\year}
      {}
      {\skipentry}
    }
    {\iffieldint{\year}
      {\ifnumequal{\thefield{year}}{\year}
        {}
        {\skipentry}
      }
      {\skipentry}
    }
}
}   

但是,\prinbibliography[check=2013]结果是Check '2013' not found.还有其他方法可以做到这一点吗?

编辑:下面是最小不起作用的示例:

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage{biblatex}


\foreach \year in {2012,2013}{%
 \defbibcheck{\year}{
  \iffieldint{origyear}
    {\ifnumequal{\thefield{origyear}}{\year}
      {}
      {\skipentry}
    }
    {\iffieldint{\year}
      {\ifnumequal{\thefield{year}}{\year}
        {}
        {\skipentry}
      }
      {\skipentry}
    }
}
}


\begin{filecontents*}{\jobname.bib}
@inproceedings{Bar2013,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2013}
}
@inproceedings{Bar2012,
    author = {F. Bar},
booktitle = {International Conference on Information},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2012}
}
\end{filecontents*}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography[check=2013]
\end{document} 

答案1

像这样吗?

\begin{filecontents*}{\jobname.bib}
@inproceedings{Bar2011,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2011 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2011}
}

@inproceedings{Bar2013,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2013 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = 2013
}

@inproceedings{Bar2012,
    author = {F. Bar},
booktitle = {International Conference on Information 2012},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2012}
}

@inproceedings{Bar2012b,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2012}
}

@inproceedings{Bar2014,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing 2014},
pages = {1--2},
title = {{A meaningless title}},
year = {2014}
}
\end{filecontents*}

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage{biblatex}

\defbibcheck{ylist}{%
  \iffieldint{year}{%
    \xdef\fldyear{\thefield{year}}\xdef\doskip{1}%
    \foreach \yr in \yrlist{%
      \ifnumequal{\fldyear}{\yr}{\xdef\doskip{0}\breakforeach}{}%
    }%
    \ifnumequal{\doskip}{1}{\skipentry}{}%
  }%
  {\skipentry}%
}

\addbibresource{\jobname.bib}
\begin{document}
\def\yrlist{2012,2013,2011,2010}
Years: \yrlist

\nocite{*}
\printbibliography[check=ylist]
\end{document} 

在此处输入图片描述

编辑: MWE按年份参考:

\begin{filecontents*}{\jobname.bib}
@inproceedings{Bar2011,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2011 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2011}
}

@inproceedings{Bar2013,
    author = {F. Bar and B. Foo},
    booktitle = {The conference 2013 on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = 2013
}

@inproceedings{Bar2012,
    author = {F. Bar},
booktitle = {International Conference on Information 2012},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2012}
}

@inproceedings{Bar2012b,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2012}
}

@inproceedings{Bar2014,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing 2014},
pages = {1--2},
title = {{A meaningless title}},
year = {2014}
}
\end{filecontents*}

\documentclass{article}
\usepackage{filecontents}
\usepackage{pgffor}
\usepackage{biblatex}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
%
\def\yrlist{2011,2012,2013}

\foreach \yr in \yrlist{%
  \defbibcheck{ylist}{%
    \iffieldint{year}{%
        \ifnumequal{\thefield{year}}{\yr}{}{\skipentry}%
    }%
    {\skipentry}%
  }%
  \renewcommand{\refname}{REFERENCES: \yr}%
  \printbibliography[check=ylist]
}
\end{document} 

在此处输入图片描述

答案2

你可以适应奥黛丽的回答一个非常相似的问题(如何按字母顺序拆分参考书目?)

\makeatletter
\def\ifskipbib{\iftoggle{blx@skipbib}}
\makeatother

\def\yearlist{}
\forcsvlist{\listadd\yearlist}{2010,2011,2012,2013}
\forlistloop{\DeclareBibliographyCategory}{\yearlist}
\renewcommand*{\do}[1]{\defbibheading{#1}{\section*{#1}}}
\dolistloop{\yearlist}
\AtDataInput{\ifskipbib{}{\addtocategory{\thefield{year}}{\thefield{entrykey}}}}

第一个代码块确保跳过未出现在参考书目中的条目(您不希望那里有一个空的 2010)。

第二个块循环遍历第二行中给出的所有年份,并为每个年份创建不同的类别。然后定义这些子书目的标题。最后,最后一行将条目与其年份类别进行匹配。

\documentclass{article}
\usepackage{biblatex}

\begin{filecontents*}{\jobname.bib}
@inproceedings{Bar2013,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2013}
}
@inproceedings{Bar2012,
    author = {F. Bar},
booktitle = {International Conference on Information},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2012}
}
\end{filecontents*}

\makeatletter
\def\ifskipbib{\iftoggle{blx@skipbib}}
\makeatother

\def\yearlist{}
\forcsvlist{\listadd\yearlist}{2010,2011,2012,2013}
\forlistloop{\DeclareBibliographyCategory}{\yearlist}
\renewcommand*{\do}[1]{\defbibheading{#1}{\section*{#1}}}
\dolistloop{\yearlist}
\AtDataInput{\ifskipbib{}{\addtocategory{\thefield{year}}{\thefield{entrykey}}}}

\addbibresource{\jobname.bib}
\begin{document}
  \nocite{*}
  \printbibheading
  \bibbycategory
\end{document} 

您的代码还有一个半自动版本。

通过定义新命令

\newcommand{\yearcheck}[1]{%
  \defbibcheck{#1}{
    \iffieldint{origyear}
      {\ifnumequal{\thefield{origyear}}{#1}
        {}
        {\skipentry}
      }
      {\iffieldint{year}
        {\ifnumequal{\thefield{year}}{#1}
          {}
          {\skipentry}
        }
        {\skipentry}
      }
   }
}

然后可以使用它来创建年份检查

\yearcheck{2012}
\yearcheck{2013}

这似乎在循环中不起作用,\foeach例如\foreach \year in {2012,2013} {\yearcheck{\year}}

或者更好的是,通过循环(感谢@g.kov)

\foreach \year in {2012,2013} {\global\yearcheck{\year}}

打印参考书目也可以通过循环来实现

\foreach \year in {2012,2013} {\printbibliography[check=\year,title={\year}]}

平均能量损失

\documentclass{article}
\usepackage{filecontents}
\usepackage{biblatex}
\usepackage{pgffor}

\newcommand{\yearcheck}[1]{%
  \defbibcheck{#1}{
    \iffieldint{origyear}
      {\ifnumequal{\thefield{origyear}}{#1}
        {}
        {\skipentry}
      }
      {\iffieldint{year}
        {\ifnumequal{\thefield{year}}{#1}
          {}
          {\skipentry}
        }
        {\skipentry}
      }
   }
}

\begin{filecontents*}{\jobname.bib}
@inproceedings{Bar2013,
    author = {F. Bar and B. Foo},
    booktitle = {The conference on nothing},
pages = {1--2},
title = {{A meaningless title}},
year = {2013}
}
@inproceedings{Bar2012,
    author = {F. Bar},
booktitle = {International Conference on Information},
pages = {3--4},
title = {{Advanced functionality and performance or nothing }},
year = {2012}
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\foreach \year in {2012,2013} {\global\yearcheck{\year}}
\begin{document}
  \nocite{*}
  \foreach \year in {2012,2013} {\printbibliography[check=\year,title={\year}]}
\end{document} 

相关内容