# How to print the internal ID of the bibliography entries in the output format for referring to files?

I know how the LaTeX bibliography works and of course, you usually should not reference the internal bibliography ID in your output, but I want to do that for one specific reason: I want to provide a copy of all sources I refer as files. To identify, which files matches which citation, there needs to be some unique string (that does not change). I then just rename/append/prepend that string in the file name.

However, I still want to use the numeric style, which of course then uses numbers, which change while I am editing the document. So I cannot just use the number. Also, of course it should be known before I compile the document, because I have to rename the file and don't want to compile, look at the result, and rename again.

As such, I assumed the ID you use in your .bib file would be very well suitable for that.

But how can I do that technically? IMHO the ID should not be too obtrusive (so don't mention it right at the beginning instead of the ID – yet again, this seems to be what the draft style does – but I still want a "productive" version/output with the ID).

Here are the important LaTeX parts:

% !TeX program = lualatex
% !TeX encoding = UTF-8
% !TeX spellcheck = de_DE
\documentclass[12pt,a4paper,titlepage,numbers=noenddot]{scrartcl}
\KOMAoption{listof}{totocnumbered, leveldown}
% […]
\usepackage[style=numeric,
sortcites=true,
sorting=none,
defernumbers=true,
backref=true,
backend=biber]{biblatex}
\usepackage{nameref}


Note: If you can suggest a better "fixed ID/string" for each bibliography entry that I can rename the files to, feel free to use that instead in your solution.

I use biber v2.12 and LuaLaTeX v1.10.0.

For most intents and purposes the entry key is just a normal field called entrykey on the biblatex side. You can easily print it in the bibliography if you like.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric, backend=biber]{biblatex}

\DeclareFieldFormat{entrykey}{\texttt{#1}}
\renewbibmacro*{finentry}{\newunit\newblock\printfield{entrykey}\finentry}

\begin{document}
\autocite{sigfridsson,worman,geer,nussbaum}
\printbibliography
\end{document}


If you don't want to print the field directly, but rather want to access its contents, for example to generate an internal link or a label, you probably want to use \thefield{entrykey}.

If you provide the copies of your sources as external documents that are shared together with your main document, the way to go would probably be the file field (which is defined in the data model, but not printed by the standard styles). The file field could hold a relative path to the file in question. In that case you wouldn't even have to take the entry key, but could take any name you like.

If you include the sources in your document directly, you might be interested in Inserting a footnote on a bibliography entry (which uses \thefield{entrykey} as suggested).

• Thanks. I think I could achieve your latest comment (linking to fields directly) even without \thefield, which only printed the thing literally, just by adjusting the field format: \DeclareFieldFormat{file}{Copy in \href{run:./references/#1}{#1}} (and entrykey with file, of course)
– rugk
Jun 9 '20 at 16:58
• Oh no, there is a problem: As soon as I only change \DeclareFieldFormat{entrykey}{\texttt{#1}} to \DeclareFieldFormat{file}{\texttt{#1}} from your solution, extra dots seem to appear in front of the bibliography entries that follow on entries that do not have a file entry set. See this image.
– rugk
Jun 16 '20 at 9:47
• @rugk Please ask a new question about that. There should be no such issue if you use code parallel to what is shown above, but I can't tell without having seen the code you actually use. Jun 16 '20 at 14:20
• Okay, did so: Actually I have two separate problems, so I created two new questions. See tex.stackexchange.com/q/550720/98645 and tex.stackexchange.com/q/550729/98645. Thanks. :)
– rugk
Jun 23 '20 at 10:39
• I think it should be \finentry and not \finentrypunct. Jun 23 '20 at 11:14