使用循環定義 bibchecks

使用循環定義 bibchecks

我正在嘗試為我的參考書目建立子類別,其中包含年份標題(使用 biblatex)。我發現我可以使用 defbibcheck 按年份檢查,如下所示:

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

然而,因為已經有很多年了,我不想每年都有一份。我想我可以\foreachpgffor這樣的包中使用:

\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} 

相關內容