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 am new here, so let me know if this question is inappropriate. I've been stuck for many hours on this puzzle. I know it should be easy, but for me...?

I want to create a Notebook (call it "Index of Related"), located in directory "C:\somewhere\strange" (not necessarily in $Path) which contains a list of notebooks I use at the same time, but quite independently of one another. One application might be a list of all the Mathematica notebooks I use in my microeconomics course.

From inside "Index of Related", if I click on a button, I want Mathematica to load some other notebook, just as if I had used File/Open in Mathematica.

I can't seem to create buttons to execute simple File/Opens! Every coding I've tried adding to Index of Related" seems to load the other notebooks into or inside Index of Related or generate $Failed.

Example X: Example of an application:

  • File 1, located in C:\directory1 : Slide show for the talk....

  • File 2, located in c:\dogs\small : My text for the talk....

  • File 3, located somewhere in $Path : Handouts for the talk....
  • File 4: References for the talk....
  • Files 5-8, located all over the place: Examples for the talk, created for other projects, so in various other directories....

Now, while creating the talk I first load "Index of Related". I stumble on a reference, so I open Files 2 and 4 and make changes. In a later session, I want to create from this reference a slide, so I open and work in File 2.

share|improve this question
add comment

2 Answers 2

The following code

Button["Open File 1",  NotebookOpen["filename"]]

opens an existing notebook (with name and complete path in "filoename") in a new window.

Example that should work on all systems:

base = FileNameJoin[{$InstallationDirectory, "SystemFiles", 
    "FrontEnd", "Palettes"}];
Column[{
  Button["BasicMathAssistant", 
   NotebookOpen[FileNameJoin[{base, "BasicMathAssistant.nb"}]]],
  Button["StylesheetChooser", 
   NotebookOpen[FileNameJoin[{base, "StylesheetChooser.nb"}]]],
  Button["WritingAssistant", 
   NotebookOpen[FileNameJoin[{base, "WritingAssistant.nb"}]]]
  }]

Mathematica graphics
Mathematica graphics

share|improve this answer
add comment

If you don't need buttons and don't insist on constructing the index by coding, then you can just use Text cells where you type a name for the notebook, select the name, then use the menu command Insert > Hyperlink to open a dialog. In that dialog, select "Other notebook or URL", then use its Browse button to locate the notebook, etc.

For example, if you type "ChartElementSchemes" in the Text cell and then create the hyperlink to that palette, you'll just see the characteristic coloring indicating a hyperlink. If you examine the cell's contents, you'll see:

Cell[TextData[ButtonBox["BasicMathAssistant",
 BaseStyle->"Hyperlink",
 ButtonData->{
 FrontEnd`FileName[{$RootDirectory, "Applications", "Mathematica.app", 
 "SystemFiles", "FrontEnd", "Palettes"}, "ChartElementSchemes.nb", 
 CharacterEncoding -> "UTF-8"], None}]], "Text"]

While this method doesn't allow you to just type code and doesn't create nice buttons to see, it does have the advantage that you can in fact browse to find the notebooks in question. Of course you can fancy up what you see by creating a Table in the text cell and include a frame, say.

share|improve this answer
add comment

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.