Notepad++ is a versatile text editor and source code editor for Windows. I use it as my default text editor on Windows. For convenience of compiling .tex files while editing we can simply add a run command to Notepad++.
This is a simple “how to” for conveniently using Notepad++ as the editor for LaTex (using MiKTex) on Windows.
- Install MiKTeX
- Install Notepad++. (This comes with syntax highlighting for LaTeX, but for BibTex add the user style.)
- (Optional) Install Sumatra PDF
- Create a .bat file with the following code:
:: Called from Notepad++ Run :: [path_to_bat_file] "$(CURRENT_DIRECTORY)" "$(NAME_PART)" :: Change Drive and to File Directory %~d1 cd %1 :: Run Cleanup call:cleanup :: Run pdflatex -> bibtex -> pdflatex -> pdflatex pdflatex %2 bibtex %2 :: If you are using multibib the following will run bibtex on all aux files :: FOR /R . %%G IN (*.aux) DO bibtex %%G pdflatex %2 pdflatex %2 :: Run Cleanup call:cleanup :: Open PDF (Script updated based on comments by 'menfeser' :: START "" "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" %2.pdf START "" %2.pdf :: (Alternative) Open PDF with Sumatra PDF :: START "" "C:\Progra~2\SumatraPDF\SumatraPDF.exe" %2.pdf -reuse-instance :: Cleanup Function :cleanup :: del *.log del *.dvi del *.aux del *.bbl del *.blg del *.brf del *.out goto:eof
- Add the batch file as a run command:
- Notepad++ -> Run -> <PATH_TO_BAT_FILE> “$(CURRENT_DIRECTORY)” “$(NAME_PART)”
- (Note the surrounded ” before and after CURRENT_DIRECTOR and NAME_PART)
- Create a keyboard shortcut for this.
- Now create a LaTeX file in Notepad++, Save and Run (using the short key defined).
Note:
- MiKTex should be added automatically to Windows “path” when it is installed, if not add “WHERE_MIKTEX_INSTALLED\miktex\bin” to path manually.
- This is just a work flow that works for me, you can modify it to suit yours.
- Plagiarised from various sources on the Internet. 🙂
30 replies on “LaTeX on Windows with MiKTeX and Notepad++”
thanks for making this!
you might want to add a “tskill acroRD32”
so that you don’t have to close adobe reader all the time 🙂
LikeLike
Thanks for the tip…
LikeLike
The kill switch is great but it closes all open Acrobat windows, including some that I’d like to stay open. Is there any way to just close the pdf of interest?
LikeLike
I use Sumatra PDF. It doesn’t require you to close the pdf document before you recompile, and it shows changes immediately.
LikeLike
I had some trouble getting Sumatra to open the newly compiled file. I have both Acrobat Pro and Sumatra installed. I got it to work by changing the RUN command to pass on the full name of the pdf, in addition to the two items in used in Nimal’s approach:
“” “$(CURRENT_DIRECTORY)” “$(NAME_PART)” “$(NAME_PART).pdf”
And in the batch-file I changed the START command to:
START “” “C:\Program Files\SumatraPDF\SumatraPDF.exe” %3
A remaining annoyance is that the pdf will open in a new window as you recompile. I’d prefer a refresh (or, equivalently, automatic closing of the old pdf and opening of the new file).
PS Along the way I learned that %3 is just the third argument in the RUN command, in case that helps anyone.
LikeLike
And the answer is to use Sumatra’s command line switch to “reuse” the current instance:
START “” “C:\Program Files\SumatraPDF\SumatraPDF.exe” %3 -reuse-instance
LikeLike
There is a critical shortage of informative articles like this.
LikeLike
Nice,
but your start command does not work as you think.
The syntax is:
So better do:
or still better:
which uses the default pdf viewer!
LikeLike
Thanks for correcting me.
I didn’t look into that much as it worked for me.
LikeLike
I’m having a little trouble getting this working, any assistance would be much appreciated.
The batch file I’m using, based on the comments to the topic, is as follows:
LikeLike
Oh, and the problem is that when I run the batch file within Notepad++, I get the error:
Windows cannot find ‘.pdf’. Make sure you typed the name correctly, and then try again.
LikeLike
The quotations used in your start command are not correct.
START “ ” %2.pdf
It should be,
Hope this helps you…
LikeLike
Hey, thanks, this is cool. One thing I can’t get to work though. When the file is compiled, all output files are put in the notepad++ folder, not in the original folder where the compiled file is. Any idea what needs to be changed to fix this?
LikeLike
I’m not sure how that happens.
What is your OS?
LikeLike
Win XP
LikeLike
It works for me on XP and 7.
Try putting ” before and after the $(CURRENT_DIRECTORY) and $(NAME_PART) in the Notepad++ run command. Like,
LikeLike
Thanks for the post, but I can’t get this to work. I click “Run…” in the Run menu, type the following into the field:
C:\Program Files (x86)\Notepad++\call_latex.bat "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
and hit “Run” but nothing happens.
Can you explain note #1 to me? I’ve added a “WHERE_MIKTEX_INSTALLED” system variable with the value “C:\Program Files (x86)\MiKTeX 2.9\miktex\bin”. Was this correct?
LikeLike
I could see that your [path_to_bat_file] has some spaces in it.
Can you try putting that file in C: and try again?
You can try surrounding [path_to_bat_file] with double quotes:
"C:\Program Files (x86)\Notepad++\call_latex.bat" "$(CURRENT_DIRECTORY)" "$(NAME_PART)"
You should add “C:\Program Files (x86)\MiKTeX 2.9\miktex\bin” to the environment variable “PATH”. If the MikTeX installation was correct, it should be added automatically. So just check the existing PATH variable and append to it only if required.
LikeLike
Thanks for the help. Double quotes around the path in the run input fixed it. Everything is working well now!
LikeLike
This is a version with 2 slight tweaks:
* A 3rd parameter is passed to the batch file if you want to display the output – no 3rd parameter will build but not display
– So I map:
to CTRL+F7 and
to CTRL+SHIFT+F5 (to match TeXnicCenter)
* Because Acrobat locks open PDFs I installed FoxIt reader, and force the output to open in that (keeping acrobat as my default)
LikeLike
Thanks Chris…
That’ll be a useful tweak.
LikeLike
It turns out on further testing that FoxIt may need its starting directory specified. Calling it using:
seemed to work.
LikeLike
… except start expects a title, so it should be
LikeLike
As pdf viewer I just use:
texworks %2.pdf
LikeLike
Thanks for the tip. very useful
LikeLike
You are my hero. This works perfectly! Thanks a lot!
LikeLike
Many thanks for this batch file!
Any possiblity to have something similar to use with Sublime Text?
Very best regards,
Devlin
LikeLike
Thanks for tutorial. How to add forward and inverse search feature to the batch file?
LikeLike
Kudos! extremely helpful post, and very easy to implement.
Thanks!
LikeLike
Hello,
I followed these steps exactly and it worked once. The second time I tried, I get the error that the …*.dvi, …*.aux, etc. files cannot be found. Any idea what’s happening? Thanks.
LikeLike