![哪个 LaTeX 命令会打印有关“Overfull \hbox”的警告消息?](https://linux22.com/image/466555/%E5%93%AA%E4%B8%AA%20LaTeX%20%E5%91%BD%E4%BB%A4%E4%BC%9A%E6%89%93%E5%8D%B0%E6%9C%89%E5%85%B3%E2%80%9COverfull%20%5Chbox%E2%80%9D%E7%9A%84%E8%AD%A6%E5%91%8A%E6%B6%88%E6%81%AF%EF%BC%9F.png)
我想覆盖打印的命令Overfull \hbox...
,但似乎不是\GenericWarning
。它是什么?
答案1
这来自于 tex 引擎,在经典 TeX 中无法改变。
在 luatex 中有一个回调允许用任意 Lua 代码替换警告,所以在这里我用它来引发 tex 错误。
\documentclass{article}
\makeatletter
\directlua{
luatexbase.add_to_callback(
"hpack_quality",
function(i,d,h,f,l)
if(i=="overfull") then
tex.error("Overfull line: "..
string.format("\@percentchar.4f",d/65536,3) ..
"pt in paragraph lines " ..
f .. "-" .. l)
end
end,
"error on overfull hbox"
)
}
\makeatother
\begin{document}
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
One twoxxxxxxxxxxxxxx threexxxxxxxxxxxx four
One two xxxxxxxxxxxxxxthree xxxxxxxxxxxx four
One two xxxxxxxxxxxxxx three xxxxxxxxxxxx four
\begin{quote}
\rule{12cm}{1cm}
\end{quote}
\end{document}
产生三个错误:
! Overfull line: 5.4100pt in paragraph lines 22-40.
<argument> ...ype:D \tex_hskip:D \c_zero_dim \fi: \tex_par:D
\hook_use:n {para/after}\@...
l.40
?
! Overfull line: 7.9400pt in paragraph lines 22-40.
<argument> ...ype:D \tex_hskip:D \c_zero_dim \fi: \tex_par:D
\hook_use:n {para/after}\@...
l.40
?
! Overfull line: 46.4331pt in paragraph lines 42-43.
<argument> ...ype:D \tex_hskip:D \c_zero_dim \fi: \tex_par:D
\hook_use:n {para/after}\@...
l.43 \end{quote}
?