我正在使用具有特定参考书目样式(bst 文件)的 BibTeX,我不能放弃它。
这是 .bst 文件的链接[乔恩]
我需要编辑 .bst 文件以获取条目编号。此 .bst 文件是作者年份引用样式书目,需要与 harvard.sty 配合使用
我尝试将 plain.bst [条目在方括号内编号] 与 alpha.bst [条目以 bib 文件中的昵称作为前缀] 进行比较,以为这样就能找到所需的更改,但是没有成功。
使用上述 bst 文件,我的条目看起来像(例如文章):
LastName, FirstName, year, Title, Journal ... volume, pages LastName, FirstName, 2ndAuthorFullName, year, Title, Journal, bla bla bla bla bla bla bla bla bla bla ...
而我需要它看起来像这样(编号是这里的主要问题)(类似于 plain.bst):
[1] LastName, FirstName, year, Title, Journal, volume, pages [2] LastName, FirstName, 2ndAuthorFullName, year, Title, Journal, bla bla bla bla bla bla bla bla bla bla ...
这些数字仅用于列出项目,不用于引用。[Alan Munn]
由于兼容性要求,我无法转到 latex 或替换我的 .bst 文件。
我们能做什么?
答案1
这是一种方法(代码由 Alan Munn 提供)。
\begin{filecontents}{\jobname.bib}
@book{Labov1972,
Address = {Philadelphia},
Author = {William Labov},
Publisher = {University of Pennsylvania Press},
Title = {Sociolinguistic Patterns},
Year = {1972}}
@book{Chomsky1957,
Address = {The Hague},
Author = {Noam Chomsky},
Publisher = {Mouton},
Title = {Syntactic Structures},
Year = {1957}}
\end{filecontents}
\documentclass{article}
\usepackage{natbib,etoolbox,lipsum,hyperref}
\bibliographystyle{MyBstFile}
% increase \bibhang to take care of the numbers
\setlength{\bibhang}{2pc}
\makeatletter
% patch \@lbibitem to print the current number before the authors
\patchcmd{\@lbibitem}
{]}
{][\theNAT@ctr] }
{}{}
\makeatother
\begin{document}
\cite{Chomsky1957,Labov1972} \lipsum[2]
\bibliography{\jobname}
\end{document}
我添加hyperref
只是为了确保锚点设置正确(它们是)。
这个简单的补丁有一个缺陷,即数字没有与最后一位数字对齐。为此,应该采取更复杂的方法:我决定在辅助文件中写入最后一个数字,这样我们就可以在下次运行时设置最宽的标签。
感谢 Alan Munn 提供有意义的参考。
\begin{filecontents}{\jobname.bib}
@book{Labov1972,
Address = {Philadelphia},
Author = {William Labov},
Publisher = {University of Pennsylvania Press},
Title = {Sociolinguistic Patterns},
Year = {1972}}
@book{Chomsky1957,
Address = {The Hague},
Author = {Noam Chomsky},
Publisher = {Mouton},
Title = {Syntactic Structures},
Year = {1957}}
@article{Barker1998,
Author = {Chris Barker},
Journal = {Natural Language \& Linguistic Theory},
Pages = {679-717},
Title = {Partitives, Double Genitives and Anti-Uniqueness},
Volume = {16},
Year = {1998}}
@book{Berwick1985,
Address = {Cambridge, MA},
Author = {Berwick, Robert C.},
Publisher = {MIT Press},
Title = {Acquisition of syntactic knowledge},
Year = {1985}}
@phdthesis{Carlson1977,
Author = {Carlson, Gregory N.},
School = {University of Massachusetts, Amherst},
Title = {Reference to Kinds in {E}nglish},
Year = {1977}}
@book{Carlson1995,
Address = {Chicago},
Editor = {Carlson, Gregory N. and Pelletier, Francis Jeffrey},
Publisher = {Chicago University Press},
Title = {The Generic Book},
Year = {1995}}
@article{Chierchia1998,
Author = {Gennaro Chierchia},
Journal = {Natural Language Semantics},
Pages = {339-405},
Title = {Reference to Kinds across Languages},
Volume = {6},
Year = {1998}}
@book{Crain1998,
Address = {Cambridge, Massachusetts},
Author = {Crain, Stephen and Thornton, Rosalind},
Publisher = {The MIT Press},
Title = {Investigations in {U}niversal {G}rammar: A Guide to Experiments on the Acquisition of Syntax and Semantics},
Year = {1998}}
@article{Dayal2004,
Author = {Dayal, Veneeta},
Journal = {Linguistics and Philosophy},
Number = {4},
Pages = {393--450},
Title = {Number Marking and (In)Definiteness in Kind Terms},
Volume = {27},
Year = {2004}}
@article{Dobrovie-Sorin1998b,
Author = {Carmen Dobrovie-Sorin and Brenda Laca},
Journal = {Actes de Langues et Grammaires},
Pages = {165-179},
Title = {La g{\'e}nericit{\'e} entre la r{\'e}f{\'e}rence {\`a} l'esp{\`e}ce et la quantification g{\'e}n{\'e}rique},
Volume = {III},
Year = {1998}}
\end{filecontents}
\documentclass{article}
\usepackage{natbib,etoolbox,lipsum,hyperref}
\bibliographystyle{MyBstFile}
% increase \bibhang to take care of the numbers (adjust at will)
\setlength{\bibhang}{2pc}
\makeatletter
% patch \@lbibitem to print the current number before the authors
\patchcmd{\@lbibitem}
{]}
{]\bbl@box{\theNAT@ctr} }
{}{}
% add to the aux file the information about the last number
\apptocmd{\endthebibliography}
{\if@filesw\write\@mainaux{\string\bbl@lastnumber{\theNAT@ctr}}\fi}
{}{}
% allocate a length, set to a provisional value
\newlength{\bbl@lastnumberwd}
\setlength\bbl@lastnumberwd{0pt}
% this command will be in the aux file and sets the widest label width
\newcommand\bbl@lastnumber[1]{%
\settowidth\dimen@{[#1]}%
\global\bbl@lastnumberwd\dimen@}
% a command to print the number
\newcommand{\bbl@box}[1]{%
\makebox[\bbl@lastnumberwd][r]{[#1]}%
}
\makeatother
\begin{document}
\cite{Chomsky1957,Labov1972} \lipsum[2]
\nocite{*}
\bibliography{\jobname}
\end{document}