Skip to content

Commit b8731d7

Browse files
committed
deactivate underscores when expanding natbib \bibitem optional labels
1 parent c62a961 commit b8731d7

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

MANIFEST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,9 @@ t/structure/lit.bib
16741674
t/structure/crazybib.pdf
16751675
t/structure/crazybib.tex
16761676
t/structure/crazybib.xml
1677+
t/structure/crazybibkeys.pdf
1678+
t/structure/crazybibkeys.tex
1679+
t/structure/crazybibkeys.xml
16771680
t/structure/csquotes.pdf
16781681
t/structure/csquotes.tex
16791682
t/structure/csquotes.xml

lib/LaTeXML/Package/natbib.sty.ltxml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ DefPrimitiveI('\reset@natbib@cites', undef, sub {
528528

529529
# Kinda rediculous simulating this here (we can almost pull it off in TeX)
530530
# but the TeX tends to be quite brittle in the wilds of arXiv, so...
531-
DefMacro('\lx@NAT@parselabel Semiverbatim {}', sub {
531+
DefMacro('\lx@NAT@parselabel {}{}', sub {
532532
my ($gullet, $label, $key) = @_;
533533
my ($number, $year, $authors, $fullauthors);
534534
my $bare = 1;
@@ -560,7 +560,10 @@ DefMacro('\lx@NAT@parselabel Semiverbatim {}', sub {
560560
($a1, @tokens) = NAT_peel_arg(@tokens);
561561
$authors = $a1; $year = Tokens(@tokens); $bare = 0; } }
562562
if ($bare) {
563-
@tokens = Expand($label)->unlist;
563+
# Goal: deactivate underscores
564+
# (but not quite Semiverbatim, as math should be active things like \ddot{a})
565+
my @safe_tks = map { Equals($_, T_SUB) ? T_OTHER("_") : $_ } $label->unlist;
566+
@tokens = Expand(Tokens(@safe_tks))->unlist;
564567
# \bibitem[Jones et al.(1990)]{key}...
565568
# \bibitem[Jones et al.(1990)Jones, Baker, and Williams]{key}...
566569
# \bibitem[Jones et al., 1990]{key}...

t/structure/crazybibkeys.pdf

24.7 KB
Binary file not shown.

t/structure/crazybibkeys.tex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
\documentclass{article}
2+
\usepackage{natbib}
3+
\begin{document}
4+
% These could cause problems if used with \cite, but are OK standalone in {thebibliography}.
5+
\begin{thebibliography}{}
6+
7+
\bibitem[_xy(1899)]{_xyz_1899}
8+
A name of something. (accessed Nov 01, 1899).
9+
10+
\bibitem[Ex$\ddot{a}$mple(1899)]{mathy}
11+
Another name.
12+
13+
\end{thebibliography}
14+
\end{document}

t/structure/crazybibkeys.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?latexml class="article"?>
3+
<?latexml package="natbib"?>
4+
<?latexml RelaxNGSchema="LaTeXML"?>
5+
<document xmlns="http://dlmf.nist.gov/LaTeXML">
6+
<resource src="LaTeXML.css" type="text/css"/>
7+
<resource src="ltx-article.css" type="text/css"/>
8+
<bibliography xml:id="bib">
9+
<title>References</title>
10+
<biblist>
11+
<bibitem key="_xyz_1899" xml:id="bib.bib1">
12+
<tags>
13+
<tag role="number">1</tag>
14+
<tag role="year">1899</tag>
15+
<tag role="authors">˙xy</tag>
16+
<tag role="refnum">˙xy (1899)</tag>
17+
<tag role="key">_xyz_1899</tag>
18+
</tags>
19+
<bibblock>
20+
A name of something. (accessed Nov 01, 1899).
21+
</bibblock>
22+
</bibitem>
23+
<bibitem key="mathy" xml:id="bib.bib2">
24+
<tags>
25+
<tag role="number">2</tag>
26+
<tag role="year">1899</tag>
27+
<tag role="authors">Ex<Math mode="inline" tex="\ddot{a}" text="ddot@(a)" xml:id="bib.bib2.m1">
28+
<XMath>
29+
<XMApp>
30+
<XMTok name="ddot" role="OVERACCENT">¨</XMTok>
31+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
32+
</XMApp>
33+
</XMath>
34+
</Math>mple</tag>
35+
<tag role="refnum">Ex<Math mode="inline" tex="\ddot{a}" text="ddot@(a)" xml:id="bib.bib2.m2">
36+
<XMath>
37+
<XMApp>
38+
<XMTok name="ddot" role="OVERACCENT">¨</XMTok>
39+
<XMTok font="italic" role="UNKNOWN">a</XMTok>
40+
</XMApp>
41+
</XMath>
42+
</Math>mple (1899)</tag>
43+
<tag role="key">mathy</tag>
44+
</tags>
45+
<bibblock>
46+
Another name.
47+
</bibblock>
48+
</bibitem>
49+
</biblist>
50+
</bibliography>
51+
</document>

0 commit comments

Comments
 (0)