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

相关文章

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

Open a folder or workspace... (File -> Open Folder)

问题:vscode Open with Live Server 时 显示Open a folder or workspace... (File -> Open Folder)报错 解决:不可以单独打开文件1.html ; 需要在文件夹里打开 像这样

android java.io.IOException: open failed: ENOENT (No such file or directory)-api23+权限受权

问题描述 在安卓上,清单明明已经受权了读写文件权限,但偏偏就是创建不了目录和文件 调用mkdirs()总是返回false. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_E

bash: arm-linux-gcc: No such file or directory

ubuntu出故障重装了系统,一直用着的gcc使用不了,提示bash: arm-linux-gcc: No such file or directorywhich找到的命令所在的目录 在google上翻了一阵发现此类问题的帖子不多,后来在Freescale的的LTIB环境配置文档中发现有这么一段:     # Packages required for 64-bit Ubuntu

编译linux内核出现 arm-eabi-gcc: error: : No such file or directory

external/e2fsprogs/lib/ext2fs/tdb.c:673:29: warning: comparison between : In function 'max2165_set_params': -。。。。。。。。。。。。。。。。。。 。。。。。。。。。。。。。 。。。。。。。。 host asm: libdvm <= dalvik/vm/mterp/out/Inte

Vue3上传图片报错:Current request is not a multipart request

当你看到错误 "Current request is not a multipart request" 时,这通常意味着你的服务器或后端代码期望接收一个 multipart/form-data 类型的请求,但实际上并没有收到这样的请求。在使用 <el-upload> 组件时,如果你已经设置了 http-request 属性来自定义上传行为,并且遇到了这个错误,可能是因为你在发送请求时没有正确地设置

QT 编译报错:C3861: ‘tr‘ identifier not found

问题: QT 编译报错:C3861: ‘tr’ identifier not found 原因 使用tr的地方所在的类没有继承自 QObject 类 或者在不在某一类中, 解决方案 就直接用类名引用 :QObject::tr( )