You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用T1字体编码时TinyTeX因Latin1日志文件引发警告的问询

问题:T1编码下含重音字符的超宽hbox导致tinytex日志编码警告

现象描述

当UTF-8编码的TeX文件使用T1字体编码,且存在含重音字符的超宽hbox时,运行tinytex::latexmk()生成的日志文件为Latin1(ISO-8859-1)编码,触发tinytex抛出编码相关警告。

可复现示例

R代码运行输出

tinytex::latexmk("tiny.tex")
## [1] "tiny.pdf"
## Warning messages:
## 1: In xfun::read_utf8(log) :
##   The file tiny.log is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 51
## 2: In grep("^(LaTeX|Package [[:alnum:]]+) Warning:", x) :
##   unable to translate 'r/bx/n/10 vari-able di-cot<f3>mica\T1/cmr/m/n/10 . ' to a wide string
## 3: In grep("^(LaTeX|Package [[:alnum:]]+) Warning:", x) :
##   input string 51 is invalid

测试用TeX文件tiny.tex内容

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\begin{document}
\begin{itemize}
\item In this line we get an overfull hbox because the word \textbf{variable dicotómica}.
\end{itemize}
\end{document}

系统环境

  • R版本:4.3.1
  • tinytex版本:0.46
  • xfun版本:0.40
  • TeX环境:TeXLive 2023.20230613-3(系统自带,未安装TinyTeX发行版)
  • 操作系统:Debian/GNU Linux(测试版,区域设置en_US.UTF-8);Windows系统存在同类问题

临时解决方法

注释或删除\usepackage[T1]{fontenc},改用默认的OT1字体编码,此时超宽hbox的日志信息为ASCII编码,可避免警告。

疑问

是否有方法直接生成UTF-8编码的日志文件?或是需要tinytex通过读取字节并调用iconv()来处理编码不兼容问题?


解决方案建议

1. 生成UTF-8编码的日志文件

  • 切换LaTeX引擎:使用lualatex或xelatex编译文件,这两个引擎原生支持UTF-8,生成的日志文件也会是UTF-8编码,同时能很好地支持T1字体编码需求(或直接使用系统UTF-8字体)。
  • 设置编译参数:尝试给pdflatex传递编码相关参数,例如在调用tinytex::latexmk()时指定引擎参数:
    tinytex::latexmk("tiny.tex", engine_args = c("-encoding=utf8"))
    

2. 修改tinytex的日志读取逻辑

如果需要继续使用pdflatex,可以手动处理日志编码以避免警告:

  • 手动读取日志并转码:
    log_file <- "tiny.log"
    log_content <- iconv(readLines(log_file, encoding = "ISO-8859-1"), from = "ISO-8859-1", to = "UTF-8")
    
  • 若希望tinytex内置该处理,可优化xfun::read_utf8()的调用逻辑:当检测到UTF-8读取失败时,自动尝试用Latin1读取并转码为UTF-8。目前可通过自定义编译后的日志处理流程临时规避该问题。

内容的提问来源于stack exchange,提问作者Achim Zeileis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 22:43:24