在 biblatex 中操作标题字段的字符串

在 biblatex 中操作标题字段的字符串

我需要从匿名条目的字段First~Second中获取第一个字符串(考虑单个字符串)title并:

  1. 将第一个字符串的格式与标题的其余部分不同,例如:

    LES MILLES 和 un noit trans。作者:M. Galland。巴黎:Compaigne des Libraires,1745 年。

    《一千零一夜之书》由理查德·F·伯顿翻译和注释。伦敦:伯顿俱乐部,1885 年。

  2. 使用该字符串作为引用标签,例如

    LES MILLES...,1745 年;这本书......,1885 年

因此,样式文件需要检查author名称editor,如果没有,则将标题的第一个单词重新格式化为大写,并将其用作引文的标签。

我的尝试

这是我迄今为止尝试过的。

我尝试通过使用xstring类似这样的内容:

\newbibmacro{author+title}{%
    \ifnameundef{author}%
        {\ifnameundef{editor}%
        {%
          \StrCut[1]{\thefield{title}}{ }\StringA\StringB%
          \SpecialTitleFormat{\StringA}\space\StringB%
          \setunit\newblock
        }%
        {\usebibmacro{editor}
            \setunit{\labelnamepunct}\newblock
            \usebibmacro{title}}}%
        {\usebibmacro{author}%
          \setunit{\labelnamepunct}\newblock%
          \usebibmacro{title}}

我尝试shorttitle通过 biber 的\DeclareSourcemap功能将该字符串重新映射到字段

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=title,
            fieldset=shorttitle,
            match=\regexp{(\w+).*},
            fieldvalue={$1}]
    }
  }
}
\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield{title}%
        \clearfield{title}}
       {\printfield[shorttitle]{shorttitle}}}
    {\printfield{label}}}

这种方法的问题在于,引用标签和参考书目中的重点是通过不同的方式从该领域获取的,这使得它不一致,例如~参考书目部分有作品,但标签没有。

以下是 MWE:

\documentclass{article}
\usepackage{filecontents}
% Bibliographic Database
\begin{filecontents*}{\jobname.bib}
@book{simple,
  title = {Simple anonym entry},
  publisher = {Publisher},
  year = {2013},
}
@book{1001nights,
  title = {The~Book of the thousand nights and a night},
  subtitle = {A plain and literal translation of the Arabian nights' entertainments},
  translator = {Richard F. Burton},
  annotator = {Richard F. Burton},
  location = {London},
  publisher = {Burton Club},
  year = {1885},
  }
@book{1001nuit,
  title = {Les~milles et un nuit},
  subtitle = {Contes Arabes},
  translator = {M. Galland},
  address = {Paris},
  publisher = {Compaigne des Libraires},
  year = {1745},
}
@book{editoranonym,
  title = {An anonym entry with an editor},
  editor = {Editor, Ed},
  publisher = {Publisher},
  year = {2000},
}
\end{filecontents*}
% Biblatex Style file
\begin{filecontents*}{\jobname.bbx}
\ProvidesFile{\jobname.bbx}

\RequireBibliographyStyle{standard}

% I'm redefining the book driver to use an author+title bibmacro
\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author+title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}}

\RequirePackage{xstring}
\DeclareRobustCommand{\SpecialTitleFormat}[1]{%
  \MakeUppercase{#1}}

% author+title bibmacro
% this should check for author and editor, and, in their absence, use
% the title field
\newbibmacro{author+title}{%
    \ifnameundef{author}%
        {\ifnameundef{editor}%
      {%
        \StrCut[1]{\thefield{title}}{ }\StringA\StringB%
        \SpecialTitleFormat{\StringA}\space\StringB%
        \setunit\newblock
      }%
      {\usebibmacro{editor}
            \setunit{\labelnamepunct}\newblock
            \usebibmacro{title}}}%
        {\usebibmacro{author}%
          \setunit{\labelnamepunct}\newblock%
          \usebibmacro{title}}
  }
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=title,
                fieldset=shorttitle,
            match=\regexp{(\w+).*},
            fieldvalue={$1}]% 
          }
        }
      }

\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield{title}%
        \clearfield{title}}
       {\printfield[shorttitle]{shorttitle}}}
    {\printfield{label}}}

\endinput
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage[bibstyle=\jobname,citestyle=verbose]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{xstring}

\begin{document}

\thispagestyle{empty}

\citetitle{simple} \citetitle{1001nights} \citetitle{1001nuit} \citetitle{editoranonym}

\printbibliography

\end{document}

图像

答案1

使用新的格式指令可能会更好地处理此问题。可以使用一些特定于语言的列表和字段来识别标题中单词应大写的字符串hyphenation

以下是使用 样式对此想法的粗略演示authoryear,该样式已用作 的labeltitle最后手段labelname。请注意,可以使用本地化模块中的参考书目附加功能来实现本地化大写,但这种方法需要在字段otherlanguage给出的环境中包装引文和参考书目hyphenation

\documentclass{article}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[style=authoryear]{biblatex}

\forcsvlist{\listcsadd{bibprep:english}}{of,Of,the,The}
\csletcs{bibprep:american}{bibprep:english}
\csletcs{bibprep:british}{bibprep:english}
\forcsvlist{\listcsadd{bibprep:french}}{de,De,des,Des,le,Le,les,Les}

\DeclareFieldFormat{firstupper}{\MakeFirstUppercase{#1}}
\makeatletter
\newrobustcmd*{\MakeFirstUppercase}[1]{%
  \toggletrue{bbx@firstupper}%
  \expandafter\MakeFirstUppercase@i#1 &}
\def\MakeFirstUppercase@i#1 #2&{%
  \iftoggle{bbx@firstupper}
    {\MakeUppercase{#1}%
     \togglefalse{bbx@firstupper}%
     \def\do##1{\ifstrequal{#1}{##1}{\toggletrue{bbx@firstupper}\listbreak}{}}%
     \iffieldundef{hyphenation}
       {\dolistcsloop{bibprep:\bbl@main@language}}
       {\dolistcsloop{bibprep:\thefield{hyphenation}}}}
    {#1}
  \ifblank{#2}{}{\MakeFirstUppercase@i#2&}}
\newtoggle{bbx@firstupper}
\makeatother

% use new format to print labeltitle
\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield[firstupper]{title}%
        \clearfield{title}}
       {\printfield[firstupper]{shorttitle}}}
    {\printfield{label}}}    
\renewbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[firstupper]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

% just for demonstration
\DeclareSourcemap{\maps[datatype=bibtex]{\map{\step[fieldset=label,null]}}}

\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{companion,cms,moraux,kullback,britannica} \\
\citefield{companion,cms,moraux,britannica}[firstupper]{indexsorttitle} \\
\citefield{companion,cms,moraux,kullback,britannica}[firstupper]{title}
\printbibliography
\end{document}

在此处输入图片描述

相关内容