Lua/TeX/METAPOST/textext string issue/puzzle
I have lua code that generates this for METAPOST: ApplicationComponentLogo( w, h, "withcolor (0.686,1.000,1.000) withtransparency (1,0.200)", "withcolor (0.000,0.000,0.000) withtransparency (1,1.000) withpen pencircle scaled 1.000", "\{Hello\}, "&ditto&"(a)"&ditto&" [World]!") shifted (x, -y); draw pic; The string to be typeset, eventually is this: {Hello}, "(a)" [World]! So, with double quotes in the string. The function creating the actual string to pass to METAPOST (above) is this: local function mpLabelString( xmlLabelString) -- Returns a string where each " is replaced by a METAPOST compatible result, except for outer double quotes" rep = { [1] = { "\"", "\"&ditto&\"" }, } local tmpString = string.formatters( "%!tex!", xmlLabelString) return lpeg.replacer(rep):match(tmpString) end That works. Then, in METAPOST the vardef ‘ApplicationComponentLogo’ calls a vardef makeTeXLabel draw makeTeXLabel( w, h, name) shifted (w/2,0); which, for now, simplified does this: vardef makeTeXLabel( expr w, h, name) = save p; picture p ; save s; string s; s := "\framed{" & name & "}”; % s := "\type-" & name & "-"; p := textext( s); p enddef; But, this is what is in string s before it is sent to textext(): \framed {{Hello}, "(a)" [World]!} In other words, the escapes on the curly braces are lost and now the curly braces are ignored by TeX. I tried adding a doubling of the backslahes to the replacement: rep = { [1] = { "\"", "\"&ditto&\"" }, [2] = { "\\", "\\\\" }, } But then the string that is typeset (and given to textext()) becomes \framed {\\{Hello\\}, "(a)" [World]!} And the result in the output is the same. No curly braces. My route is probably to complex anyway, but what can I do for the curly braces to be actually typeset? G
On Wed, 1 Apr 2020, Gerben Wierda wrote:
My route is probably to complex anyway, but what can I do for the curly braces to be actually typeset?
MkII had a feature called \sometxt http://dl.contextgarden.net/myway/sometxt.pdf I wonder if that still works in MkIV. Aditya
Actually, the backslashes disappear before the call to textext() G
On 1 Apr 2020, at 23:44, Aditya Mahajan
wrote: On Wed, 1 Apr 2020, Gerben Wierda wrote:
My route is probably to complex anyway, but what can I do for the curly braces to be actually typeset?
MkII had a feature called \sometxt http://dl.contextgarden.net/myway/sometxt.pdf
I wonder if that still works in MkIV.
Aditya ___________________________________________________________________________________ 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 ___________________________________________________________________________________
participants (2)
-
Aditya Mahajan
-
Gerben Wierda