# Make custom citation command link to bibliography entry

For my bachelor thesis, I want to have both simple numeric citations in parentheses and the author year style for citations that are used as actual objects in the text. My solution so far is that I defined a custom citation style for the latter; however, this does not link to the corresponding bibliography entry.

MWE

\documentclass[a4paper,english]{article}
\usepackage[backend=biber, style=numeric]{biblatex}
\usepackage{hyperref}
\newcommand\Mycite[1]{%
\citeauthor{#1}~(\citeyear{#1})}

\begin{document}

RAMSES is "a grid-based hydro solver with adaptive mesh refinement" \cite{ramses-web} \\

confer to \Mycite{emilio-paper-2014}

\printbibliography
\end{document}


contents of refs.bib:

@misc{ramses-web,
title = {Ramses-Website},
howpublished = {\url{https://www.ics.uzh.ch/~teyssier/ramses/Documentation.html}},
note = {2018-08-27}
}

@ARTICLE{emilio-paper-2014,
author = {{Tomassetti}, M. and {Porciani}, C. and {Romano-D{\'{\i}}az}, E. and
{Ludlow}, A.~D.},
title = "{Simulating the H$_{2}$ content of high-redshift galaxies}",
journal = {\mnras},
archivePrefix = "arXiv",
eprint = {1403.7132},
keywords = {methods: numerical, ISM: molecules, galaxies: evolution, galaxies: formation},
year = 2015,
month = feb,
volume = 446,
pages = {3330-3345},
doi = {10.1093/mnras/stu2273},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}


How can I make my custom citation command link to the entry? I'm also fine with other suggestions that use different commands but provide the same output.

• It is usually a bad idea to mix two citation styles and it is usually not simple to pull off. Have a look at tex.stackexchange.com/q/452170/35864 for an example that combines numeric and author-year citations. – moewe Sep 30 '18 at 13:36
• Is there any rule to decide whether or not a particular reference is going to be cited as numeric or author-year? What are you going to do about the bibliography? Are there going to be two separate bibliographies? – moewe Sep 30 '18 at 15:06
• @moewe I don't quite understand how the code given in the link works and can't manage to adapt it to my situation right now. Basically, I want to cite sources for certain numbers or statements numerically; on the other hand, if I want to explain something not too much in depth, I want to confer to the paper with the author-year scheme. Example: "The sun has a metallicity of 0.196. [1]" Here, I would use the numerical scheme. This would link to either a website or a paper as a source. On the other hand: "This code does the following, for more in-depth explanation confer to abc et al., 2010." – DerAstrophysiker Oct 1 '18 at 11:58
• @moewe They should be in the same bibliography. Also, the sources can include websites (apart from Arxiv), which is why the authoryear style does not fit for this case. – DerAstrophysiker Oct 1 '18 at 11:59
• Have a look at my answer below, I think it pretty much allows you to do that. Feel free to comment under the answer if you want anything changed. But please note that for your use case I'd strongly advise you not to use two different citation schemes. – moewe Oct 1 '18 at 12:00

The primary reason that you don't get links in your \Mycite is that the two commands you use to build it (\citeauthor and \citeyear) do not link to the bibliography. One could redefine these building blocks to link their text and that would sort of resolve the issue here, but I recommend a different approach.

Defining \Mycite as done in the MWE has two huge drawbacks

1. It can't deal with pre- and postnotes, i.e. the optional arguments of \cite: \autocite[cf.][380]{sigfridsson}

2. It fails spectacularly when you cite multiple entries at once. Try \Mycite{sigfridsson,worman}.

There are more possible complications that will only become relevant if you use advanced features (citation tracking and counting come to mind). Some of those drawbacks can be worked around easily, some workarounds would be more arduous. But there is a better approach.

In general new citation commands for biblatex should be defined via \DeclareCiteCommand and not by gluing together several high-level citation commands with \newcommand.

So you could try something like

\documentclass{article}
\usepackage[style = numeric, labeldateparts, defernumbers = true, backend = biber, autocite=inline]{biblatex}
\usepackage{hyperref}

\newbibmacro*{cite:authoryear}{%
\printtext[bibhyperref]{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\printdelim{nonameyeardelim}}}
{\printnames{labelname}%
\setunit{\printdelim{nameyeardelim}}}%
{\usebibmacro{cite:shorthand}}}}

\newbibmacro*{cite:shorthand}{%
\printfield{shorthand}}

\newbibmacro*{cite:label}{%
\iffieldundef{label}
{\printfield[citetitle]{labeltitle}}
{\printfield{label}}}

\iffieldundef{labelyear}
{}
{\printtext[parens]{\printlabeldateextra}}}

\DeclareCiteCommand{\aycite}
{\usebibmacro{prenote}}%
{\usebibmacro{citeindex}%
\usebibmacro{cite:authoryear}}
{\multicitedelim}
{\usebibmacro{postnote}}

\begin{document}
The first two citations \autocite{sigfridsson} and \autocite{worman}.
The others are \aycite{baez/online} and \aycite{ctan,markey}.

\printbibliography
\end{document}


The output in that example is less than ideal, though. All entries get a label number in the bibliography even those which were only cited with author-year labels and author and year are not as prominent in the bibliography as they are with style=authoryear making the entries harder to locate. Additionally, only the choice of the citation command decides the citation format: That requires you to remember which item is to be cited with which command.

If there is a simple rule that governs whether an entry is going to be cited as numeric or author-year then I suggest you look for an automatic solution that uses only one command that decides which format to use on its own. Such a citation scheme can be found in Two different bibliographies with different styles and sortings, Vol.2 where the format is decided by a keyword, but it could also be decided by the entry type or via an ad-hoc (document-dependent) category assignment.

In general I would avoid mixing several citation styles in the same document. It is very unusual to mix styles and it might confuse people at first. There is a good reason why most style guides advocate consistency in citation styles. For some very restricted uses I can see benefits in using different styles, but I'm not sure if what you have in mind really falls into such a category.

• Thanks, this solved my issue. Regarding your advice to use one citation style: The issue here is that some sources may be websites where I have neither author nor a real "title" to go by, maybe not even a year. I simply don't know how I should cite them if not numerically. – DerAstrophysiker Oct 1 '18 at 12:21
• @DerAstrophysiker Mhhhh, in my experience most websites do have some kind of title, author information and date associated with them if only I look hard enough. Certainly most websites that I would want to cite in a scientific work do. biblatex's authoryear style falls back to label or title if no author and year are given, but you could also use shorthand. If push comes to shove you can use numeric citations everywhere. But I'd like to discourage you from mixing citation styles in the strongest possible terms. – moewe Oct 1 '18 at 12:27