4

I used amsrefs package for references as follows:

\begin{bibdiv}
\begin{biblist}
\bib{BW}{article}{
author={Bertram, A.},
author={Wentworth, R.},
title={Gromov invariants for holomorphic
maps on Riemann surfaces},
date={1996},
journal={jams},
volume={9},
number={2},
pages={529\ndash 571},
}
\end{biblist}
\end{bibdiv}

Is there a solution to convert this type of reference list to a format that can be processed by bibtex?

  • sadly, there's no automatic method. one was originally intended, but with the death of the developer, someone else took over and the rules changed. on the other hand, this looks like an article that should be indexed by mathscinet, and from mathscinet you can get references in bibtex format. – barbara beeton Feb 6 '17 at 20:33
4

The latex package https://www.ctan.org/pkg/ltb2bib does exactly this.

9

Possibly something like this:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\processamsrefs}{m}
 {
  \iow_open:Nn \g_kadir_amsrefs_stream { #1.bib }
 }
\NewDocumentCommand{\bib}{mmm}
 {
  \kadir_amsrefs_bib:nnn { #1 } { #2 } { #3 }
 }

\iow_new:N \g_kadir_amsrefs_stream
\seq_new:N \l__kadir_amsrefs_output_seq
\seq_new:N \l__kadir_amsrefs_author_seq
\tl_new:N \l__kadir_amsrefs_pages_tl

\cs_new_protected:Nn \kadir_amsrefs_bib:nnn
 {
  \seq_clear:N \l__kadir_amsrefs_output_seq
  \seq_clear:N \l__kadir_amsrefs_author_seq
  \keys_set:nn { kadir/amsrefs } { #3 }
  \seq_put_left:Nx \l__kadir_amsrefs_output_seq
   {
    author = { \seq_use:Nn \l__kadir_amsrefs_author_seq { ~and~ } }
   }
  \seq_put_left:Nx \l__kadir_amsrefs_output_seq { @#2\c_left_brace_str #1 }
  \seq_put_right:Nx \l__kadir_amsrefs_output_seq { \c_right_brace_str }
  \iow_now:Nx \g_kadir_amsrefs_stream
   {
    \seq_use:Nn \l__kadir_amsrefs_output_seq { ,^^J }
   }
 }

\keys_define:nn { kadir/amsrefs }
 {
  author  .code:n = \seq_put_right:Nn \l__kadir_amsrefs_author_seq { #1 },
  title   .code:n = \seq_put_right:Nn \l__kadir_amsrefs_output_seq { title = {{ #1 }} },
  pages   .code:n = \__kadir_amsrefs_pages:n { #1 },
  date    .code:n = \seq_put_right:Nn \l__kadir_amsrefs_output_seq { year = { #1 } },
  unknown .code:n = 
   \seq_put_right:Nx \l__kadir_amsrefs_output_seq
    { \l_keys_key_tl = { \exp_not:n { #1 } } },
 }

\cs_new_protected:Nn \__kadir_amsrefs_pages:n
 {
  \tl_set:Nn \l__kadir_amsrefs_pages_tl { #1 }
  \tl_replace_all:Nnn \l__kadir_amsrefs_pages_tl { \ndash } { - }
  \seq_put_right:Nx \l__kadir_amsrefs_output_seq
   { pages = { \exp_not:V \l__kadir_amsrefs_pages_tl } }
 }

\ExplSyntaxOff

\processamsrefs{\jobname}

\bib{BW}{article}{
author={Bertram, A.},
author={Wentworth, R.},
title={Gromov invariants for holomorphic
maps on Riemann surfaces},
date={1996},
journal={jams},
volume={9},
number={2},
pages={529\ndash 571},
}

\bib{Bourbaki70}{book}{
        title={Th\'eorie des ensembles},
        author={Bourbaki, Nicolas},
        date={1970},
        publisher={Hermann},
        address={Paris}
}

\stop

If you run this through LaTeX, you will get a .bib file with the contents

@article{BW,
author={Bertram, A. and Wentworth, R.},
title={{Gromov invariants for holomorphic maps on Riemann surfaces}},
year={1996},
journal={jams},
volume={9},
number={2},
pages={529-571},
}
@book{Bourbaki70,
author={Bourbaki, Nicolas},
title={{Th\'eorie des ensembles}},
year={1970},
publisher={Hermann},
address={Paris},
}

Use your preferred file name instead of \jobname.


Expanded version for coping with other complex keys.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\processamsrefs}{m}
 {
  \iow_open:Nn \g_kadir_amsrefs_stream { #1.bib }
 }
\NewDocumentCommand{\bib}{mmm}
 {
  \kadir_amsrefs_bib:nnn { #1 } { #2 } { #3 }
 }

\iow_new:N \g_kadir_amsrefs_stream
\seq_new:N \l__kadir_amsrefs_output_seq
\seq_new:N \l__kadir_amsrefs_author_seq
\tl_new:N \l__kadir_amsrefs_pages_tl

\cs_new_protected:Nn \kadir_amsrefs_bib:nnn
 {
  \seq_clear:N \l__kadir_amsrefs_output_seq
  \seq_clear:N \l__kadir_amsrefs_author_seq
  \keys_set:nn { kadir/amsrefs } { #3 }
  \seq_put_left:Nx \l__kadir_amsrefs_output_seq
   {
    author = { \seq_use:Nn \l__kadir_amsrefs_author_seq { ~and~ } }
   }
  \seq_put_left:Nx \l__kadir_amsrefs_output_seq { @#2\c_left_brace_str #1 }
  \seq_put_right:Nx \l__kadir_amsrefs_output_seq { \c_right_brace_str }
  \iow_now:Nx \g_kadir_amsrefs_stream
   {
    \seq_use:Nn \l__kadir_amsrefs_output_seq { ,^^J }
   }
 }

\keys_define:nn { kadir/amsrefs }
 {
  author     .code:n = \seq_put_right:Nn \l__kadir_amsrefs_author_seq { #1 },
  pages      .code:n = \__kadir_amsrefs_pages:n { #1 },
  title      .code:n = \__kadir_amsrefs_entry:nn { title } { #1 },
  date       .code:n = \__kadir_amsrefs_entry:nn { year } { #1 },
  address    .code:n = \__kadir_amsrefs_entry:nn { address} { #1 },
  place      .code:n = \__kadir_amsrefs_entry:nn { address } { #1 },
  conference .code:n = \keys_set:nn { kadir/amsrefs/conference } { #1 },
  book       .code:n = \keys_set:nn { kadir/amsrefs } { #1 },
  % subkeys
  conference/title .code:n = \__kadir_amsrefs_entry:nn { booktitle } { #1 },
  % other keys
  unknown .code:n = 
   \seq_put_right:Nx \l__kadir_amsrefs_output_seq
    { \l_keys_key_tl = { \exp_not:n { #1 } } },
 }

\cs_new_protected:Nn \__kadir_amsrefs_entry:nn
 {
  \seq_put_right:Nn \l__kadir_amsrefs_output_seq { #1 = { #2 } }
 }

\cs_new_protected:Nn \__kadir_amsrefs_pages:n
 {
  \tl_set:Nn \l__kadir_amsrefs_pages_tl { #1 }
  \tl_replace_all:Nnn \l__kadir_amsrefs_pages_tl { \ndash } { - }
  \seq_put_right:Nx \l__kadir_amsrefs_output_seq
   { pages = { \exp_not:V \l__kadir_amsrefs_pages_tl } }
 }

\ExplSyntaxOff

\processamsrefs{\jobname}

\bib{BW}{article}{
  author={Bertram, A.},
  author={Wentworth, R.},
  title={Gromov invariants for holomorphic
  maps on Riemann surfaces},
  date={1996},
  journal={jams},
  volume={9},
  number={2},
  pages={529\ndash 571},
}

\bib{Bourbaki70}{book}{
  title={Th\'eorie des ensembles},
  author={Bourbaki, Nicolas},
  date={1970},
  publisher={Hermann},
  address={Paris}
}
\bib{MR919828}{article}{
  author={Gersten, Steve M.},
  title={Reducible diagrams and equations over groups},
  conference={
   title={Essays in group theory},
  },
  book={
   series={Math. Sci. Res. Inst. Publ.},
   volume={8},
   publisher={Springer},
   place={New York},
  },
  date={1987},
  pages={15--73},
}
\stop

The .bib output is

@article{BW,
author={Bertram, A. and Wentworth, R.},
title={Gromov invariants for holomorphic maps on Riemann surfaces},
year={1996},
journal={jams},
volume={9},
number={2},
pages={529-571},
}
@book{Bourbaki70,
author={Bourbaki, Nicolas},
title={Th\'eorie des ensembles},
year={1970},
publisher={Hermann},
address={Paris},
}
@article{MR919828,
author={Gersten, Steve M.},
title={Reducible diagrams and equations over groups},
booktitle={Essays in group theory},
series={Math. Sci. Res. Inst. Publ.},
volume={8},
publisher={Springer},
address={New York},
year={1987},
pages={15--73},
}
  • Add \usepackage{l3str} if this error occurs: Undefined control sequence. <argument> \c_right_brace_str l.69 } – Kadir Feb 7 '17 at 11:41
  • @Kadir Better, update your TeX distribution. ;-) – egreg Feb 7 '17 at 13:51
  • @egreg, Is it true that the program requires every "author" entry to end with a comma? That is not a requirement of the amsrefs format -- only the last author of a block of authors needs a comma. – Paulo Ney Feb 22 '18 at 6:06
  • Also the program does not seem to allow an empty line inside entries -- which is also allowed by AMSRefs. I was wondering which other assumptions is it making. – Paulo Ney Feb 22 '18 at 6:17
  • @PauloNey If I prepare a document using amsrefs with the two shown entries and I remove the comma between the two author fields, I get Package rkeyval Warning: Missing comma. So I won't change the code, because I don't think it's worth supporting coding that's not recommended. About the blank lines, just add \endlinechar=-1 after \processamsrefs{\jobname}. – egreg Feb 22 '18 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.