Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm doing some coding in MM9, but my program is getting quite large. It's mostly a bunch of functions defined at the beginning of it, but it's getting to the point where I have to scroll for a few seconds to get to the bottom of the notebook and it's getting annoying to find things without using Ctrl + F. It may seem like nitpicking but it slows down my workflow so I figured I'd ask here.

Is there some way to make my code nicer? I once investigated "minimizing" functions but it appears MM doesn't really support that. Could I put some functions and constants in a spare notebook and have my main one read that before executing, like I would in C++?

MM is usually so elegant, I imagine there must be a solution for this!

share|improve this question
    
Use sections (Alt-4, Alt-5, etc.) in the notebook to structure it, then fold them so they're invisible. If you have lots of functions that you don't change much, use packages. –  Szabolcs Apr 15 at 22:03
    
Hi, this looks really useful but I'm trying it and it's driving me a little insane -- I can make sections but it's not letting me collapse them by double clicking at the right. I managed to make one that does that, but when I made another section in another cell it wouldn't collapse, and also made any code I pasted in there a different color and not able to be evaluated, even if I changed the formatting to "Input"...what am I missing? Thank you! –  YungHummmma Apr 15 at 22:35
    
Place the cursor not in a cell, but inbetween two cells. Then press Alt-4 which created a section header cell. Type the name of the section. Now everything below this section header will belong to the section (up to the next header) and can be collapsed by double clicking the corresponding cell bracket (vertical blue line on the right). –  Szabolcs Apr 15 at 22:44
    
Thank you, this works! One last problem though: when I have my sections created, I want to continue and make more code, but when I add new cells at the bottom (even with the bottom section collapsed), they seem to get added to that bottom section, which I don't want. What's wrong? Thanks! –  YungHummmma Apr 15 at 22:50
    
Everything from the last section header up to the end of the document is part of the last section. Make a new section for your new cells. –  Szabolcs Apr 15 at 23:31
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.