仅当字段已被替换时才更改 biblatex 字段格式

仅当字段已被替换时才更改 biblatex 字段格式

在我的文档中,我希望将所有由连续大写字母组成的缩写设置为字体大小的 90%。我可以在文本中手动执行此操作。但如果涉及期刊缩写,我不知道如何在引用中实现这一点。

ADeclareFieldFormat不起作用,因为该字段shortjournal仅用于journal在存在时覆盖该字段。并且我不想journal在所有情况下都将该字段设置为小 10%,而只在完整期刊标题被替换的情况下才这样做shortjournal

简而言之:我怎样才能重新格式化journal引文中的字段,但仅限于它们已被替换的情况shortjournal,就像在我的 MWE 中一样?

我正在使用 XeLaTex 进行编译。

M(尚未)WE:

\documentclass{book}
\usepackage{relsize}
\newcommand{\abk}{\textscale{0.9}}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ARTICLE{AB,
         author    = {Author Beta},
         title     = {Title},
         shortjournal = {ABC},
         journal ={AllButCrash},
         pages = {1-23},
         year={2009}}
@ARTICLE{CD,
         author    = {Changed Director},
         title     = {Title},
         journal ={Boring Texts},
         pages = {23-42},
         year={2019}}
\end{filecontents}

\usepackage[backend=biber,style=verbose-inote,sorting=nyt,bibencoding=utf8,citereset=chapter,citepages=separate,refsection=none,autocite=footnote,isbn=false,doi=false,url=false,eprint=false,date=short]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    %Shortjournal berücksichtigen      
      \map[overwrite]{
      \step[fieldsource=shortjournal]
      \step[fieldset=journal,origfieldval]
    }
    }
}

\begin{document}
A reference here.\footcite{AB} All Abbreviations in Capitals -- whom I call \abk{AAIC} -- should be in a font size 10 percent smaller. So that they don't look like THIS.\footcite{CD}

\end{document}

答案1

您尝试进行的数据替换不会留下任何痕迹。因此,如果没有更多信息,biblatex我们就无法知道源地图数据是否发生了更改。但我们可以通过字段注释来添加此类信息。

因此,我们可以在同一张地图中添加这样的注释:

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    % Shortjournal berücksichtigen
    \map[overwrite]{
      \step[fieldsource=shortjournal, final]
      \step[fieldset=journaltitle, origfieldval]
      \step[fieldset=journaltitle+an, fieldvalue={=shortened}]
    }
  }
}

这样,journaltitle当字段在源映射中被替换时shortjorunal,它还将收到一个字段注释=shortened,然后我们可以将其用作格式指令中的条件:

\DeclareFieldFormat{journaltitle}{%
  \iffieldannotation[journaltitle]{shortened}{%
    \mkbibemph{\abk{#1}}%
  }{%
    \mkbibemph{#1}%
  }%
}

在全:

\documentclass{book}

\usepackage{relsize}
\newcommand{\abk}{\textscale{0.9}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@Article{AB,
  author       = {Author Beta},
  title        = {Title},
  shortjournal = {ABC},
  journaltitle = {AllButCrash},
  pages        = {1-23},
  year         = {2009},
}
@Article{CD,
  author       = {Changed Director},
  title        = {Title},
  journaltitle = {Boring Texts},
  pages        = {23-42},
  year         = {2019},
}
\end{filecontents}

\usepackage[
  backend=biber,
  style=verbose-inote,
  sorting=nyt,
  bibencoding=utf8,
  citereset=chapter,
  citepages=separate,
  refsection=none,
  autocite=footnote,
  isbn=false,
  doi=false,
  url=false,
  eprint=false,
  date=short,
  ]{biblatex}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    % Shortjournal berücksichtigen
    \map[overwrite]{
      \step[fieldsource=shortjournal, final]
      \step[fieldset=journaltitle, origfieldval]
      \step[fieldset=journaltitle+an, fieldvalue={=shortened}]
    }
  }
}

\DeclareFieldFormat{journaltitle}{%
  \iffieldannotation[journaltitle]{shortened}{%
    \mkbibemph{\abk{#1}}%
  }{%
    \mkbibemph{#1}%
  }%
}

\begin{document}
A reference here.\footcite{AB} All Abbreviations in Capitals -- whom I call
\abk{AAIC} -- should be in a font size 10 percent smaller. So that they don't
look like THIS.\footcite{CD}

\end{document}

在此处输入图片描述

另一种选择是不进行任何数据替换,而是直接在相关的 bibmacro 中处理条件,在这种情况下journal

\documentclass{book}

\usepackage{relsize}
\newcommand{\abk}{\textscale{0.9}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@Article{AB,
  author       = {Author Beta},
  title        = {Title},
  shortjournal = {ABC},
  journaltitle = {AllButCrash},
  pages        = {1-23},
  year         = {2009},
}
@Article{CD,
  author       = {Changed Director},
  title        = {Title},
  journaltitle = {Boring Texts},
  pages        = {23-42},
  year         = {2019},
}
\end{filecontents}

\usepackage[
  backend=biber,
  style=verbose-inote,
  sorting=nyt,
  bibencoding=utf8,
  citereset=chapter,
  citepages=separate,
  refsection=none,
  autocite=footnote,
  isbn=false,
  doi=false,
  url=false,
  eprint=false,
  date=short,
  ]{biblatex}
\addbibresource{\jobname.bib}

\renewbibmacro*{journal}{%
  \iffieldundef{shortjournal}
    {\ifboolexpr{
      test {\iffieldundef{journaltitle}}
      and
      test {\iffieldundef{journalsubtitle}}
     }
       {}
       {\printtext[journaltitle]{%
          \printfield[titlecase]{journaltitle}%
          \setunit{\subtitlepunct}%
          \printfield[titlecase]{journalsubtitle}}}}
    {\printfield{shortjournal}}}

\DeclareFieldFormat{shortjournal}{\mkbibemph{\abk{#1}}}

\begin{document}
A reference here.\footcite{AB} All Abbreviations in Capitals -- whom I call
\abk{AAIC} -- should be in a font size 10 percent smaller. So that they don't
look like THIS.\footcite{CD}

\end{document}

相关内容