bibtex因openout_any=p拒绝编译

bug描述

我从MacTex2020升级到MacTex2024后,若编译时,将中间文件输出到./<临时文件夹>文件夹,且<临时文件夹>=.xxx(隐藏文件),则执行bibtex命令时,会报错:

bibtex: Not writing to .xxx/main.blg (openout_any = p; no  extended check).
I couldn't open file name `.xxx/main.blg'

最终./.xxx下生成的pdf中,所有引用都显示为[?],文章结尾没有引用文献列表。

出bug的场景

手动编译

# xelatex -> bibtex -> xelatex -> xelatex 

xelatex -output-directory=./.xxx main.tex
# 正常编译,临时文件都输出到 ./.xxx 

bibtex .xxx/main.tex 
# 或者 
TEXMFOUTPUT=./.xxx bibtex .xxx/main.tex
# 报错如下:
# bibtex: Not writing to .xxx/main.blg (openout_any = p; no  extended check).
# I couldn't open file name `.xxx/main.blg'

xelatex -output-directory=./.xxx main.tex
# 正常编译,临时文件都输出到 ./.xxx 
xelatex -output-directory=./.xxx main.tex
# 正常编译,临时文件都输出到 ./.xxx

Texifier/Texpad

勾选隐藏中间文件后,Texifier.app(原名Texpad.app)将中间文件输出到./.texpadtmp/(无法修改成其他目录)。

image-20250207042532556

并选择bibtex作为引用文献引擎

image-20250207042557241

编译时会报错如上。最终编译生成的pdf中,所有引用都显示为[?],文章结尾没有引用文献列表。

VSCode

手动设置vscode的配置文件(如下),让中间文件输出到./.vsclatextmp

在使用recipe latexmk 时能正常编译出引用文献,在使用recipepdflatex -> bibtex -> pdflatex*2xelatex -> bibtex -> xelatex*2bibtex时不能正常编译,会报错如上。最终编译生成的pdf中,所有引用都显示为[?],文章结尾没有引用文献列表。


"latex-workshop.latex.outDir": "%DIR%/.vsclatextmp", 
"latex-workshop.latex.tools": [
        {
            "name": "latexmkrc",
            "command": "touch",
            "args": [
                "%DIR%/latexmkrc"
            ]
        },
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-output-directory=%OUTDIR%", "-f",
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%DOCFILE%"
            ]
        }, {
            "name": "xelatex",
            "command": "xelatex",
            "args": [
                "-output-directory=%OUTDIR%",
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        }, {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-output-directory=%OUTDIR%",
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        }, {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                 "%OUTDIR%/%DOCFILE%"
            ],
            "env": { "TEXMFOUTPUT": "%OUTDIR%" }
        }
    ],
"latex-workshop.latex.recipes": [
        {
            "name": "latexmk",
            "tools": [
                "latexmkrc",
                "latexmk",
                "move_aux",
                "copy_pdf"
            ]
        }, {
            "name": "pdflatex -> bibtex -> pdflatex*2",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex",
                "copy_pdf"
            ]
        }, {
            "name": "xelatex -> bibtex -> xelatex*2",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex",
                "copy_pdf"
            ]
        }, {
            "name": "pdflatex",
            "tools": [
                "pdflatex",
                "copy_pdf"
            ]
        }, {
            "name": "xelatex",
            "tools": [
                "xelatex",
                "copy_pdf"
            ]
        }, {
            "name": "bibtex",
            "tools": [
                "bibtex"
            ]
        },
    ],

原因

MacTex升级后,增加了openout_any = p (默认值) 的限制,这限制 bibtex 的输出文件,只能写到当前工作目录,及其非隐藏子目录下。

解决方法

使用下面几个方法中任意一个,就能正常编译参考文献。

输出到非隐藏文件夹

适用于手动编译和vscode(因为Texifier.app/Texpad.app无法修改存放临时文件的文件夹名称,只能是.texpadtmp

改成<临时文件夹>=xxxx(非隐藏文件)

加环境变量openout_any

手动编译时,执行bibtex命令时,加上环境变量,即:

openout_any = a bibtex

在vscode中,配置文件中修改为:

{
      "name": "bibtex",
      "command": "bibtex",
      "args": [
           "%OUTDIR%/%DOCFILE%"
      ],
      "env": { "openout_any": "a" }
  }

全局设置openout_any

适用于任何使用场景,包括手动编译、vscode、texpad。

修改默认设置latex的全局设置,使openout_any = a

获得texmf.cnf路径

kpsewhich texmf.cnf
# 返回:
# /usr/local/texlive/2024/texmf.cnf

修改texmf.cnf (latex的全局配置):

sudo vim /usr/local/texlive/2024/texmf.cnf

向该文件中,添加一行openout_any = a (如果已经有openout_any = 某这行,就将这行改为openout_any = a)