
我正在使用 biblatex (與 xelatex)。更具體地說,我使用 Zotero,然後從 Zotero 匯出為 bib 格式。
一切正常,但我的參考書目只有黑色。這當然是正常行為...但是,我的目標是為了測試目的對每個圍兜元素進行不同的著色,以確保我不會忘記圍兜的元素,例如“音量”。例如,我想套用以下顏色代碼。
volume -> dark blue
pages -> turqoise
url -> brown
title -> red
isbn -> yellow
booktitle -> pink
publisher -> orange
author -> grey
date -> black
是否有可能做到這一點 ?
答案1
您可以使用 變更欄位的顯示方式\DeclareFieldFormat
。
所以你要做的就是重新定義\DeclareFieldFormat
相關欄位。
但有一些注意事項,
並非所有「領域」都是領域。
biblatex
知道欄位、清單和姓名清單。這三種類型使用不同的\Declare...Format
指令。所以你需要知道你的領域的類型如果您不想完全覆蓋它,您需要知道原始定義。我在這裡假設您仍然像往常一樣想要斜體和引號,只有顏色應該改變。
- 儘管可以使用
xpatch
s修補欄位格式\xpretofieldformat
,但您需要知道是否有任何類型得到特殊處理。因為您只能修補通用或特定類型的格式,但不能同時修補兩者。
- 儘管可以使用
對於標準樣式,大多數格式化指令可以在 中找到biblatex.def
。
對於字段,這應該像搜尋字段、複製並在定義中\DeclareFieldFormat
添加命令一樣簡單。\color{...}
不要忘記,\DeclareFieldFormat
同一欄位可能有多個特定類型(在標準樣式中,您應該發現它們彼此相鄰)。
對於列表,您會執行類似的操作,但您會搜尋\DeclareListFormat
. (見publisher
下文。)
名字比較複雜。您首先必須找出要著色的名稱使用哪種名稱格式。使用中的author
格式。並定義為.所以我們從現在開始複製的定義,呼叫它,添加並告訴它。sortname
style=authoryear
sortname
family-given/given-family
family-given/given-family
coloured:family-given/given-family
\colour{...}
sortname
coloured:family-given/given-family
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=authoryear, backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage[svgnames]{xcolor}
\DeclareFieldFormat{volume}{\color{DarkBlue}\bibstring{volume}~#1}% volume of a book
\DeclareFieldFormat[article,periodical]{volume}{\color{DarkBlue}#1}% volume of a journal
\DeclareFieldFormat{pages}{\color{Turquoise}\mkpageprefix[bookpagination]{#1}}
\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\color{Brown}\url{#1}}
\DeclareFieldFormat{title}{\color{Red}\mkbibemph{#1}}
\DeclareFieldFormat
[article,inbook,incollection,inproceedings,patent,thesis,unpublished]
{title}{\color{Red}\mkbibquote{#1\isdot}}
\DeclareFieldFormat
[suppbook,suppcollection,suppperiodical]
{title}{\color{Red}#1}
\DeclareFieldFormat{isbn}{\mkbibacro{ISBN}\addcolon\space \color{Yellow}#1}
\DeclareFieldFormat{booktitle}{\color{Pink}\mkbibemph{#1}}
\DeclareListFormat{publisher}{%
\color{Orange}%
\usebibmacro{list:delim}{#1}%
#1\isdot
\usebibmacro{list:andothers}}
\DeclareNameFormat{coloured:family-given/given-family}{%
\color{Grey}%
\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:andothers}}
\DeclareNameAlias{sortname}{coloured:family-given/given-family}
\begin{document}
\cite{sigfridsson,vizedom:related,westfahl:space,worman,geer,nussbaum,ctan}
\printbibliography
\end{document}
您可以在編譯時使用 Biber 選項--validate-datamodel
來幫助您檢查條目是否符合資料模型。