Title: How to deal with lots of brackets in a formula?
Tags: linux;vim;worksheet-function;latex;maple
Question: 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.
Comment: well, an idea, on pcollins@example.com. is you can write |____| below pairs of brackets. That gives great clarity, though I don't know software if any, does that.. Also, some development IDEs might color code pairs but that probably wouldn't give the clarity you're after.


Here is another answer: 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:
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

Here is another answer: 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" pcollins@example.com.
You're probably aware of the matchparen plugin that ships with Vim. There are also plugins like rainbow_parentheses.vim that improve on that.

{'source': 'StackExchangeDataset', 'subset': 'superuser.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:11/13/13', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<linux><vim><worksheet-function><latex><maple>', 'Title': 'How to deal with lots of brackets in a formula?', 'ViewCount': 94, 'id': 675223, 'user_AboutMe': '<p>I am an electron, little but free.</p>\n', 'user_AccountId': 2497889.0, 'user_DisplayName': 'Libin Wen', 'user_Reputation': 214.0, 'user_Views': 7.0, 'user_id': 207447.0}}