Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

(I have recently taken to Mathematica... still a noobie)

Is there an elegant way of hiding/collapsing only a portion of a function (for example, in Matlab, within a function, one can collapse the for or while loops)

( if functions could span multiple cells, this would have been straight-forward!)

Thanks

share|improve this question
One thing I like about Mathematica is that stuff that "doesn't exist" can often be made exist quite easily. I think this is doable and useful to have (+1). Some kind of shortcut that wraps the selected boxes with an InterpretationBox with a button "+" that restores the original boxes for example. If I have time I'll try it and post if it works. Let's hope someone does it first and better than I can – Rojo Mar 14 '12 at 22:57

2 Answers

The Mathematica Front End does not have this feature. Wolfram Workbench does though.

However, it is possible to collapse cell groups in notebooks by double clicking their brackets. This is useful.

For navigating functions, the Ctrl+. key combination (extend selection) is extremely useful.

share|improve this answer
CTRL-. was a nice find! – my account_ram Mar 14 '12 at 20:29
5  
+1. One of the reasons that FE does not have this seems to be that it is centered around Mathematica expressions, not lines of code (unlike WB). There is a certain impedance mismatch between the two. I think, IDEs are more oriented towards statement-based rather than expression-based languages. – Leonid Shifrin Mar 14 '12 at 21:04
@my account_ram for completeness: You can also double/triple/n-click anywhere in a cell and get the same effect as with Ctrl-., i.e. selection of successive expression levels. – Yves Klett Mar 15 '12 at 10:03

Also, for ease of use when working with sections etc., activate the "Show open/close icon for cell groups" checkbox under Edit->Preferences. This adds a toggle chevron on the left side.

Mathematica graphics

The frontend encourages/enforces you to break long code passages into smaller parts, which is not always a bad idea, especially for testing and debugging (although debugging in Mathematica is something of a sore point when you are used to other systems). Still, a solution for in-cell partitioning would be nice-to-have.

There is also some option to format sections so that a click on their content toggles open/close instead of just the tiny triangle, but I can“t remember at the moment how that worked. Perhaps someone will chip in here.

share|improve this answer
Just noticed for the first time that the "Language" option, while set to German by default here does change exactly nothing and leaves everything at English. I think the last german language pack was for version 5? – Yves Klett Mar 15 '12 at 9:05
Mathematica 8 does not have a German language pack, so that drop down menu doesn't really do anything for German. – Searke Mar 15 '12 at 13:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.