
\csxdef
BibLaTeX データベースのすべてのエントリをループし、各キーに基づいてを生成したいと思います。私が望む擬似コードは次のとおりです。
\foreach \EntryKey in \ListOfAllBibliography {%
\edef\UrlKeyValue{\citefield{\EntryKey}{url}}%
\StrBehind*{\UrlKeyValue}{//}[\UrlKeyValueExtracted]%
\IfStrEq{\UrlKeyValue}{}{}{%
\csxdef{Bib \UrlKeyValueExtracted}{\EntryKey}%
}%
}%
この特定のケースでは、このループは次のものと同等である。
\csxdef{Bib books.google.com/books?id=hEYuAQAAIAAJ}{knuth1984texbook}%
\csxdef{Bib books.google.com/books?id=54A3MuBzIrEC}{goossens1994latex}%
期待される出力はムウェ これが機能するのは次の場合です。
参考文献:
- 1つの選択肢は、Pythonでこれを行うことです。bibデータベースをcsvに変換するですが、LaTeX で行うことを希望します。
コード:
\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{xstring}% used only in pseudo code for this MWE.
\usepackage{pgffor}
\usepackage{etoolbox}
\usepackage{biblatex}
\addbibresource{mybib.bib}
\begin{document}
%% Pseudo code for desired looping:
% \foreach \EntryKey in \ListOfAllBibliography {%
% \edef\UrlKeyValue{\citefield{\EntryKey}{url}}%
% \StrBehind*{\UrlKeyValue}{//}[\UrlKeyValueExtracted]%
% \IfStrEq{\UrlKeyValue}{}{}{% Skip if the url= key us missing
% \csxdef{Bib \UrlKeyValueExtracted}{\EntryKey}%
% }%
% }%
\foreach \x in {hEYuAQAAIAAJ, 54A3MuBzIrEC} {%
\ifcsdef{Bib books.google.com/books?id=\x}{%
PASS: Found (\citefield{\csuse{Bib books.google.com/books?id=\x}}{title}).
}{%
FAIL: Missing csdef for \x.
}%
\par
}
\end{document}
答え1
内部から、データベースbiblatex
内のすべてのエントリをループすることはできません.bib
。ファイル内のすべてのエントリをループすることしかできません.bbl
。すべてのエントリを手動で引用したり使用したりした場合は、\nocite{*}
通常、それほど大きな違いはありませんが、エントリのクローン作成や相互参照などのより高度な機能を使用すると、元のデータベースに反映されない追加の「クローン」エントリが発生する可能性があります。
利用可能なすべてのエントリをループする最良の方法は、おそらく です\AtDataInput
。このフックは、エントリが.bbl
ファイルから読み込まれるたびに実行されます (読み込みの最後)。この時点で、フィールドはコマンド シーケンスとして展開可能です(したがって、展開不可能で、この例では役に立たない や を\abx@field@<field name>
操作する必要はありません)。\citefield
\documentclass{article}
\usepackage{xstring}
\usepackage{pgffor}
\usepackage{biblatex}
\makeatletter
\AtDataInput{%
\ifundef\abx@field@url
{}
{\edef\UrlKeyValue{\abx@field@url}%
\StrBehind*{\UrlKeyValue}{//}[\UrlKeyValueExtracted]%
\csxdef{Bib \UrlKeyValueExtracted}{\abx@field@entrykey}}}
\makeatother
\begin{filecontents}{\jobname.bib}
@book{knuth1984texbook,
title={The texbook},
author={Knuth, D.E. and Knuth, A.D. and Bibby, D.},
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},
%pages={11-15},
myFieldA={Also Useful Book},
myFieldB={on Shelf 5},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\foreach \x in {hEYuAQAAIAAJ, 54A3MuBzIrEC} {%
\ifcsdef{Bib books.google.com/books?id=\x}{%
PASS: Found (\citefield{\csuse{Bib books.google.com/books?id=\x}}{title}).
}{%
FAIL: Missing csdef for \x.
}%
\par
}
\end{document}
答え2
私のパッケージについてはご存知かもしれませんusebib
が、実験的なバージョンも持っていますexpl3
。あなたの質問がきっかけで、引用キーが保存されるシーケンスという機能を追加することにしました。
どのように動作するのでしょうかusebib3
? ロードする bib ファイル内の各エントリに対して、エントリのフィールドを含むプロパティ リストが設定されます。その後、プロパティ リストから各フィールドを取得してアクセスできます。
あなたの場合、キーとしてフィールドurl
、値としてそれらが属する引用キーを含む新しいプロパティ リストを作成できます。
usebib3.sty
(バージョン0.3)
\RequirePackage{expl3,xparse,url}
\ProvidesExplPackage{usebib3}{2022/05/06}{v. 0.3}{Use fields read in bib files}
\prop_new:N \l__usebib_temp_prop
\prop_new:N \g__usebib_temp_prop
\seq_new:N \g_usebib_discard_seq
\seq_new:N \g_usebib_keys_seq
\NewDocumentCommand{\bibinput}{m}
{
\clist_map_function:nN { #1 } \usebib_main:n
}
\NewExpandableDocumentCommand{\usebibentry}{mm}
{
\prop_item:cf { g_usebib_entry_#1_prop } { \str_lower_case:n { #2 } }
}
\NewExpandableDocumentCommand{\usebibentryurl}{O{|}m}
{
\__usebib_url:nf { #1 } { \prop_item:cn { g_usebib_entry_#2_prop } { url } }
}
\NewDocumentCommand{\newbibfield}{m}{}
\@ifpackageloaded{hyperref}
{
\cs_new_protected:Nn \__usebib_url:nn
{
\url{ #2 }
}
}
{
\cs_new_protected:Nn \__usebib_url:nn
{
\tl_rescan:nn { \url #1 #2 #1 }
}
}
\cs_generate_variant:Nn \__usebib_url:nn { nf }
\cs_generate_variant:Nn \prop_item:Nn { cf }
\NewDocumentCommand{\newbibignore}{m}
{
\seq_gput_right:Nx \g_usebib_discard_seq { \str_lower_case:n { #1 } }
}
\cs_new_protected:Nn \usebib_main:n
{
\group_begin:
\char_set_active_eq:NN @ \usebib_read_entry:w
\char_set_catcode_active:n { `@ }
\file_input:n { #1.bib }
\group_end:
}
\cs_new_protected:Npn \usebib_read_entry:w #1#
{
\seq_if_in:NxTF \g_usebib_discard_seq { \str_lower_case:n { #1 } }
{
\use_none:n
}
{
\__usebib_read_entry:w
}
}
\cs_new_protected:Npn \__usebib_read_entry:w
{
\group_begin:
\char_set_catcode_other:n { `@ } % may appear in text
\char_set_catcode_other:n { `\% } % can be used in URLs
\char_set_catcode_other:n { `\# } % can be used in fields
\__usebib_read_entry:n
}
\cs_new_protected:Nn \__usebib_read_entry:n
{
\prop_gset_from_keyval:Nn \g__usebib_temp_prop { USEBIBREADKEY=#1 }
\group_end:
\__usebib_save_entry:
}
\cs_new_protected:Nn \__usebib_save_entry:
{
\prop_clear:N \l__usebib_temp_prop
\prop_map_inline:Nn \g__usebib_temp_prop
{
\str_if_eq:nnTF { ##1 } { USEBIBREADKEY }
{
\seq_gput_right:Nn \g_usebib_keys_seq { ##2 }
}
{
\prop_put:Nxn \l__usebib_temp_prop { \str_lower_case:n { ##1 } } { ##2 }
}
}
\prop_new:c { g_usebib_entry_ \prop_item:Nn \g__usebib_temp_prop { USEBIBREADKEY } _prop }
\prop_gset_eq:cN
{ g_usebib_entry_ \prop_item:Nn \g__usebib_temp_prop { USEBIBREADKEY } _prop }
\l__usebib_temp_prop
}
\cs_generate_variant:Nn \prop_put:Nnn { Nx }
名前を変更した bib ファイルを使用したテスト ファイルpetergrill.bib
(ここには表示されていません)
\documentclass{article}
\usepackage{usebib3}
\bibinput{petergrill}
\ExplSyntaxOn
\prop_new:N \l_petergrill_url_prop
%% save the url fields
\seq_map_inline:Nn \g_usebib_keys_seq
{
\prop_put:Nxn \l_petergrill_url_prop { \usebibentry { #1 } { url } } { #1 }
}
\NewDocumentCommand{\checkids}{mm}
{% #1 = prefix, #2 = list
\clist_map_inline:nn { #2 }
{
\prop_if_in:NnTF \l_petergrill_url_prop { #1##1 }
{
PASS:~Found~(\usebibentry{\prop_item:Nn \l_petergrill_url_prop { #1##1 }}{title}) \par
}
{
FAIL:~Missing~##1
}
}
}
\ExplSyntaxOff
\begin{document}
\checkids{https://books.google.com/books?id=}{hEYuAQAAIAAJ, 54A3MuBzIrEC}
\end{document}
この\seq_map_inline:Nn
部分は、冒頭で述べたプロパティ リストにデータを入力し、\checkids
項目が存在するかどうかを確認し、title
この場合はフィールドを出力します。