
我做了一個實驗,發現-interaction=batchmode
與 lualatex 一起使用可以最大程度地減少我擁有的一個大型乳膠檔案的編譯時間。從 77 分鐘縮短到 45 分鐘。全部運行在 Linux WSL-2 Ubuntu 20.04 上。這甚至比使用(55 分鐘)更快,lualatex foo.tex >/dev/null
因為輸出直接從來源消除,甚至不需要將輸出重定向到/dev/null
http://latexref.xyz/Command-line-options.html
因此我想更改我的 Makefiles 以使用它。最大的問題是,當錯誤發生時,我不再在螢幕上看到錯誤。一切都會記錄到日誌檔案中。
有沒有辦法使用-interaction=batchmode
但讓它停止和在螢幕上顯示錯誤?否則,我現在每次都必須打開日誌檔案來查找檔案編譯時是否有錯誤。
這是不切實際的,因為我有數十萬個 Latex 檔案需要編譯,我需要在錯誤發生時停下來查看錯誤訊息,而不是稍後。
這是一個有錯誤的 MWE
\documentclass{report}%
\begin{document}
This is a test
\sin x
\end{document}
現在
>lualatex -interaction=batchmode foo.tex
This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)
restricted system commands enabled.
>
螢幕上沒有任何顯示。該錯誤確實顯示在日誌檔案中。我也嘗試過
>lualatex -halt-on-error -interaction=batchmode foo.tex
This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)
restricted system commands enabled.
>
有沒有辦法讓批次模式在螢幕上顯示編譯錯誤然後停止?
我只使用 Lualatex。
更新
多虧了提示,檢查 Lualatex 的存在狀態就可以確定它是否成功完成。無需查看日誌檔。
答案1
If you only want to determine if an error happened or not, you can look at the exit status of the lualatex
command: It will be 0 if no error happened, otherwise it will be 1. In case of an error you can then look into the記錄檔.
如果你想直接查看錯誤,你也可以使用 Lua 回呼。
建立一個文件,mybatchmode.lua
其中包含
texconfig.interaction = 0 -- Activate batchmode
texconfig.halt_on_error = true -- Stop at first error
callback.register('show_error_message', function(...)
texio.write_nl('term and log', status.lasterrorstring)
texio.write('term', '.\n')
end)
callback.register('show_lua_error_hook', function(...)
texio.write_nl('term and log', status.lastluaerrorstring)
texio.write('term', '.\n')
end)
然後運行
lualatex -lua=mybatchmode.lua file
對於您問題中的範例文件,這將導致
This is LuaHBTeX, Version 1.15.0 (TeX Live 2022)
restricted system commands enabled.
! Missing $ inserted.
答案2
您可以使用
lualatex --interaction=batchmode file || cat file.log
所以它只顯示登入錯誤