可以thebibliography
按引用顺序排序吗?或者有没有可以排序的内联参考书目的解决方案?
最好没有额外的.bib 文件。
我当前的书目包含在文章其余部分的一个thebibliography
块内。
\begin{document}
\section{Example}
The citations in\cite{ne} the bibliography should\cite{flowers} be ordered
according which order they appear in the text.
\begin{thebibliography}{9}
\bibitem{fetebok} \emph{Internal Combustion Engine Fundamentals}
\bibitem{ne} \emph{Förbränningsmotorer}
\bibitem{flowers} \emph{HCCI Research Towards Development for Stationary Power
Applications}
\end{thebibliography}
应该输出:
The citations in[1] the bibliography should[2] be ordered
according which order they appear in the text.
Bilbiography
[1] Förbränningsmotorer
[2] HCCI Research Towards Development for Stationary Power Applications
[3] Internal Combustion Engine Fundamentals
答案1
如果您确实需要按引用顺序排序的参考书目,那么您有两种选择:
thebibliography
(1)按引用顺序编写条目
(2)使用.bib
文件\bibliographystyle{unsrt}
和BibTeX。
实际上还有第三种选择,但我这样做只是为了证明它是可能的:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\newcounter{mycite}
\newtoks\citetoks
\makeatletter
\DeclareRobustCommand\unscite[1]{%
\@ifundefined{uns@cite#1}
{\refstepcounter{mycite}\label{citelabel@#1}%
\expandafter\xdef\csname uns@cite#1\endcsname{\arabic{mycite}}%
\toks\z@=\expandafter{\the\citetoks}%
\toks\tw@=\expandafter\expandafter\expandafter{%
\csname uns@bibitem#1\endcsname}%
\edef\@tempcite{\the\toks\z@\the\toks\tw@}%
\global\citetoks=\expandafter{\@tempcite}%
}{}[\@nameuse{uns@cite#1}]}
\newcommand{\mybibitem}[2]{%
\@namedef{uns@bibitem#1}{\bibitem[\ref{citelabel@#1}]{#1}#2}}
\makeatother
% Define here the bibliography entries
\mybibitem{fetebok}{\emph{Internal Combustion Engine Fundamentals}}
\mybibitem{ne}{\emph{Förbränningsmotorer}}
\mybibitem{flowers}{\emph{HCCI Research Towards Development for Stationary
Power Applications}}
\begin{document}
\section{Example}
The citations in~\unscite{ne} the bibliography should~\unscite{flowers}
be ordered according which order they appear in the text.
\begin{thebibliography}{\arabic{mycite}}
\the\citetoks
\end{thebibliography}
\end{document}
请注意,这\unscite
不能像通常那样处理引用列表或可选参数\cite
。虽然可以,但我建议您不要采用这种方法。
答案2
我已经使用参考书目在文档中创建了 150 个参考文献,并且面临着按照文本中首次出现的顺序对它们进行排序的任务(这是科学期刊中非常常见的要求)。
您有两种选择:(1)按引用顺序写入参考书目中的条目(2)使用 .bib 文件、\bibliographystyle{unsrt} 和 BibTeX。
以上两种方法都需要大量工作,要么手动重新排序参考书目,要么手动创建数据库 .bib 文件。
https://code.google.com/p/latex-bibitemstyler/ 似乎是解决方案,但我无法让它在我的系统上运行,而且时间紧迫。所以我写了一个简短且非常不雅的 Python 2.7 解决方法,它可以完成这项工作,并可能对遇到类似问题的人有所帮助。如果在未来的版本中可以有一个标准的 LaTeX 命令来按文本中第一次引用的顺序对参考书目进行排序,我将非常感激。
print"\n\nBibSort_v1\nSorts LaTeX 'thebibliography' in order of first citation in text\nDave Williams 26Mar2017\nRun the code in the same directory as your LaTeX source file\nUsing Python 2.x"
filename = raw_input("\n\nEnter LaTeX source filename (e.g. 'input.tex'): ")
fileobject = (open(filename, 'r'))
rawtext = fileobject.read()
fileobject.close()
start = '\\begin{document}'
end = '\\begin{thebibliography}'
bodytext = rawtext[rawtext.find(start)+len(start):rawtext.rfind(end)]
start = '\\begin{thebibliography}'
end = '\\end{thebibliography}'
bibliography = rawtext[rawtext.find(start)+len(start):rawtext.rfind(end)]
authorlist = []
for char in range(0,len(bodytext) - 10):
if bodytext[char:char+6] == '\\cite{':
author = ''
char +=6
while (bodytext[char] != '}'):
if (bodytext[char] == ' '):
char+=1
elif(bodytext[char] == ','):
char +=1
if author in authorlist:
author = ''
else:
authorlist.append(author)
author=''
else:
author += (bodytext[char])
char +=1
if author in authorlist:
pass
else:
authorlist.append(author)
labellist = []
reflist = []
for char in range(0,len(bibliography) - 7):
ref =''
if bibliography[char:char+9] == '\\bibitem{':
char+=9
label =''
while(bibliography[char] != '}'):
label += bibliography[char]
char+=1
labellist.append(label)
char+=1
while (bibliography[char:char+9] != '\\bibitem{'):
if char == len(bibliography) -1:
break
elif (bibliography[char]) == '\n':
char +=1
else:
ref += (bibliography[char])
char +=1
reflist.append(ref)
dictionary = dict(zip(labellist, reflist))
output =''
orphanlist =''
try:
for name in authorlist:
output += '\\bibitem{' + name + '}\n' + dictionary[name] + '\n\n'
if len(authorlist) < len(labellist):
output+="%" + "-"*80 + "\n"
output+= "%"+ " The following %d references are in thebibliography but not cited in the text:\n\n" % (len(reflist) - len(authorlist))
orphanlist = list(set(labellist)-set(authorlist))
for name in range(0, len(orphanlist)-1):
output += '\\bibitem{' + orphanlist[name] + '}\n' + dictionary[orphanlist[name]] + '\n\n'
print("\n\n%d unique references were found in the text and sorted in order of appearance in the text" % (len(authorlist)))
print("%d additional references were found in \\thebibliography which were not used in the text" % (len(orphanlist)))
print("\nNew bibliography saved as:\n%s\n\nUsing a text editor, Copy all contents of this file,\nand Paste over the existing mybibliography in your LaTeX source file:\n%s\n" % (filename[:-4]+'_NewBib.txt',filename))
fileobject = open(filename[:-4]+'_NewBib.txt', 'w')
fileobject.write(output)
fileobject.close
except (TypeError, ValueError), e:
print e
print "\nThere may be a mis-match between the labels in your bibliography\n and one or more labels in your in-text citations.\nPerhaps there is a typo, or you've used a capital letter in one\nbut not the other.\nPlease check your the flagged citation using 'find' in your\n Latex editor and run this Python script again."
答案3
是的,有一种方法可以按文本中出现的顺序对 \bibitems 进行排序。看看https://code.google.com/p/latex-bibitemstyler/,一个可以完美完成这项工作的小程序。