To make my code clearer, I want to state that I run all the programs listed here portably.
Step 1: First we need the some prerequisite software:
- Notepad++
- MikTeX: if you've ever run LaTeX on Windows, you should know what this is.
- PPLatex: This is a small program that parses a LaTeX log file and extracts its errors, warnings, etc.
Step 3: Now we create a batch file with the following code, adjusting it according to your needs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | @echo off SET PROGPATH=%~dp0.. :: The folder where I hold all my programs is one directory above the batch file. ::MIKTEX setup SET TEXMFLOCAL=%PROGPATH%\MiktexPortable295105 :: TEXMFLOCAL is not actually used by Miktex. :: I defined it because the next four lines use it, :: which I took from Miktex Portable. SET MIKTEX_BINDIR=%TEXMFLOCAL%\miktex\bin SET MIKTEX_COMMONSTARTUPFILE=%TEXMFLOCAL%\miktex\config\miktexstartup.ini SET MIKTEX_GS_LIB=%TEXMFLOCAL%\ghostscript\base;%TEXMFLOCAL%\fonts SET MIKTEX_USERSTARTUPFILE=%TEXMFLOCAL%\miktex\config\miktexstartup.ini ::The next few are my personal set up SET TEXAUXDIR=%TEMP%\tex :: TEXAUXDIR is where the aux files are placed. SET MYTEXSTY=%PROGPATH%\NPCPackages :: MYTEXSTY is where I put my homemade packages SET PPLATEXPATH=%PROGPATH%\pplatex-1.0-rc1\bin :: pplatex reads the log file my tex file and gives a summary of the errors and warnings. SET Path="%MIKTEX_BINDIR%";%Path% :: In the next line, I create a subfolder in TEXAUXDIR specific to this file IF NOT EXIST "%TEXAUXDIR%\%~n1" mkdir "%TEXAUXDIR%\%~n1" pdflatex.exe --include-directory=%MYTEXSTY% --aux-directory=%TEXAUXDIR%\%~n1 -output-directory=%~dp1 --interaction=nonstopmode "%1" cd /d %~dp0 & %PPLATEXPATH%\pplatex --input %TEXAUXDIR%\%~n1\%~n1.log |
Step 4: Now we will set up the NppExec Plugin to work with this batch file. Goto to the menu Plugins > NppExec > Execute. In the space provided put in the following code:
1 2 | set proghome = $(NPP_DIRECTORY)\.. $(proghome)\path\to\batch\file.bat "$(FULL_CURRENT_PATH)" |
Notepad++ is now set up to compile LaTeX code. At this point, if you press F6 while editing LaTeX code, it will compile and the output will be displayed in the NppExec console.
The following are tweaks I did to Notepad++ to make compiling more convenient.
Tweak 1: Create shortcut to compile script.
- If you go back to the Execute dialog box, you can save this script under a name. (I called it "compile")
- Now we need to map this script to a menu item. Go to Plugins > NppExec > Advanced Options. You will a dialog box like the picture below. In the bottom left, give the menu item a name (I called it "Compile") and select the name of the script. Once you click "Add/Modify", it will appear in the top right. Click okay. Now you will see your menu item in the Macros menu.
- Finally, to map a hotkey to it, go to the Setting menu > Shortcuts Mapper. Click on Plugin commands and scroll until you find the name of your menu command. Double click it and you can change the hotkey.
Tweak 2: Access the pdf viewer. I use SumatraPDF viewer to view my PDF files. I use this because it doesn't lock the PDF file. This means that I will be able to keep the viewer open while I compile my LaTeX file and the file will simply update.
- Make another batch file with the following contents.
- Make another script by going to the Execute dialog box (See Step 4 above) with the following contents. If you want to understand what some of the commands do, see here or just type the commands in the NppExec console.
- Add a hotkey to it too (See Tweak 1 above)
1 2 3 4 5 | @echo off SET PROGPATH=%~dp0.. SET SUMATRAPATH=%PROGPATH%\SumatraPDF SET Path=%SUMATRAPATH%;%Path% START SumatraPDF "%~dp1%~n1%.pdf " -reuse-instance |
1 2 3 4 5 | npp_console ? npe_console a+ -- set proghome = $(NPP_DIRECTORY)\.. $(proghome)\path\to\batch\file.bat "$(FULL_CURRENT_PATH)" npp_console + |
Tweak 4: Code Completion. FingerText, another plugin for Notepad++, allows you to type a hotstring and have it be replaced by longer strings of code. In this Tweak we will make putting \begin{environment}...\end{environment} easier.
- Install the FingerText plugin (see Step 2 above).
- Go to Plugins > FingerText > Create Snippet from Selection (make sure you have not selected anything).
- Under "TriggerText" type "begin"
- Under "Scope" type "ext:tex"
- Under "Snippet Content" put
1 2 3 | begin{$[![envname]!]} \end{$[![envname]!]} [>END<] |
Now, when you type "\begin" followed by the TAB key, it will automatically put in the \begin{envname}...\end{envname} code and your cursor will have "envname" highlighted in both places. When you start typing, it will change both of them at the same time. You just have to hit the arrow key down to get out.
With these steps and tweaks, this has made Notepad++ the best LaTeX IDE I have used yet, and I have tried more than half a dozen.