4

Suppose I have a bibliography entry that looks like this (I'm using biblatex):

@article{foo,
  author = {A. Author},
  title = {Super article},
  archivePrefix = "arXiv",
  eprint        = "3301.1234",
  primaryClass  = "hep-ex"
}

I would like to create a command \arxiv, that I could use like \arxiv{foo}, that would print

[1][arXiv:3301.1234]

where [1] would be the same a what \cite does, and the second part would link to the arXiv page for the article, e.g. http://arxiv.org/abs/3301.1234.

Can this be done? I want this so I can cite arXiv papers in beamer, and if somebody (or I later) pulls apart the slides, the citation is useful even without the bibliography slides.

Mico
  • 506,678
SU3
  • 519

1 Answers1

4

You can define \arxivcite. It is a normal \cite and additionally prints the eprint information if available

\DeclareCiteCommand{\arxivcite}[\mkbibbrackets]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}%
   \newunit
   \usebibmacro{eprint}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

For numeric-comp, try

\makeatletter
\DeclareFieldFormat{eprint:cite:arxiv}{%
  arXiv\addcolon\space
  \ifhyperref
    {\href{http://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}}}
    {\nolinkurl{#1}}}
\makeatother

\newbibmacro*{cite:eprint}{%
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {\printfield[eprint:cite:\strfield{eprinttype}]{eprint}}}

\DeclareCiteCommand{\arxivcite}
  {}
  {\printtext[labelnumberwidth]{%
     \usebibmacro{prenote}%
     \usebibmacro{citeindex}%
     \printtext[bibhyperref]{%
       \printfield{labelprefix}%
       \printfield{labelnumber}}%
     \usebibmacro{postnote}}%
   \printtext[brackets]{\usebibmacro{cite:eprint}}}
  {\multicitedelim}
  {}

which disables any -comp features for this particular command. You will have to have a \DeclareFieldFormat{eprint:cite:<type>} for every eprint type you intend to use.

moewe
  • 175,683
  • arXiv runs TeX Live 2011, you must be sure this solution is compatible with such an old distribution. – giordano Mar 19 '16 at 08:59
  • @giordano Where in the question does it say that the solution needs to run on the arXiv systems? The solution does not employ any fancy commands as you can see, so I'm quite confident it works with a fairly wide range of older biblatex versions. Whether the one included in TeX live 2011 is amongst those I cannot say with certainty; I just had a look at biblatex 1.0 dated November 2010 however and am fairly optimistic that it will actually do the right thing there and with all newer versions. – moewe Mar 19 '16 at 09:31
  • Indeed I gave it fro granted that it was needed for arXiv, sorry, my fault. I was just asking whether \DeclareCiteCommand was available in earlier version of the package. – giordano Mar 19 '16 at 10:01
  • @giordano \DeclareCiteCommand is one of the basic commands biblatex provides and has been available at least since version 1.0. I would suspect it was available in all official releases of biblatex, but that I cannot say with certainty. – moewe Mar 19 '16 at 10:12
  • Thanks for the answer. However, I'm getting ! Package biblatex Error: Bibliography macro 'cite' undefined. – SU3 Mar 20 '16 at 21:01
  • @SU3 What bibliography style are you using. I naturally assumed you were using numeric. Please show a full MWE of your problem. – moewe Mar 21 '16 at 06:48
  • I was using numeric-comp. Your example works when I switch to numeric. However, the formatting options seem to be rather limited as eprint macro produces the full string. Your command's output look approximately like this: [1. arXiv: 1408.7084 (hep-ex)] with 1408.7084 (hep-ex) linked. I would like for formatting to be more flexible. For example [1][arXiv:1408.7084] with the whole string in the second pair of brackets linked and using smaller font. I looked up biblatex \printfield, but I couldn't find ones that print parts of what \usebibmacro{eprint} prints. – SU3 Mar 21 '16 at 21:11
  • @SU3 With numeric-comp things get more complicated (and the macro is not cite), what if you cite two keys both with arXiv identifiers, do you want "[1][arXiv:1408.7084][2][arXiv:1408.7085]"? Getting things outside the brackets is not always that easy, what about postnotes or prenotes do they go in the first or second set of brackets or outside entirely? You can modify the eprint:arxiv field format. – moewe Mar 22 '16 at 07:11
  • @moewe Using your second example, I was able to produce what I wanted. Thanks! The only problem is that I get ! Undefined control sequence. for \abx@arxivpath. – SU3 Mar 22 '16 at 17:52
  • 1
    @SU3 Ah, yes, I forgot the \makeatletter...\makeatother bit. The code should now work together with hyperref. – moewe Mar 22 '16 at 18:41