2

I have some scripts in ".nb" format and I am more used to launch them in Linux command line in Linux but I need them in ".m" format.

Usually I open the ".nb" script with the Mathematica Notebook and I can save it as ".m" script.

Is there any command line to perform this operation ?

Smilia
  • 592
  • 4
  • 14
  • Why do you want to do it from a command line? A notebook can only be edited with the graphical interface. Why can't you convert it to a plain text format when you are finished editing it with the GUI? Or better: if you prefer the command line, why don't you write the .m file directly instead of the .nb? – Szabolcs Nov 16 '18 at 16:21
  • 1
    If you set the cells with code to initialization cells and set the AutoGeneratedPackage notebook option to True then every time you save you will get also an updated .m file – Gustavo Delfino Nov 16 '18 at 17:57
  • I need to do it because I need to execute a lot of .nb files that I didn't written (they are those of my students). And maybe later I would like to write a script to do the job. I would like to avoid to open the Mathematica editor, in that case a simple "save as " .m file answers my question. So apparently there is no solution without opening the mathematica notebook or modifying the .nb file. – Smilia Nov 17 '18 at 16:22
  • 1
    Of course there are possibilities to do this from the command line, the comments just tried to make clear that the problem could be solved easier with a solution different from what you have asked for. What would work is to write Mathematica code which builds a list of notebooks filenames, then for each of them opens it and calls the save as command programmatically. This would be easiest to write as a notebook and run from the mathematica frontend, but with some extra effort could be made to work from the command line. If you show some initial effort I am sure you will get any help needed... – Albert Retey Nov 18 '18 at 19:44
  • If you do not want to open the notebooks, how are you planning to check that your students' solutions are correct? I am not arguing with you. This is a serious question. – Szabolcs Nov 19 '18 at 18:06
  • Your comment confirms that if I had tried to guess at what you want, my answer would not have been useful to you. There are many issues: what do you mean by "converting to an .m file"? If it's really a simple "Save As" to .m, then you'd only get the code in initialization cells. Did the student make sure to set all relevant cells to "initialization"? If you run typical code on the command line, there would be no output whatsoever. What use would running it be then? – Szabolcs Nov 19 '18 at 18:23
  • 2
    You also seem to simply want to automate things, which is something entirely different form runnings things on the command line. Which one do you want? – Szabolcs Nov 19 '18 at 18:23
  • I would like to automate things indeed. Write a script that convert a given .nb file to a .m file. – Smilia Nov 19 '18 at 21:02

0 Answers0