Unintuitive macro editing

This post is not really about solving a problem because somehow I solved it, but I feel totally clueless about why. Maybe someone can shed some light.

I’m trying to wrap equations inside <html-class|equation|> so I can apply CSS styling to equations when exporting to html. I can actually do it manually on the editor, however if I try to define a macro inside the style file to automate it it’s very hard.

For example, this that looks like the most straigthforward way is a dead end because when I hit ENTER, <hybrid|equation> will be quietly removed:
macro1

Why? No idea. It looks like Texmacs doesn’t like it. Maybe it thinks it’s invalid but doesn’t say why. It remembers me of ed. I would love if it spat some garbage, some error, a clue, an insult, anything but deleting my input.

I have managed to edit the style file using a plain text editor and this actually works:

  <assign|equation-web|<\macro|body>
    <\html-class|equation>
      <\equation>
        <arg|body>
      </equation>
    </html-class>
  </macro>>

Inside the style file editor it looks like this little abomination:
macro2

Now, if I try to enter the above inside Texmacs it’s possible but an exercise in frustration.
This is again a dead end since hitting ENTER will delete \equation as before.
macro3

The trick it’s activating html-class and then we can finally get the macro.
I think it’s insane. I have searched for active/inactive in the documentation and it looks like it just affects the rendering. What the hell is going on here?

As a bonus:

  1. If I rename the macro from equation-web to tmhtml-equation Texmacs crashes.
  2. For some reason there was an old version of a macro when I selected Edit macro... from the menu. Where are those stored? Not in my style file, not in the document.

I’m myself sometime put down by the source editing mode, but I came to learn quite rapidly that most of the time is me not realising what is going on, than a real bug. Joris is a very careful programmer and even if bug in TeXmacs exists, most of the time weird behaviour just hide a complex situation.

  1. My first remark is that, in TeXmacs style files or in preamble you do not have to have \inactive or \active tags, they are useful only when you are in “non-source” mode and therefore you need a way to specify to TeXmacs that you do not want it to interpret a tag but to show it to you. Think about “quote” and “unquote” in scheme. So all the inactive tags there, they do not allow TeXmacs to interpret your code, you have to remove them.

  2. I think you cannot have \tmhtml-equation refer to \equation because in first place this mechanism consist in replacing any tag \mytag to an equivalent \tmhtml-mytag if it exists, so in this case your \equation will become \tmhtml-equaiton and you have an infinite loop. Probably TeXmacs should detect this, but it currently does not. You will have to have \tmhtml-equation and \equation to refer to the same underlying rendering macro if you need. Maybe you have to give a look at some code to get an idea on how to work with the TeXmacs macro language. Also the book of Joris give a lot of informations and similarly there is a lot of info in the Help .

  3. You can change the way the scheme macro language is rendered on screen. Please give a look at the help, because there are some subtle points about it, for example usually the \concat and \document tags are not shown, and the first is rendered via an “inline” sequence of its argument while the second by going to a new line for every argument. So the spatial arrangement of the macro matters, that is also the reason why it is not easy to change. That is to say: you cannot y=just reformat the macro as you like, the formatting has a semantic meaning, (think about Python, for example, or Markdown)

HTH

As for your task, does not simply add

<assing|tmhtml-equation|body|<html-class|equation|\body>>

works? Why you have to refer to equation again? If you really need, the way to go I think is to write

<assign|internal-equation|equation>
<assing|tmhtml-equation|body|<html-class|equation|<internal-equation|\body>>>

Hi, thanks for your reply.

Yes, I don’t think it’s a bug. From what I have read TeXmacs wants to make sure that the input is valid so I’m sure that I’m trying to do something invalid and it doesn’t allow me. The problem I think is that it doesn’t give feedback. I’m sorry that this feels like complaining, it’s not my intention.

Regarding your points:

  1. For some reason TeXmacs automatically inserts inactive tags when editing the style file. I don’t know why.
  2. That makes sense.
  3. Yes I noticed that you can show the document and concat tags if you wish.

Regarding your other reply about tmhtml-equation maybe I didn’t understand the explanation given in the documentation:

My understanding is that in the example given when the document is exported to html, and only then, strong will be substituted with tmhtml-strong like it’s some way of specifying output-dependent tags. I think that in order to avoid the circular dependency I should copy the source of the equation macro inside tmhtml-equation and modify it as I wish (with html-class, for example).

Anyway, I think the best path would be to hack the converter scheme source code and make sure that it outputs CSS classes to every output. They could be appended with some prefix like tm- which could be even be configured. Since html elements can have several classes I don’t see any problem with this approach since the user can continue adding aditional classes with html-class. But I’m not there yet.

My understand of the export is the following: every time TeXmacs has to export a tag \XXX from the original document it has two choices: if \tmhtml-XXX exists then expand this instead of \XXX, if not continue by expanding \XXX. The expansion continue until primitives are reached. Your way of understanding does not take into account that the document is different from the fully expanded document (i.e. without any macro), and that you do not want to expand everything before converting, otherwise you loose semantic content, which you maybe want to preserve. this is the role of the tmhtml macros.

This seems overkill to me, also you maybe do not want to expand all the macros in the way they are designed.

Maybe you have to think first what is a use case for which the current mechanism does not work. If you look at TeXmacs website and at the blog “Notes on TeXmacs” you see that you can achieve a lot with the current setup.

I still have to read Massimiliano’s answers, but I also wish the macro editor were more extensively described either in the documentation or in a tutorial.
There are some explanations in the manual, which I went through perhaps too quickly, when I did so I did not have the feeling that they covered every aspect, maybe it is worth to see if something is left out and what.