9

I'm encountering a problem using TexShop (with Tex Live 2016 distribution) when try to cite a reference directly in a table. The cite key contains a '&', I guess LaTeX might treat it as a normal tabular separate mark, although it is in the '\citep{}' command. The code is like this:

\documentclass[preprint]{aastex6}

\begin{document}

\begin{table}
\centering
\caption{Test for cite key contains `\&'. \label{tab:test}}
\begin{tabular}{lll}
Citation Failed     & {\citet{2007A&A...465..587S}} & Nothing appears\\
Citation Succeeded  & {\citet{2015MNRAS.453.1619A}} & A paper appears\\
\end{tabular}
\end{table}

I want to cite \citet{2007A&A...465..587S} in the table, 
whose cite key contains `\&', you can see the citation works 
here but not in the table. I didn't encounter this problem 
with CTeX in Windows, compiling the same script.

\bibstyle{aasjournal}
\bibliography{bbb.bib}

\end{document}

Typeset with LaTeX will give you the following error:

./aaa.tex:9: Missing \endcsname inserted.
to be read again
\global
l.9 ...n Failed & {\citet{2007A&A...465..587S}
} & Nothing appears\
?

Meanwhile, the .aux will get a wrong name for '2007A&A...465..587S':

\citation{2007A\global \advance \columncount by 1\relax \saveampersand A...465..587S}

which should be (if you cite this paper in other places of article, only if it's not in a table):

\citation{2007A&A...465..587S}

Using this incorrect .aux file, BibTeX will tell you:

White space in argument---line 19 of file aaa.aux
: \citation{2007A\global
: \advance \columncount by 1\relax \saveampersand A...465..587S}
I'm skipping whatever remains of this command

Finally, the citation won't appear in the .pdf file, as a contrast, the second paper cited in the table will appear, like this:

pdf

Yes, I can change the cite key by deleting '&' and then problem solved, but I'm trying to figure out how to solve the problem without changing cite key, because the cite key is usually generated automatically by other tools, and it is not a easy task to change all the cite keys of such type.

The 'bbb.bib' used in this example is:

@article{2007A&A...465..587S,
Adsnote = {Provided by the SAO/NASA Astrophysics Data System},
Adsurl = {http://adsabs.harvard.edu/abs/2007A%26A...465..587S},
Author = {{Shi}, J.~R. and {Gehren}, T. and {Zhang}, H.~W. and {Zeng}, J.~L. and {Zhao}, G.},
Doi = {10.1051/0004-6361:20066709},
Journal = {\aap},
Keywords = {line: formation, line: profile, stars: abundance, stars: late-type, galaxies: evolution},
Month = apr,
Pages = {587-591},
Title = {{Lithium abundances in metal-poor stars}},
Volume = 465,
Year = 2007,
Bdsk-Url-1 = {http://dx.doi.org/10.1051/0004-6361:20066709}}

@article{2015MNRAS.453.1619A,
Adsnote = {Provided by the SAO/NASA Astrophysics Data System},
Adsurl = {http://adsabs.harvard.edu/abs/2015MNRAS.453.1619A},
Archiveprefix = {arXiv},
Author = {{Alexeeva}, S.~A. and {Mashonkina}, L.~I.},
Doi = {10.1093/mnras/stv1668},
Eprint = {1507.05446},
Journal = {\mnras},
Keywords = {line: formation, Sun: abundances, stars: abundances, stars: late-type},
Month = oct,
Pages = {1619-1631},
Primaryclass = {astro-ph.SR},
Title = {{Carbon abundances of reference late-type stars from 1D analysis of atomic C I and molecular CH lines}},
Volume = 453,
Year = 2015,
Bdsk-Url-1 = {http://dx.doi.org/10.1093/mnras/stv1668}}

EDIT: Change all the pictures into source code. Posted the '.bib' file used in the code. EDIT: According to the comments below, the problem might be caused by the deluxtable macro, so I changed deluxtable into table and tried again, same problem occurred. EDIT: According to @DavidCarlisle, The problem is caused by aastex6.cls and/or aasjournal.bst. Add \string before & will solve the problem. You won't meet this problem using standard LaTeX template. Also, many people suggest simply do NOT use & in the cite keys, so that you won't meet the problem anywhere.

16
  • 1
    Welcome, some characters are just invalid within BibKeys. Sorry.
    – Johannes_B
    Aug 12, 2016 at 6:25
  • @Johannes_B: Yes, I'm starting to think maybe it is just impossible.
    – yayagua
    Aug 12, 2016 at 6:34
  • 6
    Rather than posting screenshots it is better to code the actual code, and then highlight it using {}. This way people can copy and paste your code into their own documents and test it and try to fix your problem. It makes it much easier for people to hep you and hence m much more likely that some one will. This said, it is also better to post a full minimal working example of compilable code and, in your case, a bibtex entry.
    – user30471
    Aug 12, 2016 at 6:47
  • 1
    What automatic tools is this? I've never encountered one which would create a key with special symbols. Besides, changing them wouldn't be a problem. Just search and replace or a simple regex.
    – Runar
    Aug 12, 2016 at 7:25
  • since you have provided no example this is untested, but I assume it would work if you used \newcommand\zzzz{{\cite{2007A&A...465..587S}} in the preamble, and then used \zzzz in the table. Aug 12, 2016 at 7:41

2 Answers 2

9

Since you have provided no example I haven't tested this (but confirmed to work in comments above).

You can hide the & if you used

\newcommand\zzzz{{\cite{2007A&A...465..587S}}}

in the preamble, and then used \zzzz in the table

If the cite works in normal text it would work in standard latex tables, so the problem must be with the deluxtable macros you are using (but just not using & in cite keys, and sticking to simple [:a-zA-Z0-9] would be good advice)



Example added by CarLaTeX

EDIT: This is the MWE I used to test it (maybe does it works also with deluxtable macros?):

\documentclass[10pt,preprint]{aastex}
\usepackage[english]{babel}
\usepackage{chemformula}
\usepackage{natbib}

\newcommand{\kH}{{\cal H}}
\newcommand\zzzz{{\cite{2007A&A...465..587S}}} 

\begin{document}

\begin{deluxetable}{lll}
\tablecaption{blablabla. \label{tab:bla}}
\tablehead{
\colhead{Species} & \colhead{Model atom} & \colhead{A + \ion{H}{1}}
}
\startdata
\ion{Li}{1} & \zzzz & BB3\\
\ion{C}{1} & \citet{2015MNRAS.453.1619A} & \kH $^1$ = 0.3 \\
\enddata
\tablecomments{blablabla}
\end{deluxetable}

\bibliographystyle{plainnat}
\bibliography{bbb.bib}

\end{document}

And this is the bbb.bib file:

@book{2007A&A...465..587S,
  author = {Author, A. and Perche Alsuno},
  year = {2007},
  title = {A duvenen propri vusa kel simbul la},
  publisher = {Publisher},
}

@book{2015MNRAS.453.1619A,
  author = {Alexeeva, A. and Mashonkina, P.},
  year = {2015},
  title = {Keschi l e nurmal},
  publisher = {Publisher},
}

I don't know how much this is similar to the original, I invented the \kH command and I don't know if the OP uses natbib or what else and with which style, however the result is this:

enter image description here

3
  • I agreed with that deluxtable macro may cause the problem at the beginning, so I tried just normal table, and same problem occurred. You can see the question was edited using the source code but not pictures, as you advised. This time I used table.
    – yayagua
    Aug 13, 2016 at 22:04
  • @yayagua your new aastex6 example runs without error if you do {\citet{2007A\string&A...465..587S}} Aug 13, 2016 at 22:10
  • @DavidCarlisle I did what you said, here's the result: 1. Test with standard LaTeX, without aastex6.cls and aasjournal.jst: Yes, this worked. You are right, the problem might be caused by the template. 2. Add \string before &: Also worked with aastex6 template. Great! Thank you!
    – yayagua
    Aug 13, 2016 at 22:36
3

According to BibDesk you should not use & in a citation key:

... characters " "@',#}{~%" (including the space character) are never allowed, while you will be warned if you use one of "&$^" in a cite key. Cite keys are essentially TeX commands, so you should avoid using underscores, for instance, if you ever need to print the actual cite key itself.

EDIT: According to comments below, the quoted info is not 100% correct. I'll post a better if I find one.

5
  • 2
    What BibDesk says about & is simply wrong.
    – egreg
    Aug 12, 2016 at 8:07
  • BibDesk doesn't say & is 100% forbidden, it says the user "will be warned". And I guess it means that BibDesk will issue the warning. (Never used BibDesk, though...) So I guess & might cause problems and is not a safe character. Of course it would be better to tell when &can be used.
    – Paapaa
    Aug 12, 2016 at 8:13
  • @Paapaa it's the deluxtable macros not bibdesk or bibtex that need to document that Aug 12, 2016 at 8:29
  • There are a couple of other errors in that quote - you can't use numbers in TeX commands (of course you can give them as arguments) but you can in cite keys, and (at least with biblatex, quite possibly bibtex as well) you can print cite keys containing underscores.
    – Chris H
    Aug 12, 2016 at 8:30
  • Yes, you can use numbers in bibtex citekeys.
    – JPi
    Aug 12, 2016 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .