I would like to loop through all entries in the BibLaTeX database and generate a \csxdef
based on the each key. The pseudo code for what I desire is:
\foreach \EntryKey in \ListOfAllBibliography {%
\edef\UrlKeyValue{\citefield{\EntryKey}{url}}%
\StrBehind*{\UrlKeyValue}{//}[\UrlKeyValueExtracted]%
\IfStrEq{\UrlKeyValue}{}{}{%
\csxdef{Bib \UrlKeyValueExtracted}{\EntryKey}%
}%
}%
For this particular case, this loop should be equivalent to
\csxdef{Bib books.google.com/books?id=hEYuAQAAIAAJ}{knuth1984texbook}%
\csxdef{Bib books.google.com/books?id=54A3MuBzIrEC}{goossens1994latex}%
The expected output of the MWE when this works is:
References:
- One option would be to do this in python as per Converting bib database into csv, but would prefer to do it in LaTeX.
Code:
\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}
%
cannot be used to comment out lines in a.bib
file. See tex.stackexchange.com/a/21710/4427%
to comment out field even within an entry. Outside of entries everything is a comment, but Biber will warn you about "possible junk" unless you use%
to show that you actually intended to place a comment. See also tex.stackexchange.com/q/261261/35864.