5

To expedite the work I do I have created a Mathematica Package that has all the functions I need to plot the data I need to analyze.

The problem is every now and then I will need to slightly modify one of the functions and will need to go and look for the .m package, copy the function onto the notebook, change the name, and work from there. I was wondering if there is any way that I could create a function inside the Package that would print the contents of the functions so I don't have to lose time searching. Something like PrintFunPac[Function1] that would return the definition of Function1.

Tried googling and didn't find anything. Thanks!

M.O.
  • 425
  • 2
  • 7

1 Answers1

5

You can always enter

?? <packagename>`*

where <packagename> is the name of the package/context you want to inspect.

For example

?? Developer`*

contains many useful symbols.

For deeper hidden symbols, you can also try

?? <packagename>`*`*

Another helpful tool is hidden in the package "GeneralUtilities`". Run the following and be amazed:

Needs["GeneralUtilities`"]
PrintDefinitions[HoldPrint];
Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
  • 1
    Thank you so much!. The first thing you said ?? <packagename>* did return the definition of the functions but with the ``packagenamePrivate`` in front of the variables' name, but your solution of ``Needs["GeneralUtilities"]; PrintDefinitions[HoldPrint];`` worked!! Thank you so much! – M.O. Sep 12 '18 at 18:47
  • You're welcome! – Henrik Schumacher Sep 12 '18 at 18:51
  • @M.O. I think it is not clear what is the goal. Your question suggested you want to access the code and edit it but PrintDefinitions creates notebooks that are not ready to play with. Or is preview code the main goal? – Kuba Sep 13 '18 at 10:41
  • @Kuba, I thought I had been pretty straightforward but I guess not. The package I have created is done, but as the input data changes and the images are needed for different purposes, every now and then I need to change the functions of the package a bit. I was asking a way to get the definition of the function of my package, meaning the code, from mathematica instead of searching for the .m, copying the function, pasting it in the .nb, changing its name and then make the changes. Using Needs["GeneralUtilities"]; PrintDefinitions[HoldPrint];` as Henrik suggested did just that. – M.O. Sep 13 '18 at 13:02
  • @M.O. That is what I thought too, but then PrintDefinitions, for me at least, generates notebook with interactive (Tooltips/Hyperlinks) symbols that are not just a plain code you can slightly edit and evaluate. – Kuba Sep 13 '18 at 13:08
  • But one can "copy as input". Still a bit annoying, but it is still better than searching for the source file... – Henrik Schumacher Sep 13 '18 at 13:10
  • Yeah, you can copy it as plain text and it works.input text for me adds the public names of the functions with the name of the package added to it, so for what I need copying as plain text works perfectly. – M.O. Sep 13 '18 at 13:16
  • 1
    @M.O. Huh! Yeah, that works. Great! So I also learned something here! =D – Henrik Schumacher Sep 13 '18 at 13:18