Biblatex 參考書目中的兩個或三個字母縮寫

Biblatex 參考書目中的兩個或三個字母縮寫

在我的參考書目中,我需要縮寫名字,保留二字母和三字母。

  • John 應縮寫為 J。
  • 克萊爾應縮寫為 Cl。
  • Charles 應縮寫為 Ch。
  • 克里斯汀應縮寫為 Chr。
  • Philippe 應該縮寫為 Ph.
  • ETC。

解決方案是將參考書目資料中的名字修改為

查爾斯

{\放鬆查爾斯}查爾斯


以下範例使用\DeclareSourcemapBiblatex 中的自訂巨集進行更改Charles{\relax Ch}arles但我正在尋找更通用的解決方案,該解決方案將自動修改以兩個或三個輔音開頭的所有名字。

\documentclass{article}
\usepackage{filecontents}
 \begin{filecontents}{\jobname.bib}
  @book{Book1,
  author = {Doe, Charles},
  title  = {An Important Book},
  publisher = {Publisher},
  date = {2012},
}
@book{Book2,
  author = {Doe, Charlotte},
  title  = {Another Important Book},
  publisher = {Publisher},
  date = {2014},
}
@book{Book3,
  author = {Smith, Theodore},
  title  = {A very Important Book},
  publisher = {Publisher},
  date = {2016},
}
\end{filecontents}
\usepackage[style=verbose,firstinits=true, backend=biber]{biblatex}
\DeclareSourcemap{
 \maps[datatype=bibtex]{
    \map{
    \step[fieldsource=author, 
            match={Charles},
            replace=\regexp{\{\\relax \x20Ch\}arles}]
  }
 }
}
\addbibresource{\jobname.bib}
\begin{document}

\cite{Book1}

\cite{Book2}

\cite{Book3}

\end{document}

結果

答案1

一個可能的起點是使用 Yves de Saint-Pern 在課堂上編寫的程式碼法人權利,我在下面翻譯。

編輯 :此處提供的正規表示式也會捕獲姓氏,這可能會導致 Biblatex 之外的問題,例如在使用imakeidx.這個問題的暫定解決方案是此處提供

您可以在文件中使用它biber.conf或將其包含在您的.bbx.

某些語言可能需要額外的名字正規表示式模式,但添加它們非常簡單。

\DeclareStyleSourcemap{%
  \maps[datatype=bibtex]{%
    \map{%
        % Author field
      \step[fieldsource=author,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)}},%
        replace={\regexp{\{$1\}$3}}]% Protect last names (first last)
      \step[fieldsource=author,%
        match={\regexp{([^,]\s)\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))}},%
        replace={\regexp{$1\{$2\}}}]% Protect last names (last, first)
      \step[fieldsource=author,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))([^\}])}},%
        replace={\regexp{\{\\relax\{\}$1\}$3}}]% Insert \relax after abbreviating
      % Editor field
      \step[fieldsource=editor,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)}},%
        replace={\regexp{\{$1\}$3}}]% Protect last names (first last)
      \step[fieldsource=editor,%
        match={\regexp{([^,]\s)\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))}},%
        replace={\regexp{$1\{$2\}}}]% Protect last names (last, first)
      \step[fieldsource=editor,%
        match={\regexp{\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))([^\}])}},%
        replace={\regexp{\{\\relax\{\}$1\}$3}}]% Insert \relax after abbreviating
}}}%

就正規表示式而言,我不是專家,但我敢說該表達式的意思是:

\b(Chr|Ch|Th|Ph|[B-DF-HJ-NP-TV-XZ](l|r))(\S*,)

\b以 ( 開頭的單字 ( )\S*表示:以任意數量的非空格字元結尾):( ChrChris) 或Ch(Charles) 或Th(Thomas) 或Ph(Philippe),或以子音開頭的任何組合(該[B-DF-HJ-NP-TV-XZ部分是一組範圍:字母B 到D、F 到H、J 到N、P 到T、V 到X、Z),後面跟著lr(Bruno 或 Claire 屬於該類別)。

相關內容