2

I am using the solution given in the answer here to start my reference counter at 0 instead of 1. However when using the phys style I end up with the following problem:

This code:

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[style=phys]{biblatex}

\DeclareFieldFormat{labelnumber}{%
  \ifinteger{#1}
    {\number\numexpr#1-1\relax}
    {#1}}
\addbibresource{ref.bib}

\begin{document}
\cite{a}\cite{b}
\cite{a,b}
\end{document}

outputs

wrong ref numbers

instead of [0][1][0,1]

2 Answers 2

3

Adding \expanded seems to fix the issue.

\begin{filecontents*}{\jobname.bib}
@article{a,
  author={A. Uthor},
  title={Title},
  journal={Journal},
  year={2020},
}
@article{b,
  author={W. Riter},
  title={Title},
  journal={Journal},
  year={2020},
}
\end{filecontents*}

\documentclass{article}

\usepackage[style=phys]{biblatex}

\DeclareFieldFormat{labelnumber}{%
  \expanded{\ifinteger{#1}
    {\number\numexpr#1-1\relax}
    {#1}}}
\addbibresource{\jobname.bib}

\begin{document}
\cite{a}\cite{b}
\cite{a,b}
\end{document}

enter image description here

2

For a numeric-comp-based style things are slightly more tricky, because the labelname may not be a raw number, but a macro expanding to a number. That means we need to adjust the test \ifinteger to expand its argument.

\documentclass{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[style=phys]{biblatex}

\makeatletter
\newrobustcmd*{\pxifinteger}[1]{%
  \begingroup
  \protected@edef\tempa{\endgroup%
    \blx@imc@ifinteger{#1}}%
  \tempa}

\DeclareFieldFormat{labelnumber}{%
  \pxifinteger{#1}
    {\number\numexpr#1-1\relax}
    {#1}}
\makeatother
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson}

\cite{worman}

\cite{sigfridsson,worman}
\end{document}

[0]//[1]//[0, 1]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .