Since some posts build up quite lengthy programs, I thought maybe some unobtrusive way of posting the full source code of a file would be useful. I thought about a fold-out code block a la [hidecode], which displays a button that has to be clicked in order to make the content appear. This would have two benefits:

  1. Users don't have to copy and paste multitudes of code sections into Mathematica until the program is ready to be evaluated. Instead, they can read the "browser-formatted" answer, or copy the code into Mathematica. Due to the "trial and error" nature that I think programming in and learning Mathematica is this would benefit many readers of that question.

  2. This code would not necessarily have to be formatted properly for display in code blocks, sections like \!\( \*UnderoverscriptBox[\(\[Integral]\), \(0\), \(1\)]\(\[Pi]\ \*SuperscriptBox[\(r\), \(2\)] \[DifferentialD]r\)\) would be perfectly fine in an environment thought only for code that is to be copied into Mathematica. The plus side of this is that all the pretty formatting provided by the frontend would immediately appear once the code is pasted.

Of course there are some issues with that:

  1. Most importantly: Posts must be of no less value if the fold-out section is deleted without substitute. The code should be helpful to people that want to play around with the section, but should have no impact whatsoever on the information provided in the post.

  2. They should be used sparsely, i.e. only for long answers and when they are beneficial. A three code line answer does not need such a section.

Both of these could be dealt with by user interaction, which seems to work quite well, seeing how often the first comment is "please provide a working example" and the user follows the request (at least to my observations).

  • Code blocks already have an upper limit on the height. If the code doesn't fit, a scrollbar appears. It sounds like you are practically asking for an attachment feature---if the code is not for reading, just copying, why copy it at all (it's so easy to corrupt the text with that), why not just attach a notebook?
    – Szabolcs
    Commented Feb 29, 2012 at 12:07
  • An attachment feature is not likely to be added though: meta.stackexchange.com/questions/4637/…
    – Szabolcs
    Commented Feb 29, 2012 at 18:31


You must log in to answer this question.

Browse other questions tagged .