From: Gerben Wierda <gerben.wierda@rna.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Lua/TeX/METAPOST/textext string issue/puzzle
Date: Wed, 1 Apr 2020 21:34:21 +0200 [thread overview]
Message-ID: <96375A43-3F61-4190-BE97-E3DEB623D835@rna.nl> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1878 bytes --]
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
[-- Attachment #1.2: Type: text/html, Size: 5506 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
next reply other threads:[~2020-04-01 19:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-01 19:34 Gerben Wierda [this message]
2020-04-01 21:44 ` Aditya Mahajan
2020-04-02 9:52 ` Gerben Wierda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=96375A43-3F61-4190-BE97-E3DEB623D835@rna.nl \
--to=gerben.wierda@rna.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).