Folding computation

In a paper I am writing I sometimes have lengthy computations that probably will need to be removed further down the line. Currently I would like to keep them (in a folded state, expandable on click). I saw that there is the fold tag but it only works at the level of paragraphs and outside math. Here is an example of intermediate computation that I would like to fold:


I would like to collapse the inner tabular to be just an empty line.

As a simpler example I would like to make this:


become this:

and make the ... active so that a right-click can toggle between the two states. Here is the code of the simple table in the full state:

<\equation*>
  <tabular*|<tformat|<table|<row|<cell|1+2+3+4>>|<row|<cell|<tabular*|<tformat|<table|<row|<cell|=3+3+4>>|<row|<cell|=6+4>>>>>>>|<row|<cell|=10>>>>>
</equation*>

Is that possible? I tried most tags in the “fold” section but none of them work inside of math.

2 Likes

After a quick test, the impossibility seems to be caused by the editor and not by the typesetter.

This for example can be composed within the editor, by first writing the equations, then selecting them (I think one is selecting all the cells, but not the table), then clicking one of the “fold” entries in the menu and finally copy-pasting the table from the fixed to the “foldable” argument of folded-std

<\eqnarray*>
  <\folded-std>
    <tabular|<tformat|<table|<row|<cell|a>|<cell|=>|<cell|b>>|<row|<cell|c>|<cell|=>|<cell|d>>|<row|<cell|e>|<cell|=>|<cell|f>>|<row|<cell|g>|<cell|=>|<cell|h>>>>>
  <|folded-std>
    <tabular|<tformat|<table|<row|<cell|a>|<cell|=>|<cell|b>>|<row|<cell|c>|<cell|=>|<cell|d>>|<row|<cell|e>|<cell|=>|<cell|f>>|<row|<cell|g>|<cell|=>|<cell|h>>>>>
  </folded-std>

  <tformat|<table|<row|<cell|x>|<cell|=>|<cell|y>>>>
</eqnarray*>

In this case, the table outside the fold environment, at the end of the eqnarray* environment, is “forced in” by the editor.

Composing the file in plain text one can also write

    <\eqnarray*>
    <\folded-std>
      <tabular|<tformat|<table|<row|<cell|a>|<cell|=>|<cell|b>>|<row|<cell|c>|<cell|=>|<cell|d>>|<row|<cell|e>|<cell|=>|<cell|f>>|<row|<cell|g>|<cell|=>|<cell|h>>>>>
    <|folded-std>
      <tabular|<tformat|<table|<row|<cell|a>|<cell|=>|<cell|b>>|<row|<cell|c>|<cell|=>|<cell|d>>|<row|<cell|e>|<cell|=>|<cell|f>>|<row|<cell|g>|<cell|=>|<cell|h>>>>>
    </folded-std>
  </eqnarray*>

and the editor displays it, and one can edit it at will.

Sorry that I cannot help more than this. On topic, I am often not satisfied with the online documentation of TeXmacs—I would like to have a much richer one.

Said this, how do you obtain the fold environment with the active ...?

1 Like

Well, the ... is not active, per se.
But consider this:

<\folded-plain>
  <text-dots>
<|folded-plain>
  Test
</folded-plain>

A right-click immedtiately to the left of the ... make the “unfold” menu appear. An even better alternative is using folded-explain:

<\unfolded-explain>
  <text-dots>
<|unfolded-explain>
  Test
</unfolded-explain>

This actually makes the text-dots active!! folded-documentation and folded-group also looks great.

1 Like

You are right. I tried editing the source and manually including a folded-grouped tag. That gives the exact effect I was going for. This would be so nice!! The only bug is that the editor. This is my current workaround:

Start with a multiline equation with the computations.


I usually do not use eqnarray but rather just an equation* and then immediately inside I create a tabular* by pressing alt+t
This is the code:

<\equation*>
  <tabular*|<tformat|<table|<row|<cell|1+2+3+4>>|<row|<cell|=3+3+4>>|<row|<cell|=6+4>>|<row|<cell|=10>>>>>
</equation*>

Next, position your cursor on the first line of that you would like to collapse and create an empty row above using meta+up:


Now write \ folded-grouped

followed by <RET>

Go righ by one step to position yourself in the second argument and press alt+t to create a tabular

Now highlight the rows you want to transfer:

and cut and paste them inside the table

Now position your cursor immediately after the table to be hidden:


and press <RET> to obtain:

Now a normal click on the highlighted region gives:

This is sooo coool!!!

Thank you everyone. This is almost life-changing. I guess some optimized macros for slightly more beautiful markup and ease of insertion and this is a killer feature.

One should investigate whether this works in HTML export. If so this is the new way to write papers! With details available on demand!

P.S. \folded-documentation looks even better

3 Likes

Nice experiments! Note that folded is just a macro which uses the hidden tag to avoid showing one of the arguments. The transition from folded to unfolded is obtained just by changing the macro tag via some editor support. This should not be hard to implement for other folding macros. Also there are other macros designed for beamer talks which provide some content dynamicims and which could maybe be used also in this context (to explore). As for HTML export I think we need to code some support. It would ideed be nice to have this kind of environment, especially for notes where one want to keep some computations but not pollute the document. Also this is going in the direction of some “org-mode” support and outlining. There is a outline style in tm-forge so one could look there to see how to implement appropriate editor support for such kind of tags. Very nice indeed!