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.

Some of the built-in Stylesheets (e.g. PastelColor) connect together input and output cells by setting the CellFrame and CellMargins of the bottom of the input cell and the top of the output cell to zero. However, when there is no output the input cell looks ugly because it is missing the bottom part of its frame. There is a style defined in the Stylesheet called InputOnly which has a full frame and looks much better, but I have to apply it manually with the Format/Style menu (select Other and type "InputOnly" into the input field).

enter image description here

Is there a way to get Mathematica to automatically use the InputOnly style for input cells with no corresponding output?

share|improve this question
    
Thanks for the Accept. Let me know if you have any problems with that method. –  Mr.Wizard Jun 9 '12 at 14:55
    
Added notebooks tag because I had trouble finding this question and for some reason I didn't think to search for stylesheet and I couldn't remember InputOnly. –  Mr.Wizard Dec 19 '13 at 12:30

2 Answers 2

up vote 4 down vote accepted

Wouldn't it be better to simply redefine the styles so that the frame line is hidden?

If after setting the style to PastelColor I open the private style definitions (Edit Stylesheet...) and paste each of these lines separately, allowing Mathematica to "interpret the text":

Cell[StyleData["Input"], CellFrame -> 2]

Cell[StyleData["Output"], CellMargins -> {{66, 10}, {7, -2}}]

I get this behavior:

enter image description here

Is this not what you desire?

share|improve this answer
    
Thanks, this is perfect. I hadn't thought of using a negative margin width to conceal the bottom of the input cell's frame. Clever! –  Simon Woods Jun 9 '12 at 14:58

This may not be a completely satisfying answer, but perhaps someone else can build upon it. I don't think Mathematica has the capability to put compositional conditions into the styles of cells, to check "what's around them".

What you could do instead is to set InputOnly to be your default style, and include a costum CellEvaluationFunction that switches the style to input in cases where the return value of the compution is not Null.

Here is an example outlining the idea, however it could be improved.

styleSwich[] := (SelectionMove[EvaluationNotebook[], All, 
    EvaluationCell]; 
  NotebookWrite[EvaluationNotebook[], 
   NotebookRead[EvaluationNotebook[]] /. "InputOnly" -> "Input", 
   After])

inputOnlyEvaluator[expression_, 
  StandardForm] := (Block[{res = ToExpression[expression]}, 
   If[res === Null, Null, styleSwich[]; 
    NotebookWrite[EvaluationNotebook[], res];]])

CellPrint[
 ExpressionCell[5, "InputOnly", 
   CellEvaluationFunction -> inputOnlyEvaluator]]

To implement this in the style sheet, you just need to add CellEvaluationFunction -> inputOnlyEvaluator to the stylesheet definition, and then put styleSwitch and inputOnlyEvaluator into your init file to make sure they are there.

This is a one way trip however, and after you have evaluated a cell that produces an output cell, the cell will continue to be Input style. If you wanted both to be able to switch between each other, you'd need to make a new CellEvaluationFunction in a similar style for the Input cell.

share|improve this answer

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.