1

I'm trying to create a custom \cite command that takes in three arguments: the book/article name and the initial and final pages of the part that I'm citing. This is the code so far:

\renewcommand{\cite}[3]{
(vedi~\ifthenelse{\equal{#2}{#3}}
{\parencite[\pno~#2]{#1}}
{\parencite[\ppno~#2~\hspace{-0.035cm}--\hspace{-0.035cm}~#3]{#1}}\hspace{0.035cm})\\}

So if the input is

\cite{book_1}{64}{64}

the output is

enter image description here

I'd like to modify is so that that output corresponds to the input

\cite{book_1, 64}

if the initial and final cited pages are the same, and

\cite{book_1, 64-65}

if they're different. Is there a way to do this?

1
  • Why do you want to do this, rather than just use the optional arguments to the \cite command? e.g. \cite[p.64]{book1}
    – Seamus
    Feb 8, 2019 at 16:34

1 Answer 1

2

Personally, I don't think the usual input

\autocite[64]{sigfridsson}
\autocite[64-65]{sigfridsson}

is too complicated or far inferior to \cite{key}{64}{65}.

Here is a solution that only slightly modifies the macro \mknormrange to drop the second page number if it is equal to the first. We then need to change around the order of commands in the postnote formats to give expected output with respect to "p."/"pp.". Then you can use the standard biblatex postnote syntax

\autocite[<startpage>-<endpage>]{<key>}
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

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

\addbibresource{biblatex-examples.bib}

\DeclareFieldFormat{postnote}{\mknormrange*[{\mkpageprefix[pagination]}]{#1}}
\DeclareFieldFormat{volcitepages}{\mknormrange*[{\mkpageprefix[pagination]}]{#1}}
\DeclareFieldFormat{multipostnote}{\mknormrange*[{\mkpageprefix[pagination]}]{#1}}

\makeatletter
\def\blx@normrange@process#1#2{%
  \ifstrequal{#1}{#2}
    {\blx@range@out@value{#1}}
    {\blx@range@out@value{#1\bibrangedash#2}}}
\makeatother

\begin{document}
\autocite[64-64]{sigfridsson}

\autocite[64-65]{sigfridsson}

\printbibliography
\end{document}

(Sigfridsson and Ryde 1998, p. 64)//(Sigfridsson and Ryde 1998, pp. 64–65)

You must log in to answer this question.

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