使用存储在参考书目中的 URL 创建超链接?

使用存储在参考书目中的 URL 创建超链接?

我想知道我是否可以创建一个超链接,以某种方式自动使用 bib 文件存储的标签“url”?只是为了防止在同一文本中链接到参考文献和网络源时出现错误,例如:

母语:

\documentclass{article}
\usepackage{filecontents}
\usepackage[style=nature, url=true]{biblatex}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@online{UseCase20,
  title = {{Use-Case 2.0 ebook}},
  journal = {Ivar Jacobson International},
  year = {2014},
  month = {Jul},
  note = {[Online; accessed 25. Dec. 2018]},
  url = {https://www.ivarjacobson.com/publications/white-papers/use-case-ebook}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\href{https://www.ivarjacobson.com/publications/white-papers/use-case-ebook}{sometext} \footcite{UseCase20}
\printbibliography
\end{document}

我想做一些这样的工作:

\documentclass{article}
\usepackage{filecontents}
\usepackage[style=nature, url=true]{biblatex}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@online{UseCase20,
  title = {{Use-Case 2.0 ebook}},
  journal = {Ivar Jacobson International},
  year = {2014},
  month = {Jul},
  note = {[Online; accessed 25. Dec. 2018]},
  url = {https://www.ivarjacobson.com/publications/white-papers/use-case-ebook}
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\href{\citeurl{UseCase20}}{sometext} \footcite{UseCase20}
\printbibliography
\end{document}

但不幸的是,这在第 18 节中被打破了;

\href{\citeurl{UseCase20}}{sometext}

编辑:

所有测试的 MWE:

\documentclass{article}
\usepackage{filecontents}
\usepackage[style=nature, url=true]{biblatex}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@online{UseCase20,
    title = {{Use-Case 2.0 ebook}},
    journal = {Ivar Jacobson International},
    year = {2014},
    month = {Jul},
    note = {[Online; accessed 25. Dec. 2018]},
    url = {https://www.ivarjacobson.com/publications/white-papers/use-case-ebook}
}
\end{filecontents}
\addbibresource{\jobname.bib}
%https://tex.stackexchange.com/a/413372/118709
\DeclareCiteCommand{\citelink}
    {\boolfalse{citetracker}%
        \boolfalse{pagetracker}%
        \usebibmacro{prenote}}
    {\iffieldundef{postnote}
        {\href{\thefield{url}}{\printfield{title}}}
        {\href{\thefield{url}}{\thefield{postnote}}}}
    {\multicitedelim}
    {}
% https://tex.stackexchange.com/a/412927/118709
\DeclareCiteCommand{\citeqrurl}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\qrcode{\thefield{url}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}
% https://tex.stackexchange.com/a/413519/118709
\DeclareCiteCommand{\geturl}
    {\boolfalse{citetracker}\boolfalse{pagetracker}}
    {\iffieldundef{postnote}
        {\xdef\biburl{\thefield{url}}}
        {%
            \edef\geturlTmpCmd{\csfield{postnote}}%
            \expandafter\xdef\geturlTmpCmd{\thefield{url}}%
        }%
    }
    {}
    {}
\begin{document}
~\\
\citelink{sometext}{UseCase20}\footcite{UseCase20}\\
~\\
\citeqrurl{sometext}{UseCase20}\footcite{UseCase20}\\
~\\
\geturl{UseCase20}
%The \href{\biburl}{UseCase}\footcite{UseCase20}\\.
\printbibliography
\end{document}

答案1

\citeurl不会返回相关条目的 URL(以可扩展的方式),而是用于打印格式化URL。这意味着它不能用作 的 URI 参数\href。如果您希望能够将\href条目的 URL 转换为任意文本,最简单的方法是创建一个新的\cite...宏。由于\cite...宏具有固定的参数结构,因此下面的宏的工作方式如下

\citehrefurl[<arbitrary text that is going ot be linked>]{<entrykey>}

你可以使用任意参数创建新命令。通常我强烈建议不要通过\cite...命令创建新命令\newcommand,但在这种情况下我们可以例外。

\documentclass{article}
\usepackage[style=nature, url=true]{biblatex}
\usepackage{hyperref}

\DeclareCiteCommand{\citehrefurl}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}}
  {\iffieldundef{url}
     {\PackageWarning{biblatex}
        {The entry \thefield{entrykey} has no URL.\MessageBreak
         No link will be created}%
      \printfield{postnote}}
     {\href{\thefield{url}}
        {\iffieldundef{postnote}
           {\PackageWarning{biblatex}
              {Text argument missing,\MessageBreak
               using the title for entry\MessageBreak
               \thefield{entrykey}}%
            \printfield[citetitle]{labeltitle}}
           {\printfield{postnote}}}}}
  {}
  {}

\newcommand*{\citehrefurlwrap}[2]{\citehrefurl[#2]{#1}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{UseCase20,
  title   = {Use-Case 2.0 ebook},
  author  = {Ivar Jacobson and Ian Spence and Kurt Bittner},
  date    = {2011-12},
  url     = {https://www.ivarjacobson.com/publications/white-papers/use-case-ebook},
  urldate = {2018-12-25},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\citehrefurl{UseCase20}

\citehrefurl[some text]{UseCase20}

\citehrefurlwrap{UseCase20}{some other text}

\citeurl{UseCase20}

\href{https://www.ivarjacobson.com/publications/white-papers/use-case-ebook}{sometext}

\printbibliography
\end{document}

抱歉,目前没有图片。我无法上传它们。如果您愿意,请随意添加结果的屏幕截图。

这基本上是一个稍微修改过的版本贾昆来自\citelink他们的回答如何使用自定义文本创建 bib 文件中提供的 URL 链接而这又受到了从 citeurl 创建二维码

相关内容