Group Abstract Group Abstract

Message Boards Message Boards

How to find my notebook stylesheet?

Posted 6 years ago

A very simple question which I cannot answer: How can I find the name of my notebook stylesheet?

P1. Within a notebook "Styles etc.nb" It is easy to write:

    meNb = EvaluationNotebook[]
    NotebookObject[...Styles etc.nb ...]

    sdo = Options[meNb, StyleDefinitions]
    {StyleDefinitions -> 
      FrontEnd`FileName[{"Wolfram"}, "ProgrammingLabDefault.nb", 
       CharacterEncoding -> "UTF-8"]}

P2. The documentation fur Styledefinitions tells, I would get the stylesheet filename from that:

    Options[nb, StyleDefinitions]
    {StyleDefinitions -> "Default.nb"}

P3. But I get that interpreter type "FileName". I don't know how to evaluate that further. I would write:

    sd = Last[sdo[[1]]]
    FrontEnd`FileName[{"Wolfram"}, "ProgrammingLabDefault.nb", 
     CharacterEncoding -> "UTF-8"]

P4. I cannot Interpret that interpreter type "FrontEnd`FileName":

    Interpreter["FileName"][sd]
    Failure[... Enter a valid value...RestrictionFailure...]

or

    Interpreter["FrontEnd`FileName"][sd]
    ... FrontEnd`Filename is not a known type for interpreter 

P5. What I need is to take the filename parts out of P3. and write something like:

    ExpandFileName[ FileNameJoin[{"Wolfram", "ProgrammingLabDefault.nb"}]]
    C:\Users\Werner\OneDrive\Dokumente\Wolfram\ProgrammingLabDefault.nb
POSTED BY: Werner Geiger
6 Replies
Posted 6 years ago
POSTED BY: Werner Geiger
Posted 6 years ago
POSTED BY: Hans Milton
Posted 6 years ago

Thanks, Hans & Kuba. Both methods are solutions but not better than mine in my second post above

sdf = Append[sd[[1]], sd[[2]]]

Somewhat crazy.

The "Interpreter" reference documentation shows many examples, where Interpreter is resolved to what is expected. For example:

In[1]:= Interpreter["Number"]["4.5e7"]
Out[1]= 4.5*10^7

Hence I would expect

Interpreter["FileName"][sd]

to be expanded into the full filename. But it isn't. It gives a RestrictionFailure instead.

Anyway, I can live with my strange solution.

POSTED BY: Werner Geiger

Nothing fancier but you can use this:

https://mathematica.stackexchange.com/a/139349/5478

POSTED BY: Kuba Podkalicki
Posted 6 years ago

I have to apologize to you, Kuba. It was nonsense to say that your solution is not better than mine.

In fact, my solution is wrong and yours normally works. Thanks a lot. I had tried my solution with a stylesheet from a subdirectory Wolfram\ProgrammingLabDefault.nb only.

We still have a problem, when we add any own additional StyleDefinitions. As an example:

setPS1[] := SetOptions[
  EvaluationNotebook[],
  StyleDefinitions -> Notebook[
    {
     (* Style Environment Names with correct Magnifications *)
     Cell[StyleData[All, "Printout"], Magnification -> 1.0],
     Cell[StyleData[All, "Working"] , Magnification -> 1.0 ]
     }
    ]
  ]

If we execute that once, the findStyleSheet-function will no longer work, since CurrentValue[thisNb,StyleDefinitions] does no longer give the StyleDefinitions for the stylesheet name, but that own StyleDefinitions prepended.

I think I can easily solve that circumstance, but I have no time at the moment.

POSTED BY: Werner Geiger
Posted 6 years ago

What I could do is extract the parts of sd:

In[49]:= sd
Out[49]= FrontEnd`FileName[{"Wolfram"}, "ProgrammingLabDefault.nb", 
 CharacterEncoding -> "UTF-8"]

In[56]:= sdf = Append[sd[[1]], sd[[2]]]
Out[56]= {"Wolfram", "ProgrammingLabDefault.nb"}

In[57]:= sdf = FileNameJoin[sdf]
Out[57]= "Wolfram\\ProgrammingLabDefault.nb"

In[58]:= sdf = ExpandFileName[sdf]
Out[58]= "C:\\Users\\Werner\\OneDrive\\Dokumente\\Wolfram\\\
ProgrammingLabDefault.nb"

But this is somewhat brute force and no reasonable solution.

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard