LaTeX + Notepad++

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. 🙂

29 thoughts on “LaTeX on Windows with MiKTeX and Notepad++”

  1. 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 🙂

      1. 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?

    1. 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.

      1. 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

  2. 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!

  3. 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
    
    1. 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.

  4. 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?

        1. 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)"
  5. 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?

    1. 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.

  6. 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
    
  7. 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.

    1. … except start expects a title, so it should be

      start /D%1 "" "C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe" %2.pdf
  8. Many thanks for this batch file!

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

    Very best regards,

    Devlin

Leave a Reply