根據語言欄位值有條件地隱藏 Bibtex 欄位的部分內容

根據語言欄位值有條件地隱藏 Bibtex 欄位的部分內容

我想使用 XeLaTeX 和 Biber 建立一個有參考書目的文件。參考書目中有中文的書籍和文章,也有英文或德文的書籍和文章。有些作者用中文和英文寫過文章(或書籍,這裡不重要)。在中文文章中,我也想用漢字來給出作者的中文名字,而在他的英文文章中則不需要這樣。

下面是我的 .bib 檔案的範例。該\zh{}函數也用於防止 LaTeX 列印腳註中的字元:

@article{Liu2008,
  author    = {Liu, {Guofu \zh{(刘国福)}}},
  title     = {The Latest Development of Immigration Law: On the Transformation of China's Emmigration and Immigration Administration Law (移民法的最新发展——兼论中国出入境管理法的改造和重塑)},
  journal   = {Journal of Henan Administrative Institute of Politics and Law (河南省政法管理干部学院学报)},
  year      = {2008},
  volume    = {5},
  pages     = {46--58},
  language  = {chinese},
  keywords  = {article,hani}
}

@book{Liu2011,
  author    = {Liu, {Guofu \zh{(刘国福)}}},
  title     = {Chinese Immigration Law},
  year      = {2011},
  publisher = {Ashgate},
  address   = {Farnham},
  language  = {english},
  keywords  = {monography,latn}
}

現在的重點是:如果兩筆記錄中作者欄位的內容相同,Biber 當然只會將作者視為同一作者。如果我在英文文章中也不使用漢字,Biber就會寫出全名,以便區分「兩個」作者,而忽略了他們實際上是同一個人的事實。因此,即使在英文或德文文章中,我也需要在作者姓名中包含漢字。

這樣做,我得到了我想要的一切:在參考書目中,作者的名字有“LIU,Guofu(劉國福)(2008)”的模式,在腳註中只有“LIU 2008”(只要有沒有其他作者叫劉)。

我在 .tex 檔案的前導部分中使用以下程式碼片段來完成此操作:

\providecommand{\zh}[1]{}
\AtBeginBibliography{%
 \renewcommand*{\zh}[1]{#1}
}

\zh{}但是:如果條目沒有將中文設定為語言,我如何告訴 LaTeX 不要列印作者欄位中的部分。有沒有這樣的方法來有條件地設定這個?另外,腳註不應出現漢字。如果我能直接告訴 LaTeX 如何在 .tex 檔案中執行操作,那就太好了。

還有多個作者的文章,則應該有「王麗萍;王麗萍」的模式。張愛玲(2008)”,我猜想,是什麼讓使用另一個漢字輸入字段變得有些複雜,因為這樣所有的漢字名稱都會出現在拉丁字符的作者姓名列表之後。


編輯(2014-03-22):

看來我的問題已經在其他地方考慮過:

如何使用 biblatex、biber 和 polyglossia 建立多語言(英語、日語)參考書目

因此,從 bibLaTeX 3.0 和 biber 2.0(這兩個版本目前都處於實驗階段)開始,可以保存大多數領域的轉錄或翻譯,更令人驚訝的是,有一種方法可以設定顯示模式(顯示原始內容)語言、顯示翻譯等)分別為每個.bib 條目。

編輯(2014-03-23):

另一種方法,使用名稱詞綴:

https://tex.stackexchange.com/a/66825/47927

這似乎是 ienissei 提案的可行範例。

答案1

為了最終對我自己的問題給出一個全面的答案以供將來參考,以下將做我最初想要的:

首先,不需要使用\zh{},因為此範例將使用名稱詞綴,如 Audrey 此處所述:https://tex.stackexchange.com/a/66825/47927

我沒有使用titleaddon奧黛麗提議的部分,因為我不需要這個。另外,我堅持只使用姓氏順序。

因此,參考書目條目應該是這樣的(關鍵字“latn”或“hani”旨在代表相應文章的書寫系統,並用於有條件地隱藏名稱的中文部分):

@article{Liu2008,
  author    = {Liu, 刘国福, Guofu},
  title     = {The Latest Development of Immigration Law: On the Transformation of China's Emmigration and Immigration Administration Law (移民法的最新发展——兼论中国出入境管理法的改造和重塑)},
  journal   = {Journal of Henan Administrative Institute of Politics and Law (河南省政法管理干部学院学报)},
  year      = {2008},
  volume    = {5},
  pages     = {46--58},
  language  = {chinese},
  keywords  = {article,hani}
}

@book{Liu2011,
  author    = {Liu, 刘国福, Guofu},
  title     = {Chinese Immigration Law},
  year      = {2011},
  publisher = {Ashgate},
  address   = {Farnham},
  language  = {english},
  keywords  = {monography,latn}
}

現在是 .tex 檔案的部分(根據上面連結的 Audrey 帖子稍作編輯):

% Keep name affixes for English names
\forcsvlist{\listadd\nameaffixlist}{Junior,Senior}
\newcommand{\ifnameaffix}[1]{%
 \ifboolexpr{test{\ifrmnum{#1}} or test{\ifinlist{#1}{\nameaffixlist}}}}

% Set label format using last-first order
\DeclareNameFormat{labelname}{%
 \ifboolexpr{test{\ifblank{#7}} or test{\ifnameaffix{#7}}}
  {\ifcase\value{uniquename}%
   \usebibmacro{name:last}{#1}{#3}{#5}{#7}\or
   \ifuseprefix
    {\usebibmacro{name:last-first}{#1}{#4}{#5}{#8}}
    {\usebibmacro{name:last-first}{#1}{#4}{#6}{#8}}\or
    \usebibmacro{name:last-first}{#1}{#3}{#5}{#7}\fi}%
  {\ifnumequal{\value{uniquename}}{0}%
   {\usebibmacro{name:cjk}{#1}{}{}}
   {\usebibmacro{name:cjk}{#1}{#3}{}}}%
 \usebibmacro{name:andothers}
}

% Set name field format also using last-first order
\DeclareNameFormat{last-first}{%
 \ifboolexpr{test{\ifblank{#7}} or test{\ifnameaffix{#7}}}
  {\iffirstinits
   {\usebibmacro{name:last-first}{#1}{#4}{#5}{#7}}
   {\usebibmacro{name:last-first}{#1}{#3}{#5}{#7}}}
  {\usebibmacro{name:cjk}{#1}{#3}{#7}}%
 \usebibmacro{name:andothers}
}
\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}

% Making Chinese name appear after first name in parentheses, but only if the keyword 'hani' exists (see bib entries above for reference)
\newbibmacro*{name:cjk}[3]{%
 \usebibmacro{name:delim}{#2#3#1}%
 \usebibmacro{name:hook}{#2#3#1}%
 \mkbibnamelast{#1}%
 \ifblank{#2}{}{\bibnamedelimd\mkbibnamefirst{#2}}%
 \ifkeyword{hani}{%
  \ifblank{#3}{}{\bibnamedelimd\mkbibnameaffix{\mkbibparens{#3}}}%
 }{}
}

\AtEveryBibitem{\clearlist{language}}
\AtBeginBibliography{%
 \renewcommand*{\multinamedelim}{\addsemicolon\space}
}

需要考慮的一件事:如果參考書目中僅顯示作者的第一次出現,並且後續出現由破折號替換,則此腳本將根據第一個條目的語言選擇第一次出現。因此,如果第一個條目不是中文,但後面的一個條目是中文,則中文名稱將不會出現在任何地方。


編輯(2018-01-22):

巨集名稱name:lastname:first已更改為name:familyand name:given,巨集\mkbibnamefirst也相應地重命名為\mkbibnamegiven和。進一步,應改為.我最近沒有測試這個答案。我想,由於 BibLaTeX 軟體包在此期間已經更新了幾次,所以其他一些事情也必須改變。\iffirstinits\ifgiveninits\ifblank\ifdefvoid

這是我作為 MWE 的最終設定(儘管代碼相當多):

\begin{filecontents}{example.bib}
    @article{Liu2008,
      author    = {Liu, 刘国福, Guofu},
      title     = {The Latest Development of Immigration Law: On the Transformation of China's Emmigration and Immigration Administration Law (移民法的最新发展——兼论中国出入境管理法的改造和重塑)},
      journal   = {Journal of Henan Administrative Institute of Politics and Law (河南省政法管理干部学院学报)},
      year      = {2008},
      volume    = {5},
      pages     = {46--58},
      language  = {chinese},
      keywords  = {article,hani}
    }

    @book{Liu2011,
      author    = {Liu, 刘国福, Guofu},
      title     = {Chinese Immigration Law},
      year      = {2011},
      publisher = {Ashgate},
      address   = {Farnham},
      language  = {english},
      keywords  = {monography,latn}
    }
\end{filecontents}

\documentclass{article}

\usepackage{fontspec}
\setmainfont[SmallCapsFeatures={LetterSpace=2}]{TeX Gyre Termes}

\usepackage{xeCJK} 
\setCJKmainfont[Script=CJK]{Noto Serif CJK SC}
\CJKsetecglue{\,}

\usepackage[
 backend=biber,
 language=autobib,
 autolang=hyphen,
 style=authoryear,
 defernumbers=true,
 sortlocale=en-GB,
 urldate=long,
 dateabbrev=false,
 sortcites=true,
 sorting=anyvt,
 safeinputenc
 ]{biblatex}
% =====

\renewbibmacro*{labeltitle}{\iffieldundef{shorttitle}%
 {\printfield{title}\clearfield{title}}%
 {\mkbibemph{\printfield{shorttitle}}\addspace\printtext[parens]{\printfield{year}}}%
}

\renewbibmacro*{date+extradate}{\ifkeyword{law}%
 {}%
 {\printtext[parens]{%
   \iflabeldateisdate%
    {\printfield{issue}\setunit*{\addspace}\printdateextra}%
    {\printlabeldateextra}}}%
}
\renewbibmacro*{issue+date}{\ifkeyword{law}%
 {}%
 {\iflabeldateisdate%
  {\printfield{issue}\setunit*{\addspace}\printtext[parens]{\printdate}}%
  {\printtext[parens]{\printfield{issue}\setunit*{\addspace}\printdate}}}%
}
\renewbibmacro*{cite:labeldate+extradate}{\ifkeyword{law}%
 {}%
 {\iffieldundef{labelyear}%
  {}%
  {\printtext[bibhyperref]{\mkbibparens{\printlabeldateextra}}}}%
}

\renewcommand*{\multinamedelim}{\addnbthinspace\slash\thinspace}
\renewcommand*{\finalnamedelim}{\multinamedelim}
\renewcommand*{\labelnamepunct}{\addcolon\addspace}
\renewcommand*\mkbibnameprefix[1]{\textsc{#1}}
\renewcommand*\mkbibnamefamily[1]{\textsc{#1}}
\renewcommand*\bibnamedash{\rule[.48ex]{3em}{.5pt}\addspace}
\DeclareFieldFormat*{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat*{extradate}{\addnbthinspace\mknumalph{#1}}
\DeclareFieldFormat*{url}{URL\addcolon\addspace\url{#1}}

% =====
% Settings for Chinese names

\forcsvlist{\listadd\nameaffixlist}{Junior,Senior}

\newcommand{\ifnameaffix}[1]{%
 \ifboolexpr{ test {\ifrmnum{#1}} or test {\xifinlist{#1}{\nameaffixlist}} }}

% Based on definitions from biblatex.def

\newbibmacro*{name:cjk}[3]{%
 \usebibmacro{name:delim}{#2#3#1}%
 \usebibmacro{name:hook}{#2#3#1}%
 \mkbibnamefamily{#1}%
 \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}%
 \ifkeyword{hani}{%
  \ifdefvoid{#3}{}{\bibnamedelimd\mkbibnamesuffix{\mkbibparens{\upshape #3}}}%
 }{}}
 
\newbibmacro*{name:cjk-short}[3]{%
 \usebibmacro{name:delim}{#2#3#1}%
 \usebibmacro{name:hook}{#2#3#1}%
 \mkbibnamefamily{#1}%
 \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}%
 \ifkeyword{hani}{%
  \ifdefvoid{#3}{}{}%
 }{}}

\DeclareNameFormat{given-family}{%
 \ifboolexpr{ test {\ifdefvoid{\namepartsuffix}} or test {\ifnameaffix{\namepartsuffix}} }%
  {\ifgiveninits%
   {\usebibmacro{name:given-family}
    {\namepartfamily}
    {\namepartgiveni}
    {\namepartprefix}
    {\namepartsuffix}}%
   {\usebibmacro{name:given-family}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}}%
  {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartsuffix}}%
 \usebibmacro{name:andothers}}

\DeclareNameFormat{family-given}{%
 \ifboolexpr{ test {\ifdefvoid{\namepartsuffix}} or test {\ifnameaffix{\namepartsuffix}} }%
  {\ifgiveninits%
   {\usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiveni} 
    {\namepartprefix}
    {\namepartsuffix}}%
   {\usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}}%
  {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartsuffix}}%
 \usebibmacro{name:andothers}}

\DeclareNameFormat{family-given/given-family}{%
 \ifboolexpr{ test {\ifdefvoid{\namepartsuffix}} or test {\ifnameaffix{\namepartsuffix}} }%
  {\ifnumequal{\value{listcount}}{1}%
   {\ifgiveninits%
    {\usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiveni}
    {\namepartprefix}
    {\namepartsuffix}}%
   {\usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}%
   \ifboolexpe{ test {\ifdefvoid\namepartgiven} and test {\ifdefvoid\namepartprefix} }%
    {}%
    {\usebibmacro{name:revsdelim}}}%
   {\ifgiveninits%
    {\usebibmacro{name:given-family}
     {\namepartfamily}
     {\namepartgiveni}
     {\namepartprefix}
     {\namepartsuffix}}%
    {\usebibmacro{name:given-family}
     {\namepartfamily}
     {\namepartgiven}
     {\namepartprefix}
     {\namepartsuffix}}}}%
  {\usebibmacro{name:cjk}{\namepartfamily}{\namepartgiven}{\namepartsuffix}}%
 \usebibmacro{name:andothers}}
  
\DeclareNameFormat{labelname}{%
 \ifcase\value{uniquename}%
  \usebibmacro{name:family}
   {\namepartfamily}
   {\namepartgiven}
   {\namepartprefix}
   {\namepartsuffix}%
  \or%
  \ifboolexpr{ test {\ifdefvoid{\namepartsuffix}} or test {\ifnameaffix{\namepartsuffix}} }%
   {\ifuseprefix%
    {\usebibmacro{name:given-family}
     {\namepartfamily}
     {\namepartgiven}  % i
     {\namepartprefix}
     {\namepartsuffix}}% i
    {\usebibmacro{name:given-family}
     {\namepartfamily}
     {\namepartgiven}   % i
     {\namepartprefix}  % i
     {\namepartsuffix}}}% i
   {\usebibmacro{name:cjk-short}{\namepartfamily}{\namepartgiven}{\namepartsuffix}}%
 \or%
  \ifboolexpr{ test {\ifdefvoid{\namepartsuffix}} or test {\ifnameaffix{\namepartsuffix}} }%
   {\usebibmacro{name:given-family}%
    {\namepartfamily}
    {\namepartgiven}
    {\namepartprefix}
    {\namepartsuffix}}%
   {\usebibmacro{name:cjk-short}{\namepartfamily}{\namepartgiven}{\namepartsuffix}}%
 \fi%
 \usebibmacro{name:andothers}}
 
\DeclareFieldFormat{citetitle}{\mkbibemph{#1}\ifkeyword{law}{\addspace\printtext[parens]{\printfield{year}}}{}}

\AtEveryBibitem{\clearlist{language}}
\AtBeginBibliography{%
 \renewcommand*{\multinamedelim}{\addsemicolon\addspace}%
}

\DefineBibliographyExtras{english}{%
 \protected\def\mkbibdatelong#1#2#3{%
  \iffieldundef{#3}
   {}
   {\stripzeros{\thefield{#3}}%
    \iffieldundef{#2}{}{\nobreakspace}}%
  \iffieldundef{#2}
   {}
   {\mkbibmonth{\thefield{#2}}%
    \iffieldundef{#1}{}{\space}}%
  \iffieldbibstring{#1}
   {\bibstring{\thefield{#1}}}
   {\stripzeros{\thefield{#1}}}%
 }%
}

\addbibresource{example.bib}

\begin{document}

Some text.\footnote{\cite{Liu2008}, \cite{Liu2011}.}

\printbibliography

\end{document}

參考書目的輸出是:

在此輸入影像描述

註腳的輸出是:

在此輸入影像描述

相關內容