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.
Make sure you have math.exe
in your PATH
variable.
Create a bat file
:: Change drive and go to file directory
%~d1
cd %1
:: Run MathKernel in script mode
math -noprompt -script %2
and save it.
Open a simple Mathematica script file in Notepad++ (e.g., type Print@"Hello"
), press F6 to execute.
Type the following lines in the window that pops up:
NPP_SAVE
<Path_to_bat_file> "$(CURRENT_DIRECTORY)" "$(FULL_CURRENT_PATH)"
This will save your current script and execute it with math.exe
in batch mode.
Click on “Save” and type in a recognizable name such as math -script
.
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.
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.
Note
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.