Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How exactly is a custom stylesheet processed? Which style depends on (inherits from) which other style.

Consider e.g. setting a font. I would expect that setting the font for "Section" to YY after setting the font for "All" to XX would result in the font being YY for Sections and XX for everything else, but the "All" overrides it. For "Text" and "Section" its works as expected. "All" seems to be a global override (at least for the FontFamily.

Can someone clarify this?

share|improve this question
    
All styles ultimately inherit from Core.nb. The style applied will be the most "inner" one. For stylesheets the styles applied will be the private styles, then the styles from the stylesheet that your private styles inherit from -- usually Default.nb, and then from Core.nb –  Mike Honeychurch Oct 28 '12 at 21:56

1 Answer 1

up vote 13 down vote accepted

The question I'll answer here is "How is the cell style of a given cell resolved." There are several other questions one could ask about option resolution, and I won't attempt to answer all of them here, but I will show in some exhaustive detail, at the cell level, what's happening.

First, a parent set of options is calculated at the notebook level and passed down to cells. I won't discuss how those are computed (feel free to ask another question about that), but the options passed down from the notebook level are identical to all cells within that notebook (except inline cells, which inherit many properties from their parent cells...once again, that goes a bit beyond the scope of my answer).

Starting with those options, further options are merged in from the following locations:

  1. The fully resolved style corresponding to the primary stylename, if one exists.
  2. If the cell is a docked cell, then stylenames/options from the DockedCellsStyle option are applied.
  3. The cell's FormatType is determined, and the named style corresponding to the FormatType is applied.
  4. If the cell is an inline cell, the named style "InlineCell" is applied.
  5. If the cell is an inline cell which is presently being edited, the named style "InlineCellEditing" is applied.
  6. If the style has multiple stylenames applied to it, then the further stylenames are resolved and applied in order of appearance.
  7. Finally, the options set specifically on the cell are applied.

More should be said about how stylenames are resolved into styles (which is to say, a collection of option settings). Without touching on issues of style or stylesheet inheritance, here is what happens every time a named style is resolved for use by a cell:

  1. Begin with the "All" style.
  2. Merge in the named style definition.
  3. If one exists, merge in the environment-specific version of the style definition.

So, back to the initial question. Why does setting a font on the "All" style affect the style resolution of a "Section" cell, which one would expect to override the "Section" cell? The issue here comes up in the resolution of the FormatType. Section cells have a FormatType of TextForm, and Mathematica is making an attempt to resolve the named cell style "TextForm". In doing so, it's pulling in "All" yet again.

I, for one, don't really find the "All" style all that useful. I much prefer to work with either generic environment styles (e.g., StyleData[All, "environment name"]) or the "Notebook" style. Those styles are applied exclusively at the notebook level, and so become part of the background default that all cells inherit from, as I describe above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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