12
$\begingroup$

I'd like to make some features of my notebooks responsive to some properties of styles in the active stylesheet. Is there a way to do this? I can't seem to get anything out of StyleData. What I'm looking for is something of the form

StyleData["SomeStyle", "FontName"]
StyleData["SomeStyle", "FontSize"]

etc.

Are there functions or settings I can use to programmatically get information about properties of a style?

$\endgroup$
  • 1
    $\begingroup$ Open the stylesheet (possibly Default.nb). If necessary, choose a style from the "Choose a style" drop-down menu. Select the now-displayed cell named after that style. Now use the Option Inspector, either browsing for what you want in the outline hierarchy or else by using the Search box in the Option Inspector. $\endgroup$ – murray Nov 13 '12 at 21:59
  • 1
    $\begingroup$ @murray: How can I do that in code? (See edit.) $\endgroup$ – orome Nov 13 '12 at 22:08
12
$\begingroup$

You need

 CurrentValue[{StyleDefinitions, stylename}]

Examples:

 CurrentValue[{StyleDefinitions, "Section"}]

enter image description here

 CurrentValue[{StyleDefinitions, "Section", "CellFrame"}]
 (* {{0, 0}, {0, 1}} *)
 CurrentValue[{StyleDefinitions, "Subsection", "FontFamily"}]
 (* "Helvetica" *)
 CurrentValue[{StyleDefinitions, "Graphics", "CapForm"}]
 (* "Square" *)

etc.

$\endgroup$
  • $\begingroup$ Hey, do you know how to get the info for a particular screen environment such as printout? $\endgroup$ – Rojo Feb 16 '13 at 22:24
  • $\begingroup$ It seems a particular option you can get with CurrentValue[notebook, {StyleDefinitions, "style/Printout", theOption}], but I still haven't found how to get the whole list $\endgroup$ – Rojo Feb 16 '13 at 22:31
  • $\begingroup$ Hi @Rojo, i don't know how to get the definitions for combo styles. I would expect/wish that using the stylenames (like "Section/SlideShow" or StyleData["Section", "SlideShow"]) would work; but it doesn't (ver 9 on windows vista). And, the option values returned by CurrentValue[notebook, {StyleDefinitions, "style/Printout", theOption}] do not match the defined/inherited values of these options based on the definitions in Default.nb. For example, CurrentValue[{StyleDefinitions, "Section/xx", "FontSize"}] gives 14 for xx in {"PrintOut","Condensed","Working","SlideShow"}. $\endgroup$ – kglr Feb 17 '13 at 1:07
  • $\begingroup$ That's sad. Thanks! $\endgroup$ – Rojo Feb 17 '13 at 6:51
  • $\begingroup$ It is possible to use CurrentValue to get some property of a style of the same stylesheet I'm defining? I.e. if I want to use the same FontColor many times and I don't want to write it explicitely all times? I tried but I get a wrong color... Thanks $\endgroup$ – unlikely Mar 4 '16 at 16:59
2
$\begingroup$

This is just an addendum concerning screen environments. To obtain all the styles associated with an environment use a list as in:

CurrentValue[EvaluationNotebook[], {StyleDefinitions, {"Text", "Printout"}}]

{CellMargins -> {{49, Inherited}, {Inherited, Inherited}}, Hyphenation -> True, LineSpacing -> {1, 3}, TabSpacings -> {2.5}, CounterIncrements -> "Text", MenuSortingValue -> 1400, MenuCommandKey -> "7", FontFamily -> "Source Sans Pro", FontSize -> 15}

or to obtain a specific setting:

CurrentValue[EvaluationNotebook[], {StyleDefinitions, {"Section", "SlideShow"}, FontSize}]

40

$\endgroup$
1
$\begingroup$

(Very incomplete answer!)

Open the style sheet, e.g.:

nb = NotebookOpen[
    "/Applications/Mathematica.app/SystemFiles/FrontEnd/StyleSheets/\
     Creative/PastelColor.nb"]

Find what you want, e.g., style for Section:

NotebookFind[nb, "Styles for Title and Section Cells"]
NotebookFind[nb, "Section"]
SelectionMove[nb, Next, Cell]

Read it:

properties = NotebookRead[nb]

Of course to use my method, you already need to know in detail the structure of the style sheet.

$\endgroup$

Your Answer

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

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