LaTeX forum ⇒ LEdHow to use alternative PDF-viewers (especially PDF-XChange)

Information and discussion about LEd, an integrated LaTeX environment for Windows
grbn
Posts: 6
Joined: Fri Mar 27, 2009 3:58 pm

How to use alternative PDF-viewers (especially PDF-XChange)

Postby grbn » Fri Mar 27, 2009 4:31 pm

Using LEd is nice, but if you are inexperienced in writing batch-files it might be difficult to configure it to work with alternative viewers.

I was not satisfied using Adobe Reader and prefer PDF-XChange viewer, so I wanted to change that. Furthermore, I wanted to be able to compile a new pdf using pdflatex while the old one is still open (in default, you have to close it by hand first). After a lot of trial and error it works now. It is not a very elegant solution (i am not a programmer) but it works, so I thought to place it here so someone else can use it. If someone has a better/less quirky solution, please reply on this topic.

You need to change three things: change the arguments given to pdflatex.bat, edit pdflatex.bat, and use a vbs file to close the open document properly. So there we go:

1: open tex_cmd.gd with a text editor. You can find the file in your LEd installation directory, submap \Definitions. Go to line the line defining the pdflatex command, which should start like
  1. "11007=11007=Command.PDFLaTeX=PDFLaTeX=/l53007/l=exec:pdflatex.bat"
followed by a few parameters. Change these into:
  1. <MAINFILEDIR> <MAINFILENAMEEXT> <MAINFILEDISK> <BatchesDir> <MAINFILENAME>
. Now there are 5 arguments passed to the .bat file which you need to edit now.

2: go to the LEd\Batches directory, copy and backup your PdfLaTeX.bat to for instance PdfLaTeX.bat.bak, and edit PdfLaTex.bat using a text editor to the following:
  1. C:
  2. cd %4
  3. ClosePdf.vbs
  4. %3
  5. cd %1
  6. pdflatex.exe %2
  7. %5.pdf


So what does this mean? The %4 for instance means the fourth argument passed to this bat file, which is <BatchesDir> now, which is the directory of the batch files of LEd. You should read a bat file like a set of command line commands, so what now happens is: the script goes to the batches directory, runs ClosePdf.vbs, goes to your LaTeX-project directory, creates a pdf, and opens it in your viewer. So what still misses is a script for closing the pdf-file that is already open. We will fix that in step three.

3: Go to the batch directory of LEd again (\Batches). Create a new text document, and type the following:
  1. ' VB Script Document, to close a pdf before running pdflatex
  2. option explicit
  3. dim WshShell
  4. set WshShell = WScript.CreateObject("WScript.Shell")
  5. WScript.Sleep 50
  6.  
  7. 'Start the viewer if it is not yet started
  8. WshShell.Exec("C:\Program Files\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe")
  9.  
  10. 'Change foces to viewer to be able to send keys to it, and sent Ctrl+w to close the active document
  11. WshShell.AppActivate "PDF-XChange Viewer"
  12. WScript.Sleep 0
  13. WshShell.SendKeys "^w"
  14. WScript.Sleep 0
  15.  
  16. 'Change focus to LEd to observe the compilation.
  17. WshShell.AppActivate "LEd"


So this starts the pdf viewer if it was not yet open, changes focus to it and sends the keystroke Ctrl+w to it. This is the usual keystroke to close a document. Immediately after this, it switches back to LEd.

Last remarks:
  • if this does not work, first make sure that the paths are correct. If this is correct and you don't get error messages, you might want to increase the timers in the vbs script: change WScript.Sleep 0 to WScript.Sleep 500 for instance, and see if this solves the problem.
  • The scripting is fairly general, so mutatis mutandis this might work for other pdf viewers too (Foxit, Sumatra etc).

User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Postby T3. » Fri Mar 27, 2009 6:31 pm

You don't have to send keys to PDF-XChange. There is a command line option /close that you can use. This batch file should be equivalent to your solution (not tested):
  1. @echo off
  2. %3
  3. cd %1
  4. PDFXCview /close %2
  5. pdflatex %2
  6. start "" PDFXCview %2

I assumed that PDF-XChange binaries are on the search path. If not, replace PDFXCview with a fully qualified path.

Cheers,

Tomek

grbn
Posts: 6
Joined: Fri Mar 27, 2009 3:58 pm

Postby grbn » Sat Mar 28, 2009 9:41 pm

Thanks a lot! A knew there should be a better solution :-)

Your code needed some small improvements: %2 refers to file.tex so this does not work, that was why I was using %5. The code below is working, and now the vbs script is made obsolete now.

  1. %3
  2. cd %1
  3. start PDFXCview /close %5.pdf
  4. pdflatex.exe %2
  5. %5.pdf

User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Postby T3. » Sun Mar 29, 2009 12:15 am

grbn wrote:Your code needed some small improvements: %2 refers to file.tex [...]
Ah, in that case you can use (in qoutes, in case of a file name with spaces): "%~dpn0.pdf" (on NT based systems %~dpn0 expands to the full file name without extension).
grbn wrote:
  1. %3
  2. cd %1
  3. start PDFXCview /close %5.pdf
  4. pdflatex.exe %2
  5. %5.pdf
Don't launch PDFXCview with start command before pdflatex. This spawns PDFXCview and doesn't wait for it to finish. Compilation will fail if pdf is not closed before pdflatex is executed.

Cheers,

Tomek

grbn
Posts: 6
Joined: Fri Mar 27, 2009 3:58 pm

Postby grbn » Tue Mar 31, 2009 5:45 pm

Thanks for replying. Indeed, using "%dpn0.pdf" worked fine.

Using the 'start' command did in fact work fine on my system, removing it worked fine too. Could you please explain a bit more what is the difference between the two?

Another question: do you know a good website where I can find these kind of batch command basics?

So now I use this code, without having to change the .gd file of LEd:
  1. %3
  2. cd %1
  3. PDFXCview /close "%~dpn2.pdf"
  4. pdflatex.exe %2
  5. "%~dpn2.pdf"

User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

Postby T3. » Fri Apr 03, 2009 12:27 am

grbn wrote:Using the 'start' command did in fact work fine on my system, removing it worked fine too. Could you please explain a bit more what is the difference between the two?

I don't want to go into details here. It's not a batch programming forum after all. In short, start launches a command but doesn't wait until it is finished (think of it as executing the command in the background) and the next command is executed immediately.

grbn wrote:Another question: do you know a good website where I can find these kind of batch command basics?

If you want to learn more about batch programming techniques you can take a look at this and this and this sites. For specific questions you can post to this discussion group or contact me privately.

Cheers,

Tomek

grbn
Posts: 6
Joined: Fri Mar 27, 2009 3:58 pm

Postby grbn » Mon Apr 06, 2009 10:32 am

Thanks a lot for you help.


Return to “LEd”

Who is online

Users browsing this forum: No registered users and 2 guests