Categories
Tech Notes

LaTeX on Windows with MiKTeX and Notepad++

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:

  1. MiKTex should be added automatically to Windows “path” when it is installed, if not add “WHERE_MIKTEX_INSTALLED\miktex\bin” to path manually.
  2. This is just a work flow that works for me, you can modify it to suit yours.
  3. 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 🙂

Like

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?

Like

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.

Like

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

Like

Nice,

but your start command does not work as you think.

The syntax is:

start "title" "program"

So better do:

START "" "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe" %2.pdf

or still better:

START "" %2.pdf

which uses the default pdf viewer!

Like

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:

:: 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
START "" %2.pdf


:: Cleanup Function
:cleanup
:: del *.log
del *.dvi
del *.aux
del *.bbl
del *.blg
del *.brf
del *.out
goto:eof

Like

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.

Like

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?

Like

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,

<PATH_TO_BAT_FILE> "$(CURRENT_DIRECTORY)" "$(NAME_PART)"

Like

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?

Like

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.

Like

Thanks for the help. Double quotes around the path in the run input fixed it. Everything is working well now!

Like

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:

[path_to_bat_file] "$(CURRENT_DIRECTORY)" "$(NAME_PART)" 

to CTRL+F7 and

[path_to_bat_file] "$(CURRENT_DIRECTORY)" "$(NAME_PART)" show 

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)

:: 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
if (%3)==() goto cleanup
::START "" %2.pdf
"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %2.pdf

:: Cleanup Function
:cleanup
:: del *.log
del *.dvi
del *.aux
del *.bbl
del *.blg
del *.brf
del *.out
goto:eof

Like

It turns out on further testing that FoxIt may need its starting directory specified. Calling it using:

start /D%1 "C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %2.pdf

seemed to work.

Like

… except start expects a title, so it should be

start /D%1 "" "C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %2.pdf

Like

Many thanks for this batch file!

Any possiblity to have something similar to use with Sublime Text?

Very best regards,

Devlin

Like

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.

Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s