如何将 LaTeX 警告视为错误 [英] How do I treat LaTeX warnings as errors

查看:48
本文介绍了如何将 LaTeX 警告视为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于 Windows 的 MiKTeX 2.8 发行版.

I am using the MiKTeX 2.8 distibution for Windows.

我们主要开发软件,并使用 LaTeX 来制作我们的用户说明.我们使用 LaTeX 是因为:

We develop software primarily, and use LaTeX to make our user instructions. We use LaTeX because:

  • 在源代码控制下跟踪更改等非常棒.
  • 与 Word 文档不同,源文件不会突然损坏.
  • 多个文档可以共享单个部分,因此我们可以将 DRY 原则应用于我们的文档,并避免某些文档与其他文档不同步.您可以在 Word 中拥有主文档,但我发现它们非常脆弱.

作为构建服务器上无人值守构建过程的一部分,我们使用 MiKTeX 的 texify 可执行文件构建文档.这很好用.

As a part of the unattended build process on our build server, we build the documentation using MiKTeX's texify executable. This works fairly well.

但是,当开发人员出错时会出现问题(例如,对不存在的 label 的 ef).诸如此类的错误只会在 LaTeX 中生成警告.texify 没有注意到警告,我们在文档中留下了错误.

However, problems occur when a developer makes an error (e.g. a ef to a label that doesn't exist). An error such as that only generates a warning in LaTeX. The warning goes unnoticed by texify, and we're left with errors in the documentation.

我目前有一个构建步骤,它扫描日志文件以查找以LaTeX 警告"开头的行,如果有的话,构建会失败.这行得通,但显然很不稳定,并且可能会让警告溜走.它目前不用于开发机器上的本地构建,但如果这是唯一的方法,我可能必须将它与我们当前使用的编辑器集成(TeXworks 与 MiKTeX 一起提供).

I currently have a build step which scans log files for lines beginning with 'LaTeX Warning' and fails the build if there are any. This works, but is obviously pretty flaky, and may let warnings slip through. It currently is not used on local builds on dev machines, but if that's the only way to do it, I may have to integrate it with the editor we're currently using (TeXworks shipped with MiKTeX).

如果出现任何警告(例如未定义的引用),我希望构建失败,并且我不想对日志文件进行片状扫描.有什么提供这个功能的吗?

I'd like to fail the build if any warnings such as an undefined reference occur, and I'd rather not do flaky scans of log files. Does anything offer this feature?

如果我可以在开发机器和构建服务器上的本地构建中使用此功能,那将是一个巨大的好处.

If I can use this feature in local builds on dev machines as well as on the build server it would be a huge bonus.

推荐答案

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

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.

这篇关于如何将 LaTeX 警告视为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆