From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/106670 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Gerben Wierda Newsgroups: gmane.comp.tex.context Subject: Re: How do I handle strings with " characters in it in METAPOST? Date: Sun, 29 Mar 2020 16:25:55 +0200 Message-ID: <486B6941-5A01-406F-96B2-898DF824FBFE@rna.nl> References: <2CE77B0F-FC9E-4EDB-8A40-F4C5DC3A99B8@rna.nl> <6cd1c797-83de-f317-f46d-1a9ed9cd10a8@gmail.com> <36E421F8-0294-4D04-8C45-0718B47E1727@rna.nl> <84b1bf6c-d34b-ec3a-d574-2d730c3e09c0@gmail.com> 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="===============7354857907244228523==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="7596"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mailing list for ConTeXt users To: Wolfgang Schuster Original-X-From: ntg-context-bounces@ntg.nl Sun Mar 29 16:26:13 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 1jIYtB-0001s6-O2 for gctc-ntg-context-518@m.gmane-mx.org; Sun, 29 Mar 2020 16:26:13 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 61AAA182E42; Sun, 29 Mar 2020 16:25: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 ESc_OuV54Pf8; Sun, 29 Mar 2020 16:25:57 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5AE3B182E47; Sun, 29 Mar 2020 16:25:57 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 032C2182E2C for ; Sun, 29 Mar 2020 16:25:57 +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 9eKZktV_NWFb for ; Sun, 29 Mar 2020 16:25: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 4E313182E0A for ; Sun, 29 Mar 2020 16:25:56 +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 CC64B366338B; Sun, 29 Mar 2020 16:25:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rna.nl; s=dkim_rsa2048; t=1585491955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Lp6WCmtEtqoi9ngnjYAt0SHGFMSvmS+l1I+WCR2VULU=; b=Z1aENTDGu5BXtsVkHhB/ulYH+SXhnZTTxubr9RitK0E/bu4lON4K+ffePdHNIQDN/GoGA3 N7n45tMXv4IB9tJXZ7rvc4mYjViAipYOJU42aCQgpzlmI+1bCnLZx9U91xi0sdfz8XpVnX 4TWwjV//ozFpvCHKuBIOkQkUgROAlDvbEFAVUiqeYLWe33jaEmSNFLcRbHrR0qdC9li2i9 rEJA8LG+OYblnBay3/jUCrcW18evVVoIhUaF70vRJaOgYIKUTzhzf5aVlGIWqH5bz6iDLF ob7b2Xo+GH1QdaaePtSDQEYfoI4SHNfWziK4Odz0bvzjxoE/upWFTNK9hcviJA== In-Reply-To: <84b1bf6c-d34b-ec3a-d574-2d730c3e09c0@gmail.com> 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:106670 Archived-At: --===============7354857907244228523== Content-Type: multipart/alternative; boundary="Apple-Mail=_8F6CDAE0-28C1-43E0-86EC-7E72EF6125AB" --Apple-Mail=_8F6CDAE0-28C1-43E0-86EC-7E72EF6125AB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 We should move this to the thread What alternative for scantokens( "btex " & texcommands & " etex=E2=80=9D)?= I=E2=80=99ve put my vardef there. The calls to this vardef are created = by lua code. I need to fix two things: use a string variable to build a btex-etex = construct and be able to use (almost) any character in that variable.=20 I can adapt the strings, if I know what I have to replace things with. I = can manipulate the strings while still in lua. But if I change it and = then via MP hand it to a \type{} statement in ConTeXt the replacement = will be typeset literally. So, it will be pretty complex. If I drop the = use of \type{} inside the btex-etex I have to =E2=80=98escape' = everything that TeX doesn=E2=80=99t see as normal text catcode. That, = again might play havoc with breaking words across lines later. G > On 29 Mar 2020, at 15:09, Wolfgang Schuster = wrote: >=20 > Gerben Wierda schrieb am 29.03.2020 um 15:06: >>> On 29 Mar 2020, at 14:35, Wolfgang Schuster = > wrote: >>>=20 >>> Gerben Wierda schrieb am 29.03.2020 um 14:30: >>>>> On 29 Mar 2020, at 12:58, Wolfgang Schuster = > wrote: >>>>>=20 >>>>> Gerben Wierda schrieb am 29.03.2020 um 12:52: >>>>>> I am using MetaFun (Lua code) to create METAPOST commands from an = XML file. One of the issues I am running into that in METAPOST I have to = handle strings with " characters in them and METAPOST doesn=E2=80=99t = like those. The argument using the string >>>>>> Foo "Bar=E2=80=9D Foo >>>>>=20 >>>>> ^^^ >>>>>=20 >>>>> Use correct left quotation marks or \quotation{=E2=80=A6}. >>>> I=E2=80=99m not hard coding the string, I=E2=80=99m reading it from = an XML. So, whatever I do, I need to do it by manipulating the string. >>>> E.g. if the string I read contains >>>> Foo "Bar=E2=80=9D Foo >>>> your suggestion means I have to programmatically change that to >>>> Foo \quotation{Bar} Foo >>>> which is too complicated, given that I don=E2=80=99t have regular = expression replace at my disposal. >>>> I might be able to change al =E2=80=9C instances into something = else by walking through the string and building a new one. >>>=20 >>> Your example uses " before Bar and not =E2=80=9C which is the = problem. >> Yes, I am aware that that is my problem. It is just that I do not = have the luxury to decide myself what will be put in the string. It must = work for any string. So, I will have to be putting that string to \type = and make sure that is used as the label. >=20 > Does btex .. etex help or can't you change the strings and replace the = quotation marks before you pass them to MetaPost? >=20 > \starttext >=20 > \startMPcode > draw textext.urt("One"); > draw btex "Two" etex shifted (0,15); > label.urt("Three",(0,30)); > label.urt(btex "Four" etex,(0,45)); > \stopMPcode >=20 > \stoptext >=20 > Wolfgang --Apple-Mail=_8F6CDAE0-28C1-43E0-86EC-7E72EF6125AB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 We = should move this to the thread

What alternative for scantokens( "btex " & = texcommands & " etex=E2=80=9D)?

I=E2=80=99ve put my vardef = there. The calls to this vardef are created by lua = code.

I need to fix two things: use = a string variable to build a btex-etex construct and be able to use = (almost) any character in that variable. 

I can adapt the strings, if I know what I have to = replace things with. I can manipulate the strings while still in = lua. But if I change it and then via MP hand it to a \type{} statement = in ConTeXt the replacement will be typeset literally. So, it will be = pretty complex. If I drop the use of \type{} inside the btex-etex I = have to =E2=80=98escape' everything that TeX doesn=E2=80=99t see = as normal text catcode. That, again might play havoc with = breaking words across lines later.

G

On 29 = Mar 2020, at 15:09, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com> wrote:

Gerben= Wierda schrieb am 29.03.2020 um 15:06:
On 29 Mar = 2020, at 14:35, Wolfgang Schuster <wolfgang.schuster.lists@gmail.com <mailto:wolfgang.schuster.lists@gmail.com>> = wrote:

Gerben Wierda schrieb am 29.03.2020 = um 14:30:
On 29 Mar 2020, at 12:58, Wolfgang Schuster = <wolfgang.schuster.lists@gmail.com <mailto:wolfgang.schuster.lists@gmail.com>> = wrote:

Gerben Wierda schrieb am 29.03.2020 = um 12:52:
I am using = MetaFun (Lua code) to create METAPOST commands from an XML file. One of = the issues I am running into that in METAPOST I have to handle strings = with " characters in them and METAPOST doesn=E2=80=99t like those. The = argument using the string
Foo "Bar=E2=80=9D Foo

    ^^^

Use correct left quotation marks or = \quotation{=E2=80=A6}.
I=E2=80=99m not hard = coding the string, I=E2=80=99m reading it from an XML. So, whatever I = do, I need to do it by manipulating the string.
E.g. if = the string I read contains
Foo "Bar=E2=80=9D Foo
your suggestion means  I have to programmatically change = that to
Foo \quotation{Bar} Foo
which is too = complicated, given that I don=E2=80=99t have regular expression replace = at my disposal.
I might be able to change al =E2=80=9C = instances into something else by walking through the string and building = a new one.

Your example uses " = before Bar and not =E2=80=9C which is the problem.
Yes, I am aware that that is my problem. It is = just that I do not have the luxury to decide myself what will be put in = the string. It must work for any string. So, I will have to be putting = that string to \type and make sure that is used as the label.

Does btex .. etex help or can't = you change the strings and replace the quotation marks before you pass = them to MetaPost?

\starttext

\startMPcode
draw = textext.urt("One");
draw btex "Two" etex shifted = (0,15);
label.urt("Three",(0,30));
label.urt(btex "Four" etex,(0,45));
\stopMPcode

\stoptext

Wolfgang

= --Apple-Mail=_8F6CDAE0-28C1-43E0-86EC-7E72EF6125AB-- --===============7354857907244228523== 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== --===============7354857907244228523==--