5
$\begingroup$

Bug introduced in 10.0.2 or earlier and persists through 11.3

[CASE:4061425], confirmed

TL;DR;

How can I add a style definition to a notebook with existing, arbitrary StyleDefinitions already set?

Full question, my attempt

Consider the following two example notebooks:

NotebookPut@Notebook[
  {Cell["abc", "Text"]},
  StyleDefinitions -> Notebook@{
     Cell[StyleData[StyleDefinitions -> "Default.nb"]],
     Cell[StyleData["Text"], FontColor -> Green]
     }
  ]

NotebookPut@Notebook[
  {Cell["abc", "Text"]},
  StyleDefinitions -> Notebook@{
     Cell[StyleData[
       StyleDefinitions -> Notebook@{
          Cell[StyleData[StyleDefinitions -> "Default.nb"]],
          Cell[StyleData["Text"], FontColor -> Green]
          }
       ]],
     Cell[StyleData["Text"], FontSize -> 40]
     }
  ]

The first one has StyleDefinitions set which override the FontColor of "Text" style cells to be Green, and inherit the rest from "Default.nb". The second one has StyleDefinitions inheriting the ones from the previous example, and overrides the FontSize of "Text" style cells.

This yields:

abc green

and

abc big

Clearly, the second example is not what's expected. Looking at the stylesheet (of the second notebook) shows the following:

Unkown StyleData syntax

The question is: why is this not working?

Checking the docs

Looking at the documentation of StyleData (Details, point 6):

  • Parent stylesheets are defined by a style cell with the form StyleData[StyleDefinitions -> stylesheet], where stylesheet can take any of the forms allowed for the StyleDefinitions option at the notebook level.

And the referenced documentation for StyleDefinitions reads:

For me, this means that I can nest StyleDefinitions arbitrarily, mixing "name.nb" specifications and Notebook[…] type specifications without any restrictions.

And finally

Is this a bug? Am I missing something? Is there a way to wrap an existing style sheet, no matter whether it is a notebook, or a Notebook[…]? Specifically, this came up since I need to temporarily change a few style definitions in a notebook that already has a Notebook[…] type style sheet set.

$\endgroup$
  • 1
    $\begingroup$ Please report this unless you already did. $\endgroup$ – Kuba May 1 '18 at 6:17
  • 1
    $\begingroup$ The StyleData reference page is in error. StyleDefinitions->Notebook[] cannot be used in that context. $\endgroup$ – ihojnicki May 5 '18 at 12:00
  • $\begingroup$ @ihojnicki So it is not supposed to work? That's a shame… Would be nice to have a uniform way to wrap StyleDefinitions $\endgroup$ – Lukas Lang May 5 '18 at 12:03
  • 1
    $\begingroup$ @Mathe172 I'm certainly open to the idea of extending it. $\endgroup$ – ihojnicki May 5 '18 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.