Hot answers tagged

13

"Style" /. Developer`CellInformation[nb] where nb is the NotebookObject for the notebook you care about. Since you could have multiple cells selected, this will always return a list. It's also possible to have no cells selected, in which case CellInformation will return $Failed and the above code would throw an error.


12

I think I found it but I'd be more than happy to look at other alternatives if any provided: Shift + Ctrl + O to open Options > Notebook options > Evaluation options > Global preferences from the drop down menu at the top Change InitializationCellEvaluation to True and InitializationCellWarning to False The next time the .nb file is launched, the ...


11

You are inventing your own grouping types. If you open the Options Inspector and go to Cell Options -> General Properties -> CellGroupingRules the drop-down shows several options available: "NormalGrouping", "TitleGrouping", "SectionGrouping", "InputGrouping", "OutputGrouping", "GraphicsGrouping", "GroupTogetherGrouping", and "GroupTogetherNestedGrouping". ...


9

In the course of researching this question, I discovered an answer. Looking at the Option Inspector -> Cell Options -> General Properties for each of the cells shown above, reveals the option: CellGroupingRules. Unfortunately, there is little in terms of documentation for this option. Upon inspection, CellGroupingRules has the value of {"TitleGrouping", 0},...


7

Now, with v9, I can undelete this answer :) You could set a context dependent on a certain counter value. Add to your stylesheet, to the "Input" style, the following option CellContext:>"Section"<>ToString@CurrentValue[{"CounterValue", "Section"}]<>"`" and in my few tests you get a context dependent on the last section number. It can ...


6

Does this work as you wish? CreatePalette@Button["Evaluate down", With[{nb = InputNotebook[]}, SelectionMove[nb, Previous, Cell]; With[{prevCell = SelectedCells[nb] /. {c_} :> c}, Function[cell, SelectionMove[cell, All, Cell]; SelectionEvaluateCreateCell@nb ]~Scan~ Intersection[ Reverse@TakeWhile[Reverse@Cells[nb]...


6

If applying a new stylesheet doesn't change the appearance then it looks like the styling is local to each cell. If you have a look at the underlying expression of some of these input cells by going to the menu and choosing Cell > Show Expression you should see some StyleBoxes, as per this example using your code that you have supplied: So if it is the ...


5

I could only get the kind of behavior you seek with an EventHandler and PassDownEvents -> True, in this case ClickPane. Manually Below is the ClickPane. We're going to replace "HL" manually by a Hyperlink later. First execute this and we'll paster the output later into the desired cell. I will use a "Section" cell for illustration; hence the style "...


4

The link that @rm -rf provides does most of what you have asked for. For the final part of your question Actually, ideally what I'd like to do, is say: Export all cells except the Input and Code cells. i.e. selective Export by types of cells. Evaluate this code -- which you can modify for your particular circumstances -- in your notebook. tmp = ...


4

Does this fit your needs? Scan[ SetOptions[#, CellGroupingRules -> None] &, Cells[] ]


4

You can use CellEventActions by adding it to the Stylesheet or hard-coding it for each cell. Here is a cell that changes when clicked. DynamicModule[{bgd = LightRed}, CellPrint[ TextCell["Click within this cell", "Output", Background -> Dynamic[bgd], CellEventActions -> {"MouseClicked" :> (bgd = LightGreen)} ...


4

Here's one possible way of doing this. Type some text into 2 successive text cells, then select the cell brackets, open the option inspector (Format / Option Inspector ...) and alter the values displayed at Cell Options / Display Options / CellMargins. For instance, if the 2 text items are "Hello" and "World", then the resulting Cell expressions might be (...


3

Here is the code that should be added to KeyEventTranslations.tr. To learn more about editing this, and similar, system files look at this question and its related. (* Command, d - deletes the current cell (or selected set of cells) and its (or their) related group(s) if the group has exactly 1 Input cell; otherwise deletes only the cell from ...


3

Another quick(?) and dirty way: Let nb be the notebook to be printed. E.g., execute nb = EvaluationNotebook[] in the notebook you would like. Then execute NotebookPrint[NotebookGet@nb /. CellGroupData[data_, Closed] :> CellGroupData[data, Open]] or Export["/tmp/foo.pdf", NotebookGet@nb /. CellGroupData[data_, Closed] :> CellGroupData[data, Open]...


3

This is not a full response, but I have some info that might be helpful. The subsection issue is caused by the Stylesheet entry for Subsubsection, changing it to the default of 50 should fix it, or anything >40. Cell[ StyleData["Subsubsection"], CellGroupingRules -> {"SectionGrouping", 50} ] The issue is that the default for SectionGrouping ...


3

yes, but a notebook has a more involved structure than the .m files you have investigated. The code to do what you want isn't very complicated, though: CreateDocument[{CellGroup[{ TextCell["section", "Section"], TextCell["content", "Text"] }, Closed]}]


3

All the prints belong to one cell group because they all have style "Print" which has option CellGroupingRules->"GraphicsGrouping" as seen from the "Core.nb" stylesheet. Apparently Cells with this option are grouped together. On the other hand style "Output" has CellGroupingRules->"OutputGrouping" and such Cells aren't grouped together and also aren't ...


3

Here are two cells with weird embedded styles, including colors, background colors, and sizes: Select both cells and press Shift+Ctrl+N to re-parse to StandardForm:


2

CellContext seems to work on the notebook level, although its a Cell option. Anyway the behavior seems to be hardcoded to Mathematica and I wasn't able to see any indication inside the notebook apart from the option. But you can emulate the behavior using the command Begin. For example at the start of each Subsection you can run the command Begin[ToString[...


2

One possibility would be to (programmatically) add dynamic options to all cells. E.g., one cell could look like : Cell["1-1", "Input", Evaluatable->Dynamic[eval], CellOpen->Dynamic[open], Background->Dynamic[bcolor]] Then, if you evaluate in a subsequenc cell (or by Button) this: eval = True; open = True; bcolor = LightGray the Cell becomes ...


2

If you'd like to be able to do this without adding a custom keyboard shortcut, you can do it by repeatedly pressing Ctrl+. (this is the shortcut for Edit menu -> Extend Selection). For those unfamiliar with the wonderful Extend Selection command, it is nearly equivalent to double/triple/quadruple mouse clicking to select ever-larger expressions, with 2 nice ...


2

You can use CellGroupData with 1 as the second argument for creation of cell groups where only first cell is open: Do[NotebookWrite[EvaluationNotebook[], Cell@CellGroupData[{Cell["Section " <> ToString[i], "Subsection"], Cell[ToBoxes@ExpressionCell@f[i], "Output"]}, 1]], {i, 3}]; The quotes around the text are not shown because I have ...


2

Ok so I fixed it: Cell[StyleData[StyleDefinitions -> "Default.nb"], CellMargins->{{21, 3}, {4, 4}}] Cell[StyleData[All], ShowGroupOpener->False, FontFamily->"Avenir"] Cell[StyleData["Title"], CellMargins->{{10, 3}, {4, 4}}, FontColor-> RGBColor[0,0.0,0.6], CellGroupingRules->{"SectionGrouping", 9}] Cell[StyleData["Section"], ...


2

To make it work, you have to set the option CellGrouping -> Manual either for the target notebook, or globally in the Option Inspector (Ctrl+Shift+O). Then the following code works as expected: nb = CreateDocument[{}, CellGrouping -> Manual]; SelectionMove[EvaluationNotebook[], All, Notebook]; NotebookWrite[nb, NotebookRead[EvaluationNotebook[]]];


1

I found this method. lastOutputOfGroup[cellObject_CellObject] := With[{groupCells = Cases[NotebookGet@Notebooks[cellObject], CellGroupData[cells : {NotebookRead@cellObject, ___}, ___] :> cells, \[Infinity]]}, ToExpression@First@Last@Cases[groupCells, Cell[_, "Output", ___], \[Infinity]] ] that apparently works: lastOutputOfGroup[...


1

I have cell grouping set to Manual Grouping in the Cell ► Grouping menu. The Documentation clearly states: With CellGrouping -> Automatic, cells are automatically grouped in a hierarchical way based on their styles. With CellGrouping -> Manual, cells must be grouped manually, either by setting up explicit CellGroupData expressions, or by ...


1

You're not using CellGroupingRules correctly. It groups by the number you provide it. Change 1001. to 10000. and it works.


1

You can select parent cell group of currently selected object in notebook nb with SelectionMove[nb, All, CellGroup] and then open it using FrontEndTokenExecute[nb, "SelectionOpenAllGroups"]. To open all groups containing currently selected cell you can use something like this: FixedPoint[ ( SelectionMove[nb, All, CellGroup]; If[MatchQ[...


1

By long toing and froing I came butt against the answer. Here you are: Open the notebook prepared for the slide show. Assume its name is mySlideShow.nb. In the Slide Show palette press the "Start Presentation" button. The notebook will come into the Slide Show mode. Go to Menu/Format/Option Inspector. 2a. From the drop down menu of the "Selection" field ...


1

SetOptions[EvaluationNotebook[], StyleDefinitions -> Notebook[{Cell[StyleData[StyleDefinitions -> "XXXXXX.nb"]], Cell[StyleData[All, "Working"], ShowGroupOpener -> True],Cell[ StyleData[All, "Presentation"], ShowGroupOpener -> True]}, StyleDefinitions -> "PrivateStylesheetFormatting.nb"] ] where "XXXXX.nb" is the name of ...



Only top voted, non community-wiki answers of a minimum length are eligible