From b8878f713ca77a56609112b9737b0e69c048b601 Mon Sep 17 00:00:00 2001 From: Norman Gray Date: Tue, 2 Dec 2014 14:35:35 +0000 Subject: [PATCH] Change the way that eprint repository prefixes are processed. The previous technique was smart, but did _not_ match the stipulations in http://arxiv.org/help/faq/references -- these require that the specific string arXiv:yyyy.nnnn, with a leading space, and warn not to have a '{' just before the 'arXiv:' (who knows...). The previous version did have a close-up '{'. This technique is slightly clumsier in some ways, but is more straightforward in the .bst file, and requires no LaTeX magic in the style file. Incidentally changed the test framework in the test/ directory, to support multiple independent tests rather than a compendium test-everything one.. --- .gitignore | 1 - mn2e-insert.sty | 44 --------------- mn2e.bst | 55 ++++++++++++++----- tests/Makefile | 34 +++++++++--- tests/mn2e-example.tex | 2 +- tests/mn2e-test.aux | 3 - tests/mn2e-test.bib | 32 ++++++++++- tests/test-eprints.aux | 7 +++ tests/test-eprints.bbl-correct | 29 ++++++++++ tests/test-multiauthor.aux | 31 +++++++++++ ...l-correct => test-multiauthor.bbl-correct} | 11 +--- 11 files changed, 166 insertions(+), 83 deletions(-) delete mode 100644 tests/mn2e-test.aux create mode 100644 tests/test-eprints.aux create mode 100644 tests/test-eprints.bbl-correct create mode 100644 tests/test-multiauthor.aux rename tests/{mn2e-test.bbl-correct => test-multiauthor.bbl-correct} (87%) diff --git a/.gitignore b/.gitignore index abfaff6..6e0a580 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ *.bbl *.blg -*.diff mn2e-insert.txt diff --git a/mn2e-insert.sty b/mn2e-insert.sty index fd66dc8..46e5a86 100644 --- a/mn2e-insert.sty +++ b/mn2e-insert.sty @@ -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@. - \@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 diff --git a/mn2e.bst b/mn2e.bst index 06f927d..2acc3ce 100644 --- a/mn2e.bst +++ b/mn2e.bst @@ -534,16 +534,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} @@ -1802,14 +1833,10 @@ FUNCTION {begin.bib} % The following is the contents of mn2e-insert.sty, minus comments and whitespace. % DO NOT EDIT THIS TEXT, % 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$ -"\def\mn@eprint#1#2{\mn@eprint@#1:#2::\@nil}" write$ newline$ -"\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$ + "\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$ } EXECUTE {begin.bib} diff --git a/tests/Makefile b/tests/Makefile index 14f418a..e9b77aa 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 diff --git a/tests/mn2e-example.tex b/tests/mn2e-example.tex index 4da6f03..328a521 100644 --- a/tests/mn2e-example.tex +++ b/tests/mn2e-example.tex @@ -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 diff --git a/tests/mn2e-test.aux b/tests/mn2e-test.aux deleted file mode 100644 index fae8fba..0000000 --- a/tests/mn2e-test.aux +++ /dev/null @@ -1,3 +0,0 @@ -\citation{*} -\bibstyle{../mn2e} -\bibdata{mn2e-test} diff --git a/tests/mn2e-test.bib b/tests/mn2e-test.bib index 7d3bbdb..e370855 100644 --- a/tests/mn2e-test.bib +++ b/tests/mn2e-test.bib @@ -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} } @@ -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} +} diff --git a/tests/test-eprints.aux b/tests/test-eprints.aux new file mode 100644 index 0000000..a5c38e7 --- /dev/null +++ b/tests/test-eprints.aux @@ -0,0 +1,7 @@ +% Tests the eprint='prefix:ref' support +\citation{eprint1} +\citation{eprint2} +\citation{eprint3} +\citation{eprint4} +\bibstyle{../mn2e} +\bibdata{mn2e-test} diff --git a/tests/test-eprints.bbl-correct b/tests/test-eprints.bbl-correct new file mode 100644 index 0000000..c184f4c --- /dev/null +++ b/tests/test-eprints.bbl-correct @@ -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} diff --git a/tests/test-multiauthor.aux b/tests/test-multiauthor.aux new file mode 100644 index 0000000..7df0645 --- /dev/null +++ b/tests/test-multiauthor.aux @@ -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} diff --git a/tests/mn2e-test.bbl-correct b/tests/test-multiauthor.bbl-correct similarity index 87% rename from tests/mn2e-test.bbl-correct rename to tests/test-multiauthor.bbl-correct index 2ee9ca7..c1ad59b 100644 --- a/tests/mn2e-test.bbl-correct +++ b/tests/test-multiauthor.bbl-correct @@ -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 @@ -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}