From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106716 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Gerben Wierda Newsgroups: gmane.comp.tex.context Subject: Minimum example of problem getting curly braces printed in METAPOST Date: Thu, 2 Apr 2020 14:05:55 +0200 Message-ID: <68992ADC-44A8-410D-90D6-CFCD31EE77F6@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="===============4744561236365370584==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="15855"; mail-complaints-to="usenet@ciao.gmane.io" To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Apr 02 14:06:33 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 1jJycC-000431-UN for gctc-ntg-context-518@m.gmane-mx.org; Thu, 02 Apr 2020 14:06:32 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7DB7E182FAC; Thu, 2 Apr 2020 14:05:59 +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 a2hiOGeZ2otA; Thu, 2 Apr 2020 14:05:57 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 8EB93182F46; Thu, 2 Apr 2020 14:05:57 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id B6E62182F46 for ; Thu, 2 Apr 2020 14:05:56 +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 ZtvRVfMjN9Iq for ; Thu, 2 Apr 2020 14:05:56 +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 E6FD1182EC8 for ; Thu, 2 Apr 2020 14:05:55 +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 60B1136915B0 for ; Thu, 2 Apr 2020 14:05:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rna.nl; s=dkim_rsa2048; t=1585829155; 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=j/6PhnhgGOKknWottHJUeir0XjIhQxvrACZrdl4kQ8s=; b=TsC4o4k5/bubHDsQjvVNCaDhOs+SknIRnHSGg+DCeTcmV0eMDM2aeoYlMlQNQjPBUycH+S SKnPV0Y3QjkLO9Mx7zCwGXb7clcSr/iopzPQxN+ZmmQoacD+4/JQF+fuEOx/QkWPVj1WBZ TQv5VAaYecXvPgwDSRwRXm92A1SUpVyJ65kPoJiS0PWEQPE+h1CB7T5QAJei1x/nlOaRwx JsqHlRwoOpOH6eBfAgvWfq7Qc0/DMYdHYSkJZJWEVBS7Vcq8t08+4rwGw8l4eyMgR/wRnI KlCMkbDS8sFIhVL5IK8sR4wJ8y702H8qCePN+wScPUy+8qoEsoLKFV0UyoUh3A== 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:106716 Archived-At: --===============4744561236365370584== Content-Type: multipart/alternative; boundary="Apple-Mail=_2576916D-A296-4F37-A017-2A359337D557" --Apple-Mail=_2576916D-A296-4F37-A017-2A359337D557 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Here is a minimum example of a problem that I have in getting curly = braces printed in METAPOST in code that is generated by lua. Any help is welcome. \usemodule[scite] \setupxml [entities=3Dyes] \startluacode function warn( ... ) texio.write_nl("-----> " .. string.format(...)) end 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&\"" }, -- DOESN'T WORK: [2] =3D { "\\", "\\\\" }, } local tmpString =3D string.formatters( "%!tex!", xmlLabelString) warn( "STRING.FORMAT XML \"%s\"", xmlLabelString) warn( "STRING.FORMAT TeX-ed \"%s\"", tmpString) warn( "STRING.FORMAT Replaced \"%s\"", = lpeg.replacer(rep):match(tmpString)) return lpeg.replacer(rep):match(tmpString) end function warnAndConTeXt( ...) warn( ...) context( ...) end function moduledata.test( filename) local labelString context( "The string to typeset is:\\par\\type-{Label} \"a\" = [Text]!-") context( "\\par The attempts are:") context( "\\par1. \\type-Label Text-") context( "\\par2. \\type-Label [Text]!-") context( "\\par3. \\type-Label \"a\" [Text]!-") context( "\\par4. \\type-{Label} [Text]!-") context( "\\par5. \\type-{Label} \"a\" [Text]!-") context.startMPpage { instance =3D "doublefun" } context( "picture pic;") labelString =3D "1. Label Text OK" warnAndConTeXt( "pic :=3D Foo( 0, 0, 150, 50, \"%s\");", = mpLabelString( labelString)) labelString =3D "2. Label [Text]! OK" warnAndConTeXt( "pic :=3D Foo( 0, -75, 150, 50, \"%s\");", = mpLabelString( labelString)) labelString =3D "3. Label \"a\" [Text]! OK" warnAndConTeXt( "pic :=3D Foo( 0, -150, 150, 50, \"%s\");", = mpLabelString( labelString)) labelString =3D "4. {Label} [Text]! MISSING curly braces" warnAndConTeXt( "pic :=3D Foo( 0, -225, 150, 50, \"%s\");", = mpLabelString( labelString)) labelString =3D "5. {Label} \"a\" [Text]! MISSING curly braces" warnAndConTeXt( "pic :=3D Foo( 0, -300, 150, 50, \"%s\");", = mpLabelString( labelString)) context( "drawdot (0,0) withpen pencircle scaled 4 withcolor red;") context.stopMPpage() end \stopluacode \usemodule[article-basic] = %\enabletrackers[metapost.tracingall,metapost.lua,metapost.runs,metapost.t= extexts,metapost.scrintersectionPoints,metapost.runs,metapost.graphics,met= apost.terminal] \starttext \definefontfamily[mainface][rm][Optima] \setupbodyfont[mainface,10pt] \startMPinclusions[+]{doublefun} \stopMPinclusions \startMPdefinitions{doublefun} vardef makeTeXLabel( expr w, h, name) =3D show "NAME makeTeXLabel:", name; save p; picture p ; save s; string s; s :=3D "\framed{" & name & "}"; % Curly braces will be missing. I need = this to work. % s :=3D "\type-" & name & "-"; % Curly braces are displayed, but this = must become a vbox in the end, so can't use it show "SCAN:", s; p :=3D textext( s); p enddef; vardef Foo( expr xpos, ypos, width, height, str) =3D show "NAME Foo:", str; % Backslashes are already gone here save pic; picture pic; pic :=3D makeTeXLabel( width, height, str) shifted (xpos, ypos); draw pic; pic enddef; \stopMPdefinitions \ctxlua{moduledata.test("My ArchiMate Model Export BES.xml")} \typefile[option=3DTEX]{test11.tex} \stoptext The question is: how can I get this to work? The strings that have to be = printed inside the METAPOST picture come from an XML and can contain = about anything. But in the end that string will have to be vertically = typeset as a paragraph, hence I cannot use \type (which works). --Apple-Mail=_2576916D-A296-4F37-A017-2A359337D557 Content-Type: multipart/mixed; boundary="Apple-Mail=_DC9B24FF-7C20-4E05-845E-EF5A2C715E32" --Apple-Mail=_DC9B24FF-7C20-4E05-845E-EF5A2C715E32 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Here = is a minimum example of a problem that I have in getting curly braces = printed in METAPOST in code that is generated by lua.

Any help is welcome.

\usemodule[scite]
\setupxml
 [entities=3Dyes]


\startluacode

function warn( ... )
  texio.write_nl("-----> " .. = string.format(...))
end

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&\""   = },
    =   -- DOESN'T WORK: [2] =3D { "\\", "\\\\" = },
  = }
  local = tmpString =3D string.formatters( "%!tex!", = xmlLabelString)
  warn( = "STRING.FORMAT XML \"%s\"", xmlLabelString)
  warn( "STRING.FORMAT TeX-ed \"%s\"", = tmpString)
  warn( = "STRING.FORMAT Replaced \"%s\"", = lpeg.replacer(rep):match(tmpString))
  return = lpeg.replacer(rep):match(tmpString)
end

function warnAndConTeXt( ...)
  warn( ...)
  context( ...)
end

function moduledata.test( filename)
  local labelString
  context( "The string to typeset = is:\\par\\type-{Label} \"a\" [Text]!-")
  context( "\\par The attempts = are:")
  = context( "\\par1. \\type-Label Text-")
  context( "\\par2. \\type-Label = [Text]!-")
  = context( "\\par3. \\type-Label \"a\" [Text]!-")
  context( "\\par4. \\type-{Label} = [Text]!-")
  = context( "\\par5. \\type-{Label} \"a\" = [Text]!-")
  = context.startMPpage { instance =3D "doublefun" }
  context( "picture = pic;")
  = labelString =3D "1. Label Text OK"
  warnAndConTeXt( "pic :=3D Foo( 0, 0, 150, 50, = \"%s\");", mpLabelString( labelString))
  labelString =3D "2. Label [Text]! = OK"
  = warnAndConTeXt( "pic :=3D Foo( 0, -75, 150, 50, \"%s\");", = mpLabelString( labelString))
  labelString =3D "3. Label \"a\" [Text]! = OK"
  = warnAndConTeXt( "pic :=3D Foo( 0, -150, 150, 50, \"%s\");", = mpLabelString( labelString))
  labelString =3D "4. {Label} [Text]! MISSING curly = braces"
  = warnAndConTeXt( "pic :=3D Foo( 0, -225, 150, 50, \"%s\");", = mpLabelString( labelString))
  labelString =3D "5. {Label} \"a\" [Text]! MISSING = curly braces"
  = warnAndConTeXt( "pic :=3D Foo( 0, -300, 150, 50, \"%s\");", = mpLabelString( labelString))
  context( "drawdot (0,0) withpen pencircle scaled 4 = withcolor red;")
  = context.stopMPpage()
end
\stopluacode

\usemodule[article-basic]
%\enabletrackers[metapost.tracingall,metapost.lua,metapost.runs= ,metapost.textexts,metapost.scrintersectionPoints,metapost.runs,metapost.g= raphics,metapost.terminal]

\starttext

\definefontfamily[mainface][rm][Optima]
\setupbodyfont[mainface,10pt]

\startMPinclusions[+]{doublefun}

\stopMPinclusions

\startMPdefinitions{doublefun}
vardef makeTeXLabel( expr w, h, name) = =3D
  show = "NAME makeTeXLabel:", name;
  save p; picture p ;
  save s; string s;
  s :=3D "\framed{" & name & "}"; % = Curly braces will be missing. I need this to = work.
  % s :=3D = "\type-" & name & "-"; % Curly braces are displayed, but this = must become a vbox in the end, so can't use it
  show "SCAN:", s;
  p :=3D textext( s);
  p
enddef;

vardef Foo( expr xpos, ypos, width, height, str) = =3D
  show = "NAME Foo:", str; % Backslashes are already gone = here
  save = pic; picture pic;
  pic :=3D makeTeXLabel( width, height, str) shifted = (xpos, ypos);
  draw = pic;
  = pic
enddef;

\stopMPdefinitions

\ctxlua{moduledata.test("My ArchiMate Model Export = BES.xml")}
\typefile[option=3DTEX]{test11.tex}

\stoptext
The question is: how can I get this to = work? The strings that have to be printed inside the METAPOST picture = come from an XML and can contain about anything. But in the end that = string will have to be vertically typeset as a paragraph, hence I cannot = use \type (which works).

= --Apple-Mail=_DC9B24FF-7C20-4E05-845E-EF5A2C715E32 Content-Disposition: attachment; filename=test11.tex Content-Type: application/octet-stream; x-unix-mode=0644; name="test11.tex" Content-Transfer-Encoding: 7bit \usemodule[scite] \setupxml [entities=yes] \startluacode function warn( ... ) texio.write_nl("-----> " .. string.format(...)) end local function mpLabelString( xmlLabelString) -- Returns a string where each " is replaced by a METAPOST compatible result, except for outer double quotes" rep = { [1] = { "\"", "\"&ditto&\"" }, -- DOESN'T WORK: [2] = { "\\", "\\\\" }, } local tmpString = string.formatters( "%!tex!", xmlLabelString) warn( "STRING.FORMAT XML \"%s\"", xmlLabelString) warn( "STRING.FORMAT TeX-ed \"%s\"", tmpString) warn( "STRING.FORMAT Replaced \"%s\"", lpeg.replacer(rep):match(tmpString)) return lpeg.replacer(rep):match(tmpString) end function warnAndConTeXt( ...) warn( ...) context( ...) end function moduledata.test( filename) local labelString context( "The string to typeset is:\\par\\type-{Label} \"a\" [Text]!-") context( "\\par The attempts are:") context( "\\par1. \\type-Label Text-") context( "\\par2. \\type-Label [Text]!-") context( "\\par3. \\type-Label \"a\" [Text]!-") context( "\\par4. \\type-{Label} [Text]!-") context( "\\par5. \\type-{Label} \"a\" [Text]!-") context.startMPpage { instance = "doublefun" } context( "picture pic;") labelString = "1. Label Text OK" warnAndConTeXt( "pic := Foo( 0, 0, 150, 50, \"%s\");", mpLabelString( labelString)) labelString = "2. Label [Text]! OK" warnAndConTeXt( "pic := Foo( 0, -75, 150, 50, \"%s\");", mpLabelString( labelString)) labelString = "3. Label \"a\" [Text]! OK" warnAndConTeXt( "pic := Foo( 0, -150, 150, 50, \"%s\");", mpLabelString( labelString)) labelString = "4. {Label} [Text]! MISSING curly braces" warnAndConTeXt( "pic := Foo( 0, -225, 150, 50, \"%s\");", mpLabelString( labelString)) labelString = "5. {Label} \"a\" [Text]! MISSING curly braces" warnAndConTeXt( "pic := Foo( 0, -300, 150, 50, \"%s\");", mpLabelString( labelString)) context( "drawdot (0,0) withpen pencircle scaled 4 withcolor red;") context.stopMPpage() end \stopluacode \usemodule[article-basic] %\enabletrackers[metapost.tracingall,metapost.lua,metapost.runs,metapost.textexts,metapost.scrintersectionPoints,metapost.runs,metapost.graphics,metapost.terminal] \starttext \definefontfamily[mainface][rm][Optima] \setupbodyfont[mainface,10pt] \startMPinclusions[+]{doublefun} \stopMPinclusions \startMPdefinitions{doublefun} vardef makeTeXLabel( expr w, h, name) = show "NAME makeTeXLabel:", name; save p; picture p ; save s; string s; s := "\framed{" & name & "}"; % Curly braces will be missing. I need this to work. % s := "\type-" & name & "-"; % Curly braces are displayed, but this must become a vbox in the end, so can't use it show "SCAN:", s; p := textext( s); p enddef; vardef Foo( expr xpos, ypos, width, height, str) = show "NAME Foo:", str; % Backslashes are already gone here save pic; picture pic; pic := makeTeXLabel( width, height, str) shifted (xpos, ypos); draw pic; pic enddef; \stopMPdefinitions \ctxlua{moduledata.test("My ArchiMate Model Export BES.xml")} \typefile[option=TEX]{test11.tex} \stoptext --Apple-Mail=_DC9B24FF-7C20-4E05-845E-EF5A2C715E32 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii

--Apple-Mail=_DC9B24FF-7C20-4E05-845E-EF5A2C715E32-- --Apple-Mail=_2576916D-A296-4F37-A017-2A359337D557-- --===============4744561236365370584== 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== --===============4744561236365370584==--