![BibLaTeX のカスタム フィールド](https://rvso.com/image/449617/BibLaTeX%20%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%20%E3%83%95%E3%82%A3%E3%83%BC%E3%83%AB%E3%83%89.png)
.bibエントリにオプションのカスタムフィールドを追加したいと考えています。これらのフィールドを参考文献に含める必要はありませんが、次の方法でアクセスできるようにしたいと考えています。
\citefield{<entry-key>}{<custom-field-name>}
答えはおそらく以下に挙げた参考文献のどこかにあると思いますが、私が最初に適応しよう\DeclareSourcemap
とした試みは\DeclareFieldFormat
失敗しました。
参考文献:
コード:
\begin{filecontents}{mybib.bib}
@book{knuth1984texbook,
title={The texbook},
author={Knuth, D.E. and Knuth, A.D. and Bibby, D. and American Mathematical Society and Addison-Wesley Publishing Company and Addison-Wesley},
isbn={9780201134483},
lccn={85030845},
series={Computers \& typesetting},
url={https://books.google.com/books?id=hEYuAQAAIAAJ},
year={1984},
publisher={Addison-Wesley},
myFieldA={Useful Book},
myFieldB={on Shelf 4},
}
@book{goossens1994latex,
title={The LaTeX Companion},
author={Goossens, M. and Mittelbach, F. and Samarin, A.},
isbn={9780201541991},
lccn={lc93023150},
series={Addison-Wesley series on tools and techniques for computer typesetting},
url={https://books.google.com/books?id=54A3MuBzIrEC},
year={1994},
publisher={Addison-Wesley},
myFieldA={Also Useful Book},
myFieldB={on Shelf 5},
}
\end{filecontents}
%% -----------------
\documentclass{article}
\usepackage{biblatex}
\addbibresource{mybib.bib}
\begin{document}
This should print ``Also Useful Book'':
\citefield{goossens1994latex}{myFieldA}
\end{document}
答え1
必要なフィールドが少数で、マークアップのセマンティクスを少しだけ犠牲にしても構わない場合 (引用用)、「カスタム フィールド」を使用すれば済みますbiblatex
(標準スタイルではカスタム フィールドは使用されませんが、非標準のフィールドを使用している場合は、本当に「空」であるかどうかを確認する必要がある場合があります)。
コメントで、フィールドにカスタム名を付けたいとおっしゃっているので、SourceMap を使用してカスタム フィールドの値を のbiblatex
データ モデルで使用可能なフィールドの 1 つにコピーすることで、これを実現できます。つまり、ファイルにカスタム名を付けることはできます.bib
が、実際に引用を行うときには、フィールド「knows」を使用する必要がありますbiblatex
。
これは次のようになります:
\begin{filecontents}[overwrite]{mybib.bib}
@book{knuth1984texbook,
title={The texbook},
author={Knuth, D.E. and Knuth, A.D. and Bibby, D. and American Mathematical Society and Addison-Wesley Publishing Company and Addison-Wesley},
isbn={9780201134483},
lccn={85030845},
series={Computers \& typesetting},
url={https://books.google.com/books?id=hEYuAQAAIAAJ},
year={1984},
publisher={Addison-Wesley},
myFieldA={Useful Book},
myFieldB={on Shelf 4},
}
@book{goossens1994latex,
title={The LaTeX Companion},
author={Goossens, M. and Mittelbach, F. and Samarin, A.},
isbn={9780201541991},
lccn={lc93023150},
series={Addison-Wesley series on tools and techniques for computer typesetting},
url={https://books.google.com/books?id=54A3MuBzIrEC},
year={1994},
publisher={Addison-Wesley},
myFieldA={Also Useful Book},
myFieldB={on Shelf 5},
}
\end{filecontents}
%% -----------------
\documentclass{article}
\usepackage{biblatex}
\addbibresource{mybib.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=myFieldA]
\step[fieldset=usera, origfieldval]
\step[fieldsource=myFieldB]
\step[fieldset=userb, origfieldval]
}
}
}
\begin{document}
This should print ``Also Useful Book'':
\citefield{goossens1994latex}{usera}
This should print ``on Shelf 5'':
\citefield{goossens1994latex}{userb}
\end{document}
このアプローチの利点は、データ モデルを拡張する必要がないため、よりシンプルであることです。ただし、両側でカスタム フィールド名を本当に使用する必要がある場合、私の知る限り、唯一の方法は、データ モデルを拡張してフィールドを含めることです。その場合、標準的な回答は次の @moewe によるものです。BibLaTeX/Biber を使用してまったく新しいデータ型を作成するにはどうすればよいですか?。