5
$\begingroup$

I am using Mathematica 9 on Windows 8, and I regularly want to use cell styles such as Section, SubSection and so on.

If I click the + button before creating a new cell, a context menu with a number of style options is displayed:

enter image description here

Is there a way to configure this menu to contain some of the styles that I regularly use?

$\endgroup$
  • 2
    $\begingroup$ fyi, there are actually keyboard shortcuts for the styles, predefined (see Format->Style) (I am on Mac, don't know about Windows) (and I wasn't aware that the (+) is a button :) ) $\endgroup$ – Pinguin Dirk Oct 11 '13 at 8:41
  • $\begingroup$ Thanks, @PinguinDirk, yes I read another question about this. I might go down that route instead if there is no simple answer to my question. $\endgroup$ – Anders Gustafsson Oct 11 '13 at 8:42
  • $\begingroup$ Select Format...Style from the menubar. $\endgroup$ – DavidC Oct 11 '13 at 9:21
  • $\begingroup$ Thanks, @DavidCarraher, the previous commenter also indicated this option. Ideally, I would like to avoid moving the mouse back and forth in the GUI, so keyboard shortcuts are a better option; unless there is a way to customize the context menu... $\endgroup$ – Anders Gustafsson Oct 11 '13 at 9:46
6
$\begingroup$

Here's a possible approach, I cannot say how stable it is:

(I will focus on Section, Subsection, but actually, you could do pretty nice stuff knowing about the menu and how to manipulate it. Also, as noted in my comment above, you might want to memorize the keyboard shortcuts for these things, but I liked the idea of manipulating that menu)

First we try to figure out where the menu comes from:

SetOptions[EvaluationNotebook[], "CellInsertionPointCell" -> None]

This switches off the menu. To get the normal menu back, we use:

SetOptions[EvaluationNotebook[], 
   "CellInsertionPointCell" -> 
    FrontEndResource["FEExpressions", "CellInsertionMenu"]]

For convenience, we define for now:

 orig = FrontEndResource["FEExpressions", "CellInsertionMenu"];

Looking at the FullForm of orig, we get an idea of the menu.

First, we could e.g. try to remove the Delimiters:

SetOptions[EvaluationNotebook[], 
 "CellInsertionPointCell" -> orig /. 
  Delimiter -> Unevaluated[Sequence[]]]

or set the menu to any random cell (not very useful):

SetOptions[EvaluationNotebook[], "CellInsertionPointCell" -> Cell["foo", "Text"]]

(a possible) solution for the problem at hand

and here's what you could do, just adjusting the original menu:

SetOptions[EvaluationNotebook[],
 "CellInsertionPointCell" ->
 ReleaseHold@Insert[orig,
  Hold@Sequence @@ {Delimiter, 
  PaneBox[GridBox[{{PaneBox[
        DynamicBox[
         FEPrivate`FrontEndResource["FEBitmaps", 
          "InsertionText"]], 
        BaselinePosition -> Scaled[0.4`] -> Center, 
        ImageSize -> 14], "Section"}}, 
     GridBoxAlignment -> {"Columns" -> {{Right}}, 
       "Rows" -> {{Baseline}}}, AutoDelete -> False, 
     GridBoxItemSize -> {"Columns" -> {{All}}, "Rows" -> {{All}}},
      GridBoxSpacings -> {"Columns" -> {0, 0.6`, 2, 0}, 
       "Rows" -> {{Automatic}}}], 
    ImageMargins -> {{0, 0}, {1, 1}}] :> 
   FrontEndTokenExecute[EvaluationNotebook[], "Style", 
    "Section"],
  PaneBox[
    GridBox[{{PaneBox[
        DynamicBox[
         FEPrivate`FrontEndResource["FEBitmaps", 
          "InsertionText"]], 
        BaselinePosition -> Scaled[0.4`] -> Center, 
        ImageSize -> 14], "SubSection"}}, 
     GridBoxAlignment -> {"Columns" -> {{Right}}, 
       "Rows" -> {{Baseline}}}, AutoDelete -> False, 
     GridBoxItemSize -> {"Columns" -> {{All}}, "Rows" -> {{All}}},

     GridBoxSpacings -> {"Columns" -> {0, 0.6`, 2, 0}, 
       "Rows" -> {{Automatic}}}], 
    ImageMargins -> {{0, 0}, {1, 1}}] :> 
   FrontEndTokenExecute[EvaluationNotebook[], "Style", 
    "Subsection"]}, {1, 1, 1, 1, 2, -1}]]

Note that I used Insert, so that we can pretty well choose where we insert the menu. I didn't put too much work into the styling, I actually just copied the "Plain Text" one and adjusted. Note that you could modify the menu any way you want, Inserting, Deleteing, Appending, Prepending, ... stuff - or just rewrite it all by yourself.

The result:

enter image description here

$\endgroup$
  • $\begingroup$ My goodness! Awesome! Many, many thanks for putting all your effort into solving this issue! Will this only be valid for my current session/notebook, i.e. do I need to run this every new session, or will the change be permanent? $\endgroup$ – Anders Gustafsson Oct 11 '13 at 9:51
  • $\begingroup$ Glad you like it- I'd say that goes into Stylesheets, but I am definitely no good when it comes to those, sorry. There are various resources on here and the internet about these things, I am sure you'll find a good way! (and as a note: don't accept too quickly, you don't want to scare away other good answers, do you? :) Thanks anyway though!) $\endgroup$ – Pinguin Dirk Oct 11 '13 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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