3
$\begingroup$

As shown in Difference between ParentList and Inherited we can use ParentList to nicely merge additional rules.

It seems to work nicely when it comes to inheriting between 'objects' like: $FrontEnd, $FrontEndSession, _StyleSheet, _Notebook(Object), _Cell(Object) etc.

I failed to make it work for StyleData[style] and StyleData[style, env] pair.

Here is an example:

CreateDocument[
  { Cell[BoxData@"", "Input"] }
 , StyleKeyMapping -> {ParentList, "&" -> "WolframAlphaShort"}
 , StyleDefinitions -> Notebook[
     { Cell[StyleData[StyleDefinitions -> "Default.nb"]]
     , Cell[StyleData["Input", "Working"]
       , StyleKeyMapping -> {ParentList, "Tab" -> "WolframAlphaShort"}         
       ]
     }
   ]
 ]

By default when you hit =, in an empty Input cell, it will be converted to a WolframAlphaShort cell.

I wanted to add & and Tab to do the same. The former explicitly in a notebook and the latter via stylesheet.

They both work but the original = does not anymore.

This means the Notebook's spec correctly merged stylesheet's spec but the stylesheet resolution failed to merge spec from Default.nb.

Should it happen? Is there any way to proceed without explicitly including parent spec?

At the end I want all &, Tab and = to produce WAShort cell.


related:

Updating styles which are based on styles changed in private stylesheet

$\endgroup$
  • $\begingroup$ I think this is probably a key part of what's going on: CreateDocument[{}, StyleKeyMapping -> {ParentList, "&" -> "WolframAlphaShort"}] doesn't cause the & to work, while the equivalent version putting StyleKeyMapping -> {ParentList, "&" -> "WolframAlphaShort"} in the stylesheet causes & to work but not =. $\endgroup$ – b3m2a1 Feb 12 '18 at 16:09
  • $\begingroup$ @b3m2a1 I will dig up my tests later but as far as I remember it was quite inpredicatable, e.g. InputAliases was only preserving the parent one etc. $\endgroup$ – Kuba Feb 12 '18 at 16:11

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.