Search code examples
wolfram-mathematicamathematica-frontend

Change the equation background color in text style


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.


Solution

  • 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.