# How to print a custom bibliography entry at a specific position/set its position (near the end, but before the generated backref)?

As a follow-up of my old question "How to print the internal ID of the bibliography entries in the output format for referring to files?" I still have one problem:
I do use backref=true for biblatex, and for stylistic reasons I obviously want that to be printed last in the entry.

Now e.g. here is an example:

% !TeX program = lualatex
% !TeX encoding = UTF-8

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

\usepackage[style=numeric,
sortcites=true,
sorting=none,
defernumbers=true,
%maxcitenames=3,
minbibnames=3, % cite up to three authors in bib
backref=true,
backend=biber]{biblatex}

\begin{filecontents}{mybib2.bib}
@article{test,
author={Awesome person},
title={How to be awesome in 5 easy steps.},
date = {2020-06-23},
journaltitle = {{Stackexchange Human Personalities}},
note = {Note is here},
url = {https://tex.stackexchange.com/}
}
\end{filecontents}

% special entry declaration STARTS HERE
\DeclareFieldFormat{entrykey}{Internal entry: \texttt{#1}}
\renewbibmacro*{finentry}{\newunit\newblock\printfield{entrykey}\finentry}
% special entry declaration ENDS HERE

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


That works quite well (expect for one other issue), but the actual problem here is that the "Cit. on p. 1" is printed last - yes, I know finentry makes that quite obvious, but I've searched the biblatex doc and could not find another entry I could overwrite like nearlyfinentry or finentry-1 or whatever that may be called. That's what I'd like to have. The best would of course be, if I could define it in a relative to some entry, i.e. "before backref" (in my case possibly) or "after addendum" (also quite useful in my case) or "insert before 2nd last entry shown" or "after url field" etc. I think you get what I mean.

Here the output is shown:

What I basically want is to show my (here underlined in blue) entry before the red backreference entry.

Ultimately, the order in which fields are printed in the bibliography is controlled by the bibliography driver and the bibliography macros that the driver calls.

finentry is a special bibmacro that is executed at the end of every bibliography driver. There is no analogous command for finentry-1. There is also no interface to specify "print this field between field X and Y". You need to have a look at the bibliography driver(s) in question and find out how to best proceed.

Generally there are two methods

1. Modify an existing bibmacro to print your new field.
2. Add a new bibmacro to print your new field to the driver.

Method 1 usually needs a lot less code if it is possible. Method 2 will always work, but may involve lots of code (either because you have to copy and paste the whole driver to essentially add two lines of code, or because you need to patch each driver with xpatch).

If you want to print something just before the backref in the standard styles, you can add the relevant code to the addendum+pubstate macro, which is used by all standard style drivers.

\documentclass[british]{article}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=numeric,
sortcites=true,
sorting=none,
defernumbers=true,
%maxcitenames=3,
minbibnames=3, % cite up to three authors in bib
backref=true,
backend=biber]{biblatex}

\DeclareFieldFormat{entrykey}{Internal entry: \texttt{#1}}

\newunit\newblock
\printfield{pubstate}
\newunit\newblock
\printfield{entrykey}}

\begin{filecontents}{\jobname.bib}
@article{test,
author       = {Awesome person},
title        = {How to be awesome in 5 easy steps.},
date         = {2020-06-23},
journaltitle = {{Stackexchange Human Personalities}},
note         = {Note is here},
url          = {https://tex.stackexchange.com/}
}
\end{filecontents}

\begin{document}
Lorem~\autocite{sigfridsson,worman,geer,nussbaum}
ipsum~\autocite{test}

\printbibliography
\end{document}


Just to see how you can approach these sort of things this is the @article driver from standard.bbx

\DeclareBibliographyDriver{article}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\printdelim{nametitledelim}}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{bytranslator+others}%
\newunit\newblock
\printfield{version}%
\newunit\newblock
\usebibmacro{in:}%
\usebibmacro{journal+issuetitle}%
\newunit
\usebibmacro{byeditor+others}%
\newunit
\usebibmacro{note+pages}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}


The backref is printed by the pageref bibmacro, so you want to insert your new field before that macro is called. addendum+pubstate is an obvious choice here, because it is the last bibmacro called before pageref.

Before you can settle with addendum+pubstate you should double check that addendum+pubstate is used in the same position in all drivers that you need to modify (i.e. in all drivers).

Then you look up the definition of addendum+pubstate, which is

\newbibmacro*{addendum+pubstate}{%