I wrote a package and when I import it I'd like it to print something like:

"Bla bla bla. Click HERE for the example notebook." and the the list of functions defined in the package.

I'd like HERE to be an clickable hyperlink to the example notebook that is in the package folder.

My first problem is that if I put, for example, SystemOpen[NotebookDirectory[]] in the package, when I load it it will open the notebook directory and not the package one (which makes sense, but I don't know how to automatically point to the package folder without writing the path by hand). I know that the usual path would be $UserBaseDirectory[]<>"/Applications", but I'd like to keep it general to wherever the package folder is located.

The second problem is that I can't find the command (if there is one) for creating an "hyperlink" to a mathematica command (in this case would probably be SystemOpen[path_to_notebook]).

At the moment all I have is the following (not much really):

Print["Bla bla bla. Click HERE for the example notebook."]

(I know it might be not usual to display all the functions of the package at the beginning, but it's quite useful to me at the moment).

Thanks :)


1 Answer 1


You can get the full path to the package file using $InputFileName.

In a private package of mine a long long time ago I did this:

packageDirectory = DirectoryName[$InputFileName];

TutorialNotebook[] :=
      NotebookOpen@FileNameJoin[{packageDirectory, "Tutorial.nb"}],
      Saveable -> False

However, I'd argue that the right way to do this is to integrate the documentation into the documentation center. Start here. You do not need to use most of the documentation tools. The description I linked explains how to add a simple notebook you just wrote.

As for hyperlinks, Hyperlink does work with files. If you want to execute an arbitrary command, consider Button, with a special formatting if needed.

  • $\begingroup$ Cheers, that's useful, I'll give it a try! I'm aware of the possibility of building the documentation with workbench (never tried it, though), it's just that I already have that notebook nicely formatted (I basically built the package from it), so it seemed a good idea to go for a temporary solution that doesn't takes me any extra time, until I'll have a few spare hours for playing with the actual documentation :) Thanks again! $\endgroup$
    – Fraccalo
    Commented Oct 28, 2018 at 19:38
  • $\begingroup$ Unrelated: every time I cmd+click on your (ref) link it 404s, going to URL https://reference.wolfram.com/language/ref/$%3C/span%3EInputFileName.html. I tried to edit your post to fix it, but I couldn't? $\endgroup$
    – ktm
    Commented Oct 29, 2018 at 0:07
  • $\begingroup$ @user6014 Thanks! It's fixed now. Dollar signs trigger math mode, so they cause problems occasionally. $\endgroup$
    – Szabolcs
    Commented Oct 29, 2018 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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