# Create shortcut in Mathematica for “Equal Symbol Aligned Math Cell”

How do I create a new shortcut for creating a "Equal Symbol Aligned Math Cell" in Mathematica 8?

Update I meant a keyboard shortcut. An "Equal Symbol Aligned Math Cell" is exactly what @Heike mentioned. I noticed that for some stylesheets there are keyboard shortcuts e.g. Cmd+7 for text, and I was wondering how to edit the stylesheets to add my own shortcuts, in particular for the math cells.

-

## migrated from stackoverflow.comJan 26 '12 at 14:38

This question came from our site for professional and enthusiast programmers.

A couple of questions. What do you mean by shortcut? What is an "Equal Symbol Aligned Math Cell"? A picture would be preferable, a link, though, is acceptable. Lastly, while this alters the programming environment, it isn't directly on topic for SO. A better place is Mathematica. –  rcollyer Jan 26 '12 at 4:22
@rcollyer In the "Writing assistant" palette there is an "Equal Symbol Aligned Math Cell" entry in the "Math Cells" drop down menu. I'm assuming that the OP wants a shortcut to that. –  Heike Jan 26 '12 at 9:25
@Heike, I never use the writing assistant. So, thanks. But, again what type of shortcut? –  rcollyer Jan 26 '12 at 11:10
@rcollyer neither do I but google came to the rescue. –  Heike Jan 26 '12 at 11:24
I meant a keyboard shortcut. An "Equal Symbol Aligned Math Cell" is exactly what @Heike mentioned. I noticed that for some stylesheets there are keyboard shortcuts e.g. Cmd+7 for text, and I was wondering how to edit the stylesheets to add my own shortcuts, in particular for the math cells. –  Jim Lim Jan 26 '12 at 18:14

With a little help from http://web.ift.uib.no/~szhorvat/mmatricks.php

I came up with (having no idea why I could not use F3, on Windows, but F4 works) :

Item[KeyEvent["F4"], FrontEndExecute[FrontEndNotebookWrite[FrontEndInputNotebook[],
Cell[TextData[Cell[BoxData[FormBox[GridBox[{{GridBox[{{"Placeholder]"}}, GridBoxAlignment->{"Columns" -> {{"="}}}]}}, GridBoxItemSize->{"Columns" -> {{Scaled[0.96]}}}], TraditionalForm]]]], "Text"], After]; FrontEndNotebookFind[FrontEndInputNotebook[], "\[Placeholder]", Previous,CellContents]]]  which I inserted at the end of KeyEventTranslations.tr Maybe it is a good idea to make a backup-copy of your KeyEventTranslations.tr, and remember: the copy should not end with .tr - What would the corresponding entry in an init.m be so that such a new key event would automatically be added at startup and yet you would not have to modify KeyEventTranslations.tr? – murray Jan 29 '12 at 1:21 This isn't an answer to the original question, but rather explains why I don't use the “Equal Symbol Aligned Math Cell”. Note that I used to use the writing palette to create aligned math, but now I use the solution presented below. And I have some really large notebooks full of typeset maths/physics using this solution. The Writing Assistant palette contains the button to create an “Equal Symbol Aligned Math Cell” which is actually a GridBox embedded inside of a "Text" cell. Specifically, it creates Cell[TextData[Cell[BoxData[ FormBox[GridBox[{{GridBox[{{"\[Placeholder]"}}, GridBoxAlignment -> {"Columns" -> {{"="}}}]}}, GridBoxItemSize -> {"Columns" -> {{Scaled[0.96]}}}], TraditionalForm]]]], "Text"]  I find this a little hacky and (as mentioned in the comments to the question) a bit unstable. Luckily, Mathematica has a simpler alignment system built-in. Just insert a DisplayFormula cell and set the cell alignment from Left to AlignmentMarker using the Format ► Text Alignment ► On AlignmentMarker. Then you can set the formula to align where ever you want, using \[AlignmentMarker, which can be entered using ⁝am⁝

Cell[BoxData[{
RowBox[{"a", "\[AlignmentMarker]", "=", "b"}], "\[IndentingNewLine]",
RowBox[{RowBox[{"c", "+", "d"}], "\[AlignmentMarker]", "=", "e"}]}],
"DisplayFormula", TextAlignment->AlignmentMarker]


which in TraditionalForm looks like:

Then, if you want, you can make a new cell style that uses this option (or modify an existing style) and assign that style a MenuCommandKey as described in here or in Adam's answer to this question.

-

This information is set in the style definitions for the cell types in the stylesheet that you are using.

Look up MenuCommandKey in your help, this is the option that you use. To see how this is set in the example, select the MyTitle cell, and then use the menu item Cell > Show Expression.

Then to get this to work, you need a stylesheet where you change the definition for the desired cell type to include this option. You can edit the stylesheet for a particular notebook from the format menu.

Stylesheet notebooks can be saved, and then if you use the File > install menu item you can make a stylesheet available across all notebooks.

-
But "Equal Symbol Aligned Math Cell" is not in the menu. –  Jim Lim Jan 27 '12 at 18:02
After a little more checking its because that isn't actually a type of cell. Its just a text cell with a specific box structure and placeholder added into it. Therefore, the above will work to reassign the keys to other styles, but not to make this work, and I don't know if you can add a key shortcut to insert expressions in this way. –  Adam Berry Jan 27 '12 at 20:36
The different StyleSheets that come with mma have different cell types available, e.g. JournalArticle. So, either the cell types have to already exist, or they can be created. Do you know which it is? –  rcollyer Jan 27 '12 at 20:55
@AdamBerry yes, you are right... –  Jim Lim Jan 28 '12 at 1:54

I suppose the keyboard shortcuts, or acceleration keys in general, are hardcoded into the Mathematica application so defining new ones might be impossible for now. You can review them by searching for "KeyboardShortcutListing" at Mathematica's help system. Of course you can always programmatically create cells of the type you want.

-
Unfortunately, this is not true. You can define shortcuts in the file: KeyEventTranslations.tr. See stackoverflow.com/a/5605423/615464 and stackoverflow.com/q/4209405/615464 –  Sjoerd C. de Vries Jan 27 '12 at 18:29
This is anything but unfortunately! Thank you very much for the correction! (Actually my statement is half-true: the solution for defining new ones is a hack and not a thing you can do programmatically from inside the Mathematica like with the tokens, that's what I meant with saying hardcoded, anyway your remark is more than valid - we should thing outside the box once in a while ;) ) –  Spawn1701D Jan 28 '12 at 16:39