* How do I handle strings with " characters in it in METAPOST? @ 2020-03-29 10:52 Gerben Wierda 2020-03-29 10:58 ` Wolfgang Schuster 0 siblings, 1 reply; 7+ messages in thread From: Gerben Wierda @ 2020-03-29 10:52 UTC (permalink / raw) To: mailing list for ConTeXt users 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’t like those. The argument using the string Foo "Bar” Foo turns into someCall( "Foo “Bar” Foo”) I guess I have to change the string into something with explicit character codes for the " characters, maybe? In a later stage, these strings will be typeset by the ConTeXt side of things so they fit into a certain area within the METAPOST picture. What is my best approach? G ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 10:52 How do I handle strings with " characters in it in METAPOST? Gerben Wierda @ 2020-03-29 10:58 ` Wolfgang Schuster 2020-03-29 12:30 ` Gerben Wierda 0 siblings, 1 reply; 7+ messages in thread From: Wolfgang Schuster @ 2020-03-29 10:58 UTC (permalink / raw) To: mailing list for ConTeXt users, Gerben Wierda 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’t like those. The argument using the string > > Foo "Bar” Foo ^^^ Use correct left quotation marks or \quotation{...}. Wolfgang ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 10:58 ` Wolfgang Schuster @ 2020-03-29 12:30 ` Gerben Wierda 2020-03-29 12:35 ` Wolfgang Schuster 0 siblings, 1 reply; 7+ messages in thread From: Gerben Wierda @ 2020-03-29 12:30 UTC (permalink / raw) To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users > On 29 Mar 2020, at 12:58, Wolfgang Schuster <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’t like those. The argument using the string >> Foo "Bar” Foo > > ^^^ > > Use correct left quotation marks or \quotation{…}. I’m not hard coding the string, I’m 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” Foo your suggestion means I have to programmatically change that to Foo \quotation{Bar} Foo which is too complicated, given that I don’t have regular expression replace at my disposal. I might be able to change al “ instances into something else by walking through the string and building a new one. G ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 12:30 ` Gerben Wierda @ 2020-03-29 12:35 ` Wolfgang Schuster 2020-03-29 13:06 ` Gerben Wierda 0 siblings, 1 reply; 7+ messages in thread From: Wolfgang Schuster @ 2020-03-29 12:35 UTC (permalink / raw) To: Gerben Wierda; +Cc: mailing list for ConTeXt users Gerben Wierda schrieb am 29.03.2020 um 14:30: > > >> On 29 Mar 2020, at 12:58, Wolfgang Schuster <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’t like those. The argument using the string >>> Foo "Bar” Foo >> >> ^^^ >> >> Use correct left quotation marks or \quotation{…}. > > I’m not hard coding the string, I’m 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” Foo > > your suggestion means I have to programmatically change that to > > Foo \quotation{Bar} Foo > > which is too complicated, given that I don’t have regular expression replace at my disposal. > > I might be able to change al “ instances into something else by walking through the string and building a new one. Your example uses " before Bar and not “ which is the problem. Wolfgang ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 12:35 ` Wolfgang Schuster @ 2020-03-29 13:06 ` Gerben Wierda 2020-03-29 13:09 ` Wolfgang Schuster 0 siblings, 1 reply; 7+ messages in thread From: Gerben Wierda @ 2020-03-29 13:06 UTC (permalink / raw) To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 1493 bytes --] > On 29 Mar 2020, at 14:35, Wolfgang Schuster <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> 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’t like those. The argument using the string >>>> Foo "Bar” Foo >>> >>> ^^^ >>> >>> Use correct left quotation marks or \quotation{…}. >> I’m not hard coding the string, I’m 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” Foo >> your suggestion means I have to programmatically change that to >> Foo \quotation{Bar} Foo >> which is too complicated, given that I don’t have regular expression replace at my disposal. >> I might be able to change al “ instances into something else by walking through the string and building a new one. > > Your example uses " before Bar and not “ 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. G [-- Attachment #1.2: Type: text/html, Size: 4124 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 13:06 ` Gerben Wierda @ 2020-03-29 13:09 ` Wolfgang Schuster 2020-03-29 14:25 ` Gerben Wierda 0 siblings, 1 reply; 7+ messages in thread From: Wolfgang Schuster @ 2020-03-29 13:09 UTC (permalink / raw) To: Gerben Wierda; +Cc: mailing list for ConTeXt users 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’t like those. The argument using the string >>>>> Foo "Bar” Foo >>>> >>>> ^^^ >>>> >>>> Use correct left quotation marks or \quotation{…}. >>> I’m not hard coding the string, I’m 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” Foo >>> your suggestion means I have to programmatically change that to >>> Foo \quotation{Bar} Foo >>> which is too complicated, given that I don’t have regular expression >>> replace at my disposal. >>> I might be able to change al “ instances into something else by >>> walking through the string and building a new one. >> >> Your example uses " before Bar and not “ 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 ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How do I handle strings with " characters in it in METAPOST? 2020-03-29 13:09 ` Wolfgang Schuster @ 2020-03-29 14:25 ` Gerben Wierda 0 siblings, 0 replies; 7+ messages in thread From: Gerben Wierda @ 2020-03-29 14:25 UTC (permalink / raw) To: Wolfgang Schuster; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 2917 bytes --] We should move this to the thread What alternative for scantokens( "btex " & texcommands & " etex”)? I’ve 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 ‘escape' everything that TeX doesn’t 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’t like those. The argument using the string >>>>>> Foo "Bar” Foo >>>>> >>>>> ^^^ >>>>> >>>>> Use correct left quotation marks or \quotation{…}. >>>> I’m not hard coding the string, I’m 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” Foo >>>> your suggestion means I have to programmatically change that to >>>> Foo \quotation{Bar} Foo >>>> which is too complicated, given that I don’t have regular expression replace at my disposal. >>>> I might be able to change al “ instances into something else by walking through the string and building a new one. >>> >>> Your example uses " before Bar and not “ 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 [-- Attachment #1.2: Type: text/html, Size: 5967 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-03-29 14:25 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-03-29 10:52 How do I handle strings with " characters in it in METAPOST? Gerben Wierda 2020-03-29 10:58 ` Wolfgang Schuster 2020-03-29 12:30 ` Gerben Wierda 2020-03-29 12:35 ` Wolfgang Schuster 2020-03-29 13:06 ` Gerben Wierda 2020-03-29 13:09 ` Wolfgang Schuster 2020-03-29 14:25 ` Gerben Wierda
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).