Jim Schummer's WinEdt Stuff: Macros, tweaks, etc.

July 2010 Note: this stuff is for WinEdt 5.5 (and so presumably works in 5.6). I also have an old WinEdt 5.4 page. However, I have not yet found time to play with WinEdt 6.0, and may not anytime soon. Most of this page is still relevant for 6.0, but you will have to install some things manually.


I use WinEdt, a customizable text editor. Users can write (and share) macros to perform many editing/compiling tasks. Here are some modest contributions of mine.

Disclaimer: I hereby declare that I am not liable for anything. If this software causes your computer to blow up, too bad. That's what backups are for. Upon anyone who does not take this disclaimer seriously, I shall bestow the Eternal Curse of the Soft Wrap. (Victims of this curse often hear their computer screens talking to them, saying "When it comes to line breaks, I am smarter than you!" Trust me, you don't want this curse.) If you have questions, you can probably find help on the WinEdt mailing list. Do post there if you have a question.


PDF manipulation via pdftk

The PDF toolkit known as pdftk is a command line program that performs various operations on PDF files. I think of it as the "psutils" of PDF (though it does not perform the n-up operation).

I have written two preliminary, MUI-based interfaces that simply pass the appropriate arguments to pdftk.

  • pdfselect: allows page selection, file merging, and encryption.
  • pdfoverlay: allows the addition of a watermark or stamp.

Some of these operations can be performed using the pdfpages LaTeX package, and for which there is a WinEdt macro. However, that method requires passing through pdfLaTeX, while the pdftk approach should be a bit faster.

To use these macros, the user must have pdftk.exe installed. My installation macros will not do that for you. Secondly, the latest version is 1.41. Earlier versions are prominently featured in Google searches, but they do not perform the stamp operation, and thus may cause an error.

This is my first (acceptable) version of these macros. (If I used version numbers, this would be v0.9.) They get the job done, but they do not yet deal with Adobe's habit of locking files. (Specifically, if the output file already exists and is open in Acrobat, pdftk cannot complete its task. A future version of this macro should tell Acrobat to close the file first. If there is interest in these macros, I could add this functionality.)

Installation: First be sure you have pdftk.exe on your computer. Then, download pdftk-mui.zip, extract it to any folder, open the installation macro in WinEdt, and run it (Shift-Ctrl-F9). You may want to use Options | Maintenance | Backup first, to save your current settings. (Alternatively, you could install the macros and menu items manually.)

Let me know if you find these useful.


Graphical Interface for psutils

Written by Angus Duggan, psutils is a collection of utilities for manipulating PostScript files, distributed with many TeX distributions. I find these utilities to be very handy, but they run from the command line and use many hard-to-remember arguments.

Therefore I wrote an interface to interact with (some of) these utilities and (some of) their parameters. These interfaces are based on a previous version I wrote for WinEdt 5.4. The current version uses WinEdt 5.5's new MUI engine. (In fact Alex improved my old psnup macro as an example of how to use this new engine.)

Once installed, my interface gives you a simple way to interact with the following psutils.

  • psnup: put multiple "pages" on each sheet of paper.
  • psselect: extract selected pages from a PS file into a new PS file.
  • "psbooklet": create a file which can be duplex-printed to make booklets (uses psbook and psnup utils).
  • psresize: changes the paper size of a PS file in any arbitrary way.

Installation: To install the macros, download this zip file, extract it to any folder, and run the installation macro. You may want to use Options | Maintenance | Backup first. (Alternatively, you could install the macros and menu items manually.)

Let me know if you find these useful.


MetaPost

(Note: these MetaPost macros are now hosted at winedt.org, too.)

Proof pages

For compiling my MetaPost files, I formerly used A. Standaert's MPPreview macro package, which works very nicely. It uses the MetaPost --> LaTeX --> dvips approach to produce a .ps file containing the figures.

I recently came across another method for compiling and viewing multiple MetaPost figures, and wrote a macro to take advantage of it (borrowing some ideas from A. Standaert's macros). The macro does the following.

  1. Compile the .mp file with MetaPost (of course).
  2. Gather the output filename(s) (.1, .2, .3, etc.) into a 'list'.
  3. Run pdftex on a certain .tex file which takes this 'list' as a command line input (convenient!), yielding a pdf file containing all the figures. (This special .tex file, called mpsproof.tex, was written by Daniel Luecking and placed in the public domain.)
  4. View the resulting pdf file. (I choose to view the pdf file with GSView in the interest of speed, since Acrobat has annoying habits like locking files. One could alter the macro to use Acrobat, but downloading and installing GSView is probably easier than altering the macro!)

This method may be slightly faster than the approach that uses both LaTeX and dvips, though many will consider the difference to be small. If you would like to install it, then perform the following steps.

  1. Download the macro file MP-mpsproof.edt (version 2007 May 31) and save it to a directory such as %b\Macros\.
  2. Create a menu item consisting of the following macro:
    Exe('%b\Macros\MP-mpsproof.edt','%p');
    (point to a different directory if you installed it elsewhere, and use %P if you use Main Files for MetaPost). Set "Requires file filter" to %p\%n.mp and check the "Save input file to disk" option.
When you have a metapost file open, this menu item will produce a preview of all of the figures within that file, with the following caveats.
  • If your figure numbers go above 200, you need to edit the macro file appropriately: Replace "200" with another string.
  • It is assumed that your output file names are of the default form: filename.1, filename.2, etc. (i.e. that you did not change the names using "filenametemplate").
  • pdftex must be in your PATH; GSView must be installed (or edit the macro to use Acrobat).

Single figure compilation

If you are only interested in compiling and viewing a single figure, then it is fastest to simply run metapost, and immediately open the single output file in GSView. Often, this requires the use of the "prologues" variable in your MetaPost file. Depending on your setup, you may or may not see fonts displayed properly. Third, you should select the EPS Clip option in GSView to best view the output (thanks to F. Pétiard for alerting me to this option). Simply use a macro like the following.
WinExe('','mpost %n.mp','%p','MetaPost...', 01000100,0,'','','',011);
and then view the output with GSView.

To make things even easier, I have written a more detailed macro that runs MetaPost, and then immediately displays in GSView the "current figure", which is determined by the current position of your cursor within the .mp file. If you would like to install it, then perform the following steps.

  1. Download the macro file MP-current-fig.edt (version 2007 May 31) and save it to a directory such as %b\Macros\.
  2. Create a menu item consisting of the following macro:
    Exe('%b\Macros\MP-current-fig.edt','%p');
    (point to a different directory if you installed it elsewhere). Set "Requires file filter" to %p\%n.mp and check the "Save input file to disk" option.
When you have a metapost file open, this menu item will compile it, and display in GSView only the figure corresponding to your cursor position within the file. (It searches for the previous beginfig(nn) command, and uses that to open filename.nn.) This requires the use of a prologues:=3 command, which the macro issues. You can override that choice by setting prologues in your .mp file.

A note about using LaTeX within MetaPost

If you use LaTeX commands in your labels, you include something like
verbatimtex
\documentclass{article}
\begin{document}
etex
in your .mp file. In that case, you want mpost to run with the -tex=latex switch (if you haven't done so via an environment variable). In this case, you need to edit my macros to include this switch. Thanks to John Kitz for this information.

Buttons

My Firefox and Python buttons are now included in WinEdt 5.5. Meanwhile, I have created more buttons/images for: the 7-zip compression program, the gnuplot plotting program, and the USB icon. All of these buttons are contained in this zip file.

Download and unzip the file, and put the images in the appropriate directories. It should be clear, but files named *.btn.bmp are Buttons; *.img.bmp files are Images; and *.lbtn.bmp files are Large Buttons. Edit the files Winedt.btn, Winedt.img, and Winedt-Large.btn appropriately.


Tweaks and Tips

I have tweaked some of WinEdt's standard behavior to my personal liking. Browse through what I've done to give yourself ideas. But back up your settings before trying any changes!

  • Tweak: I changed the Erase-Working-Files.edt macro in two ways: (1) only delete files that share the %N filename (except *.tmp), and (2) the Summary dialog box only displays files that exist. These are two changes that make me less likely to accidentally delete something I didn't want to.
  • Tweak: By adding only one more line to JS-HTML-Preview.edt, the HTML Preview button can launch my browser even when I am not editing an html type of file. (You will have to edit the last line, as applicable for your system, and uncheck the 'Requires Document' button for HTML Preview, under Menu-setup.)
  • Tweak: WinEdt's Accessories menu contains a Windows Explorer command which, when executed, opens an explorer window in the path of your current file. I find it convenient to also have the current file highlighted (so I can quickly see it, if the folder contains many files.) To do this, all you have to do is add the /select option. For example, use the following macro:
    Run('explorer.exe /n,/e,/select,"%f"','%p\%n%t',0,0,'Windows Explorer');
  • Tip: how to use WinEdt and gnuplot. Use the -persist option! Gnuplot is a plotting program. To compile gnuplot files via WinEdt, use Menu Setup to create the following kind of Macro:
    Run('C:\..PATH..\gnuplot\bin\wgnuplot.exe %n%t -persist','%p');
    (inserting the appropriate ..PATH.. to your gnuplot installation). Check the "Save input file to disk" option, and use the "Requires file filter" appropriately. It took me awhile to figure out the -persist option. Without it, gnuplot will compile your file, display the graph, but then instantly close. If this tip solved your problem, let me know!