对于会议,我必须将参考文献放在\bibitem
格式中。在谷歌搜索之后,我想出了这个解决方案网页:
创建一个
refs.bib
包含所有 BibTeX 条目的文件,这些条目可从 Google Scholar 或类似网站上轻松获取
.tex
使用以下条目创建一个“虚拟”文件:\documentclass{article} \begin{document} \nocite{*} \bibliography{refs} \bibliographystyle{plain} \end{document}
现在,执行以下操作:
$ latex dummy $ bibtex dummy $ bibtex dummy $ latex dummy
您将看到一个
dummy.bbl
包含所有 \bibitem 格式的 BibTeX 条目的文件。
但是,我没有看到预期的结果。还有其他解决方案或上述过程存在问题吗?
答案1
我同意评论中解释的一般流程,但我认为它们并没有完全解决你必须为会议完成的最终任务,而这很可能需要一个单独的自包含.tex
文件。
假设您有mypaper.tex
文本和一些\cite{<key>}
文件refs.bib
。然后:
首先,输入
mypaper.tex
两行:\bibliography{参考文献} \bibliographystyle{普通}
其次运行(而不是使用
\nocite
有两个缺点:(1)按和排序(2)引用论文中refs.bib
不是 -d 的参考文献):\cite
(pdf)latex mypaper bibtex mypaper
如果此步骤成功,您将获得
mypaper.bbl
包含bibitem
-s 和mypaper.blg
BiBTeX 的日志文件。(注意:latex
读取mypaper.tex
-- 并且当存在mypaper.bbl
文件时 -- 但bibtex
读取mypaper.aux
由 创建的latex
)。第三,(可选但推荐)确保所有参考资料都正确插入并显示在文件中:
(pdf)Latex Mypaper
第四,打开
mypaper.tex
,注释掉或丢弃这两\biblio...
行,并将 的全部内容粘贴到mypaper.bbl
您想要获取参考书目的位置。然后您就得到了最终的独立文件。您
(pdf)latex mypaper
至少可以跑两次才能获得最终的.dvi
或.pdf
。
编辑:.bbl
如果文件内容以常规 开头,则此复制粘贴有效。如果它以或 甚至(其中= csquote、url 等)\begin{thebibliography}
加载包开头,则必须将它们移动到序言中。如果它以定义命令开头,您可以将它们保留在此处或将它们移动到序言中。\usepackage{<name>}
\input{<name>.sty}
<name>
给原帖者注意:你使用了plain
格式,这对我来说看起来很奇怪。实际上,每个会议/组织通常都有自己的.bst
样式文件,\bibitem
根据其编辑规则生成格式。更具体地说,确保你需要按字母顺序或引文顺序排列的参考书目。在后一种情况下,你必须使用unsrt.bst
(或变体)代替plain.bst
。
答案2
将 refs.bib 文件转换为 bibitem 文件的 Python 代码
python2 bibtex2item.py < refs.bib > bibitem.txt
# filename: bibtex2item.py
import sys
bibtex = sys.stdin.read()
r = bibtex.split('\n')
i = 0
while i < len(r):
line = r[i].strip()
if not line: i += 1
if '@' == line[0]:
code = line.split('{')[-1][:-1]
title = venue = volume = number = pages = year = publisher = authors = None
output_authors = []
i += 1
while i < len(r) and '@' not in r[i]:
line = r[i].strip()
#print(line)
if line.startswith("title"):
title = line.split('{')[-1][:-2]
elif line.startswith("journal"):
venue = line.split('{')[-1][:-2]
elif line.startswith("volume"):
volume = line.split('{')[-1][:-2]
elif line.startswith("number"):
number = line.split('{')[-1][:-2]
elif line.startswith("pages"):
pages = line.split('{')[-1][:-2]
elif line.startswith("year"):
year = line.split('{')[-1][:-2]
elif line.startswith("publisher"):
publisher = line.split('{')[-1][:-2]
elif line.startswith("author"):
authors = line[line.find("{")+1:line.rfind("}")]
for LastFirst in authors.split('and'):
lf = LastFirst.replace(' ', '').split(',')
if len(lf) != 2: continue
last, first = lf[0], lf[1]
output_authors.append("{}, {}.".format(last.capitalize(), first.capitalize()[0]))
i += 1
print "\\bibitem{%s}" % code
if len(output_authors) == 1:
print output_authors[0] + " {}. ".format(title),
else:
print ", ".join(_ for _ in output_authors[:-1]) + " & " + output_authors[-1] + " {}. ".format(title),
if venue:
print "{{\\em {}}}.".format(" ".join([_.capitalize() for _ in venue.split(' ')])),
if volume:
sys.stdout.write(" \\textbf{{{}}}".format(volume))
if pages:
sys.stdout.write(", {}".format(pages) if number else " pp. {}".format(pages))
if year:
sys.stdout.write(" ({})".format(year))
if publisher and not venue:
print "({},{})".format(publisher, year)
print
print
示例输入
@article{karrer2011stochastic,
title={Stochastic blockmodels and community structure in networks},
author={Karrer, Brian and Newman, Mark EJ},
journal={Physical Review E},
volume={83},
number={1},
pages={016107},
year={2011},
publisher={APS}
}
示例输出
\bibitem{karrer2011stochastic}
Karrer, B. & Newman, M. Stochastic blockmodels and community structure in networks. {\em Physical Review E}. \textbf{83}, 016107 (2011)
答案3
针对python3进行了修改
# filename: bibtex2item.py
# python2 bibtex2item.py
import sys
# bibtex = sys.stdin.read()
try:
bibtex=open("refs.bib")
except IOError:
print("File not found or path is incorrect")
finally:
print("exit")
bibtex = bibtex.readlines()
# print(bibtex)
# r = bibtex.split('\n')
r = bibtex
i = 0
while i < len(r):
line = r[i].strip()
if not line: i += 1
if '@' == line[0]:
code = line.split('{')[-1][:-1]
title = venue = volume = number = pages = year = publisher = authors = None
output_authors = []
i += 1
while i < len(r) and '@' not in r[i]:
line = r[i].strip()
#print(line)
if line.startswith("title"):
title = line.split('{')[-1][:-2]
elif line.startswith("journal"):
venue = line.split('{')[-1][:-2]
elif line.startswith("volume"):
volume = line.split('{')[-1][:-2]
elif line.startswith("number"):
number = line.split('{')[-1][:-2]
elif line.startswith("pages"):
pages = line.split('{')[-1][:-2]
elif line.startswith("year"):
year = line.split('{')[-1][:-2]
elif line.startswith("publisher"):
publisher = line.split('{')[-1][:-2]
elif line.startswith("author"):
authors = line[line.find("{")+1:line.rfind("}")]
for LastFirst in authors.split('and'):
lf = LastFirst.replace(' ', '').split(',')
if len(lf) != 2: continue
last, first = lf[0], lf[1]
output_authors.append("{}, {}.".format(last.capitalize(), first.capitalize()[0]))
i += 1
print("\\bibitem{%s}" % code)
if len(output_authors) == 1:
print(output_authors[0] + " {}. ".format(title),)
else:
print(", ".join(_ for _ in output_authors[:-1]) + " & " + output_authors[-1] + " {}. ".format(title),)
if venue:
print ("{{\\em {}}}.".format(" ".join([_.capitalize() for _ in venue.split(' ')])),)
if volume:
sys.stdout.write(" \\textbf{{{}}}".format(volume))
if pages:
sys.stdout.write(", {}".format(pages) if number else " pp. {}".format(pages))
if year:
sys.stdout.write(" ({})".format(year))
if publisher and not venue:
print("({},{})".format(publisher, year))
print
print
答案4
好吧,我使用这个 matlab 函数逐个自动转换,这样更容易完成工作。您可以从下载GitHub,下面是matlab函数。
function [bibitem] = bibtex2bibitemtv(bibtexpath)
path = bibtexpath;
cells = importdata(path);
A = string(cells);
n = length(cells);
K_name = strings(n,1);
citecode = extractBetween(A(1),'{',',');
SVacI = zeros(9,1); % Substyle Vacation Indicator.
for i = 2:1:n-1
rawleft = extractBefore(A(i),'=');
K_name(i) = strtrim(rawleft);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if strcmp(K_name(i),"author")
SVacI(1) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
author = strtrim(extractBetween(A(i),'{','}'));
else
author = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"title")
SVacI(2) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
title = strtrim(extractBetween(A(i),'{','}'));
else
title = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"journal")
SVacI(3) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
journal = strtrim(extractBetween(A(i),'{','}'));
else
journal = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"volume")
SVacI(4) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
volume = strtrim(extractBetween(A(i),'{','}'));
else
volume = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (strcmp(K_name(i),"number"))||(strcmp(K_name(i),"issue"))
SVacI(5) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
number = strtrim(extractBetween(A(i),'{','}'));
else
number = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"pages")
SVacI(6) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
pages = strtrim(extractBetween(A(i),'{','}'));
else
pages = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"month")
SVacI(7) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
month = strtrim(extractBetween(A(i),'{','}'));
else
month = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"year")
SVacI(8) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
year = strtrim(extractBetween(A(i),'{','}'));
else
year = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif strcmp(K_name(i),"publisher")
SVacI(9) = 1;
rawright = extractAfter(A(i),'=');
ccb = regexp(rawright,'}'); % ccb = [check curly bracket]
if (ccb~=0)
publisher = strtrim(extractBetween(A(i),'{','}'));
else
publisher = strtrim(extractBetween(A(i),'=',','));
end
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For adding new references sections.
else
msg = join(["Sorry!","[", K_name(i), "]","is not being handled by the program."]);
disp(msg)
end
end
% @-> Style reference term code varifications.
% msg = join(["author","=",SVacI(1);...
% "title","=",SVacI(2);...
% "journal","=",SVacI(3);...
% "volume","=",SVacI(4);...
% "number","=",SVacI(5);...
% "pages","=",SVacI(6);...
% "month","=",SVacI(7);...
% "year","=",SVacI(8);...
% "publisher","=",SVacI(9)]);
% disp(SVacI)
if (SVacI(1)==0)||(SVacI(2)==0)||(SVacI(3)==0)||(SVacI(8)==0)
bibitem = sprintf('THE ARTICLE IS NOT CORRECT. THE AUTHOR, TITLE, JOURNAL AND YEAR SECTIONS ARE COMPULSORY! PLEASE INCLUDE THEM AND RE-RUN THE SOFTWARE:)');
elseif all(SVacI == [1 1 1 0 0 0 0 1 0])
bibitem = sprintf(' \n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s},(%s). \n',citecode,author,title,journal,year);
elseif all(SVacI == [1 1 1 0 0 0 0 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s},(%s). %s.\n',citecode,author,title,journal,year,publisher);
elseif all(SVacI == [1 1 1 0 0 0 1 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s},(%s %s). \n',citecode,author,title,journal,month,year);
elseif all(SVacI == [1 1 1 0 0 0 1 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s},(%s %s). %s.\n',citecode,author,title,journal,month,year,publisher);
elseif all(SVacI == [1 1 1 0 0 1 0 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, pp. %s,(%s).\n',citecode,author,title,journal,pages,year);
elseif all(SVacI == [1 1 1 0 0 1 0 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, pp. %s,(%s). %s.\n',citecode,author,title,journal,pages,year,publisher);
elseif all(SVacI == [1 1 1 0 0 1 1 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, pp. %s,(%s %s).\n',citecode,author,title,journal,pages,month,year);
elseif all(SVacI == [1 1 1 0 0 1 1 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, pp. %s,(%s %s). %s.\n',citecode,author,title,journal,pages,month,year,publisher);
elseif all(SVacI == [1 1 1 0 1 0 0 1 0])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s,(%s).\n',citecode,author,title,journal,number,year);
elseif all(SVacI == [1 1 1 0 1 0 0 1 1])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s,(%s). %s.\n',citecode,author,title,journal,number,year,publisher);
elseif all(SVacI == [1 1 1 0 1 0 1 1 0])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s,(%s %s).\n',citecode,author,title,journal,number,month,year);
elseif all(SVacI == [1 1 1 0 1 0 1 1 1])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s,(%s %s). %s.\n',citecode,author,title,journal,number,month,year,publisher);
elseif all(SVacI == [1 1 1 0 1 1 0 1 0])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s, pp. %s,(%s).\n',citecode,author,title,journal,number,pages,year);
elseif all(SVacI == [1 1 1 0 1 1 0 1 1])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s, pp. %s,(%s). %s.\n',citecode,author,title,journal,number,pages,year,publisher);
elseif all(SVacI == [1 1 1 0 1 1 1 1 0])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s, pp. %s,(%s %s). %s.\n',citecode,author,title,journal,number,pages,month,year);
elseif all(SVacI == [1 1 1 0 1 1 1 1 1])
disp("Attention! THE VOLUME HAS TO BE ASSOCIATED WITH NUMBER, PLEASE CHECK!")
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s, pp. %s,(%s %s). %s.\n',citecode,author,title,journal,number,pages,month,year,publisher);
elseif all(SVacI == [1 1 1 1 1 0 0 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s),(%s).\n',citecode,author,title,journal,volume,number,year);
elseif all(SVacI == [1 1 1 1 1 0 0 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s),(%s). %s.\n',citecode,author,title,journal,volume,number,year,publisher);
elseif all(SVacI == [1 1 1 1 1 0 1 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s),(%s %s).\n',citecode,author,title,journal,volume,number,month,year);
elseif all(SVacI == [1 1 1 1 1 0 1 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s),(%s %s). %s.\n',citecode,author,title,journal,volume,number,month,year,publisher);
elseif all(SVacI == [1 1 1 1 1 1 0 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s), pp. %s,(%s).\n',citecode,author,title,journal,volume,number,pages,year);
elseif all(SVacI == [1 1 1 1 1 1 0 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s), pp. %s,(%s). %s.\n',citecode,author,title,journal,volume,number,pages,year,publisher);
elseif all(SVacI == [1 1 1 1 1 1 1 1 0])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s), pp. %s,(%s %s). %s.\n',citecode,author,title,journal,volume,number,pages,month,year);
elseif all(SVacI == [1 1 1 1 1 1 1 1 1])
bibitem = sprintf('\n \\bibitem{%s}\n %s.\n \\newblock {%s.} \n \\newblock {\\emph %s}, %s(%s), pp. %s,(%s %s). %s.\n',citecode,author,title,journal,volume,number,pages,month,year,publisher);
end
结尾 示例输入:
@article{thompson1990home,
title={In-home pasteurization of raw goat's milk by microwave treatment},
year={1990},
author={Thompson, J Stephen and Thompson, Annemarie},
journal={International journal of food microbiology},
volume={10},
number={1},
pages={59--64},
publisher={Elsevier}
}
示例输出:
\bibitem{lewis2009heat}
Lewis, MJ and Deeth, HC.
\newblock {Heat treatment of milk.}
\newblock {\emph Milk processing and quality management}, 3(193), pp. 168--204,(Jan. 2009). Wiley Online Library.