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}]
...

작동하지 않습니다(경고는 없지만 매번 모든 내용이 인용됩니다).

관련 정보