Skip to content

ConTeXt, Whitespace, and Line Blocks #2744

Closed
c-forster opened this Issue · 14 comments

4 participants

@c-forster

If I have the following markdown:

| 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 *grace*
|            As lang's my arm.

And I convert it to ConTeXt, I get:

Fair fa' your honest, sonsie face,\crlf
~~~~Great Chieftain o' the Puddin'-race!\crlf
Aboon them a' ye tak your place,\crlf
~~~~~~~~~~~Painch, tripe, or thairm:\crlf
Weel are ye wordy o' a {\em grace}\crlf
~~~~~~~~~~~As lang's my arm.

With LaTeX, I get:

Fair fa' your honest, sonsie face,\\
\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}Great
Chieftain o' the Puddin'-race!\\
Aboon them a' ye tak your place,\\
\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}Painch,
tripe, or thairm:\\
Weel are ye wordy o' a \emph{grace}\\
\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}\hspace*{0.333em}As lang's my arm.

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.

@jgm
Owner
@c-forster

I corresponded with @denubis via email, who helped me come up with a solution that seems to work and is represented in #2745

@Denubis
@ousia

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.

@Denubis
@ousia

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.

@Denubis
@ousia

Thus, while \startspacedlines is indeed correct from a ConTeXt point of view, there is nothing to tell the parser to write \startspacedlines.

Many thanks for your reply, @Denubis. It is is clear to me now.

@c-forster

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.
@Denubis
@c-forster

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 hspaces 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.

@Denubis
@c-forster

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).

@c-forster c-forster pushed a commit to c-forster/pandoc that referenced this issue
csforste Improve ConTeXt writer's handling of whitespace (esp. in Line Blocks).
Fixes issue #2744.
ea06ac3
@c-forster

Updated #2745 so that it now uses \hskip 0.333em for each space, producing the output described above. If it's merged, or if other folks have input, I'll close this issue.

@jgm jgm added a commit that closed this issue
@jgm ConTeXt writer: fix whitespace at line beginning in line blocks.
Add a `\strut` after `\crlf` before space.
Closes #2744, #2745.  Thanks to @c-foster.
This uses the fix suggested by @c-foster.

Mid-line spaces are still not supported, because of limitations
of the Markdown parser.
976e7e2
@jgm jgm closed this in 976e7e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.