[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Texmacs-dev] New special env variable: path to self
From: |
Henri Lesourd |
Subject: |
Re: [Texmacs-dev] New special env variable: path to self |
Date: |
Thu, 26 Oct 2006 17:40:28 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030821 |
Lionel Elie Mamane wrote:
The problem is that as far as I can determine, there is no way for
that scheme procedure to know the position in the document of the node
being typeset.
It seems to me that there is a very easy way to determine the path of
a parameter of a Scheme macro, it is :
<<
(tm-define (my-scheme-macro parm)
(:type (tree -> tree))
(with path (path->tree parm)
blah
.......
)
>>
Using this path, you can find the path (and get a pointer to
the corresponding tree) of the embedding TeXmacs macro,
i.e., the corresponding unexpanded markup that called the
macro, not only the path of one of the arguments ; or either,
a pointer to one of the surrounding tree, and use these different
tree/paths to do the calculations you want.
For example, if your markup looks like that :
<\session>
<my-input|$PROMPT1|$INPUT1>
<output|$OUTPUT1>
.................................
</session>
, and if the <my-input|...> macro is implemented by means of
a Scheme function, then you can get the path of :
-> The surrounding <session|...> tag ;
-> The current <my-input|...> tag ;
Given that in order to be able to contain several
<my-input|...> & <output> tags, the <session|...>
tag is in reality encoded this way :
[[
<\session>
MULTIPLE TAGS
</session>
<====>
<session|<document|MULTIPLE TAGS>>
]]
, the paths of the <session>, <my-input> & <output>
tags will have the shape :
[[
path(<session|...>) == (PREFIX)
path(my-input|...>) == (PREFIX 0 2*i)
path(output|...>) == (PREFIX 0 2*i+1), 0 <= i <= N
]]
Now that we arrived here, it is probably clear that from
inside the <my-input|...> Scheme code, one can compute
the index "i", and decide a different color for using in the
display of the <my-input|...>, depending on the position
of the <my-input|...> in the embedding <session|...> tag.
Note 1 : The (tm-upwards-path p tags nottags) function
in graphics-utils.scm illustrates how to write a Scheme
function to find the first embedding tag of some kind,
starting from a path somewhere in the document ;
Note 2 : Don't forget that if your macros use Scheme,
you must use a <use-module|...> (if I correctly remember...)
in your stylesheet to force the loading of the corresponding
Scheme files **before** the opening of the document which
use the tags that use the Scheme code to display themselves ;
Hope it helps. If some problem remains for solving your
problem this way (and if I correctly understood what you
need), feel free to post new questions.
Would you be willing to accept such a patch for TeXmacs? Would you
want it done in another manner?
Joris is the person in charge of accepting patches in
this part of TeXmacs.