ConTeXt, Whitespace, and Line Blocks #2744
Are there any ConTeXt experts out there who can suggest better output?
I guess this is better (or at least, much simpler):
\definelines[spacedlines][space=on]
\starttext
\startspacedlines
Fair fa' your honest, sonsie face,
Great Chieftain o' the Puddin'-race!
Aboon them a' ye tak your place,
Painch, tripe, or thairm:
Weel are ye wordy o' a {\em{}grace}
As lang's my arm.
\stopspacedlines
\stoptext
BTW, no line breaks (\crlf
) are needed.
But activating spaces requires {\em{}grace}
. Otherwise, two spaces will be added.
The problem (and we considered startlines) is that there's no lines mode in |. Thus, the only knowledge we have is: "t":"LineBreak" where a linebreak should occur, and a unicode character for spacing. If we were in modes, yes, what you propose would be great.
@Denubis, excuse me, I cannot code.
I cannot imagine what “lines mode in |” might be.
And “if we were in modes” is misleading to me (my fault). ConTeXt also has modes.
Thanks @ousia and @Denubis; I think it's probably better to stick with \hspace[small]
because small is defined by default. Defining our own hspace
value would let us be a bit more precise, but the definition (i.e. \definehspace[fourspace][.5in]
) should really go in the file header. But the header is only output from with the --standalone
flag. That is, there are a number of imaginable reasons why one would generate ConTeXt fragments, and those fragments should compile properly (rather than throw an error that they reference some undefined value). (We could use medium
, but I think small
is closest to the 0.333em used in the LaTeX writer.)
So, with those constraints (we can't use a \startspacedlines
; and using custom values seems to carry a high cost), is this the best imaginable output for the example above?
Fair fa' your honest, sonsie face,\crlf
\strut~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]Great
Chieftain o' the Puddin'-race!\crlf
Aboon them a' ye tak your place,\crlf
\strut~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]Painch,
tripe, or thairm:\crlf
Weel are ye wordy o' a {\em grace}\crlf
\strut~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]As
lang's my arm.
So, I'm kind of just wildly stabbing in the dark w/r/t ConTeXt (with which I am not familiar and, I've learned, is significantly different from LaTeX); but from my experiments you need both a nonbreaking space (~
) and the hspace
to produce horizontal whitespace. I tried without any nonbreaking spaces (just hspace
), and the hspace
s produce nothing. I also tried with just one, but that didn't work either. For instance, compiling the following:
Fair fa' your honest, sonsie face,\crlf
\strut\hspace[small]\hspace[small]\hspace[small]\hspace[small]Great Chieftain o' the Puddin'-race!
Fair fa' your honest, sonsie face,\crlf
\strut~\hspace[small]\hspace[small]\hspace[small]\hspace[small]Great Chieftain o' the Puddin'-race!
Fair fa' your honest, sonsie face,\crlf
\strut~\hspace[small]~\hspace[small]~\hspace[small]~\hspace[small]Great Chieftain o' the Puddin'-race!
Only the third instance appears correctly.
Okay. So, while I've long heeded the advice to avoid TeX primitives in *TeX,\hskip
does seem simpler (though it clutters the output just as much and because it takes an argument not in braces is slightly confusing to read).
In the interests of consistency with the existing LaTeX writer, the size of the space should be 0.333em
; and for both consistency with the existing LaTeX writer and ease of implementation, I think we should just output one \hskip 0.333em
for each nonbreaking space (rather than, say, trying to determine the number of consecutive nonbreaking spaces, and then outputting a single \hskip
---a prospect that increases in horror with every moment I spend pondering it).
So, using hskip
instead of a set ~\hspace[small]
, the desired ConTeXt produced for the line blocks used in the example above should be:
Fair fa' your honest, sonsie face,\crlf
\strut\hskip 0.333em \hskip 0.333em \hskip 0.333em \hskip 0.333em Great Chieftain o' the Puddin'-race!
Fair fa' your honest, sonsie face,\crlf
\strut\hskip 0.333em \hskip 0.333em \hskip 0.333em \hskip 0.333em Great Chieftain o' the Puddin'-race!
Fair fa' your honest, sonsie face,\crlf
\strut\hskip 0.333em \hskip 0.333em \hskip 0.333em \hskip 0.333em Great Chieftain o' the Puddin'-race!
Correct? If there are no further emendations/qualifications, I'll change #2745 to reflect this (probably sometime this weekend).
If I have the following markdown:
And I convert it to ConTeXt, I get:
With LaTeX, I get:
The ConTeXt writer converts spaces in Line Blocks into nonbreaking spaces (
~
s), which don't get preserved as horizontal space when it is compiled to PDF.