MacOS Ventura 13下TextMate编译LaTeX问题求助
解决MacOS 13 TextMate LaTeX Bundle Unicode解码错误
问题原因
parsing.py中的UTF-8解码逻辑无法处理LaTeX编译日志或源文件中的非UTF-8字节,导致解码失败。
修复方案
1. 修正parsing.py的编码读取方式
进入Bundle目录:
cd ~/Library/Application\ Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/bin
编辑parsing.py,找到所有文件读取代码,将默认UTF-8读取改为兼容模式:
- 把
open(..., 'r')改为open(..., 'r', encoding='latin-1')(latin-1能解码所有字节,不会抛出错误); - 或者添加错误处理:
open(..., 'r', encoding='utf-8', errors='ignore'),忽略无效UTF-8字节。
如果代码中有直接的字节解码操作(比如byte_str.decode('utf-8')),同样修改为byte_str.decode('utf-8', errors='ignore')或byte_str.decode('latin-1')。
2. 确认LaTeX源文件编码
- 在TextMate中打开
.tex文件,点击顶部状态栏的编码标签,确保选择UTF-8; - 若文件含特殊字符,重新保存为UTF-8编码:
File > Save As...,右下角编码选UTF-8。
3. 替换为更新的LaTeX Bundle
备份原Bundle后,克隆最新维护版本:
mv ~/Library/Application\ Support/TextMate/Managed/Bundles/LaTeX.tmbundle ~/Library/Application\ Support/TextMate/Managed/Bundles/LaTeX.tmbundle.bak git clone https://github.com/textmate/latex.tmbundle.git ~/Library/Application\ Support/TextMate/Managed/Bundles/LaTeX.tmbundle
重启TextMate后测试编译。
验证
修改后重新编译,若TeXShop正常则该方案应解决TextMate的适配问题。
内容的提问来源于stack exchange,提问作者Jimmy Roussel
相关产品推荐
相关产品推荐

