Skip to Content.
Sympa Menu

texmacs-users - Re: [TeXmacs] Help on action

Subject: mailing-list for TeXmacs Users

List archive

Re: [TeXmacs] Help on action


Chronological Thread 
  • From: Henri Lesourd <address@hidden>
  • To: Alvaro Tejero Cantero <address@hidden>
  • Cc: address@hidden
  • Subject: Re: [TeXmacs] Help on action
  • Date: Fri, 28 Jan 2005 16:06:41 +0100



Alvaro Tejero Cantero wrote:

Hello,

You're right that "var" doesn't get assigned, but the problem is that I do not know how to assign it __inside a macro__ and __before the action__, which is what I need for the "active citation"

Look at the following code (indented for readability):


<assign|bcite|
<macro|x|
<assign|bibfilename|
<find-file|.|/home/qoptik/Literatur|<merge|<arg|x>|.pdf>>>
<action|<arg|x>|
(with s (get-env "bibfilename") (display* "bname=" (substring s 7
(string-length s))))>>>


When clicking in <bcite|Simon1994a> it produces in the terminal:


<unnamed port>:1:52: In procedure substring in expression (substring s 7 ...):
<unnamed port>:1:52: Argument 2 out of range: 7


So bibfilename is not assigned. I remember trying also to put the assign bibfilename statement outside the macro (?) and using a <with|bibfilename|<find-file|...>|<action|x|...>>, but with no results.

Do you know how to assign inside a macro?

The following markup fragment (in source mode) :
[[
<assign|macro1|<assign|var2|Yep!><value|var2>>
<macro1>
]]

is displayed as :
[[
Yep!
]]

in WYSIWYG mode in TeXmacs.

So it clearly dismisses the hypothese "the <assign> doesn't work in a TeXmacs macro" : it works
perfectly, in fact.

Let's try now with a simpler version of your macro, which doesn't uses the <action> :
[[
<assign|bcite2|
<macro|x|
<assign|bibfilename|<find-file|.|/home/henri|<merge|<arg|x>|.txt>>>
<value|bibfilename>>
]]

the following markup fragment :
[[
<find-file|.|/home/henri/|test1.txt>
<bcite2
test1>
]]

is displayed as follows (provided that the file /home/henri/test1.txt exists on your computer) :
[[
file:///home/henri/test1.txt

<error|bad find file>
]]

so it appears that the <find-file> didn't work inside the macro. How can it be so ? It could
be that the <arg|x> inside the macro didn't work. Let's build a simpler version of our macro
without this :
[[
<assign|bcite3|
<macro|x|
<assign|bibfilename|<find-file|.|/home/henri|<merge|test1|.txt>>>
<value|bibfilename>>
<bcite3
test1>
]]

Now it works, we get :
[[

file:///home/henri/test1.txt
]]

It appears that the bug is linked to the <arg|x>. So in order to build a simpler, but still buggy
version of the macro, we must try another way. Previously, we tested that the <assign> does
works in a macro. But perhaps in combination to other things it doesn't. Let's try to remove it :
[[
<assign|bcite4|
<macro|x|
<find-file|.|/home/henri|<merge|<arg|x>|.txt>>>>
<bcite4
test1>
]]

now the bug is here again ; we get :
[[

<error|bad find file>
]]

Things become more interesting ; it seems that the problem is linked to the <arg|x>, in combination with
<find-file> and <merge>. We already tried to remove the <arg|x>, we saw that it removes the bug. So
we must remove something else, either <find-file> or <merge>. Let's try with removing <find-file> :
[[
<assign|bcite5|
<macro|x|
<merge|<arg|x>|.txt>>>
<bcite5
test1>
]]

the bug is still here ! this time we get :
[[

<error|bad merge>
]]

Things become *even* more interesting, isn't it ? Could it be that this bugs arises just because we used
<merge> in combination with <arg|x> ? In such a case we would have discovered a (relatively) severe
bug in TeXmacs. But as a matter of fact, the following fragment :
[[
<assign|merge-test|<macro|x|<merge|<arg|x>|.txt>>
<merge-test|test1>
]]

works perfectly :
[[
test1.txt
]]

So the question open to us is : what is the difference between :
{{
<assign|merge-test|<macro|x|<merge|<arg|x>|.txt>>
<merge-test|test1>
}}

and :
{{
<assign|bcite5|
<macro|x|
<merge|<arg|x>|.txt>>>
<bcite5
test1>
}}

These two macros do exactly the same thing. The only difference is in the indentations. So
the only possible answer to our question is that our bug is linked to the indentations. More
precisely, if we now rewrite the <bcite5> macro this way :
[[
<assign|bcite5|<macro|x|<merge|<arg|x>|.txt>>>
]]

it appears that the following code :
[[
<bcite5
test1>
]]

is still buggy. Or either, if we write :
[[
<merge-test|
test1>
]]

then the code becomes buggy.

Finally, the root cause of the problem is that when writing a macro call, if we use multiline
entries to input parameters which should be strings, it doesn't work well. And the problem
is that as soon as a macro is written with indentations, the pretty printer forces you with a
new input with indentations/multiline entries, something it shouldn't do.

Basically, there are two solutions to your problem :

1) Rewrite your macro using only one line (but do it --by hand--, the command Source/Presentation/Compact
*doesn't* solve this problem). After this change, when you hit the '\' key, then 'bcite' then <enter>, TeXmacs
correctly proposes you your new inputs written as :
[[
<bcite|...>
]]

in the editor.

2) Go into the .tm file using emacs or any kind of ASCII editor, and find the :
[[
<\bcite5>
test1
</bcite>
]]

which, in fact, corresponds to the :
[[
<bcite5
test1>
]]

one can see in Source mode inside TeXmacs.

Then, inside your ASCII text editor, change your :
[[
<\bcite5>
test1
</bcite>
]]

to :
[[
<bcite5|test1>
]]

Thus, back inside TeXmacs, you can use your macro by copy & pasting the instance you just
corrected above.

If you want to do a package that other people can use, the solution (1) is the appropriate one.
On my computer, the following one-line macro :
[[
<assign|bcite0|<macro|x|<assign|bibfilename|<find-file|.|/home/henri|<merge|<arg|x>|.txt>>><action|
<arg|x>|(with s (get-env "bibfilename")(display* "bname=" (substring s 7 (string-length s)) "\\n"))>>>

<bcite0|test1>
]]

works perfectly (provided that the file /home/henri/test1.txt exists on your computer (to test it, change
the parameters of <find-file> and <bcite0> accordingly)).




Archive powered by MHonArc 2.6.19.

Top of Page