8
$\begingroup$

The built in Palettes of Mathematica are simply .nb files which can be found in the following place:

SystemOpen@FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
  "Palettes"}]

I was trying to open anyone of them but it turned out these files opened directly into the Palettes form.

I tried to open them in the Notepad but (as normal) they opened in the expression form.

I tried to copy the Notepad content into expression cell and convert the cell into display from but it did not work and some errors were generated.

Any idea how to open these files in the normal way so that I can explore the codes of these files?

$\endgroup$
  • 1
    $\begingroup$ There is no difference between a palette and a standalone cdf, what was evaluated is lost and what you have needs to be be converted from boxes to expressions. Here is and old topic about that (probably needs updates): How can I recover the source code from cdf file? $\endgroup$ – Kuba Jun 6 '16 at 5:42
  • 2
    $\begingroup$ Have you tried selecting Generate Notebook from Palette from the Palettes menu and then converting the generated cell into input form? That works for me. $\endgroup$ – m_goldberg Jun 6 '16 at 5:47
  • 1
    $\begingroup$ @m_goldberg In version 10.4.1 I don't have the Generate Notebook from Palette item in the Palettes menu but I do have it in versions 10.0.1 and 8.0.4. With version 8.0.4 your idea seems to work well. It is surprising that in the latest version they removed it... :( $\endgroup$ – Alexey Popkov Jun 6 '16 at 13:01
  • $\begingroup$ @AlexeyPopkov. I'm using 10.4.1 and I the item is on my Palettes menu. I'm running on OS X. It is only available when there is a palette loaded. Did you have a palette on your screen? $\endgroup$ – m_goldberg Jun 6 '16 at 15:18
  • 1
    $\begingroup$ @Mr.Wizard Thanks for the link, the workaround suggested by Kuba is very nice! Undoubtedly it is the same issue but now (version 10.4.1) the Generate Notebook from Palette menu item is absent at all. $\endgroup$ – Alexey Popkov Jun 7 '16 at 10:00
2
$\begingroup$

You can Get the palette, then apply MakeExpression in order to convert boxes into the corresponding high-level expression, and then display the result as InputForm. For example:

palette = Get@
   FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", 
     "Palettes", "SlideShow.nb"}];
InputForm @@ MakeExpression[palette, StandardForm]

screenshot

If you aren't satisfied with the default formatting produced by InputForm, I recommend reading this answer of mine.

$\endgroup$
1
$\begingroup$

Actually I think you can use NotebookGet to get the code of the palettes. With only your notebook and palette opened, Using NotebookGet@Notebooks[][[2]] can get you the expression form, if that's what you need.

But the problem is that this result, just like other outputs of NotebookGet, is full of Cell or CellBox or so, actually still hard to read. But the essential information (especially formats of grids)lies inside them so they're necessary.

Maybe I can give you more detailed and targeted solution to this problem if you can provide me a more specific desired output form.

I hope this answer can help you.

$\endgroup$
  • $\begingroup$ After NotebookGet one could apply MakeExpression in order to convert boxes into the corresponding high-level expression. $\endgroup$ – Alexey Popkov Jun 6 '16 at 5:37
  • $\begingroup$ oh,truely useful! $\endgroup$ – Wjx Jun 6 '16 at 6:04

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.