In Mathematica when your writing to a Text styled cell, if you create an formatted equation, for example pressing "x ctrl_ a", the background color changes while the equation is selected. Does anyone know what this equation format area is called, and specifically how to change the background color when the equation is selected.
2 Answers
In general, if you press Cmd-Shift-E when you're in the cell, it shows you the underlying low-level syntax that makes up the pretty formatting that you see. In my case, for x_a foo bar
, where x_a
is typeset as a subscript, it shows:
Cell[TextData[{
Cell[BoxData[
FormBox[
SubscriptBox["x", "a"], TraditionalForm]]],
" foo bar "
}], "Text",
CellChangeTimes->{{3.528581300759695*^9, 3.5285813422683*^9}, {
3.528581510346758*^9, 3.5285815118015013`*^9}}]
Now, to access the information you want, open up the stylesheet Core.nb
and look at Styles for Mathematica System-specific Elements > FormatType Styles > InlineCellEditing
. Use the above key combination to see the underlying code, which shows:
Cell[StyleData["InlineCellEditing"],
StyleMenuListing->None,
Background->RGBColor[0.964706, 0.929412, 0.839216]]
This is the background color that is used. To confirm:
Graphics[{RGBColor[0.964706, 0.929412, 0.839216], Disk[]}]
Yep! To change, you simply need to create your own stylesheet with an altered definition and use that as the default for the notebook.
Example:
To create a custom style definition for just this notebook, go to Format > Edit Stylesheet
and in the new window that says Private style definitions for <filename.nb>
, hit enter to start a new cell, use the key combo above and replace the text in there with the above (with RGB values changed to what you want) and then press the same combo to exit the CellExpression
mode. So for example:
Cell[StyleData["InlineCellEditing"],
StyleMenuListing->None,
Background->RGBColor[0.3, 0.9, 0.8]]
gives me a aqua-greenish background:
You can then save this style notebook and reuse it if you wish.
-
2Editing Core.nb is generally a bad idea--it's better to create a custom stylesheet that overrides the default behavior. One advantage of this is that your modifications will survive version upgrades more easily. (And if you're in a shared environment, you probably can't/shouldn't change the global stylesheet since it would affect everyone...) – Brett Champion Oct 26 '11 at 02:18
-
@BrettChampion Certainly, that was a ill-advised statement, which is why I edited it right away to add the custom stylesheet option. I forgot to remove that line from the answer, which I'll do now. Thanks for pointing that out – abcd Oct 26 '11 at 02:21
-
@BrettChampion Also, off-topic to this question, but along the same lines, is there a custom file I can use for additions and changes to `KeyEventTranslations.tr`? Nearly all the hacks I've seen recommend editing the system file, whereas it is easily overwritten in an upgrade. – abcd Oct 26 '11 at 02:24
-
@yoda my `KeyEventTranslations.tr` is in $UserBaseDirectory\SystemFiles\FrontEnd\TextResources\Windows ; it is however a complete copy of the system file, rather than one containing only the customizations. If you find a way to do the latter, please let me know – Mr.Wizard Oct 26 '11 at 02:34
-
@yoda Please Please ... don't forget make a backup if you mess up with KeyEventTranslations.tr – Dr. belisarius Oct 26 '11 at 02:34
-
@belisarius Yes, I have multiple backups... I've seen for myself how badly it can go wrong :D – abcd Oct 26 '11 at 02:35
-
@Mr.Wizard Yes, I know where it is, but it gets overwritten when you upgrade. I just did an upgrade from 7 to 8 and my old one was replaced. I had backups of that too, so I could simply add it in (besides I don't have very much changed). I was just curious if there was a way to have a separate custom file that loads after the `$UserBaseDirectory\...` file that includes only your changes – abcd Oct 26 '11 at 02:38
-
@yoda, perhaps either I am being unclear, or my system is different, but I believe none of the files in my user directory are overwritten. I had to copy this file from the main installation directory into a newly created matching sub-path in the user directory. C:\Users\Wizard\AppData\Roaming\Mathematica\... – Mr.Wizard Oct 26 '11 at 02:43
-
@Mr.Wizard Ah, I see the reason why now. I first edited the file in mma7 when I was first starting out with mma. I didn't know better back then and I had edited it in the main directory. Now it resides in `$UserBaseDirectory\...` for mma8, but I only remembered that it was overwritten, and had forgotten the fact that I changed it in the main dir back then. Thanks, that resolves my question :) – abcd Oct 26 '11 at 02:49
-
Woah, thanks. you have all helped me out so much. I already use a styled notebook so I will just add this all into there. – dmikalova Oct 26 '11 at 03:59
Instead of using the menu Format > Edit Stylesheet
, you can modify the notebook's style definitions directly. For example, just run the following code:
SetOptions[EvaluationNotebook[],
StyleDefinitions ->
Notebook[{
Cell[StyleData[StyleDefinitions -> "Default.nb"]],
Cell[StyleData["InlineCellEditing"],
Background -> RGBColor[0.9, 0.6, 0.6]]}]]
Which sets the stylesheet to the default one with the single modification to the inline cells.

- 14,631
- 4
- 41
- 101