Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] macros, passing paramaters to with, and using includes

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] macros, passing paramaters to with, and using includes


Chronological Thread 
  • From: Henri Lesourd <address@hidden>
  • To: Corey Sweeney <address@hidden>
  • Cc: address@hidden, address@hidden
  • Subject: Re: [TeXmacs] macros, passing paramaters to with, and using includes
  • Date: Wed, 08 Mar 2006 13:11:31 +0100

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 f!@#$%g 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>


Archive powered by MHonArc 2.6.19.

Top of Page