2

Say, I have a formula like this (in LaTeX or Maple or other text system):

Result: ((6*(k2+k3))*A123*k2*k3*(A12*A13*k2^2-2*A12*A13*k2*k3+A12*A13*k3^2-A123*k2^2-2*A123*k2*k3-A123*k3^2)*(exp(-k3*(k3^2*t-x)))^2+6*A12*(-k3+k2)*k2*k3*(A12*A13*k2^2-2*A12*A13*k2*k3+A12*A13*k3^2-A123*k2^2-2*A123*k2*k3-A123*k3^2)*exp(-k3*(k3^2*t-x)))*(exp(-k2*(k2^2*t-x)))^2+(-(6*(-k3+k2))*A13*k2*k3*(A12*A13*k2^2-2*A12*A13*k2*k3+A12*A13*k3^2-A123*k2^2-2*A123*k2*k3-A123*k3^2)*(exp(-k3*(k3^2*t-x)))^2-(6*(k2+k3))*k2*k3*(A12*A13*k2^2-2*A12*A13*k2*k3+A12*A13*k3^2-A123*k2^2-2*A123*k2*k3-A123*k3^2)*exp(-k3*(k3^2*t-x)))*exp(-k2*(k2^2*t-x))

Note: the above formula is only one part of the result of a maple calculation, I just can't break them up because there are so many many terms.

Apparently, It's very hard to read. What I want to do is to fold the matched brackets level by level. If all the brackets are folded, I can find out clearly how many terms there are. Then I can analyze from the top level to the details of every term. But I just don't know how to realize that. Maybe there are some existed software which can visualize this kind of complex formula. Any idea?

P.S. I use Linux system. The open source alternatives are better.

Libin Wen
  • 214

2 Answers2

1

Their is a vim script called foldcol.vim but I can't say more.

Personnaly I will do :

"put every calculs on one line
:%s/(/\r(\r/g
:%s/)/\r)\r/g

"delete all empty lines
:g/^$/d
"set fold as () to collapse them with "za"
:set foldmethod=marker foldmarker=(,)

"indent all text:
gg=G

It should look like :

Result: (
         (
          6*(
            k2+k3
            )
         )
         *A123*k2*k3*(
           A12*A13*k2^2-2*A12*A13*k2*k3+A12*A13*k3^2-A123*k2^2
           )
         *(
.
.
.

After working on it, remove indent : go to first line and then press :

 gg<G............ "need to press dot to repeat
 500gJ "to put all on one line
Hettomei
  • 182
1

Folding only applies to multiple lines. For a single line, the best you can do is use the recent conceal feature; unfortunately, it requires more scripting to set up, may interfere with existing syntax highlighting, and you don't have the convenient "show (more / less) folds" mappings at hand.

You're probably aware of the matchparen plugin that ships with Vim. There are also plugins like rainbow_parentheses.vim that improve on that.

Ingo Karkat
  • 23,523