LaTeX is a de facto standard for most academic publications. Just like an html, a LaTeX document is a plain text file which could be edited by any text editor of our choice. Some editors stand out for being tailored specifically for LaTeX. One nice free (as in a free beer, but not quite as in Free Speech) is LEd (LaTeX Editor). However, LEd lacks one tiny feature that I need most. It is very irritating when I compile a LaTeX document using pdfLaTeX to know that I didn't close the last revision pdf in the acrobat first. This would make pdfLaTeX complain to me that it could not write to the pdf file because Acrobat wouldn't allow so.
The obvious solution is to close the document in the Acrobat first and it would be really nice if LEd could do this for me. Other editor can do this, for example, WinEdt. However, as I stated in my previous post, Acrobat already allow us to close the opened document using DDE. So I modified the example from the acrobat SDK to get this little applet that can open and close pdf file.
To use the program, just run it with one parameter, the file name of the pdf file and the document will be closed. For example,
would close the file (if it has been opened). If we put any other argument following the file name, it will open the file (if it has not been opened yet). For example,
acroddeclose c:\test.pdf 1
will open the file.
The application and the source code could be d/l here.
Now, to integrate this into LEd, we need to modify the script of LEd. Luckily, LEd makes it very easy to do so. Everything is stored in a text-based script file. First, we need LEd to supply us with the full file name. We have to look for the main script file, located at
Definitions\tex_cmd.gd. This file controls the shortcut, bitmap image, label, hint, etc., of the script that appears on the toolbar of LEd. Most importantly, it controls the parameters that are passed to each script file. Locating the following line in the file.
11007=11007=F7=PDFLaTeX=/l53007/l=exec:pdflatex.bat <MAINFILEDIR> <MAINFILENAMEEXT> <MAINFILEDISK>
This line controls how pdfLaTeX.bat should be run. Be noted that your actual text might be different from me but what we have to look for is the line containing the word
exec:pdflatex.bat. Now, as you could see, file directory, file name and the drive is already supplied to the pdflatex.bat. However, what we need is the full file name with path, which LEd kindly provides us already. Simply append the code
11007=11007=F7=PDFLaTeX=/l53007/l=exec:pdflatex.bat <MAINFILEDIR> <MAINFILENAMEEXT> <MAINFILEDISK> <MAINFILE>
Next, we have to modify the batch file script for pdfLaTeX. Locating the file
Batches\PdfLaTeX.bat inside the LEd directory and add our program so that it closes the pdf file before compiling the document and opens the file after the compilation is done.
The new pdflatex.bat should look like this.
rem @echo off AcroDdeClose.exe %4 %3 cd %1 pdflatex.exe %2 pdflatex.exe %2 AcroDdeClose.exe %4 1