[NTG-context] How do I handle strings with " characters in it in METAPOST?

Wolfgang Schuster wolfgang.schuster.lists at gmail.com
Sun Mar 29 15:09:54 CEST 2020


Gerben Wierda schrieb am 29.03.2020 um 15:06:
> 
> 
>> On 29 Mar 2020, at 14:35, Wolfgang Schuster 
>> <wolfgang.schuster.lists at gmail.com 
>> <mailto:wolfgang.schuster.lists at 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 at gmail.com 
>>>> <mailto:wolfgang.schuster.lists at 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


More information about the ntg-context mailing list