James Schummer: WinEdt Stuff

WinEdt is a customizable text editor that integrates itself with LaTeX systems and more. Here are a few customizations I have written that others might find useful.

Some of the items below assume you are using WinEdt 7 (or 8). If you are running an older version, you may be able to adapt some of this, or see some earlier things I did for WinEdt 5 here.


Disclaimer: I hereby declare that I am not liable for anything. If your use of my advice 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 telling them "When it comes to line breaks, I am smarter than you!" Trust me, you don't want to suffer from this curse.)


Speeding up MetaPost workflow with GSview

I preview my MetaPost output using GSview. This allows for a fast edit/compile/preview cycle. Below is the macro I use, along with information on getting it to work.

However I first want to mention the nicely written package MetaPreview (formerly MPPreview) available on WinEdt.org. That package provides macros that allow you to embed either a single figure or all figures from your MetaPost file into a PDF proof sheet. The advantages of MetaPreview are: easy to install (installation macro does it all for you), PDF output, and the ability to see all of your figures at once. A possible disadvantage is speed, since MetaPreview invokes a run of pdftex. For many people this disadvantage is negligible.

On the other hand I like fast. Particularly when I am editing a file, fine-tuning some parameter in the .mp file. I want to push a "compile" button, and then see my MetaPost output as fast as possible. To do this I have written a macro which invokes MetaPost and then immediately sends only the "current figure" to GSview, where the "current figure" is defined by the current position of the cursor in WinEdt. The advantage of using my macro is: speed. The disadvantages are: your MetaPost output files must have default extensions *.1, *.2, etc.; you have to follow directions below, and know the basics of adding a menu item (no install.edt file, sorry!); the macro overrides any parameters you have entered for MetaPost in WinEdt's Execution Modes dialog. Hence many users may prefer MetaPreview instead of this approach.

If you want to try this out, do the following.

  1. Save the macro file MPwithGSview.edt to the directory %b\Macros\.
  2. In mainmenu.ini (accessed via Options interface), add the following kind of menu item.
    ITEM="MetaPost-gs-p2"
    CAPTION="&MetaPost -> GSview (prologues 2)"
    SAVE_INPUT=1
    MACRO="Exe('%b\Macros\MPwithGSview.edt','%p');"
    REQ_FILTER="%p\%n.mp"
    SHORTCUT="16461::Ctrl+M"
  3. You must have GSview installed, and WinEdt must be aware of it. (See Execution Modes, Diagnosis, if you aren't sure.)
  4. In GSview, you must enable the "EPS Clip" option. (The macro tries to warn you if this option is not already set.)
  5. Finally, your .mp file should set prologues:=2 (or 3) in your .mp file. Actually, the macro will set prologues=2 for you as a default, but any prologues command you put in your .mp file will override this. (So the only way you can screw it up is to go out of your way to write prologues:=1 in your file. So don't do that! Remember...Eternal Curse of the Soft Wrap...)

Now, hitting Ctrl-M will save your .mp file, run MetaPost, and then open the current figure (wherever your cursor is) in GSview.


Icons

Here are some 16x16 PNG images that I use as menu icons or toolbar buttons (zip file). Save them to %b\Bitmaps\Images.

(In case you don't recognize the icons: 7zip, epspdf, firefox, gnuplot, three icons I made for psutils, the outdated but much more entertaining Python snake icon (WinEdt comes with their newer and more corporate looking icon), usb, and wgnuplot.)


Miscellaneous 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!

Make the Windows Explorer action highlight your current file.

The Accessories menu has Windows Explorer command that opens your current folder. I prefer it to also highlight my current file. To achieve this, add this entry to your mainmenu.ini:

ITEM="Explore current"
CAPTION="Explore current file"
MACRO=:Run('explorer.exe /n,/e,/select,"%f"','%p\%n%t',0,0,'Windows Explorer');
IMAGE="Explorer"

Or use this in place of WinEdt's default Windows Explorer menu item.

Use gnuplot in WinEdt.

The secret: Use the -persist option! Here is the macro I use.

Run('C:\..PATH..\gnuplot\bin\wgnuplot.exe %n%t -persist','%p');
(insert the appropriate ..PATH.. to your gnuplot installation).

Grab application paths from the registry.

If you want to create a macro to run some application (such as gnuplot, above), you can hardcode the path to the application (as I did above). This is a bit of a pain if you run WinEdt on more than one computer (if the paths don't match). To solve this, you can try to get computer-specific paths to applications via the registry (as WinEdt does for LaTeX, pdf readers, etc.). Here are some examples that work for me. Put this code in %b\Config\Local Startup.edt.

First example: Gnuplot. Create an .edt file containing the following code, and execute it (Shift-Ctrl-F9) to see what happens.

Assign("gp_path","%@('HKEY_CLASSES_ROOT','gnuplot','DefaultIcon',' ')");
//Prompt("%$('gp_path')",0,1); // Debugging
FindInString("%$('gp_path')", "wgnuplot.exe", -1, 3,0000); // Find the index of 'gnuplot.exe'
ExtractByIndex(4, "%$('gp_path')", 0, %!3); // Extracting the path
//Prompt("%!4",0,1); // debugging
Assign('GNUPLOT','%!4')
Prompt("gnuplot path is %$('GNUPLOT')",0,1); // Debugging

If you have gnuplot installed, you should be prompted with its path. You now have a variable %$('GNUPLOT') that is the full path to wgnuplot.exe. You can use this variable in your menu item that calls gnuplot, instead of hard coding it as I did earlier. In other words, my menu-item for gnuplot is actually

ITEM="gnuplot compile console"
CAPTION="gnuplot compile console"
MACRO=:Run("%$('GNUPLOT'); %n%t -persist",'%p');
REQ_FILTER="%n.plt"

Here are some other examples (7zip, python, firefox) which you can use accordingly.

///// 7-zip //////////////////////////////////////
Assign("7z_path","%@('HKEY_LOCAL_MACHINE','SOFTWARE','7-Zip','Path')");
// Prompt("%$('7z_path')",0,1); // Debugging
Assign('7ZIP',"%$('7z_path');7zfm.exe");
//Prompt("7zip: %$('7ZIP')",0,1); // Debugging

///// Python. //////////////////////////////////////
Assign("python_key","%@('HKEY_CLASSES_ROOT','Python.File','shell','open','command',' ')");
//// If you want to use pythonw.exe (non-console) instead of python.exe, use:
// Assign("python_key","%@('HKEY_CLASSES_ROOT','Python.File','shell','Edit with IDLE','command',' ')");
//Prompt("%$('python_key')",0,1); // Debugging
//FindInString("%$('python_key')", " ", 1, 3); // Find the index of the " " character
FindInString("%$('python_key')", ".exe", 2, 3); // Find the index of the ".exe" characters
ExtractByIndex(4, "%$('python_key')", 1, %!3); // Extracting the path
Assign('PYTHON','%!4');
// Prompt("%!4",0,1); // Debugging

//// Firefox - a few alternatives /////////////////////////////////////
//Assign("FX_key","%@('HKEY_CLASSES_ROOT','Applications','FIREFOX.EXE','shell','open','command',' ')");
//Assign("FX_key","%@('HKEY_CLASSES_ROOT','FirefoxHTML','shell','open','command',' ')");
Assign("FX_key","%@('HKEY_CLASSES_ROOT','FirefoxURL','defaulticon',' ')");
// Maybe should use this instead: ??
//Assign("FX_key","%@('HKEY_CLASSES_ROOT','Windows','CurrentVersion','App Paths','firefox.exe',' ')");
//Prompt("%$('FX_key')",0,1); // debugging
FindInString("%$('FX_key')", "firefox.exe", 1, 3,0000); // Find the index of 'firefox.exe'
ExtractByIndex(4, "%$('FX_key')", 0, %!3); // Extracting the path
//Prompt("%!4",0,1); // debugging
Assign('FIREFOX','%!4')
// Prompt("Firefox: %$('FIREFOX')",0,1); // Debugging