[NTG-context] How to make something appear to the right of every paragraph?
Max Chernoff
mseven at telus.net
Fri Oct 14 02:50:42 CEST 2022
Hi Joel,
> When I use the code given, it compiles and displays fine. But when I
> try replacing \everypar with \EveryPar, it halts during compiling
It looks like \EveryPar is a macro and not a token list.
> These both work great, but do that for the whole document? Is there a
> way to restrict it to only apply the lines to some parts of the file,
> not every single paragraph?
Option 1:
\newif\ifprintlines
\EveryPar{%
\ifprintlines%
\vbox to 0pt{%
\dorecurse{3}{%
\rlap{%
\hskip\dimexpr\hsize+1em%
\vrule height 0.4pt width 3cm%
\relax%
}%
}%
}%
\fi%
}
\parskip=\baselineskip
\starttext
\printlinestrue
One line paragraph
Two line paragraph \\
Two line paragraph
Three line paragraph \\
Three line paragraph \\
Three line paragraph
\printlinesfalse
Four line paragraph \\
Four line paragraph \\
Four line paragraph \\
Four line paragraph
\samplefile{bryson}
\printlinestrue
\samplefile{knuth}
\stoptext
Option 2:
\startluacode
-- Constants
local RULE_OFFSET = tex.sp "1em"
local RULE_THICKNESS = tex.sp "0.4pt"
local RULE_LENGTH = tex.sp "3cm"
local show_lines = true
-- Callback
function userdata.lines(head)
if status.output_active or
tex.nest.ptr > 1 or
not show_lines
then
return head
end
local i = 0
for n in node.traverseid(node.id "hlist", head) do
i = i + 1
if i > 3 then
break
end
local offset = node.new "glue"
offset.width = RULE_OFFSET
node.slide(n.list).next = offset
local rule = node.new "rule"
rule.width = RULE_LENGTH
rule.height = RULE_THICKNESS
rule.depth = 0
offset.next = rule
end
return head
end
nodes.tasks.appendaction(
"finalizers",
"after",
"userdata.lines"
)
interfaces.implement {
name = "showlines",
public = true,
arguments = { "boolean" },
actions = function(x)
show_lines = x
end,
}
\stopluacode
\parskip=\baselineskip
\starttext
\showlines true
One line paragraph
Two line paragraph \\
Two line paragraph
Three line paragraph \\
Three line paragraph \\
Three line paragraph
\showlines false
Four line paragraph \\
Four line paragraph \\
Four line paragraph \\
Four line paragraph
\samplefile{bryson}
\showlines true
\samplefile{knuth}
\stoptext
These are both kind of hacky though. I'd recommend that you use Hans's
solution instead:
\starttext
\def\StartHack
{\margintext
[location=right,style=]
{\thinrules[n=3]}}
\def\StopHack
{\par \ifnum\prevgraf<3
\blank[\the\numexpr4-\prevgraf\relax*line]
\fi}
\StartHack \input tufte \StopHack
\StartHack test test \StopHack
\StartHack test test \StopHack
\stoptext
Thanks,
-- Max
More information about the ntg-context
mailing list