Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way that eprint repository prefixes are processed. #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.bbl
*.blg
*.diff

mn2e-insert.txt

Expand Down
44 changes: 0 additions & 44 deletions mnras-insert.sty
Original file line number Diff line number Diff line change
Expand Up @@ -72,48 +72,4 @@
\fi
\endgroup}

% \mn@eprint
%
% \mn@eprint{defaultArchivePrefix}{id} expands to a link to the given ID
% at a suitable archive. The 'id' can be either a bare ID (such as
% yymm.1234) for arXiv, or can include an archive prefix. If there is
% no prefix in the 'id', then 'defaultArchivePrefix' supplies a default.
%
% Thus
% \mn@eprint{}{arXiv:yymm.1234} -> \href{http://arxiv.org/abs/yymm.1234}{arXiv:yymm.1234}
% \mn@eprint{}{yymm.1234} -> same as \mn@eprint{}{arXiv:yymm.1234}
% \mn@eprint{arXiv}{arXiv:yymm.1234} -> same
% \mn@eprint{dblp}{1234} -> \href{http://dblp.uni-trier.de/rec/bibtex/1234.xml}{dblp:1234}
% \mn@eprint{dblp}{arXiv:yymm.1234} -> same as \mn@eprint{}{arXiv:yymm.1234}
% \mn@eprint{}{wibble:1234} -> wibble:1234 (doesn't match anything)
%
% A prefix 'PFX' is 'registered' by defining a macro
% \mn@eprint@PFX#1{...} which formats the identifier (that is, \mn@eprint's
% second argument _minus_ any colon-terminated prefix).
\def\mn@eprint#1#2{%
\mn@eprint@#1:#2::\@nil}

\def\mn@eprint@arXiv#1{\href {http://arxiv.org/abs/#1} {{\tt arXiv:#1}}}
\def\mn@eprint@dblp#1{\href {http://dblp.uni-trier.de/rec/bibtex/#1.xml} {dblp:#1}}

\def\mn@eprint@#1:#2:#3:#4\@nil{%
\def\@tempa {#1}%
\def\@tempb {#2}%
\def\@tempc {#3}%
\ifx \@tempc \@empty
\let \@tempc \@tempb
\let \@tempb \@tempa
\fi
\ifx \@tempb \@empty
% default to arXiv
\def\@tempb {arXiv}%
\fi
% If \@tempb is a 'recognised' prefix, then call it, otherwise, just
% print prefix:id and be done with it. A prefix is 'recognised' if
% there's a macro \@eprint@<prefix>.
\@ifundefined {mn@eprint@\@tempb}
{\@tempb:\@tempc}
% or call macro '@eprint@\@tempb' on the argument \@tempc
{\expandafter \expandafter \csname mn@eprint@\@tempb\endcsname \expandafter{\@tempc}}}

\relax
51 changes: 45 additions & 6 deletions mnras.bst
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,47 @@ FUNCTION {format.title}
if$
}

% The format of the output string for arXiv is specifically {\tt arXiv:nnn}, and
% not for example \texttt{arXiv:nnn} or \fancyarxivmacro{nnn}
% (see http://arxiv.org/help/faq/references).
% The format of the ascl reference isn't specified so precisely, but
% we should use the same format.
FUNCTION {format.eprint}
{ eprint empty$
{ "" }
{ " (\mn@eprint {"
archiveprefix empty$
{ "" }
{ archiveprefix }
{ " ("
% Match arxiv:nnn or arXiv:nnn
eprint #1 #6 substring$
duplicate$ "arXiv:" = swap$ "arxiv:" = or
{ eprint #7 #999 substring$ duplicate$
"\href {http://arxiv.org/abs/" swap$ * "} {{\tt arXiv:" * swap$ * "}}" *
}
{ % match ascl:
eprint #1 #5 substring$
"ascl:" =
{ eprint #6 #999 substring$ duplicate$
"\href {http://ascl.net/" swap$ * "} {{\tt ascl:" * swap$ * "}}" *
}
{ % match dblp: and DBLP:
eprint #1 #5 substring$ duplicate$
"dblp:" = swap$ "DBLP:" = or
{ eprint #6 #999 substring$ duplicate$
"\href {http://dblp.uni-trier.de/rec/html/" swap$ *
"} {{\tt dblp:" * swap$ * "}}" *
}
{ % no recognised prefix: default to arXiv
eprint duplicate$
"\href {http://arxiv.org/abs/" swap$ * "} {{\tt arXiv:" * swap$ * "}}" *
}
if$
}
if$
}
if$
* "} {" * eprint * "})" * }
if$
*
")" *
}
if$
}

FUNCTION {format.doi}
Expand Down Expand Up @@ -1804,6 +1835,13 @@ FUNCTION {begin.bib}
"\makeatletter" write$ newline$
% The following is the contents of mnras-insert.sty, minus comments and whitespace.
% DO NOT EDIT THIS TEXT,
<<<<<<< HEAD:mn2e.bst
% but instead make mn2e-insert.txt, and paste the results in here.
"\relax" write$ newline$
"\def\mn@urlcharsother{\let\do\@makeother \do\$\do\&\do\#\do\^\do\_\do\%\do\~}" write$ newline$
"\def\mn@doi{\begingroup\mn@urlcharsother \@ifnextchar [ {\mn@doi@} {\mn@doi@[]}}" write$ newline$
"\def\mn@doi@[#1]#2{\def\@tempa{#1}\ifx\@tempa\@empty \href {http://dx.doi.org/#2} {doi:#2}\else \href {http://dx.doi.org/#2} {#1}\fi \endgroup}" write$ newline$
=======
% but instead make mnras-insert.txt, and paste the results in here.
"\relax" write$ newline$
"\def\mn@urlcharsother{\let\do\@makeother \do\$\do\&\do\#\do\^\do\_\do\%\do\~}" write$ newline$
Expand All @@ -1813,6 +1851,7 @@ FUNCTION {begin.bib}
"\def\mn@eprint@arXiv#1{\href {http://arxiv.org/abs/#1} {{\tt arXiv:#1}}}" write$ newline$
"\def\mn@eprint@dblp#1{\href {http://dblp.uni-trier.de/rec/bibtex/#1.xml} {dblp:#1}}" write$ newline$
"\def\mn@eprint@#1:#2:#3:#4\@nil{\def\@tempa {#1}\def\@tempb {#2}\def\@tempc {#3}\ifx \@tempc \@empty \let \@tempc \@tempb \let \@tempb \@tempa \fi \ifx \@tempb \@empty \def\@tempb {arXiv}\fi \@ifundefined {mn@eprint@\@tempb}{\@tempb:\@tempc}{\expandafter \expandafter \csname mn@eprint@\@tempb\endcsname \expandafter{\@tempc}}}" write$ newline$
>>>>>>> upstream/master:mnras.bst
}

EXECUTE {begin.bib}
Expand Down
34 changes: 26 additions & 8 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
check: mn2e-test.bbl mn2e-test.bbl-correct
@diff mn2e-test.bbl-correct mn2e-test.bbl >mn2e-test.diff \
&& echo OK \
|| { echo FAIL; cat mn2e-test.diff; }
CHECKS=test-multiauthor test-eprints

mn2e-test.bbl: mn2e-test.aux mn2e-test.bib ../mn2e.bst
bibtex mn2e-test
%.bbl: %.aux mn2e-test.bib ../mn2e.bst
bibtex $<

mn2e-example.pdf: mn2e-example.tex mn2e-test.bbl
%.diff: %.bbl
rm -f $@
diff ${<}-correct $< >$@ || :

# The following succeeds, and prints 'All tests OK', if all of the
# .diff files are of zero size; if one or more is non-empty, it
# reports that, and ends reporting an error.
#
# 'test -s filename' is true if 'filename' exists and has non-zero size
check: $(CHECKS:=.diff)
@allgood=:; \
for f in $(CHECKS); do \
if test -s $$f.diff; then \
echo "FAIL: $$f"; allgood=false; \
else \
echo "OK: $$f"; rm $$f.diff; \
fi; \
done; \
$$allgood
@echo "All tests OK"

mn2e-example.pdf: mn2e-example.tex test-multiauthor.bbl
TEXINPUTS=..: pdflatex mn2e-example

clean:
rm -f mn2e-test.bbl mn2e-test.blg mn2e-test.diff
rm -f *.bbl *.blg *.diff
2 changes: 1 addition & 1 deletion tests/mn2e-example.tex
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ \section{Introduction}
% debugging. That's generally commented out, but if you need to
% uncomment that, then uncomment this, too.
%\def\logsortkey#1{{[\tiny #1]}}
\input{mn2e-test.bbl}
\input{test-multiauthor.bbl}

\bsp

Expand Down
3 changes: 0 additions & 3 deletions tests/mn2e-test.aux

This file was deleted.

32 changes: 30 additions & 2 deletions tests/mn2e-test.bib
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ @Book{twobook
}

% Same authors and year as {twobook}
% Also includes a DOI and a funky archivePrefix field.
% Also includes a DOI and a funky archivePrefix field (which should be ignored).
@Misc{twomisc,
author = {Albert One and Benedict Two},
title = {Two Alone in a Pamphlet (Adventures in Salami Publishing)},
howpublished = {obtained under the counter},
archivePrefix = "funky",
doi = {10.1234/nowhere/One&Two_*#foo},
eprint = {0100.0002},
xxxeprint = {0100.0002},
url = {http://example.org/my_salami#pubs},
year = {2001}
}
Expand Down Expand Up @@ -290,3 +290,31 @@ @Article{tenbis
year = 2000
}

@InProceedings{eprint1,
author = {Albert One},
title = {Article with Preprint},
booktitle = {Early Thoughts Conference},
year = 2014,
eprint = {1401.0001}
}
@InProceedings{eprint2,
author = {Benedict Two},
title = {Another Article with Preprint},
booktitle = {Early Thoughts Conference},
year = 2014,
eprint = {arxiv:1401.0002}
}
@InProceedings{eprint3,
author = {Coriolanus Three},
title = {Yet Another Article with Computing Preprint},
booktitle = {Early Thoughts Conference},
year = 2014,
eprint = {ascl:1401.003}
}
@InProceedings{eprint4,
author = {Coriolanus Three},
title = {Yet Another Article with DBLP Preprint},
booktitle = {Early Thoughts Conference},
year = 2014,
eprint = {DBLP:journals/corr/AccomazziGEBFS14}
}
7 changes: 7 additions & 0 deletions tests/test-eprints.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% Tests the eprint='prefix:ref' support
\citation{eprint1}
\citation{eprint2}
\citation{eprint3}
\citation{eprint4}
\bibstyle{../mn2e}
\bibdata{mn2e-test}
29 changes: 29 additions & 0 deletions tests/test-eprints.bbl-correct
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
\begin{thebibliography}{}
\makeatletter
\relax
\def\mn@urlcharsother{\let\do\@makeother \do\$\do\&\do\#\do\^\do\_\do\%\do\~}
\def\mn@doi{\begingroup\mn@urlcharsother \@ifnextchar [ {\mn@doi@}
{\mn@doi@[]}}
\def\mn@doi@[#1]#2{\def\@tempa{#1}\ifx\@tempa\@empty \href
{http://dx.doi.org/#2} {doi:#2}\else \href {http://dx.doi.org/#2} {#1}\fi
\endgroup}

\bibitem[\protect\citeauthoryear{One}{One}{2014}]{eprint1}
One A., 2014, in Early Thoughts Conference. (\href
{http://arxiv.org/abs/1401.0001} {{\tt arXiv:1401.0001}})

\bibitem[\protect\citeauthoryear{Three}{Three}{2014a}]{eprint3}
Three C., 2014a, in Early Thoughts Conference. (\href
{http://ascl.net/1401.003} {{\tt ascl:1401.003}})

\bibitem[\protect\citeauthoryear{Three}{Three}{2014b}]{eprint4}
Three C., 2014b, in Early Thoughts Conference. (\href
{http://dblp.uni-trier.de/rec/html/journals/corr/AccomazziGEBFS14} {{\tt
dblp:journals/corr/AccomazziGEBFS14}})

\bibitem[\protect\citeauthoryear{Two}{Two}{2014}]{eprint2}
Two B., 2014, in Early Thoughts Conference. (\href
{http://arxiv.org/abs/1401.0002} {{\tt arXiv:1401.0002}})

\makeatother
\end{thebibliography}
31 changes: 31 additions & 0 deletions tests/test-multiauthor.aux
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
% Test the multi-author support
\citation{one}
\citation{oneplus}
\citation{onereprised}
\citation{onebracketed}
\citation{two}
\citation{twoplus}
\citation{twobis}
\citation{tworeprised}
\citation{twobartearly}
\citation{twobartlate}
\citation{twobook}
\citation{twomisc}
\citation{three}
\citation{threeplus}
\citation{threereprised}
\citation{four}
\citation{fourplus}
\citation{five}
\citation{fiveplus}
\citation{seven}
\citation{sevenplus}
\citation{eight}
\citation{eightplus}
\citation{nine}
\citation{nineplus}
\citation{ten}
\citation{tenplus}
\citation{tenbis}
\bibstyle{../mn2e}
\bibdata{mn2e-test}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
\def\mn@doi@[#1]#2{\def\@tempa{#1}\ifx\@tempa\@empty \href
{http://dx.doi.org/#2} {doi:#2}\else \href {http://dx.doi.org/#2} {#1}\fi
\endgroup}
\def\mn@eprint#1#2{\mn@eprint@#1:#2::\@nil}
\def\mn@eprint@arXiv#1{\href {http://arxiv.org/abs/#1} {{\tt arXiv:#1}}}
\def\mn@eprint@dblp#1{\href {http://dblp.uni-trier.de/rec/bibtex/#1.xml}
{dblp:#1}}
\def\mn@eprint@#1:#2:#3:#4\@nil{\def\@tempa {#1}\def\@tempb {#2}\def\@tempc
{#3}\ifx \@tempc \@empty \let \@tempc \@tempb \let \@tempb \@tempa \fi \ifx
\@tempb \@empty \def\@tempb {arXiv}\fi \@ifundefined
{mn@eprint@\@tempb}{\@tempb:\@tempc}{\expandafter \expandafter \csname
mn@eprint@\@tempb\endcsname \expandafter{\@tempc}}}

\bibitem[\protect\citeauthoryear{One}{One}{2001}]{one}
One A., 2001, MNRAS, 1, 101
Expand All @@ -38,7 +29,7 @@ Repetitious press

\bibitem[\protect\citeauthoryear{One \& Two}{One \& Two}{2001b}]{twomisc}
One A., Two B., 2001b, Two Alone in a Pamphlet (Adventures in Salami
Publishing), obtained under the counter, \mn@eprint {funky} {0100.0002},
Publishing), obtained under the counter,
\mn@doi{10.1234/nowhere/One&Two_*#foo}, \url
{http://example.org/my_salami#pubs}

Expand Down