Don't use \parindent in the preamble
See https://tex.stackexchange.com/a/466041/35864 and Ulrike's comment
If biblatex uses parindent in the preamble it is a biblatex error. Packages shouldn't expect font dependant values to be correct there.
Example for tests
\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage{fontspec}
\usepackage[backend=biber,style=authoryear,citestyle=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{sigfridsson}
\printbibliography
\end{document}
\def\bibhang{\ifnumequal{\parindent}{0}{1em}{\parindent}\relax}
seems to work instead of \setlength in
https://github.com/plk/biblatex/blob/5b0bb276e9677d941b30e16df5f486cdcf3597ff/tex/latex/biblatex/biblatex.def#L289-L290
But is that (i) safe, (ii) really a good idea? Do we need the \relax?
If you change from a length to a macro you will probably break all documents/styles which changes the length \bibhang. If you move the setting of bibhang to a better place (e.g. at the begin of the bibliography), you could change existing documents too. Probably a more complicated setup will be needed: store the values of \parindent and \bibhang when setting them in biblatex.def and then compare them with the actual values at the begin of the bibliography and then make good guesses ...
You could try:
\setlength{\bibhang}{-\maxdimen}
in biblatex.def and
\ifdim\bibhang=-\maxdimen \setlength{\bibhang}{\parindent}\fi
before using \bibhang (e.g. at the beginning of the bibliography) and hope that nobody would think, that a value of -\maxdimen would be a valid value for \bibhang.
@u-fischer Thanks for the explanation.
@komascript Thank you for the suggestion. I guess an obvious nonsense 'sentinel value' is a workable, if not super pretty solution, if we want to retain \bibhang as a length and want users to be able to set the value in the preamble.
Before I implement @komascript's idea with a sentinel value I'd like to know if \parindent in \bibhang is the only problematic length or whether there are more. AFAICS the only top-level \setlengths in biblatex are
https://github.com/plk/biblatex/blob/72011856d77b245dfdc14815f03c1356100c45da/tex/latex/biblatex/biblatex.def#L289-L295
are \labelsep and \itemsep safe to use in the preamble or must they only be used in the document body as well?
A first suggestion is at https://github.com/plk/biblatex/compare/dev...moewew:parindent Comments would be most welcome.
I'm still not sure about \biblabelsep and \bibitemsep and whether the lengths used there (\labelsep and \itemsep) are safe.
@plk This solution has the potential to break \cite commands (like biblatex-apa's \fullcitebib) that use \bibhang, since \bibhang only has a usable value in the bibliography environment (biblatex-apa is not affected since it sets \bibhang explicitly). Should I look into hooks to also set \bibhang and friends for all cite commands (\blx@blxinit comes to mind) or are we OK with \bibhang only being defined in a bibliography environment and recommend style authors to make sure that \bibhang is usable with \SetDeferredBibLengths themselves.
\labelsep is theoretically problematic too, as it is normally set to 0.5em and so font dependant. But practically I see nothing changing it after the class has set it. Not even KOMA resets it with a font size change. But \itemsep is reset:
\documentclass[]{scrartcl}
\showthe\itemsep
\showthe\labelsep
\KOMAoptions{fontsize=30pt}
\showthe\itemsep
\showthe\labelsep
\stop
When both length are changed e.g. with enumitem their value change only inside lists:
\documentclass[]{scrartcl}
\usepackage{enumitem}
\setlist{itemsep=20pt,labelsep=20pt}
\begin{document}
\showthe\itemsep \showthe\labelsep
\begin{itemize}\showthe\itemsep \showthe\labelsep
\item blub
\end{itemize}
\end{document}
@u-fischer Thank you for that explanation.
Mhhh, given that we have the machinery, we might as well defer \biblabelsep and \bibitemsep. As to what enumitem and other packages might do: I think that is way outside of biblatex's jurisdiction. I'm comfortable with tracking the 'general' class-defined lengths depending on font size etc., but chasing after other settings is not something I regard as useful. In the second example I would expect the user to just set \bibitemsep and \biblabelsep themselves explicitly. In fact PL seems to have been aware of issues like this, at least the documentation includes " This length is initialized to ... at load-time." (emphasis mine).
In fact we also have
This length [
\bibhang] is initialized to\parindentat load-time.
in the docs, so biblatex is explicit about this possibly questionable behaviour. Given that we are up-front about it and it sort of worked OK so far, I'm now interested in how bad using \parindent in the preamble really is, especially compared to the alternative and complicated solution suggested above.