如何使用 BibLaTeX 和 hyperref 以详细模式将标题转换为超链接?

如何使用 BibLaTeX 和 hyperref 以详细模式将标题转换为超链接?

我使用的hyperref是 BibLaTeX 的verbose样式,对于参考书目条目和初始(但不是后续)引用,我想使用 URL 将条目和引用的标题制作成外部超链接,而不是打印出 URL。有办法吗?

怎么看我可能在参考书目中找到部分内容,但我不确定如何在初始引用中找到我要寻找的内容。

\documentclass[nobib,nohyper]{tufte-handout}
\usepackage{lipsum}
\RequirePackage{xpatch}     % For the patches below
\RequirePackage{hyphenat}   % See -- http://code.google.com/p/tufte-latex/issues/detail?id=60
\RequirePackage[
    backend=bibtex, 
    natbib=true, 
    bibstyle=verbose, citestyle=verbose,    % bibstyle extensively modifed below
    doi=true, url=true,                     % excluded from citations below
    citecounter=true, citetracker=true,
    block=space, 
    backref=true, backrefstyle=two,
    abbreviate=false            
]{biblatex}

% For tufte-like behavior (I never use \cite itself); see -- https://tex.stackexchange.com/a/47763/7844
% Not directly related to the question but included for completeness
\let\citep\footcite 

% Some customizations
\AtEveryCitekey{\clearfield{url}\clearfield{doi}\clearfield{eprint}\clearfield{isbn}}   
\renewbibmacro*{in:}{}

% Some reordering and exclusions; see -- https://tex.stackexchange.com/q/46804/7844
% I'd like to preserve these changes, making the feature requested here an option
\newbibmacro*{addendum+pubstate+pageref}{%
    \usebibmacro{addendum+pubstate}%
    \clearfield{addendum}%
    \clearfield{pubstate}%
    \setunit{\bibpagerefpunct}\newblock
    \usebibmacro{pageref}%
    \clearlist{pageref}%
    \setunit{\adddot\par\nobreak}}

\xpretobibmacro{doi+eprint+url}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{eprint}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{url+urldate}{\usebibmacro{addendum+pubstate+pageref}}{}{}

\RequirePackage[]{hyperref}
\RequirePackage[all]{hypcap}        % See -- https://tex.stackexchange.com/a/27349/7844

\begin{filecontents}{\jobname.bib}
@book{9780201134476,
author = {Knuth, Donald E},title = {{Computers & Typesetting, Volume A: The TeXbook}},
publisher = {Addison-Wesley Professional},year = {1986},isbn = {0201134470},
url = {http://www.amazon.com/dp/0201134470}}
@book{9780226458083,
author = {Kuhn, Thomas S},title = {{The Structure of Scientific Revolutions}},
publisher = {University Of Chicago Press},year = {1996},isbn = {0226458083},
url = {http://www.amazon.com/dp/0226458083}}
@book{9781903436837,
author = {Shakespeare, William},title = {{Much Ado about Nothing}},
publisher = {Arden Shakespeare},year = {2005},isbn = {1903436834},
url = {http://www.amazon.com/dp/1903436834}}
@book{9780765303615,
author = {Brin, David},title = {{Existence}},
publisher = {Tor Books},year = {2012},isbn = {0765303612},
url = {http://www.amazon.com/dp/0765303612}}
@book{9780691122946,
author = {Frankfurt, Harry G},title = {{On Bullshit}},
publisher = {Princeton University Press},year = {2005},isbn = {0691122946},
url = {http://www.amazon.com/dp/0691122946}}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\subsection*{Some initial citations}

This\citep{9780691122946} is an initial citation, which in verbose style, it has no hyperlink and I've customized the style to omit the URL in the citation, though not in the bibliographic entry. Here's another,\citep{9780226458083} and here\citep{9781903436837,9780765303615,9780691122946} are some additional ones for good measure.

I'd like the titles for these to link externally, using the URL field from the \texttt{.bib} entry (using the DOI instead of there's no URL there).

\subsection*{Something to take up some space to demonstrate internal linking}

\lipsum[1]\lipsum[2]\lipsum[3]\lipsum[4]

\subsection*{Some subsequent citations, showing back links}
This\citep{9780691122946} is a subsequent  citation, which hyperlinks back to the first corresponding citation.
So are these.\citep{9780226458083, 9781903436837,9780765303615,9780691122946}.

These work as I want them to.

\defbibnote{@prenote}{Here, as an option, instead of displaying the URL, I'd like to have the title behave as desired in the first section above:  as an external link, using the URL field from the \texttt{.bib} entry.}
\printbibliography[prenote=@prenote]

\end{document}

答案1

url仅在引用中应抑制 et al.字段标题已设置。这无法在格式化命令中完成。因此,可以对应用该title格式的参考书目宏进行所有必要的编辑。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[style=verbose,backref=true]{biblatex}
\usepackage[colorlinks]{hyperref}
\usepackage{xpatch}

% Define new format to apply hypertext references
\DeclareFieldFormat{linked}{%
  \ifhyperref
    {\iffieldundef{url}
       {\iffieldundef{doi}
          {\iffieldundef{isbn}
             {\iffieldundef{issn}
                {\iffieldundef{eprint}
                   {#1}
                   {\mkhrefeprint{#1}}}
                {\href{\worldcatsearch\thefield{issn}}{#1}}}
             {\href{\worldcatsearch\thefield{isbn}}{#1}}}
          {\href{http://dx.doi.org/\thefield{doi}}{#1}}}
       {\href{\thefield{url}}{#1}}}
    {#1}}

\def\worldcatsearch{http://www.worldcat.org/search?qt=worldcat_org_all&q=}

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

% Add missing space in arXiv format
\DeclareFieldFormat{eprint:arxiv}{%
  arXiv\addcolon\space
  \ifhyperref
    {\href{http://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}%
       \iffieldundef{eprintclass}
         {}{\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
    {\nolinkurl{#1}
     \iffieldundef{eprintclass}
       {}{\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}

\makeatother

% Use new format in titles
\renewbibmacro*{title}{% Based on generic definition from biblatex.def
  \ifboolexpr{ test {\iffieldundef{title}} and test {\iffieldundef{subtitle}} }
    {}
    {\printtext[title]{\printtext[linked]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}}%
     \newunit}%
  \printfield{titleaddon}%
  \usebibmacro{clearlinks}}

\renewbibmacro*{periodical}{% Based on generic definition from biblatex.def
  \iffieldundef{title}
    {}
    {\printtext[title]{\printtext[linked]{%
       \printfield[titlecase]{title}%
       \setunit{\subtitlepunct}%
       \printfield[titlecase]{subtitle}}}}
  \usebibmacro{clearlinks}}

% Suppress url everywhere, suppress URLs/identifiers in citations
\newbibmacro*{clearlinks}{%
  \clearfield{url}\clearfield{urlyear}%
  \ifcitation
    {\clearfield{doi}\clearfield{eprint}\clearfield{isbn}\clearfield{issn}}
    {}}

% Suppress \finentrypunct after linebreaking URLs/identifiers
\newtoggle{bbx:urlbreak}
\xpretobibmacro{finentry}
  {\iftoggle{bbx:urlbreak}{\nopunct}{}%
   \global\togglefalse{bbx:urlbreak}}{}{}

% Print URLs/identifiers at end of entry, after a linebreak
\newbibmacro*{addendum+pubstate+pageref}{%
    \usebibmacro{addendum+pubstate}%
    \clearfield{addendum}%
    \clearfield{pubstate}%
    \setunit{\bibpagerefpunct}\newblock
    \usebibmacro{pageref}%
    \clearlist{pageref}%
    \setunit{%
      \finentrypunct\par\nobreak%
      \global\toggletrue{bbx:urlbreak}}}

\xpretobibmacro{doi+eprint+url}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{eprint}{\usebibmacro{addendum+pubstate+pageref}}{}{}
\xpretobibmacro{url+urldate}{\usebibmacro{addendum+pubstate+pageref}}{}{}

\begin{filecontents}{\jobname.bib}
@book{wilde,
  title={The Importance of Being Earnest: A Trivial Comedy for Serious People},
  author={Wilde, Oscar},
  series={English and American drama of the nineteenth century},
  eprint={4HIWAAAAYAAJ},
  eprinttype={googlebooks},
  year={1899},
  publisher={Leonard Smithers and Company}}
@Periodical{jcg,
  title = {Computers and Graphics},
  issuetitle = {Semantic {3D} Media and Content},
  volume = {35},
  number = {4},
  year = {2011},
  issn = {0097-8493}}
@Manual{cmso,
  label = {CMS Online},
  title = {The Chicago Manual of Style Online},
  edition = {16},
  publisher = {University of Chicago},
  date = {2010},
  url = {http://www.chicagomanualofstyle.org}}
\end{filecontents}

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

\begin{document}
\null\vfill
Filler text.\footnote{Filler text \smartcite{kastenholz,itzhaki}.}
Filler text.\footcites[e.g][]{companion}[section 5]{cms}[10--15]{jcg}{ctan}
Filler text.\footcites[e.g][]{companion}[section 5]{cms}[10--15]{jcg}{ctan}
Filler text.\footcites[e.g.][10--15]{itzhaki}[cf.][10]{wilde}
\printbibliography
\end{document}

在此处输入图片描述

相关内容