7

I'm using biber and want to cite references inside a tikzpicture. I followed this answer that described how to do it with bibtex and it works nicely, but when switching to use biber, it doesn't work anymore:

\documentclass{article}
\usepackage{tikz}

\usepackage[backend=biber]{biblatex}

\begin{document}

\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (newpaper)    at    (0,2)    
    [label=right:{This 2011 paper ...}]    
    {\cite{newpaper}};
\node[show]    (oldpaper)   at     (0,0)    
     [label=right:{This paper came out in 1900 ...}]    
    {\cite{oldpaper}};
\draw[->]    (oldpaper) -- (newpaper);
\end{tikzpicture}


%\bibliographystyle{amsplain}
\begin{thebibliography}{10}
\bibitem{newerpaper}B. Becker, \emph{Even Newer Stuff}, 2012.
\bibitem{newpaper}C. Charles, \emph{New Stuff}, 2011.
\bibitem{oldpaper}H. Huckley, \emph{Old Stuff}, 1900.
\end{thebibliography}
\end{document} 

Example output

Does anyone know of a solution without me having to switch to use bibtex?

UPDATE:

As noted by several below, my original code I posted was an easy fix. The actual bug I found was a result of my larger LaTeX code and I found the issue. Here's the updated code that has the issue:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{external}
\tikzexternalize[prefix=fig/]

\usepackage[backend=biber]{biblatex}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{newerpaper,
    author={B. Becker},
    title={Even Newer Stuff},
    date={2012}
}

@book{newpaper,
    author={C. Charles},
    title={New Stuff},
    date={2011}
}

@book{oldpaper,
    author={H. Huckley},
    title={Old Stuff},
    date={1900}
}

\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

%\tikzexternaldisable
\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (newpaper)    at    (0,2)    
[label=right:{This 2011 paper ...}]    
{\cite{newpaper}};
\node[show]    (oldpaper)   at     (0,0)    
[label=right:{This paper came out in 1900 ...}]    
{\cite{oldpaper}};
\draw[->]    (oldpaper) -- (newpaper);
\end{tikzpicture}
%\tikzexternalenable

\printbibliography

\end{document} 

The problem is with the \tikzexternalize[prefix=fig/] command. I got around this issue by adding \tikzexternaldisable before the tikzpicture and \tikzexternalenable after the tikzpicture.

t2k32316
  • 173
  • At first glance, it seems to me it may well be working and the problem has nothing to do with the tikz drawings, but with the fact that you are supplying bibtex entries. Did you try to put these references in a .bib file and inputing it with addbibresource? – gusbrs Jul 12 '17 at 19:02
  • 1
    You say you're using biblatex but your bibliography is done by hand? If' you're really doing things by hand, then don't use biblatex. If you're really using biblatex delete your hand-done bibliography and replace it with \printbibliography , tell biblatex where to find your .bib file (using \addbibresource) and let biblatex do the work. See biblatex in a nutshell (for beginners). – Alan Munn Jul 12 '17 at 19:03
  • 1
    The answer you link to is a bit misleading, since it uses a manually created bibliography just for the example. Nobody would likely ever do exactly that in practice. – Alan Munn Jul 12 '17 at 19:07
  • Thanks everyone, I actually was using a separate bib file, but to illustrate the problem I took that example from the link I gave. It turns out my problem has to do with tikzexternalize. I updated my post to note this and I included one possible solution... I'm not sure if it's the correct one. – t2k32316 Jul 12 '17 at 20:10
  • Well, you updated your question in a direction which seems different from the original one. Anyway, in your update, what's the point of loading \usetikzlibrary{external} if you are "getting around it" with \tikzexternaldisable in the only tikz drawing you have? – gusbrs Jul 12 '17 at 20:16
  • @gusbrs would it have been better if I started a whole new question? Again, please note that the code I posted is just for illustration purposes. I have some other tikz pictures that don't have citations within them. – t2k32316 Jul 12 '17 at 20:21
  • Well, ok. Understood. Then, if you don't need to externalize this one, I guess you are done. – gusbrs Jul 12 '17 at 20:25
  • Still, I believe you could profit from this answer https://tex.stackexchange.com/a/301458/105447. – gusbrs Jul 12 '17 at 20:40
  • @gusbrs can you elaborate on how one can profit from this answer? I ran into the same problem and came here looking for a solution, but can't really see how to profit… – Fabian A. Dec 16 '18 at 19:01
  • @FabianA. I believe I assumed the OP was having trouble with externalization (also) for the lack of -shell-escape. But it's long ago, so I'm not really sure what my reasoning was. – gusbrs Dec 16 '18 at 19:07

1 Answers1

5

As suggested in the comments, you should move to biblatex's way of dealing with the bibliography, rather than doing it by hand. E.g.:

\documentclass{article}
\usepackage{tikz}

\usepackage[backend=biber]{biblatex}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@book{newerpaper,
    author={B. Becker},
    title={Even Newer Stuff},
    date={2012}
}

@book{newpaper,
    author={C. Charles},
    title={New Stuff},
    date={2011}
}

@book{oldpaper,
    author={H. Huckley},
    title={Old Stuff},
    date={1900}
}

\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (newpaper)    at    (0,2)    
    [label=right:{This 2011 paper ...}]    
    {\cite{newpaper}};
\node[show]    (oldpaper)   at     (0,0)    
     [label=right:{This paper came out in 1900 ...}]    
    {\cite{oldpaper}};
\draw[->]    (oldpaper) -- (newpaper);
\end{tikzpicture}

\printbibliography

\end{document} 

Which produces:

enter image description here

Edit: As it turned out, the issue is essentially one of the correct use of biblatex/biber, and has little to do with TikZ, so a list of starters with biblatex could be handy:

gusbrs
  • 13,740
  • 1
    +1 And just to be clear to the OP, including the .bib file in your document with {filecontents} is not the way you would do it on a daily basis, but is included for the purposes of making a self-contained example. In normal practice you would have a separate .bib file which you maintain separately, ideally using an external tool like JabRef (multiplatform) or BibDesk (Mac). – Alan Munn Jul 12 '17 at 19:32
  • Indeed, well remembered. I tried to keep it simple in the hope the link you supplied will get the OP started. – gusbrs Jul 12 '17 at 19:34
  • 1
    @AlanMunn, I complemented the answer in the spirit of your comment. – gusbrs Jul 12 '17 at 19:50