How can I remove a blank leading line from a buffer
%% How can one remove blank lines at the start of a buffer so that %% commands that grab a buffer can be used in the same way as, for %% example, \startparagraph...\stopparagraph, which allow blank %% lines around the content? %% %% The problem appears when an optional argument is allowed but none %% is provided. Adding \relax does not help; adding empty brackets %% does. I see no way to distinguish between a buffer without %% leading blank lines and a buffer that was created when brackets %% are provided. %% %% \inlinebuffer handles the leading blank lines when there is %% nothing prepended, but I need to prepend. (It also handles the %% unwanted trailing line, but that is not an issue here). %% %% How can I unpack the buffer, apply the equivalent functions of %% ignorespaspaces and removeunwantedspaces to it, and repack it? %% The buffer may contain internal blank lines and macros, and %% those should be retained. Or, is there already a function to %% strip a buffer in the manner that string.strip does a string? \setupwhitespace[none] \setupindenting[none] \define\Mark{\color[middlegray]{\itb¿\ }} \define\First{nothing yet} \define\Arg{nothing yet} \setuplanguage[en][spacing=packed] \starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition \starttexdefinition dostartBufTest [#SETUPS] \doifsomethingelse{#{SETUPS}} {\define\Arg{yes}} {\define\Arg{no}} \iffirstargument \define\First{yes} \else \define\First{no} \fi \relax \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition \starttexdefinition stopBufTest \startparagraph \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg) \stopparagraph \egroup \stoptexdefinition \starttext \startparagraph A starting paragraph. \stopparagraph \startBufTest Buffer without blank lines. \stopBufTest \startparagraph An intervening paragraph. \stopparagraph \startBufTest Buffer with blank lines. \stopBufTest \startparagraph An intervening paragraph. \stopparagraph \startBufTest\relax Buffer with \tex{relax}. \stopBufTest \startparagraph An intervening paragraph. \stopparagraph \startBufTest[] Buffer with \type{[]}. \stopBufTest \startparagraph An intervening paragraph. \stopparagraph \startBufTest[key=value] Buffer with \type{[key=value]}. \stopBufTest \startparagraph A closing paragraph. \stopparagraph \stoptext \stopmode %% -- %% Rik Kabel
On Sun, 12 Aug 2018, Rik Kabel wrote:
%% How can one remove blank lines at the start of a buffer so that %% commands that grab a buffer can be used in the same way as, for %% example, \startparagraph...\stopparagraph, which allow blank %% lines around the content? %% %% The problem appears when an optional argument is allowed but none %% is provided. Adding \relax does not help; adding empty brackets %% does. I see no way to distinguish between a buffer without %% leading blank lines and a buffer that was created when brackets %% are provided. %% %% \inlinebuffer handles the leading blank lines when there is %% nothing prepended, but I need to prepend. (It also handles the %% unwanted trailing line, but that is not an issue here). %% %% How can I unpack the buffer, apply the equivalent functions of %% ignorespaspaces and removeunwantedspaces to it, and repack it? %% The buffer may contain internal blank lines and macros, and %% those should be retained. Or, is there already a function to %% strip a buffer in the manner that string.strip does a string?
\setupwhitespace[none] \setupindenting[none] \define\Mark{\color[middlegray]{\itb¿\ }} \define\First{nothing yet} \define\Arg{nothing yet} \setuplanguage[en][spacing=packed]
\starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition
\starttexdefinition dostartBufTest [#SETUPS] \doifsomethingelse{#{SETUPS}} {\define\Arg{yes}} {\define\Arg{no}} \iffirstargument \define\First{yes} \else \define\First{no} \fi \relax \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition
\starttexdefinition stopBufTest
\startparagraph
\dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg)
\stopparagraph
\egroup \stoptexdefinition
\starttext
\startparagraph
A starting paragraph.
\stopparagraph
\startBufTest Buffer without blank lines. \stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest
Buffer with blank lines.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest\relax
Buffer with \tex{relax}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[]
Buffer with \type{[]}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[key=value]
Buffer with \type{[key=value]}.
\stopBufTest
\startparagraph
A closing paragraph.
\stopparagraph
\stoptext
\stopmode
Perhaps \ignorespaces might work, but I often find that the conceptually simplest solution is to post-process the buffer at the lua end. See http://wiki.contextgarden.net/Programming_in_LuaTeX#Manipulating_verbatim_te... for an example. Aditya
On 13/08/18 15:18, Rik Kabel wrote:
%% How can one remove blank lines at the start of a buffer so that %% commands that grab a buffer can be used in the same way as, for %% example, \startparagraph...\stopparagraph, which allow blank %% lines around the content? %% %% The problem appears when an optional argument is allowed but none %% is provided. Adding \relax does not help; adding empty brackets %% does. I see no way to distinguish between a buffer without %% leading blank lines and a buffer that was created when brackets %% are provided. %% %% \inlinebuffer handles the leading blank lines when there is %% nothing prepended, but I need to prepend. (It also handles the %% unwanted trailing line, but that is not an issue here). %% %% How can I unpack the buffer, apply the equivalent functions of %% ignorespaspaces and removeunwantedspaces to it, and repack it? %% The buffer may contain internal blank lines and macros, and %% those should be retained. Or, is there already a function to %% strip a buffer in the manner that string.strip does a string?
\setupwhitespace[none] \setupindenting[none] \define\Mark{\color[middlegray]{\itb¿\ }} \define\First{nothing yet} \define\Arg{nothing yet} \setuplanguage[en][spacing=packed]
\starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition
\starttexdefinition dostartBufTest [#SETUPS] \doifsomethingelse{#{SETUPS}} {\define\Arg{yes}} {\define\Arg{no}} \iffirstargument \define\First{yes} \else \define\First{no} \fi \relax \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition
\starttexdefinition stopBufTest
\startparagraph
% Ignore first \par \def\par{\let\par\normalpar}
\dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg)
\stopparagraph
\egroup \stoptexdefinition
\starttext
\startparagraph
A starting paragraph.
\stopparagraph
\startBufTest Buffer without blank lines. \stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest
Buffer with blank lines.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest\relax
Buffer with \tex{relax}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[]
Buffer with \type{[]}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[key=value]
Buffer with \type{[key=value]}.
\stopBufTest
\startparagraph
A closing paragraph.
\stopparagraph
\stoptext
\stopmode
%% -- %% Rik Kabel
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On 8/13/2018 5:46 AM, Henri Menke wrote:
% Ignore first \par \def\par{\let\par\normalpar} Sort of dangerous ... redefining such core commands or primitives can have side effects as one never knows what explicit \par's are issued.
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 8/13/2018 5:18 AM, Rik Kabel wrote:
%% How can one remove blank lines at the start of a buffer so that %% commands that grab a buffer can be used in the same way as, for %% example, \startparagraph...\stopparagraph, which allow blank %% lines around the content? %% %% The problem appears when an optional argument is allowed but none %% is provided. Adding \relax does not help; adding empty brackets %% does. I see no way to distinguish between a buffer without %% leading blank lines and a buffer that was created when brackets %% are provided. %% %% \inlinebuffer handles the leading blank lines when there is %% nothing prepended, but I need to prepend. (It also handles the %% unwanted trailing line, but that is not an issue here). %% %% How can I unpack the buffer, apply the equivalent functions of %% ignorespaspaces and removeunwantedspaces to it, and repack it? %% The buffer may contain internal blank lines and macros, and %% those should be retained. Or, is there already a function to %% strip a buffer in the manner that string.strip does a string?
\setupwhitespace[none] \setupindenting[none] \define\Mark{\color[middlegray]{\itb¿\ }} \define\First{nothing yet} \define\Arg{nothing yet} \setuplanguage[en][spacing=packed]
\starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition
\starttexdefinition dostartBufTest [#SETUPS] \doifsomethingelse{#{SETUPS}} {\define\Arg{yes}} {\define\Arg{no}} \iffirstargument \define\First{yes} \else \define\First{no} \fi \relax \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition
\starttexdefinition stopBufTest
\startparagraph
\dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg)
\stopparagraph
\egroup \stoptexdefinition
\starttext
\startparagraph
A starting paragraph.
\stopparagraph
\startBufTest Buffer without blank lines. \stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest
Buffer with blank lines.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest\relax
Buffer with \tex{relax}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[]
Buffer with \type{[]}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[key=value]
Buffer with \type{[key=value]}.
\stopBufTest
\startparagraph
A closing paragraph.
\stopparagraph
\stoptext
\startparagraph % \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] % \ (first: \First, arg: \Arg) \margintext{\Mark} \setupparagraphintro[first][(first: \First, arg: \Arg)] %\setupparagraphintro[next][(first: \First, arg: \Arg)] \getbuffer[TestBuffer] \stopparagraph ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 8/13/2018 03:01, Hans Hagen wrote:
On 8/13/2018 5:18 AM, Rik Kabel wrote:
%% How can one remove blank lines at the start of a buffer so that %% commands that grab a buffer can be used in the same way as, for %% example, \startparagraph...\stopparagraph, which allow blank %% lines around the content? %% %% The problem appears when an optional argument is allowed but none %% is provided. Adding \relax does not help; adding empty brackets %% does. I see no way to distinguish between a buffer without %% leading blank lines and a buffer that was created when brackets %% are provided. %% %% \inlinebuffer handles the leading blank lines when there is %% nothing prepended, but I need to prepend. (It also handles the %% unwanted trailing line, but that is not an issue here). %% %% How can I unpack the buffer, apply the equivalent functions of %% ignorespaspaces and removeunwantedspaces to it, and repack it? %% The buffer may contain internal blank lines and macros, and %% those should be retained. Or, is there already a function to %% strip a buffer in the manner that string.strip does a string?
\setupwhitespace[none] \setupindenting[none] \define\Mark{\color[middlegray]{\itb¿\ }} \define\First{nothing yet} \define\Arg{nothing yet} \setuplanguage[en][spacing=packed]
\starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition
\starttexdefinition dostartBufTest [#SETUPS] \doifsomethingelse{#{SETUPS}} {\define\Arg{yes}} {\define\Arg{no}} \iffirstargument \define\First{yes} \else \define\First{no} \fi \relax \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition
\starttexdefinition stopBufTest
\startparagraph
\dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg)
\stopparagraph
\egroup \stoptexdefinition
\starttext
\startparagraph
A starting paragraph.
\stopparagraph
\startBufTest Buffer without blank lines. \stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest
Buffer with blank lines.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest\relax
Buffer with \tex{relax}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[]
Buffer with \type{[]}.
\stopBufTest
\startparagraph
An intervening paragraph.
\stopparagraph
\startBufTest[key=value]
Buffer with \type{[key=value]}.
\stopBufTest
\startparagraph
A closing paragraph.
\stopparagraph
\stoptext
\startparagraph
% \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] % \ (first: \First, arg: \Arg)
\margintext{\Mark}
\setupparagraphintro[first][(first: \First, arg: \Arg)] %\setupparagraphintro[next][(first: \First, arg: \Arg)]
\getbuffer[TestBuffer]
\stopparagraph
Hans, That works for the over-simplified case here, but fails in practice. For a \startnarrower[left] paragraph, the mark is still in the main margin, not the 'margin' of the narrowed paragraph. Also, the placement of the text in the margin is wrong and not easily controlled as with \llap and \rlap. The code started out more like: \define\Mark{\color[middlegray]{\hskip.6cm\itb¿\ }} \setwidthof{\Mark}\to\MarkWidth ... \starttexdefinition stopBufTest \startluacode buffers.prepend("TestBuffer","\\dontleavehmode\\llap{\\Mark}") \stopluacode \setupnarrower[left=\MarkWidth] \startnarrower[left,right] \startparagraph \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition So I am still looking for a way to do this. Meanwhile I am trying to understand Aditya's examples. -- Rik
Rik Kabel schrieb am 13.08.18 um 16:28:
Hans,
That works for the over-simplified case here, but fails in practice. For a \startnarrower[left] paragraph, the mark is still in the main margin, not the 'margin' of the narrowed paragraph. Also, the placement of the text in the margin is wrong and not easily controlled as with \llap and \rlap. The code started out more like:
\define\Mark{\color[middlegray]{\hskip.6cm\itb¿\ }} \setwidthof{\Mark}\to\MarkWidth ... \starttexdefinition stopBufTest \startluacode buffers.prepend("TestBuffer","\\dontleavehmode\\llap{\\Mark}") \stopluacode \setupnarrower[left=\MarkWidth] \startnarrower[left,right] \startparagraph \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
Hi Rik, what do you want to achieve and why do you need a buffer for it? Wolfgang
On 8/13/2018 12:04, Wolfgang Schuster wrote:
Hi Rik,
what do you want to achieve and why do you need a buffer for it?
Wolfgang
Fair question. I have a document with many (400+) block quotations. Each consists of a text extract, which may be prose or poetry, and additional optional components (alternate versions or transliterations, translations, attribution). The optional components are distinguished typographically – enlarged square brackets around alternate versions, enlarged parentheses around translations, leading en-dash and hanging indent for attributions. Each component is in a buffer. The structure looks like: \startBlockQuotation[label=abc,authors={...},precis={short extract},translators={...},tprecis={{short extract},{short extract}}...] \startExtract[language=agr,align=yes,font=abc,tolerance=...,...] text of extract \stopExtract \startTransliteration[language=en,align=yes,font=abc,...] text of transliteration \stopTransliteration \startTranslation[...] text of translation \stopTranslation \startAttribution[tolerance=,...] attribution of quotation \stopAttribution \stopBlockQuotation and the code to handle it generates author index entries, a quotation precis index, and so on from the attributes of the envelope, and typesets each component based on the provided settings or defaults, placing the appropriate decorations around those components that call for them. The components are nestable, so one extract may contain another, and components can be used separately without the envelope (\startBlockQuotation or \startEpigraph) as well. (I have written it this way to ease the move to an XML-based format for storing the quotations. I realize I am combining presentation elements, like label, tolerance, and precis, and content elements, like language, and some that may be either, like align and font, in the attributes, but will deal with that later.) I prefer to leave blank lines around blocks of text and around macro commands, so: \startparagraph some text \stopparagraph but when this is done with, for example, \startAttribution, and no optional arguments are provided, I run into the problem I have described. I realize that I can simply not include the blank line after \startAttribution. I would prefer, however, to see consistent parallel structures without having to distinguish them at the time it is written. Perhaps I am being too picky, but that is what I am attempting. At this point, the \setupparagraphintro hack handles my needs, so I will proceed with that. -- Rik
Rik Kabel schrieb am 13.08.18 um 19:09:
On 8/13/2018 12:04, Wolfgang Schuster wrote:
Hi Rik,
what do you want to achieve and why do you need a buffer for it?
Wolfgang
Fair question.
I have a document with many (400+) block quotations. Each consists of a text extract, which may be prose or poetry, and additional optional components (alternate versions or transliterations, translations, attribution). The optional components are distinguished typographically – enlarged square brackets around alternate versions, enlarged parentheses around translations, leading en-dash and hanging indent for attributions. Each component is in a buffer. The structure looks like:
\startBlockQuotation[label=abc,authors={...},precis={short extract},translators={...},tprecis={{short extract},{short extract}}...]
\startExtract[language=agr,align=yes,font=abc,tolerance=...,...]
text of extract
\stopExtract
\startTransliteration[language=en,align=yes,font=abc,...]
text of transliteration
\stopTransliteration
\startTranslation[...]
text of translation
\stopTranslation
\startAttribution[tolerance=,...]
attribution of quotation
\stopAttribution
\stopBlockQuotation
and the code to handle it generates author index entries, a quotation precis index, and so on from the attributes of the envelope, and typesets each component based on the provided settings or defaults, placing the appropriate decorations around those components that call for them. The components are nestable, so one extract may contain another, and components can be used separately without the envelope (\startBlockQuotation or \startEpigraph) as well.
(I have written it this way to ease the move to an XML-based format for storing the quotations. I realize I am combining presentation elements, like label, tolerance, and precis, and content elements, like language, and some that may be either, like align and font, in the attributes, but will deal with that later.)
I prefer to leave blank lines around blocks of text and around macro commands, so:
\startparagraph
some text
\stopparagraph
but when this is done with, for example, \startAttribution, and no optional arguments are provided, I run into the problem I have described.
Try to avoid blank lines at the begin/end of environments.
I realize that I can simply not include the blank line after \startAttribution. I would prefer, however, to see consistent parallel structures without having to distinguish them at the time it is written. Perhaps I am being too picky, but that is what I am attempting.
At this point, the \setupparagraphintro hack handles my needs, so I will proceed with that.
\starttext \BeforePar{\dontleavehmode\llap{? }}\GotoPar \input knuth \startnarrower \BeforePar{\dontleavehmode\llap{? }}\GotoPar \input knuth \stopnarrower \stoptext Wolfgang
On 8/13/2018 13:46, Wolfgang Schuster wrote:
\starttext
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\startnarrower
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\stopnarrower
\stoptext
Wolfgang
I am applying it incorrectly, or it does not work with the buffers created by \grabbufferdata: \setupwhitespace[none] \setupindenting[none] \starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition \starttexdefinition dostartBufTest [#SETUPS] \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \BeforePar{\dontleavehmode\llap{? }}\GotoPar \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition \starttext \startBufTest Buffer without blank lines. \stopBufTest \startBufTest Buffer with blank lines. \stopBufTest \startBufTest[key=value] Buffer with \type{[key=value]}. \stopBufTest \stoptext -- Rik
Rik Kabel schrieb am 13.08.18 um 20:27:
On 8/13/2018 13:46, Wolfgang Schuster wrote:
\starttext
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\startnarrower
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\stopnarrower
\stoptext
Wolfgang
I am applying it incorrectly, or it does not work with the buffers created by \grabbufferdata:
\setupwhitespace[none] \setupindenting[none] \starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition \starttexdefinition dostartBufTest [#SETUPS] \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \BeforePar{\dontleavehmode\llap{? }}\GotoPar \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
\starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \dontleavehmode\llap{? }% \blank[overlay] \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition Wolfgang
On 8/13/2018 15:52, Wolfgang Schuster wrote:
Rik Kabel schrieb am 13.08.18 um 20:27:
On 8/13/2018 13:46, Wolfgang Schuster wrote:
\starttext
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\startnarrower
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\stopnarrower
\stoptext
Wolfgang
I am applying it incorrectly, or it does not work with the buffers created by \grabbufferdata:
\setupwhitespace[none] \setupindenting[none] \starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition \starttexdefinition dostartBufTest [#SETUPS] \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \BeforePar{\dontleavehmode\llap{? }}\GotoPar \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
\starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \dontleavehmode\llap{? }% \blank[overlay] \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
Wolfgang
Thank you, Wolfgang. That does it. Note that the % escaping the line end is not needed ( although it might be needed outside a \starttexdefinition environment) – the following works as well: \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \dontleavehmode{\llap{? }} \blank[overlay] \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition -- Rik
On 8/13/2018 18:43, Rik Kabel wrote:
On 8/13/2018 15:52, Wolfgang Schuster wrote:
Rik Kabel schrieb am 13.08.18 um 20:27:
On 8/13/2018 13:46, Wolfgang Schuster wrote:
\starttext
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\startnarrower
\BeforePar{\dontleavehmode\llap{? }}\GotoPar
\input knuth
\stopnarrower
\stoptext
Wolfgang
I am applying it incorrectly, or it does not work with the buffers created by \grabbufferdata:
\setupwhitespace[none] \setupindenting[none] \starttexdefinition unexpanded startBufTest \bgroup \dosingleempty\dostartBufTest \stoptexdefinition \starttexdefinition dostartBufTest [#SETUPS] \getrawparameters[BufTest][xx=yy,#SETUPS] \grabbufferdata[TestBuffer][startBufTest][stopBufTest] \stoptexdefinition \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \BeforePar{\dontleavehmode\llap{? }}\GotoPar \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
\starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \dontleavehmode\llap{? }% \blank[overlay] \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
Wolfgang
Thank you, Wolfgang. That does it. Note that the % escaping the line end is not needed ( although it might be needed outside a \starttexdefinition environment) – the following works as well:
\starttexdefinition stopBufTest
\startnarrower[left,right]
\startparagraph
\dontleavehmode{\llap{? }}
\blank[overlay]
\inlinebuffer[TestBuffer]
\stopparagraph
\stopnarrower
\egroup
\stoptexdefinition
Alas, this is not yet a workable solution. It does not work with a layout of grid=tolerant, which I am currently using (although it does work with some other grid settings). For now I will just add empty [] to the startBufTest invocations. I really think, though, that a buffers.strip function would be the way to go, instead of futzing after the damage is done. -- Rik
On Tue, 14 Aug 2018, Rik Kabel wrote:
I really think, though, that a buffers.strip function would be the way to go, instead of futzing after the damage is done.
In lua, buffers.getcontent('name') gives the contents of the buffer labelled 'name'. You can post-process this in whatever way you want. For example, you could write a lua function userdata.strip that strips the leading and ending black spaces from a string, and then call context(userdata.strip(buffers.getcontent('name))) Aditya
On 8/15/2018 5:31 AM, Aditya Mahajan wrote:
On Tue, 14 Aug 2018, Rik Kabel wrote:
I really think, though, that a buffers.strip function would be the way to go, instead of futzing after the damage is done.
In lua, buffers.getcontent('name') gives the contents of the buffer labelled 'name'. You can post-process this in whatever way you want. For example, you could write a lua function userdata.strip that strips the leading and ending black spaces from a string, and then call
context(userdata.strip(buffers.getcontent('name))) local s = [[
foo bar bar ]] print(string.fullstrip(s)) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 8/15/2018 03:07, Hans Hagen wrote:
On 8/15/2018 5:31 AM, Aditya Mahajan wrote:
On Tue, 14 Aug 2018, Rik Kabel wrote:
I really think, though, that a buffers.strip function would be the way to go, instead of futzing after the damage is done.
In lua, buffers.getcontent('name') gives the contents of the buffer labelled 'name'. You can post-process this in whatever way you want. For example, you could write a lua function userdata.strip that strips the leading and ending black spaces from a string, and then call
context(userdata.strip(buffers.getcontent('name))) local s = [[
foo
bar
bar
]]
print(string.fullstrip(s))
So, it looks likethe following is closer to working for me in a simple test harness, but not in my full-blown work: \dontleavehmode{\llap{StripA~}}\ctxlua{context(utilities.strings.striplines(string.gsub(buffers.getcontent("TestBuffer"),"^\\relax",""),"prune"))} (or similar with string.fullstrip). However, it fails when the buffer starts with an unescaped left square bracket. That is probably why the \relax is inserted, and I can see that it is not a simple job to handle this. So, I will accept that I must either append [] or get rid of the open layout for these cases. I suspect that the issue in the larger project has to do with quoting for the RE ("^\\relax") since compilation fails with: %% \stopAttribution ...getcontent("Attribution"),"^\\ %% relax","")))}\stopparagrap... Any pointers on such quoting would be appreciated. -- Rik
On Wed, 15 Aug 2018, Rik Kabel wrote:
On 8/15/2018 03:07, Hans Hagen wrote:
On 8/15/2018 5:31 AM, Aditya Mahajan wrote:
On Tue, 14 Aug 2018, Rik Kabel wrote:
I really think, though, that a buffers.strip function would be the way to go, instead of futzing after the damage is done.
In lua, buffers.getcontent('name') gives the contents of the buffer labelled 'name'. You can post-process this in whatever way you want. For example, you could write a lua function userdata.strip that strips the leading and ending black spaces from a string, and then call
context(userdata.strip(buffers.getcontent('name))) local s = [[
foo
bar
bar
]]
print(string.fullstrip(s))
So, it looks likethe following is closer to working for me in a simple test harness, but not in my full-blown work:
\dontleavehmode{\llap{StripA~}}\ctxlua{context(utilities.strings.striplines(string.gsub(buffers.getcontent("TestBuffer"),"^\\relax",""),"prune"))}
(or similar with string.fullstrip).
However, it fails when the buffer starts with an unescaped left square bracket. That is probably why the \relax is inserted, and I can see that it is not a simple job to handle this. So, I will accept that I must either append [] or get rid of the open layout for these cases.
I suspect that the issue in the larger project has to do with quoting for the RE ("^\\relax") since compilation fails with:
%% \stopAttribution ...getcontent("Attribution"),"^\\ %% relax","")))}\stopparagrap...
Any pointers on such quoting would be appreciated.
Please create a MWE. Aditya
On 8/16/2018 10:55, Aditya Mahajan wrote:
On Wed, 15 Aug 2018, Rik Kabel wrote:
I suspect that the issue in the larger project has to do with quoting for the RE ("^\\relax") since compilation fails with:
%% \stopAttribution ...getcontent("Attribution"),"^\\ %% relax","")))}\stopparagrap...
Any pointers on such quoting would be appreciated.
Please create a MWE.
Aditya
I cannot at this point, and may well have misinterpreted what I saw. -- Rik
On 8/13/2018 10:28, Rik Kabel wrote:
On 8/13/2018 03:01, Hans Hagen wrote:
On 8/13/2018 5:18 AM, Rik Kabel wrote:
\startparagraph
% \dontleavehmode\llap{\Mark}\inlinebuffer[TestBuffer] % \ (first: \First, arg: \Arg)
\margintext{\Mark}
\setupparagraphintro[first][(first: \First, arg: \Arg)] %\setupparagraphintro[next][(first: \First, arg: \Arg)]
\getbuffer[TestBuffer]
\stopparagraph
Hans,
That works for the over-simplified case here, but fails in practice. For a \startnarrower[left] paragraph, the mark is still in the main margin, not the 'margin' of the narrowed paragraph. Also, the placement of the text in the margin is wrong and not easily controlled as with \llap and \rlap. The code started out more like:
\define\Mark{\color[middlegray]{\hskip.6cm\itb¿\ }} \setwidthof{\Mark}\to\MarkWidth ... \starttexdefinition stopBufTest \startluacode buffers.prepend("TestBuffer","\\dontleavehmode\\llap{\\Mark}") \stopluacode \setupnarrower[left=\MarkWidth] \startnarrower[left,right] \startparagraph \inlinebuffer[TestBuffer] \stopparagraph \stopnarrower \egroup \stoptexdefinition
So I am still looking for a way to do this. Meanwhile I am trying to understand Aditya's examples.
Turns out another answer was hidden in Hans's reply. The following seems to meet my needs, but it may complicate other use of \setupparagraphintro (which I don't recall seeing before), so it may not be a generic solution. An empty string works fine instead of the llaped marking shown here. This is a less dangerous hack than redefining \par, but still may fail in more complex documents when \setupparagraphintro is used elsewhere. \starttexdefinition stopBufTest \startnarrower[left,right] \startparagraph \setupparagraphintro[first][\llap{\Mark}] \inlinebuffer[TestBuffer] \ (first: \First, arg: \Arg) \stopparagraph \stopnarrower \egroup \stoptexdefinition Thank you, Hans. (For a non-hack generic solution that does not interfere with other use of \setupparagraphintro, surely there must be an easy way to apply string.strip to the buffer.) -- Rik
On 8/13/2018 10:28, Rik Kabel wrote:
That works for the over-simplified case here, but fails in practice. For a \startnarrower[left] paragraph, the mark is still in the main margin, not the 'margin' of the narrowed paragraph. Also, the placement of the text in the margin is wrong and not easily controlled as with \llap and \rlap. The code started out more like:
Correcting the record: I misspoke in part above; margintext does follow the narrowed paragraph shape. -- Rik
participants (6)
-
Aditya Mahajan
-
Hans Hagen
-
Henri Menke
-
Rik
-
Rik Kabel
-
Wolfgang Schuster