且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 LaTeX 警告视为错误

更新时间:2021-06-28 16:52:32

以下(未经测试的)代码应该将任何警告变成错误:

The following (untested) code should turn any warning into an error:


enewcommand{GenericWarning}[2]{GenericError{#1}{#2}{}{This warning has been turned into a fatal error.}}

那么你可能对 silence 包感兴趣过滤警告.

Then you may be interested in the silence package to filter warnings.

但是,您还需要安排仅在最后一次运行 LaTeX 时执行此操作,因为在第一次运行期间会出现一些警告,例如未定义的引用.

However you will also need to arrange to do this only for the last run of LaTeX, because some warnings such as undefined reference are to be expected during the first runs.

具有良好 LaTeX 支持的编辑器会告诉您是否需要重新运行 LaTeX(TeXworks 不这样做吗?).他们通过解析控制台输出或日志文件来做到这一点.它实际上相当健壮(如果您真的担心可以重新定义 GenericWarning 以向所有警告添加特征字符串).我认为解析日志是正确的方法.

Editors with good LaTeX support will tell you if you need to re-run LaTeX (doesn't TeXworks do it?). They do it by parsing the console output or the log file. It is in fact reasonably robust (and if you're really worried you could redefine GenericWarning to add a characteristic string to all warnings). I think parsing the logs is the right way to do it.

将此视为针对文档运行的测试.如果有未定义的引用,则文档构建成功.构建产品是 pdf(或其他)和 TeX 日志.检查日志中的警告是一项测试.

Think of this as a test to run against the documentation. If there are undefined references, the documentation build succeeds. The build products are the pdf (or whatever) and the TeX logs. Checking for warnings in the logs is a test.