In working on improved documentation for a Biblatex style, I'd like to print nicely styled verbatim .bib entries beside the output for each, thereby juxtaposing cause and effect. This could be done by hand for each entry, but I hoped it might be easier to define a custom Biblatex citation command for typesetting .bib entries exactly as they appear in the file. A custom citation command would not only save tedium, but it would also help with automating documentation.
Unfortunately, I'm unsure how to access the literal data in a field, if this is even possible. I'd imagine Biber's already processing and parsing the data before Biblatex even sees it, and my use case is probably complicated by wanting to juxtapose unprocessed .bib data with stylized, processed Biblatex output. Here's a simplified version of what I have so far, along with the output for two entries:
\documentclass[a4paper]{article}
\usepackage[american]{babel}
\usepackage{csquotes}
\usepackage{xcolor}
\usepackage[style=mla,backend=biber]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{documentation.bib}
@article{Tibullus:2002ub,
author = {Tibullus},
date = {2002/2003},
journal = {Chicago Review},
number = {4},
pages = {102--106},
title = {How to Be Tibullus},
translator = {Wray, David},
volume = {48}}
@article{Evacuation:wj,
date = {2016-07-15},
entrysubtype = {newspaper},
journal = {The Boston Globe},
title = {Evacuation Order Lifted at Nice Airport},
url = {www.bostonglobe.com/news/world/2016/07/15/evacuation-progress-nice-airport/KO4BytWK4wFUOxjEkSpKTN/story.html}}
\end{filecontents}
\addbibresource{documentation.bib}
\DeclareCiteCommand{\samplebib}[\texttt]
{}%
{\usebibmacro{citeindex}%
\renewcommand*{\newunitpunct}{\addcomma\newline}%
\renewcommand*{\multinamedelim}{\addspace{}and\addspace{}}%
\usebibmacro{cite:mla:bib}}
{}%
{}
\newcommand{\entrycolor}{\color{teal}}
\newcommand{\fieldcolor}[1]{{\color{purple}#1}}
\newcommand{\fieldindent}{{\color{white} ~~~}}
\newcommand{\fieldcite}[1]{
\iffieldundef{#1}%
{}%
{\printtext{\fieldindent\fieldcolor{#1} = \{\printfield[noformat]{#1}\}}}%
\ifnameundef{#1}%
{}%
{\printtext{\fieldindent\fieldcolor{#1} = \{\printnames[family-given][-\value{listtotal}]{#1}\}}}%
\iflistundef{#1}%
{}%
{\printtext{\fieldindent\fieldcolor{#1} = \{\printlist{#1}\}}}%
}
\makeatletter
\newbibmacro*{cite:mla:bib}{%
{\entrycolor\printtext{@}\printfield{entrytype}}\{\printfield{entrykey}%
\newunit%
\fieldcite{author}%
\newunit%
\fieldcite{date}%
\newunit%
\fieldcite{day}%
\newunit%
\fieldcite{entrysubtype}%
\newunit%
\fieldcite{institution}%
\newunit%
\fieldcite{journaltitle}%
\newunit%
\fieldcite{journal}%
\newunit%
\fieldcite{month}%
\newunit%
\fieldcite{number}%
\newunit%
\fieldcite{options}%
\newunit%
\fieldcite{pages}%
\newunit%
\fieldcite{title}
\newunit%
\fieldcite{translator}
\newunit%
\fieldcite{url}
\newunit%
\fieldcite{volume}
\newunit%
\fieldcite{year}%
\newline%
\}
}
\makeatother
\begin{document}
\begin{refsection}
\noindent\samplebib{Tibullus:2002ub}
\printbibliography[heading=none]
\end{refsection}
\begin{refsection}
\noindent\samplebib{Evacuation:wj}
\printbibliography[heading=none]
\end{refsection}
\end{document}
The output shows that the date
entry is now gone, replaced by year
, month
, and day
as needed, without any range. Likewise the journal
field is converted with journaltitle
--though this kind of conversion is less of a problem. Other entries will have similar substitutions, too, but they boil down to the same problem. (I understand why this is the default and have no complaints!) Is it possible to insist that Biblatex should show the literal .bib input for every field, or are these values out of reach? Perhaps more importantly, have I overlooked a better way to programmatically typeset Bibtex data from an existing .bib file for documentation?
.bib
data on the LaTeX side because you'd have to undo all of Biber's pre-processing steps (most prominently date parsing, but also field aliasing [journal
->journaltitle
] and much more forcrossref
etc.) That might be possible for simple examples, but becomes less and less viable the more advanced features ofbiblatex
you want to use.journal
orjournaltitle
(that is the point of the sourcemapping by Biber). Of course Biber would have the info available, but it's not exposed to the LaTeX side of things. For most simple dates it should be possible to reconstruct thedate
value, but it would get fairly messy for complex dates.