In Fortran, I can use include "file" to insert a piece of code. Is there a similar method in Mathematica?

| improve this question | | | | |
  • 1
    $\begingroup$ Have a look at the docs on packages. $\endgroup$ – b.gates.you.know.what Dec 27 '12 at 13:45
  • $\begingroup$ @b.gatessucks I think that should be an answer... $\endgroup$ – acl Dec 27 '12 at 14:43
  • $\begingroup$ @acl Can't do it right now, please do go ahead. $\endgroup$ – b.gates.you.know.what Dec 27 '12 at 17:12

The answer is very simple:

Put your external code snippet into a file toInclude.m, for example with the content


Now in the "parent" notebook (assuming it's in the same directory as the code snippet), execute the command



<< "toInclude.m"

and you're done. Here are the references for << (Get) and Import.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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