[metapost] strings with > 4000 characters
luecking at uark.edu
Mon Sep 12 17:36:28 CEST 2011
At 03:43 AM 9/12/2011, Mojca Miklavec wrote:
>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
substring (0, 6) of S10.
With some extra effort, an array of strings of variable
length could be accessed similarly.
The problem is not so much the length of the string as
the size of the numbers required to index it. In the
above scenario, one would have to pass the index into
the array of strings and then the pair of locations in
If one were to use lengths which were powers of two, then
one could pass the location as a pair of fractions. For
example, if each S[j] had length 256, then one could get
at 10000 to 10006 by passing A=10000/256 and B=10006/256,
(or 39+16/256 and 39+22/256) which would access this by
n := floor A;
if n = floor B):
substring((A - n)*256, (B - n)*256) of S[n]
% some code to concatenate parts from different S[j]
Only fractions whose denominators are powers of two
are guaranteed to be exactly represented.
I'm actually somewhat surprised one is even allowed to build
strings longer than 4095=floor(infinity). I encountered
some years ago (TeXLive 2005) a limit on the length of a
path (path_size.mpost). It defaulted to 2000 at the time,
but it could be changed in texmf.cnf. It seems to be gone
now (version 1.504). But I can't find any obvious limit on
string lengths even as far back as 2000 (TeX Live 5).
Daniel H. Luecking
Department of Mathematical Sciences
More information about the metapost