From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106711 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Gerben Wierda Newsgroups: gmane.comp.tex.context Subject: Lua/TeX/METAPOST/textext string issue/puzzle Date: Wed, 1 Apr 2020 21:34:21 +0200 Message-ID: <96375A43-3F61-4190-BE97-E3DEB623D835@rna.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Content-Type: multipart/mixed; boundary="===============4888206171218959507==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="67691"; mail-complaints-to="usenet@ciao.gmane.io" To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Wed Apr 01 21:35:09 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJj8m-000HW1-SE for gctc-ntg-context-518@m.gmane-mx.org; Wed, 01 Apr 2020 21:35:08 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id AFB43182EC8; Wed, 1 Apr 2020 21:34:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TDLwR_IxoGcM; Wed, 1 Apr 2020 21:34:25 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 4381D182F72; Wed, 1 Apr 2020 21:34:25 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id EA99B182EC8 for ; Wed, 1 Apr 2020 21:34:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FXqpN9GhbIqb for ; Wed, 1 Apr 2020 21:34:22 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=213.125.118.53; helo=mail.rna.nl; envelope-from=gerben.wierda@rna.nl; receiver= Original-Received: from mail.rna.nl (mail.rna.nl [213.125.118.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id B0CE9182E36 for ; Wed, 1 Apr 2020 21:34:22 +0200 (CEST) Original-Received: from hermione.rna.nl (hermione.rna.nl [192.168.2.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.rna.nl (Postfix) with ESMTPSA id 156CA36889BA; Wed, 1 Apr 2020 21:34:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rna.nl; s=dkim_rsa2048; t=1585769662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=x1oCBvd1PvG/9oko4fW0qJRzXU90rXXZnErlBasF+nY=; b=nN+OAQJTZd1jlPDTsEdNTfSyL65v5pSxidXdpttQVY8lqIKzCXLz0on7zdMAq6rALerk/Z S7ZVDhcWCv9YIWrilGDHAJXrLxLRtukXgoWqCMrcLBDmkqorhaD/7Lcb8V80FCbUtzEon+ tt9YoGR8jxX6ZbID6uLCsmd8wARcZhZ8ibnK2OSotqlp00YTZ63475+k2c7g1KW9tWCPI+ +silOumUgmDSc5zyQ+lAsmwtJD3zTt2yZ48cvsWGr1p9B9zepP1DtBqdHBOQUqd8ArKs3o mwuanOuAVOMCMzEYRTTj0R94zPaueeoCyx9IIl3BtmqQE9e8EsyEVfOl/RxzkA== X-Mailer: Apple Mail (2.3445.104.14) X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:106711 Archived-At: --===============4888206171218959507== Content-Type: multipart/alternative; boundary="Apple-Mail=_CF5054A7-DD81-4D2F-A394-D79E3153F73E" --Apple-Mail=_CF5054A7-DD81-4D2F-A394-D79E3153F73E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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:=20 {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 =3D { [1] =3D { "\"", "\"&ditto&\"" }, } local tmpString =3D string.formatters( "%!tex!", xmlLabelString) return lpeg.replacer(rep):match(tmpString) end That works. Then, in METAPOST the vardef =E2=80=98ApplicationComponentLogo= =E2=80=99 calls a vardef makeTeXLabel=20 draw makeTeXLabel( w, h, name) shifted (w/2,0); which, for now, simplified does this: vardef makeTeXLabel( expr w, h, name) =3D save p; picture p ; save s; string s; s :=3D "\framed{" & name & "}=E2=80=9D; % s :=3D "\type-" & name & "-"; p :=3D 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.=20 I tried adding a doubling of the backslahes to the replacement: rep =3D { [1] =3D { "\"", "\"&ditto&\"" }, [2] =3D { "\\", "\\\\" }, } But then the string that is typeset (and given to textext()) becomes=20 \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= --Apple-Mail=_CF5054A7-DD81-4D2F-A394-D79E3153F73E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 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 =3D {
      [1] =3D { "\"", = "\"&ditto&\""   },
  }
  local tmpString =3D string.formatters( "%!tex!", = xmlLabelString)
  return = lpeg.replacer(rep):match(tmpString)
end

That works. Then, in METAPOST the = vardef =E2=80=98ApplicationComponentLogo=E2=80=99  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) =3D
  save p; picture p ;
  save s; string s;
  s :=3D "\framed{" = & name & "}=E2=80=9D;
  % s :=3D "\type-" & name & = "-";
  p :=3D 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 =3D {
      [1] =3D { "\"", = "\"&ditto&\""   },
    =   [2] =3D { "\\", "\\\\" },
  = }

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
= --Apple-Mail=_CF5054A7-DD81-4D2F-A394-D79E3153F73E-- --===============4888206171218959507== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============4888206171218959507==--