## Background

LaTeX is a powerful markup language used for typesetting documents. Its ability to professionally typeset mathematics in particular makes it a commonly used tool in academia. If you are reading this, you probably know all about LaTeX, so I don’t need to explain it in detail. Instead, I want to explain how I came to use Notepad++ as my LaTeX editor.

There are really two classes of LaTeX editors: source and WYSIWYM1. Newcomers to LaTeX may prefer WYSIWYM editors like LyX, but at some point you will run a situation where you really need to make changes directly to the markup code. Also, since many academics directly edit LaTeX source files, it is a good habit to learn how to do this from the onset if you work in this environment.

A good source editor will have features like syntax highlighting, bracket matching, auto-completion, code folding, etc. that differentiate it from a plain text editor like Notepad. These tools will be familiar to anyone who has programmed. They help improve your code's readability and can help you avoid making mistakes. A slew of tools exists that bring these features to LaTeX editing. Many of these integrate PDF viewers so that you can easily see the output of your code while you work. You can think of these as LaTeX IDE’s. In fact, Wikipedia has a large comparison table here that shows the various features offered by these editors.

Given the large number of tools available specifically for LaTeX editing, why use a “dumb” tool like Notepad++? In my experience, it’s just a better text editor than some of the more integrated tools. It gives you all the features of a good source editor that I mentioned above in a package that is lightweight, highly customizable, and most importantly won’t crash on you! It is built for Windows. If you’re looking for a cross-platform solution, this is not it. However, that it solely targets Windows brings with it added efficiency and stability. In fact, I’m writing this post in Notepad++ right now2. With four other documents open, it is using a total of 12.6MB of memory. Compare that to TeXworks, the cross-platform editor included with MiKTeX. This is really a great lightweight, extensible TeX editor, but with one document open, syntax highlighting and inline spell checking enabled, it is using 19.8MB of memory.3 Now, I’m not going to quibble over 7MB of memory in the age of web browsers using hundreds of megabytes, but I want to emphasize that Notepad++ gives you more for less. Notepad++ works with many other languages (and includes code folding) and can really serve as a general-purpose coding tool rather than one dedicated to LaTeX.

However, there is one important issue. Notepad++ does not come with a built-in method to view the PDF output of LaTeX documents or perform forward/inverse search.4 These, for me, are crucial features when working with LaTeX documents, and I certainly would not use Notepad++ without these features. The rest of this post will show you how to add them to Notepad++.

## Prerequisites

The post assumes that you already have a working LaTeX distribution that is accessible on your path.5

For the following you will need:

2. NppExec, available through the plugin manager in Notepad++6
3. SumatraPDF, a lightweight PDF reader supporting forward and inverse search
4. CMCDDE, a utility to send DDE commands to SumatraPDF
5. (optional) Aspell and dictionary, for “smart” spell checking7

## Syntax Highlighting

Notepad++ is built on the Scintilla text-editing library, which includes support for highlighting TeX files. I preferred to make some changes to the style, and unfortunately this requires you to create a user-defined language. The user interface to do this in Notepad++ is under Language > Define your language.... Here you can specify your own options and export them to a UDL (User Defined Language) XML file. If you wish, you can import my UDL file for TeX and modify it to suit your needs.8 To force Notepad++ to use your user-defined language when opening TeX files, disable the built-in TeX processor by going to Settings > Preferences... > Language Menu/Tab Settings and moving TeX from the Available items list to the Disabled items list.

Note that by default you will not have auto-complete available for a user-defined language. In order to correct this, you can copy the tex.xml file from your Notepad++ install (on my machine this is C:\Program Files (x86)\Notepad++\plugins\APIs\tex.xml) to a file named userDefineLang.xml in your settings folder (on my machine C:\Users\<username>\AppData\Roaming\Notepad++\plugins\APIs\userDefineLang.xml). This is somewhat inelegant as the same auto-completion list must be used for all user-defined languages. Notepad++ is not perfect.

## NppExec

The NppExec plugin allows us to script Notepad++ to perform actions that interact with other programs on the system. It is the crucial piece to allow us to “integrate” PDF viewing into Notepad++. Make sure that it is installed properly by checking to see if the NppExec sub-menu appears under the Plugins menu.

### The “build” batch file

We will use the plugin to call a Windows batch file that will then make the appropriate calls to our TeX distribution. Credit for the original version of these batch files goes to the blog http://blog.sophomatics.net/?p=7. I have made some modifications, and you should also consider modifications that better fit your needs.

@echo off
if "%~x1"==".tex" goto pdflatex
echo "%~f1" is not a recognized type, extension is "%~x1"
pause
exit /b

:pdflatex
cd /d "%~dp1"
IF NOT EXIST "%~dp1\build" mkdir build

pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~pd1\build" -output-directory="%~pd1\build" "%~pdn1"
echo. && echo.
bibtex.exe "%~dp1\build\%~n1.aux"
echo. && echo.
pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~pd1\build" -output-directory="%~pd1\build" "%~pdn1"
echo. && echo.
pdflatex.exe -interaction=batchmode -synctex=-1 -aux-directory="%~pd1\build" -output-directory="%~pd1\build" -quiet "%~pdn1"
echo. && echo.

type "%~dp1\build\%~n1.log" | findstr Warning:

start "openPDF" "%PROGRAMFILES(x86)%\SumatraPDF\SumatraPDF.exe"  "%~dp1\build\%~n1.pdf" -reuse-instance

echo SUMATRA>"%~dp1\build\cmcdde.tmp"
echo control>>"%~dp1\build\cmcdde.tmp"
echo [ForwardSearch("%~dp1\build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1\build\cmcdde.tmp"

"%PROGRAMFILES(x86)%\cmcdde.exe" @"%~dp1\build\cmcdde.tmp"

del "%~dp1\build\cmcdde.tmp"
exit /b

Let’s quickly break this down so that it is clear exactly what the batch file does. First we check to make sure the file we are processing has a .tex extension. If you name your LaTeX files in some different way, you will want to add another if statement to account for this.

Provided that we have a file that is (presumably) written in (La)TeX, we jump to the :pdflatex label. I prefer to place the output of my TeX builds into a subdirectory called build. This removes clutter from the directory where I save my TeX file. If this directory does not exist, we create it.

Then we start SumatraPDF minimized with two command-line options. The -inverse-search option tells SumatraPDF to call Notepad++ whenever we double-click our PDF output and pass it the line number and filename corresponding to the LaTeX source code. The -reuse-instance option tells SumatraPDF not to create a new process. Check the paths of SumatraPDF and Notepad++ in case you have installed them in different locations.

Next we run pdflatex to generate the PDF file from our LaTeX source. You will notice that we end up running pdflatex multiple times. Due to the way the process works, multiple runs of pdflatex are needed for the bibliography and any internal references to figures, tables, etc. LaTeX-specific packages are smarter about how many times the process needs to be run. Sometimes one pass is enough, but we will perform three passes here all the time. At some point I may modify this behavior, but for now the extra runs really do not create a problem for modest-sized documents.

The options on the first run specify that we should produce no output (-draftmode), halt on errors while sending all messages to a log file (-interaction=batchmode), and save all files to the auxiliary build directory (-aux-directory=).9 We use echo. && echo. to output a new line in the console window for readability. Then we use bibtex to create the bibliography if necessary and then run pdflatex again to incorporate those changes.10 The final run of pdflatex removes the -draftmode option so that we will actually get a PDF output. In order to use forward/inverse search we set the -synctex=1 option. Finally -quiet will suppress all output to the console except for errors.

Now that we have run pdflatex to generate our document, we use type to check the log file for warnings and output them to the console. Remember that we already set pdflatex to output errors to the console. We will change some settings later in NppExec to make it easier for us to spot errors in the console window.

Finally, we open the output in SumatraPDF. The remaining commands use CMCDDE to communicate with SumatraPDF, and we will discuss their function when we talk about forward search.

### Configuring NppExec

We will now use NppExec to call this batch file from within Notepad++. Navigate to Plugins > NppExec > Execute... or use the shortcut F6 to bring up the execute window.

Enter the following commands:

NPP_SAVE
C:\<path to batch file>\pdflatex_build.bat "$(FULL_CURRENT_PATH)"$(CURRENT_LINE)

The first command is part of a set of Notepad++-specific commands included in NppExec. Unsurprisingly, NPP_SAVE saves the current file. We then call the batch file described above and pass it the current file open in the editor and which line our cursor is on.11

Press Save... in the NppExec window and give this action a name like pdflatex_build. You can now run this script by pressing F6, selecting it from the menu, and pressing OK. This works well enough, but you probably want to create a keyboard shortcut so that you can easily invoke the script. In order to do that, go to Plugins > NppExec > Advanced Options.... Find the Item name: text box under the Menu item group. Enter something like Run pdflatex, and in the Associated script drop-down select the pdflatex_build script we just created. Click Add/Modify and your new menu item should appear in the list above. Make sure that Place to the Macros submenu is checked and press OK.

Now you can look under the Macro menu and see that Run pdflatex is there. We still need to assign it a keyboard shortcut to make it truly useful. To do this go to Settings > Shortcut Mapper..., select Plugin commands and find Run pdflatex (it’s probably near the bottom). Double-click it to assign a shortcut. For instance, I chose Alt+~.12 Press Close, and now you should see it in the Macro menu with the keyboard shortcut listed beside it.

### Console Highlighting

I inevitably make errors when writing source code, and LaTeX documents are no exception for me. When one of these errors comes up, I would like it prominently displayed in the console output. The settings passed to pdflatex will cause errors to show in the console window, and we can take advantage of NppExec’s console filtering to bring these to our attention. In fact, we will set NppExec to highlight errors in bold, red text and warnings in bold, blue text.13 Bring up the Console Output Filters settings by going to Plugins > NppExec > Console Output Filters.... Alternatively, you can press Shift+F6. You do not need to make any changes to the Filter tab. Instead, make it so your Replace and HighLight tabs match the images below.

Set the replacement filter to change forward slashes into back slashes. This will make the paths to files in the console output appear in the correct Windows format. This is important as the first filter on the HighLight tab will require this path format.

The first two highlight filters look for errors and display them in bold, red text. The last filter will display warnings in bold, blue text.

The main work to compile LaTeX files into PDF using Notepad++ is done, but there are a couple more things you may want to incorporate into your setup. We have already taken care of inverse search by having our batch file load SumatraPDF with the correct command-line options. You can now double-click any part of your PDF file and Notepad++ will jump to the correct line of the source. Note, though, that this will not work when you use one main LaTeX file with \include{} statements to load the parts of your document. Unfortunately I have no way around this, and this is something that many dedicated LaTeX packages handle without issue.

As for forward search, I mentioned that the last few lines of the batch file above communicate with SumatraPDF. In fact they send a forward search command that will scroll the PDF document and highlight the corresponding output of the current line of LaTeX source code. Sometimes, though, you may want to execute a forward search without having to rebuild the entire document. In that case we can create a new batch file and follow the steps in the NppExec section above to create a new menu item and keyboard shortcut.

### Batch File

We will pull the relevant sections from the pdflatex_build.bat file above to create our new batch file.

@echo off
if "%~x1"==".tex" goto doit
echo "%~f1" is not a .tex file, extension is "%~x1"
pause
exit /b

:doit

echo SUMATRA>"%~dp1\build\cmcdde.tmp"
echo control>>"%~dp1\build\cmcdde.tmp"
echo [ForwardSearch("%~dp1\build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1\build\cmcdde.tmp"

"%PROGRAMFILES(x86)%\cmcdde.exe" @"%~dp1\build\cmcdde.tmp"

del "%~dp1\build\cmcdde.tmp"

We already know what the beginning part does, so let’s now start from line 9. The echo command literally echoes its input. By using the redirection >, we can send this echo to a file in our build directory called cmcdde.tmp. Note that a single chevron will create a new file, overwriting any existing cmcdde.tmp. On the following lines we use two chevrons to indicate that we want to append the content to the existing file. The result is that we have a text file containing three lines.

The first reads SUMATRA and simply gives the name of the application that will receive our DDE command. We next specify that we want to send a control command to the application. Finally we give the name of the command (ForwardSearch) along with its necessary options.

The ForwardSearch command takes six arguments:

• Full path to the PDF file
• Full path to the LaTeX source file
• Line number of the source file
• Column number of the source file (currently unused, so pass 0)
• New window? Pass 1 to open the PDF file in a new window
• Focus? Pass 1 to give SumatraPDF focus

This particular example will have SumatraPDF scroll to and highlight the portion of the PDF file corresponding to the current line of source code in Notepad++.14 It will only create a new window if the file is not open, and it will not steal focus from Notepad++.

We send the command by executing the program cmcdde.exe and specifying this text file with our instructions. I placed cmcdde.exe in my 32-bit Program Files folder, but you may place it anywhere. Just update the path in the batch file to match your location. Finally we clean up by deleting our temporary command file.

Note that sometimes you may want to execute a forward search and simultaneously give focus to SumatraPDF. If you want that you can create another batch file where you change the focus argument in the ForwardSearch command to 1. For example, I have set up the shortcut Alt+A to execute a forward search and Alt+Shift+A to execute a forward search while changing the focus to SumatraPDF.

## Smart spell checking

Before version 6.3.3, Notepad++ did not include an inline spell checker, i.e., one that underlines your mistakes with a red squiggly as you type. This required us to run spell check manually. Now the included DSpellCheck plugin adds inline spell checking and largely renders this section obsolete. However, the inline spell checker is not very smart. While it tries to only check comments and strings, this functionality does not seem to work well for the built-in TeX language definition, and it certainly does not work for the user-defined TeX I provided above. I hope that this can be remedied in the future, but for now the result is LaTeX files with red squiggly lines that are not in fact spelling errors. If you are able to cope with that fact—and syntax highlighting certainly helps—then you do not need to bother with any of the following. Otherwise, these instructions will help you set up an external spell checker that will ignore LaTeX commands.

As stated in the prerequisites, you will need to download Aspell and the corresponding dictionary for your language.15 Then bring up the execute window with F6 and create a new script containing the following commands:

NPP_SAVE
NPP_RUN "C:\Program Files (x86)\Aspell\bin\aspell.exe" -t --add-tex-command="definecolor ppp,lstdefinestyle pp,color p,operatorname p" check "$(FULL_CURRENT_PATH)" We simply save the file, and execute Aspell. The -t option specifies TeX mode which ignores spelling errors in commands. You may notice that some of your commands (particularly those belonging to add-on packages) are not recognized by default. Use the --add-tex-command option to include those. Simply give the command name followed by a space and specify its parameters and optional parameters. A lowercase p indicates a parameter that should not be checked for spelling, while a capital P indicates one that should be checked. Similarly o and O perform those functions for optional parameters. The check command puts Aspell in spell checking mode, and we pass the full path of the file we want spell checked. Add this command to your Macro menu and assign a keyboard shortcut for easy access. ## Conclusion This setup is somewhat involved, but it turns Notepad++ into a great platform for LaTeX editing. It is not perfect, and I have tried to point out some caveats along the way. If you have suggestions to improve any of these modifications, please let me know in the comments. I also welcome suggestions for different LaTeX editing environments (although I probably will not switch to Emacs or vim). ## 48 thoughts on “LaTeX Editing Using Notepad++” 1. basser Great article! I appreciate your effort in writing this tutorial. I found that your method with inverse-search of SumatraPDF works well with master document containing only \include{} statements of other .tex files! Double-clicking .pdf file makes jump to the correct .tex file. Adding support for master tex file involves changes in batch files, where you need to specify path to it as the first parameter and few changes in numbers of referenced parameters. You should also change start "openPDF" to start /wait "openPDF" in pdflatex_build.bat. There is a great chance that ForwardSearch will fail if PDF is large and search command will precede successful opening of file. 2. Farshid Thank you for the detailed and well organized explanation. I really like Notepad++/SumatraPDF combination. Almost everything works fine for me, with the exception of Forward search for which SumtraPDF scrolls to the wrong position in PDF (this is the case also for inverse search). The problem is that I have a large project with multiple .tex files that are called by a main.tex file using \include{...}. I googled the issue with synctex when there are \include{} lines in the main document. This link suggests using \input instead of \include , but for me it is not an option, since I use \includeonly to deal with the large document at hand. Switching from synctek=-1 to synctex=1 does not work neither. 1. Marko Can you explain how you facilitate forward search? I think that slave files should include name of master file name, but I don't know how. 3. Paul Thank you for the clear and detailed tutorial. It is working fine and even the search in a master and children tex files (\include{}). 4. Michal Hi, just wanted to say that this tut is written really clearly and only with small changes I was able to apply it to notepad++. However, maybe it happens only in my computer but pdf in Sumatra doesn't display *.eps figures. Have you had similar problem? regards, Michal 1. John Bruer Post author Michal, Thanks for the comment. I use pdfLaTeX to compile my documents, which does not natively support using EPS graphics. With the epstopdf package all the graphics are converted on the fly to PDF. This worked fine for me with Sumatra. If you aren't using pdfLaTeX, you might want to try it and add \usepackage{epstopdf} to your preamble. -John 5. Michal Hi John, and thaks for your reply 🙂 I've just applied your clues and they work fine 🙂 Indeed, really helpful and useful way to write in Latex with Notepad++. However I'm no really good in this kind of programming so could you tell me what kind of soft would be good to fully utilize *.eps format (I meant a software that could be utilized with Notepad++ as well). Unfortunatelly, this pdf conversion blurs somehow some edges what is something that I would like to avoid due to some important details in my waveforms. Best regards, and thanks again! Michal 1. John Bruer Post author Michal, There are a couple of things you can check: 1) The conversion process should save the .pdf images to the same folder as the original .eps files. If you open these images in Sumatra (or maybe Adobe Acrobat just to be sure), how do they look? If you set the zoom to 100% are they any different/better? If viewing the images directly solved the blurring problem, then the problem could be in how pdflatex or Sumatra is scaling the images. Check the final document in Sumatra at 100% zoom and also in Adobe Acrobat to try to pinpoint the problem. If things look fine at 100% zoom, then I wouldn't worry. Viewing the PDF at a smaller scale may cause some definition in the image to be lost. 2) If the problem is in the conversion process itself, i.e. the .pdf image files look blurry at 100% zoom, then you can try to convert the EPS files using different software. Unfortunately, I do not have a good recommendation for this. You might have to search around. Note that epstopdf uses GhostScript to convert the files, and you may be able to fix your problem by tweaking its options. (As I understand it, the EPS to PDF conversion basically adds PDF headers to the EPS file, so it shouldn't really change the PostScript in the EPS. Thus, the images really should look the same.) 3) You can change your workflow to use latex+dvipdfm. This requires you to (1) run latex on the TeX source file to output a .dvi file, and (2) run dvipdfm to convert the .dvi file to PDF. I'm not familiar with all the necessary command line options, but you should be able to modify my scripts without too much trouble. With this setup, all of your image files will need to be in EPS format. -John 6. Benni Hi John, thanks for for this great article. The explanations were really useful. It worked on the first try. The only thing i changed, are the multiple pdflatex calls. I rather press the button more often. Greets from Germany 7. Simon Awesome tutorial. I would suggest following extension to it: I just found the FingerText Plugin for Notepad++ which lets you insert predefined snippets. That is amazing for Latex editing. For example, you may type "begin" hit the Tab key and it will insert a new begin block and allow you to instantly edit its name (simultaneously at the begin and the end part) 8. Steve Hi John- This is a great tutorial and I am excited to get this going since I use Notepad++ with several programs (Octave, R, etc.) and I am hoping to use this to keep track of my work (in addition to producing sweet looking pdf's). I am having the following problem- I receive the following error when running the pdflatex_build.bat file: pdflatex.exe: unrecognized option -aux-directory=X:\LaTeX_Files\build' On my installation it reads: This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013\W32TeX) restricted \write18 enabled. I ran latex --help to check the option format but the -aux-directory' option is not listed. Am I doing something goofy or was that option deprecated or what? Thank you in advance for any advice you can offer. All the best- Steve 1. John Bruer Post author Steve, The -aux-directory option is specific to the MiKTeX distribution. It is used here to put all of the auxiliary files into a separate directory to remove some clutter. You can remove this option, and the file should build correctly with TeX Live. You will, however, have to modify the rest of the script to remove all references to the build directory. The scripts will by default look there for the log and SyncTeX files. Let me know if you run into any trouble making the modifications. -John 9. Steve Hi John, Thank you for the encouragement, it now works like a champ! It also seems the the  -quiet  option is specific to MiKTeX. I removed that as well and it seems to be happy enough. Thank you again for your help! All the best- Steve 10. Secil Hello This looks cool, but CMCDDE.zip link does not work. Could you upload somewhere or email me the program if you have it? 11. Marko Thank you for your impressive instructions. However, I found out that inverse search is not working as I would expect it to work. Namely, I am moved to the end of the first paragraph on the next page from where I clicked in Sumatra PDF. Things are improved when I include \usepackage{pdfsync} in my .tex document, however in this case Sumatra searches for .tex file in build directory. Any suggestions how to sort this out? 1. Marko I have realised that the problem is that inverse search is less than perfect. In some (rather rare) situations it jumps to wrong page. Nothing to do with instructions on this page. 12. João Silva Thank you for this post. It helped me a lot. I changed the batch file to meet my needs. I'm using notepad++ portable and SumatraPDFPortable as well. My bath file is: @echo off if "%~x1"==".tex" goto pdflatex echo "%~f1" is not a recognized type, extension is "%~x1" pause exit /b :pdflatex cd /d "%~dp1" IF NOT EXIST "%~dp1\build" mkdir build start "inverseSearch" /min "F:\Programs\SumatraPDFPortable\SumatraPDFPortable.exe" -inverse-search "\"F:\Programs\Notepad++\notepad++.exe\" -n%%l \"%%f\"" -reuse-instance pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~pd1\build" -output-directory="%~pd1\build" "%~pdn1" echo. && echo. bibtex.exe "%~dp1\build\%~n1.aux" echo. && echo. pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~pd1\build" -output-directory="%~pd1\build" "%~pdn1" echo. && echo. pdflatex.exe -interaction=batchmode -synctex=-1 -aux-directory="%~pd1\build" -output-directory="%~pd1\build" -quiet "%~pdn1" echo. && echo. type "%~dp1\build\%~n1.log" | findstr Warning: start "openPDF" "F:\Programs\SumatraPDFPortable\SumatraPDFPortable.exe" "%~dp1\build\%~n1.pdf" -reuse-instance echo SUMATRA>"%~dp1\build\cmcdde.tmp" echo control>>"%~dp1\build\cmcdde.tmp" echo [ForwardSearch("%~dp1\build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1\build\cmcdde.tmp" "F:\Programs\cmcdde.exe" @"%~dp1\build\cmcdde.tmp" del "%~dp1\build\cmcdde.tmp" exit /b 13. Anne Hi, Thank you very much for this tutorial. I'm trying to install it but sumatraPDF being installed in ProgramFiles instead of ProgramFiles(x86), I have a problem. Obsiously, SumatraPDF doesn't open as the path is wrong. I modified the batch files before importing them in Notepad ++ but it doesn't work. Could you help me please? I don't want to uninstall SumatraPDF and reinstall it in ProgramFiles(x86)... Thank you! 🙂 1. John Bruer Post author Anne, It looks like Sumatra PDF has a new major version (v. 3). Assuming that you are running a 64-bit version of Windows, it might be installing in "Program Files" because it is now a 64-bit application. If you are running a 32-bit version of Windows, then you will only have a "Program Files" directory and no "Program Files (x86)" directory. In any case, if it is installing into the "Program Files" folder and not "Program Files (x86)", you can change the occurrences of %PROGRAMFILES(x86)% in the batch files to %PROGRAMFILES%. (Note that the percent signs are important. The batch file does not actually have the location to Program Files written explicitly. The percent signs are telling Windows to insert the location of Program Files that is appropriate for your specific machine. Look up environment variables for more information.) You should also check that the rest of the path is correct. For instance, if your "Program Files" directory is C:\Program Files, then %PROGRAMFILES$\SumatraPDF\SumatraPDF.exe will evaluate to C:\Program Files\SumatraPDF\SumatraPDF.exe. You will need to check that SumatraPDF.exe is actually in that location. Otherwise, you will need to modify the path accordingly.

Finally, it is possible that the new version of Sumatra PDF requires different command-line options to do inverse search. I am not running Windows anymore, so I have not checked this. Let me know if Sumatra PDF is opening but not doing what you expect.

Hope this helps!

-John

1. Anne

Hi John,

I had already modified the batch files and installing SumatraPDF in the ProgramFiles directory, instead of the ProgramFiles(x86) one, was my personal choice.

I eventually solved the problem by re-installing SumatraPDF into the x86 directory.

Thanks for your help anyway! 🙂

14. Luiz Ferreira

Great tutorial!

One thing that is not working for me is forward/inverse search. I keep getting "Error: Could not send DDE command." in Npp console; Double-clicking any portion of the document on SumatraPDF yields no result either, although I can see that "C:\Program Files (x86)\Notepad++\notepad++.exe" -n%l "%f" is configured as the inverse search command. CMCDDE.exe is placed in C:\Program Files (x86).

I am new to all things related to LaTex, and I could not figure out what is going wrong. Could you give some hints?

1. John Bruer Post author

Luiz,

I am not sure what exactly is wrong with your setup. What version of SumatraPDF are you using, and where is it installed?

-John

15. Luiz Ferreira

I am not sure if this was expected, but I re-installed MikTeX and now I am using an account with administrative rights to run Npp, SumatraPDF etc -- everything is working.

For the record:
SumatraPDF V3.0 is placed at C:\Program Files (x86)\SumatraPDF
Notepad++ 6.7.4 (Je suis Charlie edition) is placed at C:\Program Files (x86)\Notepad++, and so is pdflatex_build.bat
CMCDDE.exe is placed at C:\Program Files (x86)
Nnppexec is Version 0.5.2

16. Markus Pristovsek

Great instructions. So far I used my own extremely fast DVI viewer with an ancient version of UltraEdit to achieve the same. But yours is much more portable and PDF is the future anyway.

At least one of my installations was not happy with the patch of bibtex and generated the bbl-file in the directory it was started. Hence it was not found when LaTeX run again.

Enclosing it with
cd "%~dp1\build"
bibtex.exe "%~n1.aux"
cd "%~dp1\"
seems more stable anyhow.

Thank you again for your effort with that.

17. Ed Silkworth

By the way, I found that you can also add the forward search as a context menu item:

Go to Settings > Edit Popup ContextMenu
Right-click, and you should see Run pdflatex-f

I should have probably named it Go to PDF, but anyway Run pdflatex-f is the name of my plugin command for the forward search, so use whatever name you gave to your plugin command instead, in other words the name of the menu item you gave the script in NppEx Advanced Options

Happy TeXing!

1. Ed Silkworth

The blog is not posting the brackets, let try another way:
Item PluginEntryName="NppExec" PluginCommandItemName="Run pdflatex-f"/
Enclose the text above with

18. Seb

Hi John,

first of all, let me join the others here in thanking you for this excellent tutorial. I recently had to switch from a Unix-based environment and your instructions really made a difference to me. With the original setup, though, I did not get the BibTeX links inserted into the text as they should be -- even though the actual Bibliography looked fine.

I ended up replacing a couple of "~pd1\build" by "~dp1\build" in your Bat-script and then everything worked fine, including BibTeX. See below for the final modified script.

Would you be able to explain the difference between ~pd1 and ~dp1?

Thanks a lot and greetings,
Seb.

@echo off
if "%~x1"==".tex" goto pdflatex
echo "%~f1" is not a recognized type, extension is "%~x1"
pause
exit /b

:pdflatex
cd /d "%~dp1"
IF NOT EXIST "%~dp1\build" mkdir build

pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~dp1\build" -output-directory="%~dp1\build" "%~pdn1"
echo. && echo.
bibtex.exe "%~dp1\build\%~n1.aux"
echo. && echo.
pdflatex.exe -draftmode -interaction=batchmode -aux-directory="%~dp1\build" -output-directory="%~dp1\build" "%~pdn1"
echo. && echo.
pdflatex.exe -interaction=batchmode -synctex=-1 -aux-directory="%~dp1\build" -output-directory="%~dp1\build" -quiet "%~pdn1"
echo. && echo.

type "%~dp1\build\%~n1.log" | findstr Warning:

start "openPDF" "%PROGRAMFILES(x86)%\SumatraPDF\SumatraPDF.exe" "%~dp1\build\%~n1.pdf" -reuse-instance

echo SUMATRA>"%~dp1\build\cmcdde.tmp"
echo control>>"%~dp1\build\cmcdde.tmp"
echo [ForwardSearch("%~dp1\build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1\build\cmcdde.tmp"

"%PROGRAMFILES(x86)%\cmcdde.exe" @"%~dp1\build\cmcdde.tmp"

del "%~dp1\build\cmcdde.tmp"
exit /b

1. John Bruer Post author

The %n variables, where n is a number, allow you to access the command-line arguments passed to a batch script. The batch file itself is %0, and so here %1 denotes the first argument passed. In our case this is just the TeX file we want to process. When the argument refers to a file (as it does here), we can use the %~ substitutions to extract particular pieces of path information. For instance, %~d1 extracts the drive, and %~p1 extracts the path without the drive. We can combine the two to get the drive and the path: %~dp1.

Looking at it now, I'm not sure what %~pd1 is supposed to be doing. Given the context, it looks like it should have been doing the same thing as %~dp1. I am not at a Windows machine, so I can't easily check this. I will take a closer look when I get a chance.

Thanks for the comment, though, and I'm glad that you got things working.

19. Maurizio Manini

Thanks for great article.
I am a newby to LaTeX and I installed TeX Live 2015 on a Win XP pc.
I had to change pdflatex_build.bat to accomodate for lack of -aux-directory and -quiet options in pdflatex.exe.
Everything is running well except for warnings and error section.
In my log file there is no "Warning" keyword, here is an extract (error is a mispelled command):
===============================================
...
! Undefined control sequence.
l.12 l.6 \tableofcotnetns

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., \hobx'), type I' and the correct
spelling (e.g., I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
...
===============================================

As you can see, there is an exlamation point, no "Error" or "Warning" keyword.
Am I missing some trivial setting, or TeX Live log output differs from MiKTeX's?
Thank you
Maurizio

1. John Bruer Post author

I strongly suspect that this is due to a difference in log output between TeX Live and MiKTeX. I no longer am using a Windows box for this work, so I am not able to test this quickly. As you discovered, other parts of the tutorial need to be modified for use with TeX Live, and this appears to be the case here as well. If you come up with good filters for the "Console Highlighting" section that work with TeX Live, please report back. Others might be grateful for that information. Thanks for posting your experience!

20. Grimler

Thanks for this excellent guide and these good scripts! Every works great most of the time.

Only bug I've noticed is when I have a file path containing none English letters, if I have C:\åäö\MWE.tex, for example, the CMCDDE command fails because åäö gets replaced by †„” in the cmcdde.tmp file ([ForwardSearch("C:\†„”\build\MWE.pdf", "C:\†„”\MWE.tex", 0, 0, 0, 0)]). This is obviously an encoding problem but I have so far not been able to find a solution that works.

Do you know of a simple way to solve this? How to tell CMCDDE which code page to read cmcdde.tmp with for example?

1. John Bruer Post author

Thanks for the comment!

I have no experience using alternate code pages (or non-ASCII paths), so I'm not sure how much help I can be. As I understand it, the console should use the code page specified by the Windows locale. If you wish to change the console's code page, you can add the chcp ### command to the batch file, where ### is the code page desired.

This should at least make sure that the console host uses the specified code page in writing cmcdde.tmp. Furthermore, this should launch CMCDDE using that code page. I still do now know whether CMCDDE will respect the given code page. You may want to test this manually from a command prompt for added troubleshooting.

Another troubleshooting step is to invoke CMCDDE manually from the Windows run box (Windows key+R) with non-ASCII characters. This might eliminate any encoding issue that arises from the console. If this fails, then it might be a good guess that CMCDDE does not handle character encodings properly.

Beyond this, you might have to look into alternative methods for sending DDE commands. First, though, I think it's worthwhile to check the console encoding using chcp and to run CMCDDE from the run box within Windows.

21. Michka

Hi, thanks for these explanations. How could I combine your approach with latexmk ? I'd like to rely on latexmk for the compilation, but use it from Notepad++ . Should I modify your pdflatex_build.bat ? Thank you !

1. John Bruer Post author

Yep, just go ahead and edit pdflatex_build.bat. Presumably you would replace the calls to pdflatex.exe with one to latexmk.exe. You will have to configure latexmk appropriately for your usage. If you end up using a different location for your build outputs (the script here defaults to a subdirectory named build`), you will have to also modify the scripts to look for the final PDF in the correct location.

22. XX

THAT WORKED FOR ME!!! WAW!!
THANK YOU !
I AM USING THE FORWARD SEARCH ONLY, WITH THE MAGNIFICENT NOTPAD++ EDITOR !!