Skip to Content.
Sympa Menu

texmacs-users - My first non-trivial macro

Subject: mailing-list for TeXmacs Users

List archive

My first non-trivial macro


Chronological Thread 
  • From: "David G. Wonnacott" <address@hidden>
  • To: address@hidden
  • Subject: My first non-trivial macro
  • Date: Fri, 30 Jun 2006 12:06:52 -0400 (EDT)
  • Hc-host: Message scanned by SMTP2, Networking & Systems, Haverford College, Haverford, PA 19041 [v011]
  • Hc-mailscanner: Found to be clean

I have been using TeXmacs for several years now in what I consider to
be a fairly unsophisticated way, in that I have just been sticking to
the commands that are provided in the menus rather than writing my own.

I am getting to the point where the things I want to do are pushing me
past the limits of built-in functionality, and am trying to start
extending TeXmacs (as I do emacs and LaTeX, which I've been using for
a somewhat longer period of time). I'm working my way through Henri
Lesourd's tutorial and referring to the online help for various
details; the tutorial has been very helpful now that I've figured out
that escape-escape is equivalent to the alt key in all ways except
that it works on the Macintosh :-)

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.

Can anyone help me understand what's going on here? I can also send
the .tm file, or a tar file of that and the Python/code subdirectory,
if that would help. If this cannot be done in the macro system but
requires the use of guile, I would be perfectly happy with that, as I
plan to transition to using guile as well as soon as I'm comfortable
with the macro system (which seems to be necessary to interface to
guile functions in TeXmacs?).

Thanks,
Dave Wonnacott
address@hidden


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.

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. Other than
that, I've really enjoyed working with TeXmacs.


  • My first non-trivial macro, David G. Wonnacott, 06/30/2006

Archive powered by MHonArc 2.6.19.

Top of Page