3
$\begingroup$

In most of the notebooks I work in, I find myself using 2 or three cell-types almost exclusively (typically regular input, and some subset of section/subsection/chapter). A minor annoyance I run into is that to get a new cell in, say, section style, I have to click on the plus icon (the one at the bottom of the notebook that creates a new cell), select "Other style of text" from the drop down, and then make three clicks in the resulting dialog box to make the appropriate selection. It only takes 10 seconds or so, but if the menus were better designed, it could take 2!

I would really love it if I could add options for the styles that I use the most directly to the "+" menu (CellInsertionMenu), so that they appeared along with "Mathematica input", "Free-form input", "Plain text", etc., etc. Does anyone have any leads on how I might accomplish this? I've tried to be clear about what I'm trying to do, but feel free to ask for clarification if needed. Thanks!

$\endgroup$
0

4 Answers 4

6
$\begingroup$

I don't find CellInsertionMenu as a handy place for that. I'd go with one of others suggestions.

But let me answer your question anyway.

To not mess with $InsallationDirectory let's copy text file where this cell definition is stored to $UserBaseDirectory:

CopyFile @@ (
  FileNameJoin[{#, "SystemFiles", "FrontEnd", "TextResources", "MiscExpressions.tr"}
   ] & /@ {$InstallationDirectory, $UserBaseDirectory}
 )

% // SystemOpen

Find the line (* Cell insertion point menus *) and append the following expression ActionMenu-like items of your desire, e.g.:

"Section" :> FrontEndTokenExecute["Style", "Section"]

enter image description here

Works for me:

enter image description here

$\endgroup$
3
  • $\begingroup$ Works like a charm. Nice find! Thank you very much!! This will actually speed up my workflow a lot. Two advantages over reprogramming the short-cut keys (which I have also done): 1) Allows access to more than 9 styles 2) Works in notebooks created by someone else (which therefore use a different stylesheet) Thanks again. +1 and Checkmark. $\endgroup$
    – Paco Jain
    Commented Apr 27, 2015 at 18:34
  • $\begingroup$ @rdjain1 Great I could help :) $\endgroup$
    – Kuba
    Commented Apr 27, 2015 at 18:36
  • $\begingroup$ This is a great way of simplifying the usage of styles which are not accessible neither via the GUI nor with keyboard shortcuts. I can now easily use Subsubsubsection, Subsubsubsubsection, and Print cells. No more "show expression" & edit to use these styles. $\endgroup$ Commented Aug 26, 2015 at 13:40
2
$\begingroup$

1. What about a custom toolbar :

bTitle = Button["Title", FrontEndTokenExecute["Style", "Title"]];
bSection = Button["Section", FrontEndTokenExecute["Style", "Section"]];

To create a new notebook with an extra toolbar :

CreateWindow[DockedCells -> Cell[BoxData[ToBoxes[Grid[{{bTitle, bSection}}]]], "DockedCell"]];

Or, to display the toolbar in the same notebook you type in :

SetOptions[InputNotebook[], DockedCells -> Cell[BoxData[ToBoxes[Grid[{{bTitle, bSection}}]]], "DockedCell"]]

to make it disappear :

SetOptions[InputNotebook[], DockedCells -> {}]

Of course you can put anything you need in this extra toolbar (not only "text style" commands ...).

For some examples you can look at the doc.

To make this available for any notebook, an easy way is to write some custom functions in your init.m file (which is read at each new Mathematica session). So for example, execute the following code in your notebook :

showETB := SetOptions[InputNotebook[], 
DockedCells->Cell[BoxData[ToBoxes[Grid[{{bTitle, bSection}}]]], "DockedCell"]];
hideETB := SetOptions[InputNotebook[], DockedCells -> {}];

(* save that definitions in your personal init.m file :*)
initfile = FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}];
Save[initfile, {showETB, hideETB}]

Just in case, you should maybe check/backup first your init.m file. The Save command will actually append the definitions to the file.

(You can also write the definitions of showETB, hideETB, bTitle, bSection, ... in the file manually with any text editor).

Then restart Mathematica, open any notebook and enter in any Input cell showETB to show the toolbar or hideETB to hide it.

There are probably more elegant ways ... but it works.

2. What about a Palette

That could be even more useful for you and it is simpler to use :

CreatePalette[{"My Palette", bTitle, bSection}]

See the extensive doc about that. See the "install Palette" command to make this floating window available in any session from the main toolbar menu.

$\endgroup$
6
  • $\begingroup$ I like this a lot! It still would be nice to not have to permanently waste screen real estate on the toolbar, but I can make it relatively small with appropriate Style directives. But is there a way to make Mathematica open existing notebooks (and newly created ones) with the toolbar already in place? So far this is my favorite solution, with keyboard shortcuts not far behind. $\endgroup$
    – Paco Jain
    Commented Oct 27, 2014 at 18:08
  • $\begingroup$ @rdjain1 Please, see my updated answer. $\endgroup$
    – SquareOne
    Commented Oct 28, 2014 at 10:29
  • $\begingroup$ Thanks! These are features I wasn't aware of, so I appreciate you pointing them out. The kind of thing I can learn about from the docs,, but only now that I know they exist :). Thanks again! $\endgroup$
    – Paco Jain
    Commented Oct 28, 2014 at 11:43
  • $\begingroup$ @rdjain1 Don't forget to vote for all the answers that helped you, and to accept an answer if it solved your problem. $\endgroup$
    – SquareOne
    Commented Oct 28, 2014 at 19:54
  • $\begingroup$ I cannot upvote as I don't have enough rep :(. Sorry! $\endgroup$
    – Paco Jain
    Commented Oct 28, 2014 at 20:14
1
$\begingroup$

Is there a particular reason you're creating new cells this way? I cannot answer your specific question but here are a couple of faster alternatives:

If you have clicked where you want the new cell to appear, choose from the Format -> Style menu the type of cell you want.

In my experience, it is even faster to memorize the keyboard shortcuts for the few cell types you use. For example, to get a new section cell, click where you want the new cell to appear and hit Alt+4 on your keyboard. You can see the shortcuts corresponding to each style in the Format -> Style menu.

Also, if you want an input cell, you can simply start typing.

$\endgroup$
3
  • $\begingroup$ Well, I'm all about saving clicks. I believe that every physical step between thinking about what you want and having it appear on-screen is one more step away from efficient development. The method you gave using the format menu would be 3 clicks, plus (at least in M9) it involves moving the mouse between the notebook window and the floating toolbar (thankfully Wolfram did away with the floating toolbar in M10!). +1 for keyboard shortcuts, though. I suppose I can remap those as desired in KeyEventTranslations.tr. $\endgroup$
    – Paco Jain
    Commented Oct 27, 2014 at 14:52
  • $\begingroup$ I do still think that adding to the "+" menu would be the ideal solution, since I am clicking once anyway at the bottom of the notebook anyway to position my cursor for the new cell. I would upvote, but I don't have enough rep yet ;). $\endgroup$
    – Paco Jain
    Commented Oct 27, 2014 at 14:53
  • $\begingroup$ Maybe you could create : a specific toolbar at the top of your Notebook with DockedCells, or a specific Palette ... with one button for each feature you want. $\endgroup$
    – SquareOne
    Commented Oct 27, 2014 at 15:08
1
$\begingroup$

Consider any of following alternatives to the way you are currently creating new cells.

  • A normal input cell is the default style for most style sheets, so normally all you have to do for normal input is place the cursor where you want the new cell to be and start typing.

  • You can also use the context menu (right-click) to select any style with one additional click.

  • As far I know, all built-in stylesheets define keyboard shortcuts (Cmnd+1 to Cmnd+9 on OS X) for nine cell styles that allow new cells in those styles to entered with no mouse clicking at all.

  • You can make a custom style sheet (derived from the one you normally use) and assign the nine keyboard shortcuts to any styles you please. This takes more knowledge and effort than the previous suggestions, but will give you a way to create nine styles of cell of your choosing with no mouse clicking at all.

$\endgroup$
2
  • $\begingroup$ +1 for the keyboard suggestions. But if I want to use the built-in styles, then I shouldn't need to define a new stylesheet, right? Or is there a simple way to define keyboard shortcuts from within a stylesheet? My inclination would be just to reassign the Alt-# shortcuts by editing KeyEventsTranslations.tr. $\endgroup$
    – Paco Jain
    Commented Oct 27, 2014 at 15:17
  • $\begingroup$ @rdjain1. If you are willing to accept the shortcuts as assigned, you won't need to define a new stylesheet, but if you want to change the assignments to move a shortcut from a style that has one, which you don't use, to style, which doesn't have one that you do use, you will have to derive a new new style sheet or modify the built-in one. $\endgroup$
    – m_goldberg
    Commented Oct 27, 2014 at 15:29

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