一个引文中有多个参考文献,并附有链接

一个引文中有多个参考文献,并附有链接

我想要做一个上标引文中有多个参考文献但可以选择 pdf 或纸质布局。

当选择 pdf 时,我希望在引用号中包含指向参考文献的内部链接,并在文章名称中包含指向 doi 或 url 的链接。

当选择论文选项时,url 或 doi 应该出现在每篇文章的末尾,但不能同时出现。

\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}

答案1

我没有复制解决方案到一个上标引文中有多个参考文献这个答案可以使代码更短,并表明这个解决方案是普遍适用的(但是,我已经确保这个答案可以与那里给出的答案一起顺利运行)。

这个答案中的大部分代码都受到我对以下问题的回答的启发自定义网址\cite链接

为了能够链接标题,我们需要一种新的链接格式

\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}}

这需要辅助函数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

title然后我们需要通过重新定义 的biblatex.deftitle来链接该字段

\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}}

还可以改变字段格式的定义title

doi为了在“PDF 模式”下抑制所有其他链接输出(URL、DOI 等),但在“打印”模式下保留、eprint、之一url(按此顺序),我们使用以下逻辑

\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}}
            {}}}}
}

平均能量损失

\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}

在“PDF 模式”中

在此处输入图片描述

在“打印模式”

在此处输入图片描述

您不会发现我们没有在“打印模式”中抑制标题中的链接,您可以通过移动内部title宏(位)的重新定义来实现这一点。\renewbibmacro*{title}{...}\iftoggle{pdf}{%

相关内容