I wonder if there is a way to execute Mathematica code via Notepad++.

After some searching on the web, I found that there is a user-defined language that supports Mathematica highlighting, but there are no instructions on how to execute Mathematica scripts via Notepad++.

I have already installed the NppExec plugin

  • $\begingroup$ I guess the main reason this is not described anywhere is, it's not clear what the procedure should look like in general case. Mathematica expressions are meant to be evaluated “in place”, that is, in a REPL. Most good Mathematica code does not have explicit side effects. Which means, if you have a list of expressions in your text file, it's not really clear what to do with them. Make a list of unevaluated expresions, thread Evaluate over it and export/dump list of results to a fresh file? Won't that become a mess in most cases?.. $\endgroup$
    – akater
    Commented Jun 20, 2015 at 17:12
  • $\begingroup$ …Thus, I suggest you describe in little more detail how you imagine this execution would look to you, as end-user. $\endgroup$
    – akater
    Commented Jun 20, 2015 at 17:12

1 Answer 1


Here's one possible way to execute scripts, as it's understood by Mathematica itself (check out ref/program/math for reference).

You might just replicate the following instructions for using MiKTeX with Notepad++.

The following is mostly a blatant copy of that answer.

  1. Make sure you have math.exe in your PATH variable.

  2. Create a bat file

    :: Change drive and go to file directory
    cd %1
    :: Run MathKernel in script mode
    math -noprompt -script %2

    and save it.

  3. Open a simple Mathematica script file in Notepad++ (e.g., type Print@"Hello"), press F6 to execute.

  4. Type the following lines in the window that pops up:

    <Path_to_bat_file> "$(CURRENT_DIRECTORY)" "$(FULL_CURRENT_PATH)"

    This will save your current script and execute it with math.exe in batch mode.

  5. Click on “Save” and type in a recognizable name such as math -script.

  6. Go to the menubar, Plugins → NppExec → Advanced Options… Under “Menu item”, choose the script we just created above, and “Add/Modify” it to the Menu items with a suitable name. This allows us to assign shortcut keys through Settings → Shortcut Mapper → Plugin commands.

  7. Navigate to the script name and choose a shortcut key. For example, Ctrl+Shift+M is not binded to anything in default installation for now.


This will start a fresh math kernel. If, for example, in your casual Mathematica session you currently have x = 2, this definition will not be taken into account while executing script this way.

  • $\begingroup$ Thanks for your reply. I will try as soon as possible :) $\endgroup$
    – Yorgos
    Commented Jun 21, 2015 at 17:23
  • 1
    $\begingroup$ @Yorgos If you're satisfied with it, please accept the answer. (I'm not a karma chaser, I merely want questions to have answers.) $\endgroup$
    – akater
    Commented Jul 1, 2015 at 7:27

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.