Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to make a button that opens a notebook upon pressing. The point is that I would like the notebook to be made according to a specified StyleSheet.

To be more specific, here is a simple example of such a button:

    Button["Show",
 CreateDocument[
  Column[{
    TextCell["Some text" , "Text", FontSize -> 20],
    ExpressionCell[Plot[Sin[x], {x, 0, 2 \[Pi]}]]
    }],
  WindowTitle -> "Some title", WindowSize -> {450, 300}], 
 ImageSize -> {50, 18}, BaseStyle -> {"GenericButton", Bold}]

The button is then copy-pasted into any line of any TextCell of the main notebook and serves for the referencing purposes: when the reader meets the text discussing this plot this button in embedded in such a text, and he may press the button. This will generate the notebook with the plot, and the reader may see the plot in question on the spot.

Now, I would like the notebook that will be open that way to be created according to the JournalArticle StyleSheet. Is it possible to specify?

This edit I am making after having received the answers of Mike Honeychurch and m_goldberg. After all corrections here is the code I had in mind:

    Clear[x, y, z];
Button["Show a JournalArticle Notebook",
 CreateDocument[{
   (* This makes a Section title *)
   TextCell["A section", "Section", FontSize -> 40],
   (* This makes a text *)
   TextCell["Some text", "Text", FontSize -> 20],
   (* This makes a numbered formula *)
   TextCell[y == Sin[x^2] // TraditionalForm, 
    "DisplayFormulaNumbered", FontSize -> 20, TextAlignment -> Center],
   (* This makes a plot *)
   ExpressionCell[Plot[Sin[x], {x, 0, 2 \[Pi]}], "Figure"],
   (* This makes a caption for illustration *)
   TextCell["Some caption", "FigureCaption", FontSize -> 14],
   (* This makes another numbered formula *)
   TextCell[z == Exp[-x^2] // TraditionalForm, 
    "DisplayFormulaNumbered", FontSize -> 20, TextAlignment -> Center]
   },
  StyleDefinitions -> 
   FrontEnd`FileName[{"Article"}, "JournalArticle.nb", 
    CharacterEncoding -> "UTF-8"], WindowTitle -> "Some title", 
  WindowSize -> {750, 500}, Background -> LightYellow], 
 ImageSize -> {200, 18}, BaseStyle -> {"GenericButton", Bold}]

It creates a button. The latter opens the notbook. That's how it looks like: enter image description here

share|improve this question

2 Answers 2

up vote 4 down vote accepted
Button["Show", 
  CreateDocument[
    Column[{
      TextCell["Some text", "Text", FontSize -> 20], 
      ExpressionCell[Plot[Sin[x], {x, 0, 2 \[Pi]}]]}],
    StyleDefinitions -> 
      FrontEnd`FileName[{"Article"}, "JournalArticle.nb", CharacterEncoding -> "UTF-8"],
    WindowTitle -> "Some title",
    WindowSize -> {450, 300}],
  ImageSize -> {50, 18},
  BaseStyle -> {"GenericButton", Bold}]
share|improve this answer
    
Thank you, Mike. This solution, however, does not do what I expected from it. I mean that the notebook open that way does not show the formatting I expect from the one in the JournalArticle style. Please see the end below –  Alexei Boulbitch Oct 14 '13 at 9:21
    
Indeed this: Clear[y, x]; Button["Show", CreateDocument[Column[{ TextCell["A Section name", "Section", FontSize -> 20], TextCell[y == x^2, "DisplayFormulaNumbered", FontSize -> 20], TextCell["Some text", "Text", FontSize -> 20], ExpressionCell[Plot[Sin[x], {x, 0, 2 [Pi]}], "Figure"]}], StyleDefinitions -> FrontEnd`FileName[{"Article"}, "JournalArticle.nb", CharacterEncoding -> "UTF-8"], WindowTitle -> "Some title", WindowSize -> {650, 500}], ImageSize -> {50, 18}, BaseStyle -> {"GenericButton", Bold}] shows no expected formatting when open. –  Alexei Boulbitch Oct 14 '13 at 9:22
    
Further, if I add this statement after the ExpressionCell one: TextCell["A caption for illustration", "FigureCaption", FontSize -> 20], the button cannot open anything at all. Can you see the workaround? –  Alexei Boulbitch Oct 14 '13 at 9:23
1  
@AlexeiBoulbitch. This code does exactly what it promises on my system, which is V9.0.1 running on OS X 10.6.8. Just don't wrap your list of cells with Column. –  m_goldberg Oct 14 '13 at 12:55
    
@Mike Honeychurch OK, without Column it, indeed, works perfectly. What is the role of CharacterEncoding here? –  Alexei Boulbitch Oct 14 '13 at 13:39

Mike Honeychurch's answer solves your problem concerning setting the notebook style sheet. Your other problems stem from using Column to wrap your list of cells. The following, I believe, will delver a popup notebook with the formatting you want.

Button["Show", 
  CreateDocument[{
    TextCell["Fox Plot", "Section"],
    TextCell["The quick brown fox made this plot.", FontSize -> 16, "Text"], 
    ExpressionCell[Plot[Sin[x], {x, 0, 2 \[Pi]}]]}, 
    StyleDefinitions -> 
      FrontEnd`FileName[{"Article"}, "JournalArticle.nb", CharacterEncoding -> "UTF-8"], 
    WindowTitle -> "How to Fox Plot",
    WindowSize -> {500, 320}],
  ImageSize -> {50, 20},
  BaseStyle -> {"GenericButton", 12, Bold}]

button.png

foxplot.png

share|improve this answer
    
You are right, thank you. –  Alexei Boulbitch Oct 14 '13 at 13:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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