biblatex の `printbibliography` でトグルを使用する

biblatex の `printbibliography` でトグルを使用する

次の点を考慮してください。

\documentclass{article}
\usepackage[backend=bibtex8]{biblatex}
\begin{filecontents*}{bib.bib}
@mastersthesis{toto,
author={Toto},
title={My thesis},
year={2009},
school={Paris 129},
keywords={mem}
}
\end{filecontents*}
\addbibresource{bib.bib}
\newtoggle{display}
\toggletrue{display}
\begin{document}
\nocite{*}
\printbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]
\togglefalse{display}
\printbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]
\end{document}

私が期待する動作は、トグルの値に応じてdisplay、キーワードを含むエントリがmem表示されるかどうかです。

しかし、表示されるのはエラー! Package keyval Error: keyword=mem undefined.だけ です! Package keyval Error: notkeyword=mem undefined.

答え1

オプションの引数は、\printbibliographyそれが表示される前に展開する必要があります。

\begin{filecontents*}{\jobname.bib}
@mastersthesis{toto,
author={Toto},
title={My thesis},
year={2009},
school={Paris 129},
keywords={mem}
}
@mastersthesis{toto2,
author={Toto},
title={My thesis not mem},
year={2009},
school={Paris 129},
keywords={notmem}
}
\end{filecontents*}

\documentclass{article}
\usepackage[backend=bibtex8]{biblatex}

\addbibresource{\jobname.bib}
\newtoggle{display}
\toggletrue{display}
\begin{document}
\nocite{*}

\begingroup\edef\x{\endgroup\noexpand
  \printbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]%
}\x

\togglefalse{display}

\begingroup\edef\x{\endgroup\noexpand
  \printbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]%
}\x

\end{document}

ここに画像の説明を入力してください

より使いやすいインターフェースは、xparse

\begin{filecontents*}{\jobname.bib}
@mastersthesis{toto,
author={Toto},
title={My thesis},
year={2009},
school={Paris 129},
keywords={mem}
}
@mastersthesis{toto2,
author={Toto},
title={My thesis not mem},
year={2009},
school={Paris 129},
keywords={notmem}
}
\end{filecontents*}

\documentclass{article}
\usepackage[backend=bibtex8]{biblatex}
\usepackage{xparse}

\addbibresource{\jobname.bib}
\newtoggle{display}
\toggletrue{display}

\ExplSyntaxOn
\NewDocumentCommand{\xprintbibliography}{o}
 {
  \IfNoValueTF{#1}
   {
    \printbibliography
   }
   {
    \clement_xprintbibliography:x { #1 }
   }
 }
\cs_new_protected:Npn \clement_xprintbibliography:n #1
 {
  \printbibliography[#1]
 }
\cs_generate_variant:Nn \clement_xprintbibliography:n { x }
\ExplSyntaxOff

\begin{document}
\nocite{*}

\xprintbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]%

\togglefalse{display}

\xprintbibliography[\iftoggle{display}{keyword=mem}{notkeyword=mem}]%

\end{document}

答え2

まだ理解していない理由で、keyword/ をnotkeywordトグルに依存させるだけで問題ありません。

読みやすくするために、 を\iftoggle{display}{keyword}{notkeyword}新しいコマンド (etiquetteフランス語で「ラベル」を意味する ) として囲みましたが、これは必須ではありません。

\documentclass{article}
\usepackage[backend=bibtex8, defernumbers=true]{biblatex}
\begin{filecontents*}{bib.bib}
@mastersthesis{toto1,
author={Toto},
title={My thesis},
year={2009},
school={Paris 129},
keywords={mem}
}
@mastersthesis{toto2,
author={Toto},
title={My new thesis},
year={2015},
school={Paris 32},
}
\end{filecontents*}
\addbibresource{bib.bib}
\newtoggle{display}
\toggletrue{display}

\newcommand{\etiquette}{\iftoggle{display}{keyword}{notkeyword}}

\begin{document}
\nocite{*}
\printbibliography[\etiquette=mem, title={With mem keyword}]
\togglefalse{display}
\printbibliography[\etiquette=mem, title={With\emph{out} mem keyword}]
\end{document}

警告なしでコンパイルされ、期待どおりの結果が返されます。

ここに画像の説明を入力してください


驚くべきことに、その逆、つまり

\newcommand{\etiquette}{\iftoggle{display}{mem}{bubu}}
...
\printbibliography[notkeyword=\etiquette, title={Without mem keyword}]
\togglefalse{display}
\printbibliography[notkeyword=\etiquette, title={Without bubu keyword}]
...

動作しません (警告はありませんが、毎回すべてが引用されます)。

関連情報