Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] My first non-trivial macro

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] My first non-trivial macro


Chronological Thread 
  • From: Henri Lesourd <address@hidden>
  • To: "David G. Wonnacott" <address@hidden>
  • Cc: address@hidden
  • Subject: Re: [TeXmacs] My first non-trivial macro
  • Date: Sun, 02 Jul 2006 19:25:34 +0200

David G. Wonnacott wrote:

However, I am having trouble creating a macro that builds a file name
and then includes it. I would like to do this because I am working on
course notes for an introductory CS course that can be delivered in
either C++ or Python (we need a multi-paradigm language), and I'd like
to have one central text in which I define the variable
coding-language to be, say, Python, and then write something like
<in-code|foo> to include the file Python/code/foo.py where I want an
example. Then by switching coding-language to C++ we would then be
including the file C++/code/foo.py.

I have tried the following (copied right from my document while in
"Edit source tree" mode, and then formatted for easy reading -- delete
all spaces, tabs, and newlines to get exactly what came from TeXmacs):

<assign|code-file|
<macro|basename|
<value|coding-language>
/code/
<arg|basename>
<case|<equal|<value|coding-language>|Python>|.py|
<equal|<value|coding-language>|C++>|.cc>>>

I can use this successfully to build the desired file name:

<code-file|temp-test>

gives me

Python/code/temp-test.py

(I had to re-type that, since copying out of the document in normal
mode just gave me exactly what I got in "Edit source tree" mode). I
can use a regular

<include|
Python/code/temp-test.py>

to view the file, but when I use

<include|
<code-file|temp-test>>

I just get a blank line rather than the file. Needless to say, my
in-code macro that does this doesn't work either.


I just tried what you describe, and it seems that the <include>
macro doesn't tolerate anything other than constant urls as a
parameter.

What you can do is to rewrite the include as a macro written by
means of a Scheme function (namely, using <extern>), following
the way it is done in the example1 plugin for the Scheme-written
macro for reversing a string (section 3.3.1 of my tutorial). The
tutorial explains also exactly how the directory structure of the
plugin's directory should be.

You can download the tarball for the example1 plugin on my TeXmacs
page, under the link "Some example plugins [[a basic one]] ...",
at :
<<
http://www.ags.uni-sb.de/~henri/texmacs/
>>

Just removing the unnecessary example code, and cut and pasting the
Scheme function (reverse-string s) to a function (include-file x)
which reads the content of the file as one big string, and sends
it back as a result to TeXmacs, should be easy (i.e., this is only
a matter of Guile programming). When this function will be working,
the only remaining thing to do will be to add the appropriate macro
<my-include> into the example1.ts stylesheet, following the example
of the <reverse> macro which is already there.


P.S. Is there any way to tell TeXmacs that I want to create a macro
but be given a warning if that name is already in use? This would be
like \newcommand in LaTeX. I have been just trying out names to see if
they are already taken, but of course that is no defense against
collisions with other style files I may choose to work with in the
future.


The following trick works (try it !) :
<<
<if|<equal|<value|x>|<value|a-variable-which-is-not-defined>>|undefined|defined>

<assign|x|1>

<if|<equal|<value|x>|<value|a-variable-which-is-not-defined>>|undefined|defined>
>>

, namely, the <value|...> of undefined variables are all the same (as
a matter of fact, they are all equal to the value "<uninit>").

It should work during a certain amount of time, but I'm not sure
that at some point, it will not become broken.


P.P.S. I find myself missing the "C-h c" describe-key-briefly feature
of emacs, which is incredibly helpful for both learning to program and
also figuring out what's wrong with your modifier keys.

Such a feature is planned, but it doesn't exists yet in TeXmacs.


Other than
that, I've really enjoyed working with TeXmacs.


Thanks !


Best, Henri




Archive powered by MHonArc 2.6.19.

Top of Page