# Can citation numbers be stored as variables, then used in my tex file?

I'm trying to create a "flow chart" of papers that shows the progression of key ideas over time. A very basic example is this:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\newcommand{\oldpaper}{2}
\newcommand{\newpaper}{1}

\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (\newpaper)    at    (0,2)     [label=right:{This 2011 paper utilizes the good ideas and makes them even better}]    {\newpaper};
\node[show]    (\oldpaper)   at     (0,0)    [label=right:{This paper came out in 1900 and has good ideas}]    {\oldpaper};
\draw[->]    (\oldpaper) -- (\newpaper);
\end{tikzpicture}

\bibliographystyle{amsplain}
\begin{thebibliography}{10}

\bibitem{newpaper}C. Charles, \emph{New Stuff}, 2011.

\bibitem{oldpaper}H. Huckley, \emph{Old Stuff}, 1900.

\end{thebibliography}

\end{document}


The point is that the circular nodes have a number inside of them that equals the number in the bibliography, so if you're looking at the flowchart and see a paper that looks interesting, you can look at the references to see exactly what paper it is. The only way I could figure out how to do this somewhat efficiently was by the \newcommand stuff -- but this requires me compiling the code, looking at the bibliography, and then manually defining the \newpaper and \oldpaper to be what they "should" be. If I add another reference, say,

\documentclass{article}
\usepackage{tikz}

\begin{document}

\newcommand{\oldpaper}{2}
\newcommand{\newpaper}{1}

\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (\newpaper)    at    (0,2)     [label=right:{This 2011 paper utilizes the good ideas and makes them even better}]    {\newpaper};
\node[show]    (\oldpaper)   at     (0,0)    [label=right:{This paper came out in 1900 and has good ideas}]    {\oldpaper};
\draw[->]    (\oldpaper) -- (\newpaper);
\end{tikzpicture}

\bibliographystyle{amsplain}
\begin{thebibliography}{10}

\bibitem{newpaper}C. Charles, \emph{New Stuff}, 2011.

\bibitem{oldpaper}H. Huckley, \emph{Old Stuff}, 1900.

\end{thebibliography}

\end{document}


then I have to redefine my \oldpaper and \newpaper variables by hand. It's also important that the nodes are named with the same variable, that way the drawing looks right no matter what value the variables have. My real flow chart has over 30 papers in it, and the real bibliography has over 50. Obviously it's getting cumbersome to do this by hand, so I'm wondering if I can somehow use \cite{} and extract what the reference number "should be," and name/number the nodes accordingly, and it will update dynamically should I add or drop a reference (some of my references don't show up in the flow chart). I tried adding

\makeatletter
\renewcommand*{\@biblabel}[1]{#1}
\makeatother


in the preamble, then defining

\newcommand{\oldpaper}{\cite{oldpaper}}


so that the variable \oldpaper would have the value equal to the current citation number \cite{oldpaper} but that didn't work at all. The error message is:

Argument of \XC@definec@lor has an extra }

This is beyond my TeX knowledge, and I've spent hours reading about BiBTeX and googling to no avail. Does anyone know how to solve this? Thank you in advance, and I hope my question is clear.

-
Welcome to TeX.SE. Interesting question indeed! Just notice that you can use back-ticks  to make short pieces of text as TeX code. I hope you don't mind I edited the question and added this formatting. –  tohecz Aug 21 '12 at 18:16
I don't mind at all! Thanks for the tip. –  Phineas Q. Butterfats Aug 21 '12 at 19:05

Why do you want numbers as node names? You could simply use the bibkeys:

\documentclass{article}
\usepackage{tikz}

\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{newpaper}C. Charles, \emph{New Stuff}, 2011.
\bibitem{oldpaper}H. Huckley, \emph{Old Stuff}, 1900.
\end{thebibliography}
\end{document}

-
Ulrike: wow, that's a very simple, elegant solution! I've been focused on how to get the flow chart "robust" (relative positioning etc.) and totally missed this idea. Thanks! Is it possible to define a modified \cite command that eliminates the brackets for the labels inside the nodes, but leaves the ordinary \cite command alone so I can use it in the body of the paper? Thanks again, this really helps/simplifies! –  Phineas Q. Butterfats Aug 21 '12 at 19:08

The reason that your method doesn't work is that LaTeX normally does some tests to make sure that you're citing something that has a corresponding \bibitem, and it also lets you cite more than one key in each \cite command, so \cite{key} isn't so simple that it can just expand to the citation number for key.

The citation numbers for citation key key are internally stored in a macro \b@key, and these are LaTeX internals ("protected" from normal access by the @ symbol). You can access them, but are advised not to. For example, what would you expect the behaviour to be if you're using a non-standard (but supported) extension to LaTeX's bibliography system? Can you be certain that using something like hyperref won't change the internals to accomplish its goals?

So Ulrike's suggestion that you should try to find another way to do what you want is good, but what if you want to change the citation style only for your tikz nodes, but not in the bibliography itself or in other references? In such case, you might like to use something like the \citekey macro I've defined below, which acts like a wrapper to obtaining the internal values for you. Note that it will require two runs to be correct, and there may be better ways of doing this...

\documentclass{article}
\usepackage{tikz}

\newcommand*{\citekey}[1]{\csname b@#1\endcsname}

\begin{document}

%\newcommand{\oldpaper}{2}
%\newcommand{\newpaper}{1}
\newcommand{\oldpaper}{\citekey{oldpaper}}
\newcommand{\newpaper}{\citekey{newpaper}}

\begin{tikzpicture}[show/.style={circle,draw}]
\node[show]    (\newpaper)    at    (0,2)     [label=right:{This 2011 paper utilizes the good ideas and makes them even better}]    {\newpaper};
\node[show]    (\oldpaper)   at     (0,0)    [label=right:{This paper came out in 1900 and has good ideas}]    {\oldpaper};
\draw[->]    (\oldpaper) -- (\newpaper);
\end{tikzpicture}

\bibliographystyle{amsplain}
\begin{thebibliography}{10}

\bibitem{newpaper}C. Charles, \emph{New Stuff}, 2011.

\bibitem{oldpaper}H. Huckley, \emph{Old Stuff}, 1900.

\end{thebibliography}

\end{document}

-
Your \citekey definitely works, and it answers a question in my reply to Ulrike above. When defining the nodes I could use your idea, like this: \node[show] (newpaper) at (0,2) [label=right:{This 2011 paper ...}] {\citekey{newpaper}}; whereas elsewhere in the paper I can just cite things normally, like \cite{newpaper}. That way the nodes don't have brackets in them but the numbers are correct! –  Phineas Q. Butterfats Aug 21 '12 at 19:40
@PhineasQ.Butterfats: The \citekey does what I would have suggested too to answer your question. But if you start to use a bibliography package like biblatex` you probably will have to adapt the definition. –  Ulrike Fischer Aug 22 '12 at 7:50