Re: [NTG-context] How to make something appear to the right of every paragraph?
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 ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
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? Thanks! --Joel On Monday, October 10, 2022 at 04:57:07 PM MDT, Max Chernoff wrote: Hi Joel, On Mon, 2022-10-10 at 12:46 +, Joel wrote: > Hello Max, > It is preferred if the solution is just three lines per paragraph, > rather than some content parallel to the text A Lua callback solution: \startluacode -- Constants RULE_OFFSET = tex.sp "1em" RULE_THICKNESS = tex.sp "0.4pt" RULE_LENGTH = tex.sp "3cm" -- Callback function userdata.lines(head) if status.output_active or tex.nest.ptr > 1 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" ) \stopluacode \parskip=\baselineskip \starttext One line paragraph Two line paragraph \\ Two line paragraph Three line paragraph \\ Three line paragraph \\ Three line paragraph Four line paragraph \\ Four line paragraph \\ Four line paragraph \\ Four line paragraph \samplefile{bryson} \samplefile{knuth} \stoptext An \everypar solution: \appendtoks% \vbox to 0pt{% \dorecurse{3}{% \rlap{% \hskip\dimexpr\hsize+1em% \vrule height 0.4pt width 3cm% \relax% }% }% }% \to\everypar \parskip=\baselineskip \starttext One line paragraph Two line paragraph \\ Two line paragraph Three line paragraph \\ Three line paragraph \\ Three line paragraph Four line paragraph \\ Four line paragraph \\ Four line paragraph \\ Four line paragraph \samplefile{bryson} \samplefile{knuth} \stoptext Neither of these solutions are great though. Both of these solutions are pretty low-level, so there's presumably a more ConTeXt-y way of doing this. Thanks, -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
When I use the code given, it compiles and displays fine. But when I try replacing \everypar with \EveryPar, it halts during compiling with this complaint: "A number should have been here; I inserted '0'. (If you can't figure out why I needed to see a number, look up 'weird error' in the index to The TeXbook.) mtx-context | fatal error: return code: 1 " On Monday, October 10, 2022 at 09:58:11 PM MDT, Wolfgang Schuster wrote: Max Chernoff via ntg-context schrieb am 11.10.2022 um 00:57: > Hi Joel, > > On Mon, 2022-10-10 at 12:46 +, Joel wrote: >> Hello Max, >> It is preferred if the solution is just three lines per paragraph, >> rather than some content parallel to the text > A Lua callback solution: > > [...] > > An \everypar solution: > > \appendtoks% > \vbox to 0pt{% > \dorecurse{3}{% > \rlap{% > \hskip\dimexpr\hsize+1em% > \vrule height 0.4pt width 3cm% > \relax% > }% > }% > }% > \to\everypar You can use the \EveryPar register but \everypar is off limits. Wolfgang ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
On 10/10/2022 12:12 AM, Joel via ntg-context wrote: I'd like to add some area for readers to write in the margins of some text. This would leave three lines, like this to the right of the text. __ __ __ The passage would take up about the left 60% of the text and the margin note space about 30% of textwidth, so no need to use the margins. Though its easy for me to implement this code using some \thinrules and manually dropping macros in the text, is there some way ConTeXt can be told to just add them to right of every paragraph (at the start of the paragraph)? Sample: This is some text that is written in the passage and you can see the th- ree lines to the right. The text in the para- graph continues even though there are just three lines to the right. Here is another par- agraph. Here is yet another paragraph. You can see it also has the three liens. This is just for a segment of the book, not every paragraph in the book. \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 -- - Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl - ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
Max Chernoff via ntg-context schrieb am 11.10.2022 um 00:57: Hi Joel, On Mon, 2022-10-10 at 12:46 +, Joel wrote: Hello Max, It is preferred if the solution is just three lines per paragraph, rather than some content parallel to the text A Lua callback solution: [...] An \everypar solution: \appendtoks% \vbox to 0pt{% \dorecurse{3}{% \rlap{% \hskip\dimexpr\hsize+1em% \vrule height 0.4pt width 3cm% \relax% }% }% }% \to\everypar You can use the \EveryPar register but \everypar is off limits. Wolfgang ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
Hi Joel, On Mon, 2022-10-10 at 12:46 +, Joel wrote: > Hello Max, > It is preferred if the solution is just three lines per paragraph, > rather than some content parallel to the text A Lua callback solution: \startluacode -- Constants RULE_OFFSET= tex.sp "1em" RULE_THICKNESS = tex.sp "0.4pt" RULE_LENGTH= tex.sp "3cm" -- Callback function userdata.lines(head) if status.output_active or tex.nest.ptr > 1 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" ) \stopluacode \parskip=\baselineskip \starttext One line paragraph Two line paragraph \\ Two line paragraph Three line paragraph \\ Three line paragraph \\ Three line paragraph Four line paragraph \\ Four line paragraph \\ Four line paragraph \\ Four line paragraph \samplefile{bryson} \samplefile{knuth} \stoptext An \everypar solution: \appendtoks% \vbox to 0pt{% \dorecurse{3}{% \rlap{% \hskip\dimexpr\hsize+1em% \vrule height 0.4pt width 3cm% \relax% }% }% }% \to\everypar \parskip=\baselineskip \starttext One line paragraph Two line paragraph \\ Two line paragraph Three line paragraph \\ Three line paragraph \\ Three line paragraph Four line paragraph \\ Four line paragraph \\ Four line paragraph \\ Four line paragraph \samplefile{bryson} \samplefile{knuth} \stoptext Neither of these solutions are great though. Both of these solutions are pretty low-level, so there's presumably a more ConTeXt-y way of doing this. Thanks, -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
Hello Max, It is preferred if the solution is just three lines per paragraph, rather than some content parallel to the text...I'll be modifying whatever solution to fix a bunch of other situations (e.g. display a box next to each paragraph). --Joel On Monday, October 10, 2022 at 12:24:03 AM MDT, Max Chernoff wrote: Hi Joel, > I'd like to add some area for readers to write in the margins of some > text. This would leave three lines, like this to the right of the > text. Is it okay if there are rules continuously down the right column? If so, this is fairly simple to do with layers/backgrounds + MetaFun. If you want for there to be exactly three rules per paragraph, then that is more complicated. I can think of some bad solutions (\everypar, Lua callbacks), but I'll leave it to someone else to think of a good solution. Thanks, -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
Re: [NTG-context] How to make something appear to the right of every paragraph?
Hi Joel, > I'd like to add some area for readers to write in the margins of some > text. This would leave three lines, like this to the right of the > text. Is it okay if there are rules continuously down the right column? If so, this is fairly simple to do with layers/backgrounds + MetaFun. If you want for there to be exactly three rules per paragraph, then that is more complicated. I can think of some bad solutions (\everypar, Lua callbacks), but I'll leave it to someone else to think of a good solution. Thanks, -- Max ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___
[NTG-context] How to make something appear to the right of every paragraph?
I'd like to add some area for readers to write in the margins of some text. This would leave three lines, like this to the right of the text. __ The passage would take up about the left 60% of the text and the margin note space about 30% of textwidth, so no need to use the margins. Though its easy for me to implement this code using some \thinrules and manually dropping macros in the text, is there some way ConTeXt can be told to just add them to right of every paragraph (at the start of the paragraph)? Sample: This is some text that is written in the passage and you can see the th-ree lines to the right.The text in the para-graph continues eventhough there arejust three lines tothe right. Here is another par- agraph. Here is yet another paragraph. You can see it also has the three liens. This is just for a segment of the book, not every paragraph in the book. --Joel ___ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context webpage : https://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : https://contextgarden.net ___