Change the equation background color in text style
Asked Answered
D

2

5

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.

Dehydrogenate answered 26/10, 2011 at 1:23 Comment(0)
M
8

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[]}]

enter image description here

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:

enter image description here

You can then save this style notebook and reuse it if you wish.

Monotype answered 26/10, 2011 at 1:40 Comment(10)
Editing 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...)Chelonian
@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 outMonotype
@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.Monotype
@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 knowLemma
@yoda Please Please ... don't forget make a backup if you mess up with KeyEventTranslations.trEclair
@belisarius Yes, I have multiple backups... I've seen for myself how badly it can go wrong :DMonotype
@Lemma 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 changesMonotype
@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\...Lemma
@Lemma 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 :)Monotype
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.Dehydrogenate
E
3

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.

Ebony answered 26/10, 2011 at 2:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.