如何检测 biblatex 上是否启用了 citecounter 选项?

如何检测 biblatex 上是否启用了 citecounter 选项?

citecounter我认为这是包上的选项的定义biblatex

\DeclareBibliographyOption[boolean]{citecounter}[true]{%
  \ifcsdef{blx@opt@citecounter@#1}
    {\csuse{blx@opt@citecounter@#1}}
    {\blx@err@invopt{citecounter=#1}{}}}
\def\blx@opt@citecounter@true{%
  \let\blx@setcitecounter\blx@setcitecounter@global
  \let\blx@citecounter\blx@citecounter@global
  \let\abx@aux@count\blx@aux@count
  \let\abx@aux@fncount\blx@aux@fncount
  \booltrue{citetracker}}
\def\blx@opt@citecounter@context{%
  \let\blx@setcitecounter\blx@setcitecounter@context
  \let\blx@citecounter\blx@citecounter@context
  \let\abx@aux@count\blx@aux@count
  \let\abx@aux@fncount\blx@aux@fncount
  \booltrue{citetracker}}
\def\blx@opt@citecounter@false{%
  \let\blx@setcitecounter\relax
  \let\blx@citecounter\relax
  \let\abx@aux@count\@gobbletwo
  \let\abx@aux@fncount\@gobbletwo}

那么,我可以用什么来知道该选项是否已启用?

例如:

\usepackage[style=abnt,language=english,citecounter=false]{biblatex}

\if citecounter=false
    \message{Citecounter is false^^J}

\else
    \message{Citecounter is enabled^^J}
\fi

有关的:

  1. 我可以计算每篇参考文献被引用的次数吗?
  2. 如何检测 \PassOptionsToPackage 是否已被调用?
  3. 嵌套 \ifdefined 语句
  4. 检查某个包选项是否在 .sty 中声明

答案1

引用的定义表明,当且仅当该功能被停用时,才\blx@citecounter等于。因此您可以检查一下。\relaxcitecounter

一种方法是

\ifcsvoid{blx@citecounter}
  {NO CITECOUNTER}
  {CITECOUNTER}

(从技术上讲,\ifcsvoid{blx@citecounter}测试是否\blx@citecounter\relax或具有空替换的无参数宏,但这在这里应该足够了。)

如果你想坚持使用 TeX 条件语句

\makeatletter
\ifx\blx@citecounter\relax
  NO CITECOUNTER%
\else
  CITECOUNTER%
\fi
\makeatother

也可以。

答案2

除了citecounter,我还可以检查 是否也设置了。给出包上选项backref的来源:backrefbiblatex

\DeclareBibliographyOption[boolean]{backref}[true]{%
  \ifstrequal{#1}{true}
    {\let\blx@backref\blx@addbackref
     \let\abx@aux@backref\blx@aux@backref
     \booltrue{backtracker}}
    {\let\blx@backref\@gobble
     \let\abx@aux@backref\@gobblefive
     \boolfalse{backtracker}}}

我可以检查citetracker和是否都backref设置了:

\usepackage[style=abnt,language=english,backend=biber,citecounter=true]{biblatex}

\makeatletter
\ifx\blx@citecounter\relax
  \message{citecounter defined!^^J}
\else
  \message{citecounter not defined!^^J}
\fi
\makeatother

\ifcitetracker
  \message{citetracker defined!^^J}
\else
  \message{citetracker not defined!^^J}
\fi

\ifbacktracker
  \message{backref defined!^^J}
\else
  \message{backref not defined!^^J}
\fi

相关内容