我知道我可以使用\overfullrule=5pt
黑色标记来标记过满的线条。我正在使用 pdfLaTeX。有没有办法让我用洋红色代替这种标记或类似的东西?
答案1
Aditya 给出了一个非常好的、便携的解决方案(Patrick 的解决方案也很好,但便携性较差)。
我制作了一个名为 out of it 的小包overcolored
,目前可以找到在 github 上:
\documentclass[pagesize=pdftex,paper=10cm:10cm]{scrbook}
\usepackage{lipsum}
\usepackage[color=blue,
width=3pt,
height=0.5\baselineskip]{overcolored}
\begin{document}
\lipsum[1-3]
\end{document}
编辑: 我发现在复杂环境中使用 Aditya 的代码存在不少缺陷,而 Patrick 的代码则没有我能看到的任何副作用。因此,该软件包现在支持这两种实现。使用 LuaTeX 编译时,它将使用 Patrick 的代码,否则,将使用 Aditya 的代码。
我仍然需要调整选项以适应 Patrick 的代码。支持width
参数相当简单,高度有点棘手,而支持带有 PDF 注释的颜色名称似乎更加棘手……
答案2
我不确定使用老式的 TeX/pdfTeX 是否可以做到这一点,但使用 LuaTeX 可以(当然可以!)
\documentclass{article}
\usepackage{luatexbase,luacode}
\overfullrule 5pt
\begin{luacode}
local VLIST = node.id("vlist")
local HLIST = node.id("hlist")
local GLUE = node.id("glue")
local RULE = node.id("rule")
magentabox = function(head)
while head do
if head.id == VLIST or head.id == HLIST then
-- go through the hlists (the rows)
magentabox(head.head)
-- if there's a rule after the rightskip, this is the overfull box
-- node id 10 == glue, glue subtype 9 is rightskip, node id 2 is a rule
elseif head.id == GLUE and head.subtype == 9 and head.next and head.next.id == RULE then
-- this must be an overfull box
local w1, w2
w1 = node.new("whatsit","pdf_literal")
w1.data = "q 1 0 1 rg"
w1.mode = 1
w2 = node.new("whatsit","pdf_literal")
w2.data = " Q"
w2.mode = 1
w1.next = head.next -- the rule
head.next = w1 -- color start
w1.next.next = w2 -- color end
node.slide(head) -- adjust prev pointers
end
head = head.next
end
return true
end
luatexbase.add_to_callback("post_linebreak_filter",magentabox,"magentabox")
\end{luacode}
\begin{document}
\hsize 1.7in A verylongword verylongword verylongword
\end{document}
答案3
复制自TeX 珍珠作者:Paweł Jackowski。用他的话来说,永远不要低估 TeX 的花哨功能。
\def\ooops{\hbox to\wd0{\setbox0=\hbox to\wd0{\unhbox0}%
\unhbox0 \ifnum\badness>10000 \rlap{\tiny\quad Ooops!}\fi}}
\interlinepenalty=-50000 % force the break between each two lines
\maxdeadcycles=50 % allow upto 50 \outputs with no \shipout
\newtoks\orioutput \orioutput=\output % wrap the original \output routine
\output
{\ifnum\outputpenalty>-20000 \the\orioutput
\else \ifnum\outputpenalty<-\maxdimen \the\orioutput
\else
\unvbox255 % flush the entire list back
\setbox0=\lastbox % strip the very last box
\nointerlineskip % avoid doubled interline glue
\ooops % make the test and return the box back.
\advance\outputpenalty by50000
\penalty\outputpenalty % weak lie that nothing happened...
\fi\fi}
\documentclass{article}
\usepackage[textwidth=1.5in,a6paper]{geometry}
\begin{document}
\pagestyle{empty}
This completely useless example shows a not-so-useless trick, which might be
used for quite advanced applications, such as line-numbering, some kind of
paragraph decoration, page optimization and probably many others. Things become
much more complicated if math displays, \verb|\marks|, \verb|\inserts| or
\verb|\vadjusts| come into play, but they don-F¢t spoil all of the game.
\end{document}
这使
可以更改的定义,ooops
以给出彩色规则而不是文本。例如(感谢 Jake)
\def\ooops{\hbox to\wd0{\setbox0=\hbox to\wd0{\unhbox0}%
\unhbox0 \ifnum\badness>10000 \rlap{\color{magenta}{\rule{0.5em}{3ex}}}\fi}}
和加载xcolor
。
答案4
自从 topskip 给出 LuaTeX 解决方案以来,发生了很多事情。与我们相关的是新的回调hpack_quality
。只需关闭\overfullrule
并将 topskip 的 luatex 块替换为以下内容,调整b.width
和颜色以a.data
适应口味。此外,如果您更喜欢固定高度和宽度的 overfullrules,只需将它们分配给b.height
和b.depth
:
\begin{luacode}
ofbox = function(incident, detail, head, first, last)
if incident == "overfull" then
local a, b, c
b = node.new("rule",0)
b.width = tex.sp("1mm")
a = node.new("whatsit","pdf_literal")
a.data = "q 1 0 1 rg"
a.mode = 1
c = node.new("whatsit","pdf_literal")
c.data = " Q"
c.mode = 1
a.next = b
b.next = c
node.slide(a)
return a
end
end
luatexbase.add_to_callback("hpack_quality",ofbox,"ofbox")
\end{luacode}
这还具有处理过满显示数学运算的额外好处。