Too happy too soon. And I recall I ran into this earlier a while ago in another setting ago. But I thought of a solution.
I am automatically converting input from an XML file to METAPOST/ConTeXt. The input may contain one or more newlines.The text must end up in \framed[align=??, width=??] to be typeset.
I use lua to convert and make it safe to pass to METAPOST as a string argument that METAPOST can pass on to textext(), using the following function:
function doubleQuotableEscapedConTeXtString( str)
local rep = lpeg.replacer {
{ '\n', '\\blank ' },
{ '{', '{\\textbraceleft}' },
{ '}', '{\\textbraceright}' },
{ '#', '{\\texthash}' },
{ '$', '{\\textdollar}' },
{ '&', '{\\textampersand}' },
{ '%', '{\\textpercent}' },
{ '\\','{\\textbackslash}' },
{ '|', '{\\textbar}' },
{ '_', '{\\textunderscore}' },
{ '~', '{\\textasciitilde}' },
{ '^', '{\\textasciicircum}' },
{ '"', "\"&ditto&\"" },
}
return rep:match(str)
end
Where it now says \\blank, it used to say \\\\.
Problem
\\\\ gets me what I want if there is one \n (it turns into one new line), but with two \n in succession it still gets me only a single ’newline'
\\blank gets me what I want if there are multiple newlines, but gets me an extra empty line when I only want ’next line’ and multiple \blanks do not work
But I found the solution by using \strut\\ instead of \blank. In the above table:
{ ‘\n', ‘\\strut\\\\' },
This fools ConTeXt in thinking there actually is something on that line and so multiple \\ will work.
G