texmacs-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Texmacs-dev] Re: [TeXmacs] macros, passing paramaters to with, and usin


From: Henri Lesourd
Subject: [Texmacs-dev] Re: [TeXmacs] macros, passing paramaters to with, and using includes
Date: Wed, 08 Mar 2006 13:11:31 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02

Corey Sweeney wrote:

I tried this:

<assign|include-with-intro|<\macro|filename|intro>
  <\with|intro-text|intro>
    <include|/home/corey/sql-queries.tm <http://queries.tm>>
  </with>
</macro>>

However, the parameter "intro" in <with|intro-text|intro|... refuses to become a paramater from the macro (i.e. brown and italicized), and becomes the literal text "intro". Usually it happens automatically when I hit tab. Is there a way to force this to happen?

I did try this first:
<assign|include-with-intro|<\macro|filename|intro-text>
  <include|/home/corey/sql-queries.tm <http://queries.tm>>
</macro>>

But then the included file believed that intro-text was not defined at all.


I tried to do what you want ; I discovered that in any case, for some
obscure reason, the use of <include|...> inside a macro just doesn't
work :
[[
  <macro|inc0|<macro|x|<include|<arg|x>>>
]]

Thus the solution to this problem is to use Scheme for loading the
file. After having a look in build-glue-basic.scm, one can see that
there is a Scheme primitive that can perform loading a .tm file,
namely (tree-load-inclusion). Thus we write :
[[
  <macro|inc0|<macro|x|<extern|tree-load-inclusion|<arg|x>>>
]]

but it doesn't work, because before being a parameter
of (tree-load-inclusion), the <arg|x> must be converted
to the string type. Thus we (would) write :
[[
<macro|inc0|<macro|x|<extern|(lambda (x) (tree-load-inclusion (tree->string x)))|<arg|x>>>
]]

But this one *still* doesn't work, due to address@hidden problems of
symbol encoding (for the symbol ">" in "tree->string"...), because
we want to write the Scheme code directly inside the TeXmacs <extern>
markup (the clean alternative solution would be to write a Scheme
plugin where we could safely write our Scheme functions. But then
we would have to deal with the current bug in the recently implemented
lazy evaluation of Scheme plugins ; I'm afraid that discussing this
would lead us even farther in designing hacks...).

Thus we need to trick it ; the following way works :
[[
  <macro|inc0|<macro|x|<extern|(lambda (x) (tree-load-inclusion
    ((eval-string (string-append "tree-" (substring ">" 4 5) "stree"))
    x)))|<arg|x>>>
]]

[it works because the ">" symbol is encoded by TeXmacs
as "<gtr>", thus {{ (substring ">" 4 5) }} is in fact
(after encoding) {{ (substring "<gtr>" 4 5) }}, thus
it yields ">" ; then the surrounding (string-append ...)
builds the name "tree->stree", and (eval-strings) turns
this name into the corresponding lambda ; finally, this
lambda is applied to the parameter 'x' ...].


Hope it helps :=P


Best, Henri


P.S. : Look at the two attached files, they contain an
 implementation of <include-file|filename|comment> that
 works, along with the different intermediary steps to
 build it.
<TeXmacs|1.0.6>

<style|generic>

<\body>
  <value|intro-text>

  A

  \;

  \;

  \;

  Hello!

  \;

  \;

  \;

  B
</body>

<\initial>
  <\collection>
    <associate|language|english>
    <associate|page-bot|1in>
    <associate|page-even|1in>
    <associate|page-odd|1in>
    <associate|page-right|1in>
    <associate|page-top|1in>
    <associate|page-type|letter>
    <associate|par-width|6.5in>
    <associate|preamble|false>
  </collection>
</initial>
<TeXmacs|1.0.6>

<style|generic>

<\body>
  <hrule>

  Initial include text :

  <with|intro-text|12345|<include|hello.tm>>

  <hrule>

  Initial version of the inc0 macro (that doesn't work) :

  <assign|inc0|<\macro|x>
    <include|<arg|x>>
  </macro>>

  <\inc0>
    hello.tm
  </inc0>

  <hrule>

  2nd version of inc0 (that works) :

  <assign|inc0|<macro|x|<extern|(lambda (x) (tree-load-inclusion
  ((eval-string (string-append "tree-" (substring "\<gtr\>" 4 5) "stree"))
  x)))|<arg|x>>>>

  <inc0|hello.tm>

  <hrule>

  Finally, the macro that does what we want :

  
<assign|include-file|<macro|file|intro|<with|intro-text|<arg|intro>|<inc0|<arg|file>>>>>

  <include-file|hello.tm|This is my introductary text>

  <hrule>
</body>

<\initial>
  <\collection>
    <associate|page-type|letter>
    <associate|preamble|true>
  </collection>
</initial>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]