Определить бибчеки с помощью цикла

Определить бибчеки с помощью цикла

Я пытаюсь создать подкатегории для моей библиографии с заголовками по годам (используя 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} 

Связанный контент