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.

Can we hide Mathematica code, so that just input requirements are visible? e.g.

m11 = NIntegrate[
   Sqrt[lam/(2 π)]/Gamma[n]*x^(1 - 3/2)*
    Exp[(-lam*(x - mu)^2)/(
       CDF[NormalDistribution[0, 1], Sqrt[lam/x]*(1 - x/mu)] - 
         CDF[NormalDistribution[0, 1], -Sqrt[(lam/x)]*(1 + x/mu)]])^(
    n - 1), {x, 0, 250}];
m22 = NIntegrate[
   Sqrt[lam/(2 π)]/Gamma[n]*x^(2 - 3/2)*
    Exp[(-lam*(x - mu)^2)/(
       CDF[NormalDistribution[0, 1], Sqrt[lam/x]*(1 - x/mu)] - 
         CDF[NormalDistribution[0, 1], -Sqrt[(lam/x)]*(1 + x/mu)]])^(
    n - 1), {x, 0, 250}];

beta1 = (m22 - (m11)^2)/m11;
m = Table[beta1, {lam, 1, 10, 1}, {mu = 1}, {n, 3, 10}];
m // TableForm;
Export["mean.xls", m]

So that just the Table statement is visible, or just the last three lines visible?

share|improve this question
Hidden as in "not filling up the screen with pages of equations" or as in "You'll never see my source code, never, do you hear?!"? –  cormullion Aug 5 '13 at 12:23
@cormullion I am unaware both the terms –  Azeem Aug 5 '13 at 12:41
@Nasser I think Cell properties is not my mean. I need just to hide the monster's code of Mathematica. –  Azeem Aug 5 '13 at 13:59
I have not checked for straight duplicates, but if you look here, you find several probably related Q&As: mathematica.stackexchange.com/search?q=hide –  Yves Klett Aug 5 '13 at 14:05
I'm closing this until it is clarified. The most natural answer is to un-check Open in the Cell Properties menu (or the equivalent using the Option Inspector etc.) yet you say this is not what you mean. Please describe the behavior that you actually want; when and how should this code be made visible or hidden? –  Mr.Wizard Aug 5 '13 at 19:46
show 6 more comments

closed as unclear what you're asking by Mr.Wizard Aug 5 '13 at 19:44

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 4 down vote accepted

There is a somewhat larger question here. Consider organizing your work by creating applications in your $UserBaseDirectory/Applications folder. You probably don't want too many applications but you then have a place to put folders, packages, style sheets and palettes (and maybe eventually documentation) for each of your major projects.

In the following I'm going to describe several features that are in the Presentations Application that I sell, but I will also give you the code to use. (The advantage of the Application is that it has many other convenient features and it is all in an accessible place.)

Then you have four choices.

1) In your notebook put routine code, data and definitions in an Initialization Section structure, which will be initialized but usually closed. Of course, if a reader opens it up they'll see all the details.

2) Or in your notebook use Alt+CPO to close (or open) the selected cell that contains a lot of boiler-plate code. This a convenient way to work for one-off type displays. Presentations has an EvalBelow button that can be pasted, which you can place in a Text cell above the closed cell. It reminds the reader and evaluates the closed cell. Naïve readers will have to be reminded and it's a little tricky to select the thin closed cell. Here is the code for the EvalBelow button. (One of the Presentation style sheets has a button on a toolbar for opening and closing a cell and the button can be pasted from the Presentations palette.)

Button[Style[Tooltip["Eval \[DownTeeArrow]", "Evaluates the thin closed cell \
that immediately follows.\n The cell may be opened or closed with \
the Show/Hide Button\n at the top of the notebook or Alt+CPO.", 
   TooltipStyle -> "TextStyling"], FontSize -> 12, 
  FontWeight -> Bold], SelectionMove[InputNotebook[], All, 
   ButtonCell]; SelectionMove[InputNotebook[], Next, Cell]; 
 Appearance -> "Frameless", Background -> 
  RGBColor[0.8588235294117648, 0.8988235294117647, 
   0.8258823529411764], Evaluator -> Automatic, 
 Method -> "Preemptive"]

3) Put the code in a package.m package file in your application. Then the code is hidden there. It's easy to write such packages.

4) Hide the code within an Interpretation data structure. Presentations has a HiddenNotebookData routine that automatically does this. Here it is:

HiddenNotebookData::usage = 
  "HiddenNotebookData[datasymbol, dataname, datavalues] will store \
the datavalues in a skeleton structure displaying dataname but hiding \
the datavalues. It then generates an Input Set statement with the \
datasymbol on the lhs and the skeleton structure on the rhs.";

SetAttributes[HiddenNotebookData, HoldFirst];
   HiddenNotebookData] = {"ArgumentsPattern" -> {_, _, _}};
HiddenNotebookData[datasymbol_Symbol, dataname_String, 
  datavalues_] :=
     Module[ {temp},        
  temp = Interpretation[
      Style[Row[{"\[LeftSkeleton]", dataname, "\[RightSkeleton]"}], 
       ShowStringCharacters -> False], #] & @@ {datavalues};

    BoxData[RowBox[{ToBoxes[datasymbol], "=", ToBoxes[temp], ";"}](* 
     RowBox *)
             ](* Box Data *),
            GeneratedCell -> False,
            CellAutoOverwrite -> False,
            InitializationCell -> True](* Cell *)

Here is an example: The following generates a list of random numbers as a sample data set. When writing a notebook with hidden data we will temporarily have the data in the notebook.

data = RandomReal[{0, 1}, 200];

The following statement then creates an Input Set statement that will assign the data to a variable name.

HiddenNotebookData[dataset1, "17 Apr 2011 Data Set", data]

This generates an Initialization statement:

dataset1=<<17 Apr 2011 Data Set>>;

We can then eliminate the data statement and the HiddenNotebookData statement so that only the dataset1 statement remains in the notebook. Evaluation will then assign the hidden data to the dataset1 variable.

One of the advantages of this is that Mathematica will also often compress data so notebook file size will be somewhat reduced.

share|improve this answer
David, is there a reason that HiddenNotebookData does not use Compress directly? –  Mr.Wizard Aug 5 '13 at 19:51
add comment

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