bibtex报错:! File ended while scanning use of \BR@@lbibitem.

2023-10-07 21:50

本文主要是介绍bibtex报错:! File ended while scanning use of \BR@@lbibitem.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

bibtex报错: File ended while scanning use of \BR@@lbibitem.

这是笔者遇到最离谱的报错了,能解决也全凭运气

特别感谢:https://blog.csdn.net/qw11er/article/details/126689699

笔者的环境:ubuntu20.04+ texlive + vscode + latex-workshop

出现的问题时使用\bibliography时根本显示不出来参考文献

警告也是说\cite找不到citation,

找了半天没有发现任何问题

问题解决:

首先需要排除是找不到文件的问题。
源文件名为myBib.bib
原命令为\bibliography{myBib}

将命令改为\bibliography{whereismyBib}
立即出现找不到bibdata的错误,说明不是找不到文件的问题

到底是什么问题,不使用vscode latex-workshop的插件,逐步编译看看:
在命令行分别输入
pdflatex script
biblatex script
pdflatex script
pdflatex script

在第三步:pdflatex script报出了题目所示的错误
而解决方法是,打开同目录下的bbl,\bibitem之间空行即可

空行能通过build的原理目前还不清楚,应该是bbl文件的LaTeX语法的问题
也就是说bibtex工具本身生成的bbl文件有问题,这里给出bibtex版本信息如下:
bibtex版本信息

如果要使用vscode 的插件latex-workshop重现这个问题,需要更改settings.json,这个部分:

"latex-workshop.latex.clean.fileTypes": ["*.aux","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gls","*.fls","*.log","*.fdb_latexmk","*.snm","*.synctex(busy)","*.synctex.gz(busy)","*.nav","*.vrb"]//去掉了"*.bbl"

去掉了"*.bbl",即设置latex-workshop不再删除这个中间文件
再点击build,可以看出vscode终于输出这个错误了,原先连报错都没有是真的折磨:
latex-workshop报错

永久解决这个问题:

根据上面的debug原理编写一个简单的python脚本如下:

import os
import subprocess
import argparse#---------------------传入参数设定----------------------------
parser = argparse.ArgumentParser(description='传入仿真参数')
parser.add_argument('--texDir', type=str, required=True)args = parser.parse_args()# --------------------检查传入参数-----------------------------
texDir = args.texDir
if type(texDir) != str:raise ValueError('texDir应是字符串')# -------------------开始修改bbl文件-------------------------
print('begin check and fix bbl process! ')file_names = os.listdir(texDir)
tex_name = ''
for name in file_names:if name[-4:] == '.tex':tex_name = name[:-4]breakelse:continueaux_file_name = tex_name + '.aux'
bbl_file_name = tex_name + '.bbl'file_content = ''
generate_aux_command = 'pdflatex '+tex_name
generate_bbl_command = 'bibtex ' + tex_nameif aux_file_name not in file_names:subprocess.call(generate_aux_command, shell=True)
if bbl_file_name not in file_names:subprocess.call(generate_bbl_command, shell=True)with open(texDir + '/{}'.format(bbl_file_name),'r+') as file_handle:file_content = file_handle.read()# check file content
if file_content == '':subprocess.call(generate_bbl_command, shell=True)# read file content again
with open(texDir + '/{}'.format(bbl_file_name),'r+') as file_handle:file_content = file_handle.read()# fix file content:
with open(texDir + '/{}'.format(bbl_file_name),'w+') as file_handle:if file_content.count('\n\n%Type = Article') == 0 and file_content.count('\n%Type = Article') != 0:file_content = file_content.replace('\n%Type = Article','\n\n%Type = Article')file_handle.write(file_content)


以及对vscode setttings.json进行更改
在tex文件目录下打开终端:

mkdir .vscode
cd vscode/
touch settings.json

修改settings.json如下:
(记得自行更改python脚本的绝对路径 “/absolute_directory/to/python_scirpt/fix_bbl.py”):

{"editor.codeActionsOnSave": {},"latex-workshop.latex.tools": [{"name": "latexmk","command": "latexmk","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","%DOCFILE%"]},{"name": "python","command": "python","args": ["/absolute_directory/to/python_scirpt/fix_bbl.py",//这个要根据自己的脚本路径自行更改!"--texDir=%DIR%"]},{"name": "xelatex","command": "xelatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},          {"name": "pdflatex","command": "pdflatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "bibtex","command": "bibtex","args": ["%DOCFILE%",]},],"latex-workshop.latex.clean.fileTypes": ["*.aux","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gls","*.fls","*.log","*.fdb_latexmk","*.snm","*.synctex(busy)","*.synctex.gz(busy)","*.nav","*.vrb"],"latex-workshop.latex.recipes": [{"name": "XeLaTeX","tools": ["xelatex"]},{"name": "PDFLaTeX","tools": ["pdflatex"]},{"name": "BibTeX","tools": ["bibtex"]},{"name": "LaTeXmk","tools": ["latexmk"]},{"name": "fixBBL","tools":["python"]},{"name": "xelatex -> bibtex -> xelatex*2","tools": ["xelatex","bibtex","python","xelatex","xelatex"]},{"name": "pdflatex -> bibtex -> pdflatex*2","tools": ["pdflatex","bibtex","python","pdflatex","pdflatex"]}],"files.associations": {"*.tex": "latex"},"[latex]": {"editor.formatOnPaste": false,"editor.suggestSelection": "recentlyUsedByPrefix"},"files.autoGuessEncoding": true,"[python]": {"editor.formatOnType": true}}

完成以后效果应该是这样子的:
完成效果
其中可以直接点击pdflatex->bibtex->pdflatex*2
问题解决~

这篇关于bibtex报错:! File ended while scanning use of \BR@@lbibitem.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/160641

相关文章

解决systemctl reload nginx重启Nginx服务报错:Job for nginx.service invalid问题

《解决systemctlreloadnginx重启Nginx服务报错:Jobfornginx.serviceinvalid问题》文章描述了通过`systemctlstatusnginx.se... 目录systemctl reload nginx重启Nginx服务报错:Job for nginx.javas

VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”问题

《VMWare报错“指定的文件不是虚拟磁盘“或“Thefilespecifiedisnotavirtualdisk”问题》文章描述了如何修复VMware虚拟机中出现的“指定的文件不是虚拟... 目录VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virt

使用Vue.js报错:ReferenceError: “Vue is not defined“ 的原因与解决方案

《使用Vue.js报错:ReferenceError:“Vueisnotdefined“的原因与解决方案》在前端开发中,ReferenceError:Vueisnotdefined是一个常见... 目录一、错误描述二、错误成因分析三、解决方案1. 检查 vue.js 的引入方式2. 验证 npm 安装3.

PHP执行php.exe -v命令报错的解决方案

《PHP执行php.exe-v命令报错的解决方案》:本文主要介绍PHP执行php.exe-v命令报错的解决方案,文中通过图文讲解的非常详细,对大家的学习或工作有一定的帮助,需要的朋友可以参考下... 目录执行phpandroid.exe -v命令报错解决方案执行php.exe -v命令报错-PHP War

CentOS系统使用yum命令报错问题及解决

《CentOS系统使用yum命令报错问题及解决》文章主要讲述了在CentOS系统中使用yum命令时遇到的错误,并提供了个人解决方法,希望对大家有所帮助,并鼓励大家支持脚本之家... 目录Centos系统使用yum命令报错找到文件替换源文件为总结CentOS系统使用yum命令报错http://www.cppc

提示:Decompiled.class file,bytecode version如何解决

《提示:Decompiled.classfile,bytecodeversion如何解决》在处理Decompiled.classfile和bytecodeversion问题时,通过修改Maven配... 目录问题原因总结问题1、提示:Decompiled .class file,China编程 bytecode

Jenkins 插件 地址证书报错问题解决思路

问题提示摘要: SunCertPathBuilderException: unable to find valid certification path to requested target...... 网上很多的解决方式是更新站点的地址,我这里修改了一个日本的地址(清华镜像也好),其实发现是解决不了上述的报错问题的,其实,最终拉去插件的时候,会提示证书的问题,几经周折找到了其中一遍博文

【Python报错已解决】AttributeError: ‘list‘ object has no attribute ‘text‘

🎬 鸽芷咕:个人主页  🔥 个人专栏: 《C++干货基地》《粉丝福利》 ⛺️生活的理想,就是为了理想的生活! 文章目录 前言一、问题描述1.1 报错示例1.2 报错分析1.3 解决思路 二、解决方法2.1 方法一:检查属性名2.2 步骤二:访问列表元素的属性 三、其他解决方法四、总结 前言 在Python编程中,属性错误(At

DBeaver 连接 MySQL 报错 Public Key Retrieval is not allowed

DBeaver 连接 MySQL 报错 Public Key Retrieval is not allowed 文章目录 DBeaver 连接 MySQL 报错 Public Key Retrieval is not allowed问题解决办法 问题 使用 DBeaver 连接 MySQL 数据库的时候, 一直报错下面的错误 Public Key Retrieval is

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef‘ of undefined“

vue 父组件调用子组件的方法报错,“TypeError: Cannot read property ‘subDialogRef’ of undefined” 最近用vue做的一个界面,引入了一个子组件,在父组件中调用子组件的方法时,报错提示: [Vue warn]: Error in v-on handler: “TypeError: Cannot read property ‘methods