Skip to content

Commit

Permalink
deactivate underscores when expanding natbib \bibitem optional labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev committed Aug 28, 2024
1 parent c62a961 commit b8731d7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
3 changes: 3 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,9 @@ t/structure/lit.bib
t/structure/crazybib.pdf
t/structure/crazybib.tex
t/structure/crazybib.xml
t/structure/crazybibkeys.pdf
t/structure/crazybibkeys.tex
t/structure/crazybibkeys.xml
t/structure/csquotes.pdf
t/structure/csquotes.tex
t/structure/csquotes.xml
Expand Down
7 changes: 5 additions & 2 deletions lib/LaTeXML/Package/natbib.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ DefPrimitiveI('\reset@natbib@cites', undef, sub {

# Kinda rediculous simulating this here (we can almost pull it off in TeX)
# but the TeX tends to be quite brittle in the wilds of arXiv, so...
DefMacro('\lx@NAT@parselabel Semiverbatim {}', sub {
DefMacro('\lx@NAT@parselabel {}{}', sub {
my ($gullet, $label, $key) = @_;
my ($number, $year, $authors, $fullauthors);
my $bare = 1;
Expand Down Expand Up @@ -560,7 +560,10 @@ DefMacro('\lx@NAT@parselabel Semiverbatim {}', sub {
($a1, @tokens) = NAT_peel_arg(@tokens);
$authors = $a1; $year = Tokens(@tokens); $bare = 0; } }
if ($bare) {
@tokens = Expand($label)->unlist;
# Goal: deactivate underscores
# (but not quite Semiverbatim, as math should be active things like \ddot{a})
my @safe_tks = map { Equals($_, T_SUB) ? T_OTHER("_") : $_ } $label->unlist;
@tokens = Expand(Tokens(@safe_tks))->unlist;
# \bibitem[Jones et al.(1990)]{key}...
# \bibitem[Jones et al.(1990)Jones, Baker, and Williams]{key}...
# \bibitem[Jones et al., 1990]{key}...
Expand Down
Binary file added t/structure/crazybibkeys.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions t/structure/crazybibkeys.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\documentclass{article}
\usepackage{natbib}
\begin{document}
% These could cause problems if used with \cite, but are OK standalone in {thebibliography}.
\begin{thebibliography}{}

\bibitem[_xy(1899)]{_xyz_1899}
A name of something. (accessed Nov 01, 1899).

\bibitem[Ex$\ddot{a}$mple(1899)]{mathy}
Another name.

\end{thebibliography}
\end{document}
51 changes: 51 additions & 0 deletions t/structure/crazybibkeys.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<?latexml class="article"?>
<?latexml package="natbib"?>
<?latexml RelaxNGSchema="LaTeXML"?>
<document xmlns="http://dlmf.nist.gov/LaTeXML">
<resource src="LaTeXML.css" type="text/css"/>
<resource src="ltx-article.css" type="text/css"/>
<bibliography xml:id="bib">
<title>References</title>
<biblist>
<bibitem key="_xyz_1899" xml:id="bib.bib1">
<tags>
<tag role="number">1</tag>
<tag role="year">1899</tag>
<tag role="authors">˙xy</tag>
<tag role="refnum">˙xy (1899)</tag>
<tag role="key">_xyz_1899</tag>
</tags>
<bibblock>
A name of something. (accessed Nov 01, 1899).
</bibblock>
</bibitem>
<bibitem key="mathy" xml:id="bib.bib2">
<tags>
<tag role="number">2</tag>
<tag role="year">1899</tag>
<tag role="authors">Ex<Math mode="inline" tex="\ddot{a}" text="ddot@(a)" xml:id="bib.bib2.m1">
<XMath>
<XMApp>
<XMTok name="ddot" role="OVERACCENT">¨</XMTok>
<XMTok font="italic" role="UNKNOWN">a</XMTok>
</XMApp>
</XMath>
</Math>mple</tag>
<tag role="refnum">Ex<Math mode="inline" tex="\ddot{a}" text="ddot@(a)" xml:id="bib.bib2.m2">
<XMath>
<XMApp>
<XMTok name="ddot" role="OVERACCENT">¨</XMTok>
<XMTok font="italic" role="UNKNOWN">a</XMTok>
</XMApp>
</XMath>
</Math>mple (1899)</tag>
<tag role="key">mathy</tag>
</tags>
<bibblock>
Another name.
</bibblock>
</bibitem>
</biblist>
</bibliography>
</document>

0 comments on commit b8731d7

Please sign in to comment.