[metapost] strings with > 4000 characters

Mojca Miklavec mojca.miklavec.lists at gmail.com
Mon Sep 12 20:41:56 CEST 2011


On Mon, Sep 12, 2011 at 17:36, Dan Luecking wrote:
> At 03:43 AM 9/12/2011, Mojca Miklavec wrote:
>>
>> Dear list,
>>
>> I would like to ask if there is any trick that enables splitting
>> strings with > 4000 characters.
>>
>> I would like to use
>>    substring (10000,10006) of some string
>>
>> When drawing functions, one can scale down calculations towards lower
>> numbers and with some special care, one can still make it work. Is
>> there any similar trick (excluding metapost 2) for strings?
>
> You might store long strings as arrays of shorter
> strings. For example, if a long string is stored
> as S0, S1, S2, ... S[N], and each one (except the
> last) is 1000 characters long (say), then characters
> between 10000 and 10006 of the whole could be
> accessed as
>   substring (0, 6) of S10.

If I don't come up with something better, I will probably end up using
this indeed.

> The problem is not so much the length of the string as
> the size of the numbers required to index it.

I got that :(

I still wonder what happens with all the characters after 4000 ... The
string can be stored, but is there any way to use it?

> I'm actually somewhat surprised one is even allowed to build
> strings longer than 4095=floor(infinity).

Me too :)

But it is quite handy. In ConTeXt MKIV and with Hans' help I now
happily use "arbitrary" long string, but Hans does something very
dirty behind the scenes.

Here are also some answers to Nicola's suggestions:

On Mon, Sep 12, 2011 at 15:51, Nicola Vitacolonna wrote:
>
> Three tricks come to my mind (all untested!):
> 1) Repeatedly eat chunks from your strings, e.g.
> for i = 1 upto 5 : s := substring(2000,infinity) of s; endfor
> s := substring(0,6) of s;

This cuts the string after approximately 3480 characters. And please
don't ask me where that number came from.

> 2) Set warningcheck:=0;

How would this help?

> 3) Use dviluatex as the TeX engine. For example, if the substrings are to

This is sadly out of question. I'm writing this code as a fall-back
mechanism *exactly* for cases when luatex is not available. (In LuaTeX
the code works already, in a completely different and much more
optimal way.)

Mojca



Mojca



More information about the metapost mailing list