Subject: mailing-list for TeXmacs Users
List archive
From : Henri Lesourd <address@hidden>- To: Lionel Elie Mamane <address@hidden>
- Cc: address@hidden
- Subject: Re: [TeXmacs] Scheme string to tm tree conversion
- Date: Tue, 28 Feb 2006 23:52:17 +0100
Lionel Elie Mamane wrote:
Notice that the tree produced by (string->tree "<gtr>") andI see... As I expected, that's a little bit a mess.
(string->tree ">") is not the same one. Save your file and look at it
in less (or more or emacs or ...). One is \>, the other \<gtr\>.
Try with (string->tree "<"). It gives an _invalid_ tree.
Thus (after some test), it seems that if you escape
the way I described in my previous mail, it should
work (excuse me, I did a little mistake, the escaping
should be :
[[
(set! s (substring! "<" "\\<less" s)) ; starting escaping for '<'
(set! s (substring! ">" "\\<gtr\\>" s)) ; escaping '>'
(set! s (substring! "\\<less" "\\<less\\>" s)) ; finishing escaping for '<'
and :
(set! s (substring! "\\<less\\>" "<" s)) ; unescaping '<'
(set! s (substring! "\\<gtr\\>" ">" s)) ; unescaping '>'
]]
This is for full escaping, cf. remarks below, where it
is also explained why you need to double the '\').
But lets continue ; namely, for example (using a document
that contains a first line equal to "ABCDE", and a Scheme
session just after) :
[[
ABCDE
scheme] (path-assign '(0 0) (string->tree "<less>gtr<gtr>"))
scheme] _
]]
(the '_' is here to show the position of the cursor),
the evaluation of the (path-assign) command above replaces
the "ABCDE" by exactly "<gtr>".
Nevertheless, the whole picture is a little bit
more tricky, *because* :
(1) If you use a string in (path-assign (string->tree ...)),
(string->tree) will perform the unescaping of the <less>
and <gtr> above ; thus your escaping routines should
only do :
[[
"<" --> "<less>"
">" --> "<gtr>"
]]
, and then you rely on (string->tree) to reverse the
transformation ;
(2) If you are generating a TeXmacs document, you are in a
different situation, you must then perform the *whole*
escaping :
[[
"<" --> "\\<less\\>"
">" --> "\\<gtr\\>"
]]
And of course, if you perform the whole escaping in the
example above (i.e., inside a (path-assign (string->tree ...))),
then you create an incorrect markup.
Thus you must really know *exactly* what you want, in
wich context exactly you are, with these f!@#%^g escapings.
IMPORTANT SUBNOTE: The Scheme interpreter itself
uses the '\' symbol for escaping, namely you can
use it for escaping '"' and itself inside a string,
for example "x\"a\"x" is the string : {{ x"a"x }}.
Thus, the string "\\<less\\>" above is in
fact : {{ \<less\> }}.
You must of course use this convention in your
Scheme code, otherwise if you write "\<less\>",
it is in fact the string "<less>", because "\<"
is the same as "<".
To see the difference between the escaped and
unescaped **scheme** string, use (display) for
seeing the unescaped string, and (write) for
seeing the escaped string.
*Now*, it should be the whole story (hopefully...).
Cf. Above : are you directly generating the .tm file, or rather,isn't it what you want ?
No. I want (foo "<gtr>") to be the tree that gets serialized as
\<less\>gtr\<gtr\> in a .tm file. This means the '<' symbol, followed
by the letters g, t and r and then the '>' symbol. Not the '>' symbol
alone.
are you modifying a TeXmacs file using the tree API (i.e. (path-assign),
and other similar functions) ?
There are functions in TeXmacs that perform *some* escapings...Or rather would you like to get :
[[
(string->tree ">")
=>
'\<gtr\>'
]]
Yes, exactly.
In my own case, I got fed up with these escaping problems in the
strings, thus I finally decided to do my escapings myself.
So you are saying that this function is _not_ part of TeXmacs?
... but as you saw yourself, it is not so easy to figure out
exactly what they do, and also which are the places where some
hidden escapings / unescapings occur.
This is why I prefer the alternative approach when **I** figure
out exactly what I need :-), and then I build it using building
blocks for which I also know exactly what they do.
- Scheme string to tm tree conversion, Lionel Elie Mamane, 02/28/2006
- Re: [TeXmacs] Scheme string to tm tree conversion, Henri Lesourd, 02/28/2006
- Re: [TeXmacs] Scheme string to tm tree conversion, Lionel Elie Mamane, 02/28/2006
- Re: [TeXmacs] Scheme string to tm tree conversion, Henri Lesourd, 02/28/2006
- Re: [TeXmacs] Scheme string to tm tree conversion, Lionel Elie Mamane, 02/28/2006
- Re: [TeXmacs] Scheme string to tm tree conversion, Henri Lesourd, 02/28/2006
Archive powered by MHonArc 2.6.19.