Let's say I have a citation '[1]'. On clicking on '1', I would like to have a webpage pop up corresponding to the URL in the relevant bibtex entry. Also, I would like bibtex/biblatex to not generate the 'References' section. If the bibtex entry does not have a \url field, then pdflatex/bibtex should error out. I did fair research and did a bit of prompt engineering with ChatGPT as well but had no success. Help in this regard would be much appreciated.
-
Welcome to TeX.SE! Please show us the TeX code you have tried so far, then we do not have to guess what you are doing ... – Mensch May 30 '23 at 19:18
-
Welcome. // Please EDIT your question and augment it with some code, which compiles, shows your problem and is minimalistic. Thanks – MS-SPO May 30 '23 at 19:18
1 Answers
If you are using biblatex this is as easy as modifying the bibhyperref field format to get the desired links and not issuing \printbibliography to drop the bibliography at the end.
The following will link the citation to the DOI or URL if available and will error if neither DOI nor URL are available.
\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[backend=biber, style=numeric]{biblatex}
\usepackage{hyperref}
\DeclareFieldFormat{bibhyperref}{%
\iffieldundef{doi}
{\iffieldundef{url}
{\PackageError{biblatex}
{No URL/DOI for entry \thefield{entrykey}}
{I won't be able to link this entry properly.}%
#1}
{\href{\thefield{url}}{#1}}}
{\href{https://doi.org/\thefield{doi}}{#1}}}
\addbibresource{biblatex-examples.bib}
\begin{document}
Lorem \autocite{sigfridsson} (DOI)
ipsum \autocite{ctan} (URL)
dolor \autocite{worman} (no link)
\end{document}
- 175,683
-
Thanks @moewe for helping out. Appreciate it. This is awesome. Quick follow up: I see the following in the PDF with the text within the square brackets being bold. Any idea what I may be missing herein?
`Lorem [sigfridsson] (DOI)
ipsum [ctan] (URL)
dolor [worman] (no link) `
– arun kejariwal May 30 '23 at 19:54 -
@arunkejariwal You probably did not run Biber. A document with
biblatexneeds to be compiled with Biber and not with BibTeX. See https://tex.stackexchange.com/q/63852/35864 for more on what BibTeX and Biber do and https://tex.stackexchange.com/q/154751/35864 for help on getting your editor to run Biber fo you. – moewe May 30 '23 at 19:59 -
Thanks @moewe. I got it working. One more thing: In the screenshot you shared above, why are the citations number <2, 1, 3>, not <1, 2, 3>. As there's no bibliography at the end (when it exists, some prefer it to be alphabetically sorted and hence the citations numbers have no particular ordering), I would prefer to have an increasing order. Any suggestions? – arun kejariwal May 30 '23 at 20:20
-
