In a document, I need to add many links via a biblatex entry with something like:
\NewDocumentCommand{\addLink}{O{}mm}{\href{#2}{#3}}
\addLink{https://en.wikipedia.org/}{Wikipedia}\cite{Wiki}
where the bib contains:
@online{Wiki,
title = {Wikipedia},
author = {Wikipedia},
year = 2024,
url = {https://en.wikipedia.org/},
}
But manually maintaining these two lists is quite expensive, and adding a bib entry for a simple link is quite annoying and hard to maintain. Would it be possible, somehow, to avoid this by creating automatically the entry in the \NewDocumentCommand? The year can be fixed to 2024 and the author could be equal to the title unless specified otherwise in the optional argument.
MWE:
\documentclass[]{article}
\begin{filecontents}[noheader,overwrite]{main.bib}
@online{Wiki,
title = {Wikipedia},
author = {Wikipedia},
year = 2024,
url = {https://en.wikipedia.org/},
}
\end{filecontents}
\usepackage[
style=alphabetic,% also
minalphanames=3,maxalphanames=4, % [Foo+99] -> [FBB+99].
maxnames=99, % Do not put "et al". Sets maxbibnames, maxcitenames and maxsortnames.
sortcites=true,
%sorting=none,
doi=false,
url=false,
giveninits=true, % Bob Foo --> B. Foo
isbn=false,
url=false,
eprint=false,
sortcites=false, % \cite{B,A,C}: [A,B,C] --> [B,A,C]
%backref=true, % [1] Title, blabla --> [1] Title, blabla (pages 1, 45, 56)
%% TODO: customize using https://tex.stackexchange.com/questions/36307/formatting-back-references-in-bibliography
]{biblatex}
\addbibresource{main.bib}%
\NewDocumentCommand{\addLink}{O{}mm}{
\href{#2}{#3}
}
\usepackage{hyperref}
\begin{document}
You can go to \addLink{https://en.wikipedia.org/}{Wikipedia}\cite{Wiki}.
\printbibliography
\end{document}
EDIT I guess I can think of a solution that writes to a temporary file all entries, and that (maybe rename?) and loads this file at startup… but seems like quite a quite dirty solution. Is there a better one?
O{}mmmeans that you're allowing\addLink[first]{second}{third}. What's the point offirstif you don't do anything with it? – Teepeemm Jan 22 '24 at 13:32