2

I want to do Multiple references in one superscript citation but with the options of pdf or paper layout.

When pdf is selected I want an internal link in the citation number to the reference and a link in the name of the articles to the doi or url.

When the paper option is selected the url or the doi should appear at the end of each article, but not both of them.

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\addtokomafont{disposition}{\rmfamily}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{csquotes,siunitx,fancyhdr,etoolbox}
\sisetup{per-mode = symbol}
\DeclareSIUnit\cal{cal}
\newtoggle{pdf}
\togglefalse{pdf}
\usepackage[
  refsection=section,
  style=authortitle,
  backend=biber,
  hyperref=auto
  ]{biblatex}
\addbibresource{biblatex-examples.bib}
\defbibheading{refbib}[Referencia~\therefsegment]{\subsection*{#1}}
\DeclareFieldFormat{linktitle}{%
  \ifhyperref
    {\iffieldundef{doi}
       {\iffieldundef{eprint}
           {\iffieldundef{url}
             {#1}
             {\href{\thefield{url}}{#1}}}
           {\mkhrefeprint{#1}}}
       {\href{http://dx.doi.org/\thefield{doi}}{#1}}}
    {#1}}

\makeatletter
\newrobustcmd*{\mkhrefeprint}[1]{%
  \iffieldequalstr{eprinttype}{arxiv}
    {\href{http://arxiv.org/\abx@arxivpath/\thefield{eprint}}{#1}}
    {\iffieldequalstr{eprinttype}{hdl}
       {\href{http://hdl.handle.net/\thefield{eprint}}{#1}}
       {\iffieldequalstr{eprinttype}{jstor}
          {\href{http://www.jstor.org/stable/\thefield{eprint}}{#1}}
          {\iffieldequalstr{eprinttype}{pubmed}
             {\href{http://www.ncbi.nlm.nih.gov/pubmed/\thefield{eprint}}{#1}}
             {\iffieldequalstr{eprinttype}{googlebooks}
                {\href{http://books.google.com/books?id=\thefield{eprint}}{#1}}
                {#1}}}}}}
\makeatother
\iftoggle{pdf}{
    \usepackage[unicode,colorlinks,urlcolor=blue]{hyperref}
    \newcommand{\myhref}[2]{\href{#1}{#2}} % enlace externo
    \newcommand{\mylref}[2]{\hyperref[#1]{#2}} % enlace interno
    \newcommand{\myplainurl}[1]{\ttfamily \url{#1}}
    \newcommand{\myfootnote}[1]{\footnote{#1}}
    \newcommand{\myfnhref}[2]{\href[#1]{#2}}
    \def\mycite#1{\begin{refsegment}\nocite{#1}\footnotemark[\therefsegment]\end{refsegment}}
    \renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[linktitle]{\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}}%
     \newunit}%
  \printfield{titleaddon}}
    \renewbibmacro*{doi+eprint+url}{}
  \renewbibmacro*{eprint}{}
  \renewbibmacro*{url+urldate}{}
}{
    \usepackage[unicode,hidelinks]{hyperref}
    \newcommand{\myhref}[2]{{#2}\footnote{\url{#1}}} % enlace externo
    \newcommand{\mylref}[2]{{#2}\footnote{\ref{#1} en la página \pageref{#1}}} % enlace interno
    \newcommand{\myplainurl}[1]{\url{#1}}
    \newcommand{\myfootnote}[1]{\footnote{#1}}
    \newcommand{\myfnhref}[2]{{#2} \^{}{\{\ttfamily  \url{#1}\}}} % enlace que sólo aparece en el pie de página
    \def\mycite#1{\begin{refsegment}\nocite{#1}\textsuperscript{[\therefsegment]}\end{refsegment}}
    \renewbibmacro*{doi+eprint+url}{%
    \iftoggle{bbx:doi}
      {\printfield{doi}}
      {\newunit\newblock
       \iftoggle{bbx:eprint}
        {\usebibmacro{eprint}}
        {\newunit\newblock
         \iftoggle{bbx:url}
            {\usebibmacro{url+urldate}}
            {}}}}
}

\begin{document}
  \section*{Referencias}
  This should reference the first reference \mycite{itzhaki,markey,sigfridsson,geer}
\bibbysegment[heading=refbib]
\end{document}
  • So, are we talking two different bibliography styles -- one for the electronic version of the document (showing doi or url), the other for the print version (url only)? – Mico Mar 7 '15 at 20:39
  • In the pdf the title of the reference is hyperlinked to the doi or url and the print version just prints the url after the reference's title, page... – ajr-dev Mar 7 '15 at 20:41
  • 2
    Please provide a minimal working example (MWE). Nobody wants to spend time on a solution only to find out that it doesn't work with the citation or bibliography style you're using, or conflicts with your chosen class. – cfr Mar 8 '15 at 0:49
  • Could you be a bit more precise about what you mean by "[m]ultiple references in one citation" in the title? Would biblatex's (dynamic or static) set help you there (see pp. 111-113 of the biblatex documentation)? A MWE and a more precise description of what you seek to achieve would be greatly appreciated. – moewe Mar 8 '15 at 7:22
3

I have not copied the solution to Multiple references in one superscript citation into this answer to keep the code shorter and show that this solution is universally applicable (I have made sure, however, that this answer works smoothly together with the answer given there).

Major parts of the code in this answer is inspired by my answer to Custom url for \cite links.

In order to be able to link the titles we need a new link format

\DeclareFieldFormat{linktitle}{%
  \ifhyperref
    {\iffieldundef{doi}
       {\iffieldundef{eprint}
           {\iffieldundef{url}
             {#1}
             {\href{\thefield{url}}{#1}}}
           {\mkhrefeprint{#1}}}
       {\href{http://dx.doi.org/\thefield{doi}}{#1}}}
    {#1}}

Which requires a helper function for eprint

\makeatletter
\newrobustcmd*{\mkhrefeprint}[1]{%
  \iffieldequalstr{eprinttype}{arxiv}
    {\href{http://arxiv.org/\abx@arxivpath/\thefield{eprint}}{#1}}
    {\iffieldequalstr{eprinttype}{hdl}
       {\href{http://hdl.handle.net/\thefield{eprint}}{#1}}
       {\iffieldequalstr{eprinttype}{jstor}
          {\href{http://www.jstor.org/stable/\thefield{eprint}}{#1}}
          {\iffieldequalstr{eprinttype}{pubmed}
             {\href{http://www.ncbi.nlm.nih.gov/pubmed/\thefield{eprint}}{#1}}
             {\iffieldequalstr{eprinttype}{googlebooks}
                {\href{http://books.google.com/books?id=\thefield{eprint}}{#1}}
                {#1}}}}}}
\makeatother

Then we need to link the title field via this redefinition of biblatex.def's title macro

\renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[linktitle]{\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}}%
     \newunit}%
  \printfield{titleaddon}}

One could also change the definition of the title field format.

To suppress all other linked output (URL, DOI etc.) in "PDF mode", but retain one of doi, eprint, url (in that order) in "print" mode we use the following logic

\iftoggle{pdf}{%
  \renewbibmacro*{doi+eprint+url}{}
  \renewbibmacro*{eprint}{}
  \renewbibmacro*{url+urldate}{}
}{
  \renewbibmacro*{doi+eprint+url}{%
    \iftoggle{bbx:doi}
      {\printfield{doi}}
      {\newunit\newblock
       \iftoggle{bbx:eprint}
        {\usebibmacro{eprint}}
        {\newunit\newblock
         \iftoggle{bbx:url}
            {\usebibmacro{url+urldate}}
            {}}}}
}

MWE

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{filecontents}
\usepackage[style=authortitle, backend=biber]{biblatex}
\usepackage{hyperref}

\begin{filecontents*}{\jobname.bib}
@article{KingZengCounterFacts,
  author        = {Gary King and Langche Zeng},
  title         = {The Dangers of Extreme Counterfactuals},
  journaltitle  = {Political Analysis},
  volume        = {14},
  number        = {2},
  date          = {2006},
  issue         = {Spring},
  pages         = {131–159},
  doi           = {10.1093/pan/mpj004},
  url           = {http://gking.harvard.edu/files/abs/counterft-abs.shtml},
  urldate       = {2012-06-05},
}
\end{filecontents*}

\newtoggle{pdf}
\toggletrue{pdf}

\addbibresource{biblatex-examples.bib}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{linktitle}{%
  \ifhyperref
    {\iffieldundef{doi}
       {\iffieldundef{eprint}
           {\iffieldundef{url}
             {#1}
             {\href{\thefield{url}}{#1}}}
           {\mkhrefeprint{#1}}}
       {\href{http://dx.doi.org/\thefield{doi}}{#1}}}
    {#1}}

\makeatletter
\newrobustcmd*{\mkhrefeprint}[1]{%
  \iffieldequalstr{eprinttype}{arxiv}
    {\href{http://arxiv.org/\abx@arxivpath/\thefield{eprint}}{#1}}
    {\iffieldequalstr{eprinttype}{hdl}
       {\href{http://hdl.handle.net/\thefield{eprint}}{#1}}
       {\iffieldequalstr{eprinttype}{jstor}
          {\href{http://www.jstor.org/stable/\thefield{eprint}}{#1}}
          {\iffieldequalstr{eprinttype}{pubmed}
             {\href{http://www.ncbi.nlm.nih.gov/pubmed/\thefield{eprint}}{#1}}
             {\iffieldequalstr{eprinttype}{googlebooks}
                {\href{http://books.google.com/books?id=\thefield{eprint}}{#1}}
                {#1}}}}}}
\makeatother

\renewbibmacro*{title}{%
  \ifboolexpr{
    test {\iffieldundef{title}}
    and
    test {\iffieldundef{subtitle}}
  }
    {}
    {\printtext[linktitle]{\printtext[title]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}}%
     \newunit}%
  \printfield{titleaddon}}

\iftoggle{pdf}{%
  \renewbibmacro*{doi+eprint+url}{}
  \renewbibmacro*{eprint}{}
  \renewbibmacro*{url+urldate}{}
}{
  \renewbibmacro*{doi+eprint+url}{%
    \iftoggle{bbx:doi}
      {\printfield{doi}}
      {\newunit\newblock
       \iftoggle{bbx:eprint}
        {\usebibmacro{eprint}}
        {\newunit\newblock
         \iftoggle{bbx:url}
            {\usebibmacro{url+urldate}}
            {}}}}
}

\begin{document}
  \nocite{itzhaki,markey,kastenholz,sigfridsson,geer,KingZengCounterFacts}
  \printbibliography
\end{document}

In "PDF mode"

enter image description here

In "print mode"

enter image description here

You will not that we have not suppressed the links in the titles in "print mode" you can achieve this by moving the redefinition of the title macro (the \renewbibmacro*{title}{...} bit) inside the \iftoggle{pdf}{%.

| improve this answer | |
  • It works nice. Could the citations link the references? – ajr-dev Mar 9 '15 at 20:54
  • @Arturo I assume you mean the in-text superscript numbers? If that is your concern please ask a new, separate question (and make sure people realise it is a follow-up to Multiple references in one superscript citation) because the solution to that will have little (or nothing) to do with the modifications discussed here. – moewe Mar 10 '15 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.