Turn a notebook into a function

I have a code that I want to turn into a function.
I know modules and have seen this post. The problem is that my code is quite long and contains all sorts of functions of the form fun(x_):=..., numerical integrations, eigensystems and so on, and it seems Module does not handle it very well (or I just do not use it properly).

I also looked here for a description of how to call a notebook from another notebook. That should work, but I was wondering if there was any way to treat the notebook like a function with inputs I can pass, similar to most other programming languages.

How do I remove all comments in a Mathematica notebook?

Thank you for your reply to Mathematica Stack Exchange!

  • Please be sure too answer the question, Provide details and share your research!

But avoid

  • Ask for help, clarification or answering other questions.
  • Make statements based on opinions; Cover them with references or personal experience.

Use MathJax to format equations. Mathjax reference.

For more information, see our tips for writing great answers.

Game Design – Which is the best notebook for Tecnet Gameloop (Tencent Gaming Buddy)?

Thanks for responding to Game Development Stack Exchange!

  • Please be sure too answer the question, Provide details and share your research!

But avoid

  • Ask for help, clarification or answering other questions.
  • Make statements based on opinions; Cover them with references or personal experience.

Use MathJax to format equations. Mathjax reference.

For more information, see our tips for writing great answers.

python – Notebook in Google colab finds no txt input file

I'm trying to run the word2vec ipynb notebook (https://github.com/ujhuyz0110/wrd_emb/blob/master/word2vec_skipgram_medium_v1.ipynb?source=post_page—————– ———-) on Google Colab, because my computer is not strong enough to handle the files I need to enter. But when I try to load the file, I get FileNotFoundError: [Errno 2] No such file or directory: & # 39; s_test.txt & # 39; Error. I have already uploaded the file to my drive and tried to access it

drive.mount (& # 39; / content / gdrive & # 39;) `` `

before opening the file but I still get the same exception. Does anyone know how to solve this?

Exporting a Package (.m) from a Notebook (.nb)

I recently started creating Mathematica Packages. I find it easiest to develop functions in a Notebook (.nb file). That way I can add sections, comments and examples.

I do not want to duplicate code, especially by copying / pasting my function from the .nb file to the .m package file. So I would prefer to automatically export code from one Notebook to a package,

For example, I have a .nb with the following function:

toSquare = function[{x}, x^2]

Now I want to add a button that exports this function to a .m file:

button["Export as package", toPackage["myPackageName.m", {toSquare}]]

This should create a file myPackageName.m with the following content:

BeginPackage["Square`"];
toSquare :: usage = "toSquare[x] Squares numbers. ";
toSquare = function[{x},x^2];
EndPackage[]

git – Imports a Python file in JupyterLab that was exported from another Jupyter notebook

I have a JupyterLab notebook. It was exported as a Python file. Now I have to import the saved Python file with the same code blocks back into the JupyterLab.

Is that possible?

I do that because the developers release this notebook for analysis. Is there a way to share through git? I found that jupyterlab-git Extension. However, it is not supported for Python2.

Is there anyway to do that?

Many Thanks.

Slideshows – Save Mathematica Presenter Notebook as PDF?

I have used Mathematica Presenter Notebook as the main tool for the presentation. I found it an efficient alternative to LaTex and a cleaner alternative to PowerPoint.
However, projecting my screen with a projector always causes zoom or resolution issues. I'm wondering if I can somehow save my presenter notebook in a portable format like PDF.
Many thanks.

Front – Mathematica notebook opening from the screen

Yes, I have encountered this problem very often. For me, the reason is that I have 2 screens on my desktop PC and when I save a notebook that appears on the second screen and opens this notebook later, eg. On my MacBook, it sometimes happens that the Notebook window has coordinates outside of my Mac screen area.

The solution is simple: Suppose testme.nb If your notebook is (you also need to specify the path) then you can do the following:

nb = NotebookOpen["testme.nb"];
SetOptions[nb, WindowMargins -> {{0, 0}, {0, 0}}]

and it should jump to the upper left corner of your screen.

procedural programming – run a complex notebook from another master notebook?

I'm trying to use the Dynamo notebook (https://www.ssc.wisc.edu/~whs/dynamo/dynamo_3S_v1.4.1.nb) in a loop over parameters. Basically, this software uses a matrix as input, solves ODEs and some other fairly complex equations and creates a graphical output that I redirect to an EPS file. What I'm trying to do is have not just a matrix as input but a list of them and call the notebook with an index parameter that instructs the Dynamo notebook to use the matrix at that index. I could easily go through this. However, I successfully operated master-slave notebooks

nb = NotebookOpen["/path/to/file.nb"]
f[par_]: = (
index1 = par;
NotebookEvaluate[nb];
)
f[5] (* 5 is my choice for the variable index1 in my slave notebook *),

There are a lot of error messages for the Dynamo software that immediately disappear and restart the entire kernel. How can I fix this?