将 amsrefs 转换为 bibtex

将 amsrefs 转换为 bibtex

我使用的amsrefs包参考如下:

\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}

有没有解决方案可以将这种类型的参考列表转换为可以处理的格式bibtex

答案1

乳胶包装https://www.ctan.org/pkg/ltb2bib正是如此。

答案2

可能是这样的:

\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

如果你通过 LaTeX 运行它,你将得到一个.bib包含以下内容的文件

@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},
}

使用您喜欢的文件名而不是\jobname


扩展版本可应对其他复杂的键。

\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

输出.bib

@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},
}

相关内容