11
$\begingroup$

I'm setting up a stylesheet and and finding the process of defining related styles tedious and error prone. In particular, I have several related styles that need to have synchronized settings (e.g., such as "DisplayFormula" and "DisplayFormulaNumbered"). Is there a way to base one style on another, or perhaps simply to copy or duplicate an existing style as the starting point for another?

$\endgroup$
1
  • $\begingroup$ FWIW I did this here with the method that The Fultz shows. $\endgroup$
    – Mr.Wizard
    Nov 13, 2012 at 22:51

1 Answer 1

14
$\begingroup$

This required editing the cell expression (Ctrl+Shift+E, or Cmd+Shift+E on Mac), but it's exactly what you're looking for:

Cell[StyleData["childstylename", StyleDefinitions-> StyleData["parentstylename"]],
    opts...]

To do this, your stylesheet has to either contain the parent style or inherit from another stylesheet which contains the parent style.

You can see many examples of this in the built-in Mathematica stylesheets, such as the "PrintTemporary" style (based on "Print"), "Graphics3D" (based on "Graphics"), and many of the hyperlink-type styles which inherit from "Link".

Note: stylesheet inheritance is available in Mathematica v6 and later. My examples above were referenced from v8 stylesheets, but may not apply to earlier versions.

$\endgroup$
3
  • $\begingroup$ Will it work as a spec for specific environment? $\endgroup$
    – Kuba
    Jul 29, 2015 at 7:17
  • $\begingroup$ Yes, it seems it works, but there is an incorrect syntax reminder for StyleData. $\endgroup$
    – Kuba
    Aug 6, 2015 at 15:38
  • $\begingroup$ Is there a multiple inheritance? $\endgroup$
    – McSaks
    Aug 23, 2016 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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