使用传统的 .bst bibtex 样式定制电子版

使用传统的 .bst bibtex 样式定制电子版

我对使用 Biblatex/biber 自定义电子版参考文献的方式相当满意,见下文。我想知道是否有办法仅依靠可能经过调整但传统的 bibtex 样式(unsrt、plain……)来实现类似的结果。我知道各种符合 arXiv 的 bibtex 样式但在我看来,使用 bibtex 管理同一文档中的不同电子打印样式并不容易,甚至不可能。

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\colorlet{doic}{green!50!black}
\colorlet{arkc}{blue!50!black}
\colorlet{oaic}{red!50!black}
\colorlet{hdlc}{yellow!50!black}
\colorlet{arxivc}{pink!50!black}
\usepackage[hyperref=true,backend=biber,style=numeric]{biblatex}
\addbibresource{ref.bib}

\usepackage[hidelinks]{hyperref}
\urlstyle{sf}

\title{Various eprint styles with Biblatex}

% DOI links
\def\doitourl#1{http://dx.doi.org/#1}
\DeclareFieldFormat{doi}{%
    \ifhyperref
      {\color{doic}\href{\doitourl#1}{[doi:\nolinkurl{#1}]}}
      {\nolinkurl{#1}}}

% ARK links
\def\arktourl#1{http://gallica.bnf.fr/#1}
\DeclareFieldFormat{eprint:ark}{%
    \ifhyperref
        {\color{arkc}\href{\arktourl#1}{[\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% OAI links
\def\oaitourl#1{http://hal.archives-ouvertes.fr/#1}
\DeclareFieldFormat{eprint:oai}{%
    \ifhyperref
        {\color{oaic}\href{\oaitourl#1}{[oai:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% Orbi.lu links
\def\hdltourl#1{http://hdl.handle.net/#1}
\DeclareFieldFormat{eprint:hdl}{%
    \ifhyperref
        {\color{hdlc}\href{\hdltourl#1}{[hdl:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% ARXIV links       
\def\arxivtourl#1{http://arxiv.org/abs/#1}      
\DeclareFieldFormat{eprint:arxiv}{%
    \ifhyperref
        {\color{arxivc}\href{\arxivtourl#1}{[arxiv:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

\begin{document}
\maketitle
\nocite{*}
\printbibliography
\end{document}

连同ref.bib文件(为了紧凑起见,我截断了标题)

@article{Ba,
 year={2000},
 journal={Archive for Rational Mechanics and Analysis},
 volume={154},
 number={3},
 doi={10.1007/s002050000105},
 title={The Dynamics of Discrete Mechanical Systems},
 publisher={Springer-Verlag},
 author={Patrick Ballard},
 pages={199-274},
 eprinttype = {oai},
 eprint = {hal-00111308}}

@ARTICLE{Beylkin92,
  author = {Nguyen, Vinh-Phu},
  title = {Nitsche's method for two and three dimensional NURBS},
  journal = {Computational Mechanics},
  year = {2015},
  volume = {29},
  pages = {1716-1740},
  number = {6},
  eprint = {10993/13771},
  eprinttype = {hdl}}

@ARTICLE{Williams94,
  author = {C. Pfrommer},
  title = {Simulating cosmic ray physics on a moving mesh},
  journal = {International Journal for Numerical Methods in Engineering},
  eprint = {1604.07399},
  eprinttype = {arxiv}}

@book{Lame,
  title={Le\c{c}ons sur la théorie mathématique de l'élasticité des corps solides},
  author={Lamé, Gabriel},
  eprint= {ark:/12148/bpt6k5747708p},
  eprinttype = {ark},
  year={1852},
  publisher={Bachelier},
  address={Paris}}

在此处输入图片描述

答案1

完全可以通过编辑标准文件来设置它.bst,只是有点繁琐。需要做三件事。首先,您需要告诉 BibTeX通过修改列表来使条目doieprint可用:eprinttypeENTRY

ENTRY {
  ...
  doi
  eprint
  eprinttype
  ...
}

其次,您需要一个可以进行格式化的函数。具体如何设置取决于您是否想要所有附加功能。例如,添加一个开关来检测hyperref会让生活变得更加复杂。在下文中,我假设始终会加载。我还假设我们可以从上面hyperref获取类型,并且它们都是可靠的(所有条目都是已知类型,颜色将在文档中定义,eprinttype\<eprinttype>tourl<eprinttype>cETC。)这会导致类似以下的情况

FUNCTION {format.doi.eprint}
{
  doi empty$
    'skip$
    {
      "\textcolor{doic}{\href{\doitourl{" doi * "}}{[doi:\nolinkurl{" * doi * "}]}}" *
      eprint empty$
        'skip$
        { output }
      if$
    }
  if$
  eprint empty$
  eprinttype empty$
  and not
    {
      "\textcolor{" eprinttype * "c}{\href{\" * eprinttype * "tourl{" *
         eprint * "}}{[" * eprinttype * ":\nolinkurl{" * eprint * "}]}}" *
    }
    'skip$
  if$
}

最后,必须将该函数添加到条目类型的输出中。您可以通过将其添加到现有的通用函数(例如字段的函数)来实现这一点note,但我会手动完成:

FUNCTION {article}
{ output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  new.block
  crossref missing$
    { journal emphasize "journal" output.check
      format.vol.num.pages output
      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  format.doi.eprint output
  new.block
  note output
  fin.entry
}

根据所需的复杂程度,可以添加健全性测试,将已知类型的数据传递给 BibTeX,ETC


将以上内容编辑为plain.bst,重命名为eplain.bst,并使用示例源

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Ba,
 year={2000},
 journal={Archive for Rational Mechanics and Analysis},
 volume={154},
 number={3},
 doi={10.1007/s002050000105},
 title={The Dynamics of Discrete Mechanical Systems},
 publisher={Springer-Verlag},
 author={Patrick Ballard},
 pages={199-274},
 eprinttype = {oai},
 eprint = {hal-00111308}}

@ARTICLE{Beylkin92,
  author = {Nguyen, Vinh-Phu},
  title = {Nitsche's method for two and three dimensional NURBS},
  journal = {Computational Mechanics},
  year = {2015},
  volume = {29},
  pages = {1716-1740},
  number = {6},
  eprint = {10993/13771},
  eprinttype = {hdl}}

@ARTICLE{Williams94,
  author = {C. Pfrommer},
  title = {Simulating cosmic ray physics on a moving mesh},
  journal = {International Journal for Numerical Methods in Engineering},
  eprint = {1604.07399},
  eprinttype = {arxiv}}

@book{Lame,
  title={Le\c{c}ons sur la théorie mathématique de l'élasticité des corps solides},
  author={Lamé, Gabriel},
  eprint= {ark:/12148/bpt6k5747708p},
  eprinttype = {ark},
  year={1852},
  publisher={Bachelier},
  address={Paris}}
\end{filecontents*}
\documentclass{article}
\usepackage{xcolor}
\colorlet{doic}{green!50!black}
\colorlet{arkc}{blue!50!black}
\colorlet{oaic}{red!50!black}
\colorlet{hdlc}{yellow!50!black}
\colorlet{arxivc}{pink!50!black}
\usepackage[hidelinks]{hyperref}
\urlstyle{sf}

\def\doitourl#1{http://dx.doi.org/#1}
\def\arktourl#1{http://gallica.bnf.fr/#1}
\def\oaitourl#1{http://hal.archives-ouvertes.fr/#1}
\def\hdltourl#1{http://hdl.handle.net/#1}
\def\arxivtourl#1{http://arxiv.org/abs/#1}   
\begin{document}
\nocite{*}
\bibliographystyle{eplain}
\bibliography{\jobname}
\end{document}

生成的输出与问题基本相同。

相关内容