Category Archives: Software Tools

Using \raggedbottom To Identify Where To Reword

Say you are preparing a camera-ready submission and you are running a little low on space, maybe by a few lines. At this point, hopefully you are willing to put in the time and try rewording some of your sentences. A usual way to start is to identify a paragraph with a very short final line and try rewording a sentence within so that the paragraph uses one less line.

But if you have tried this route, you may notice that TeX has “optimized away” your effort by subtly padding the pages with more vertical spaces, thereby keeping the page count constant…

Long story short, you want to use \raggedbottom. Put it in the preamble and recompile. With this, LaTeX will keep the breaks at the same places, but it will not pad and hence the bottom of the pages will be ragged (duh!). Now you can usually see why your effort did not produce the desired effect: the space that you just freed up does not allow the current page/column to absorb enough material from the next.

With the ability to find a short page/column by inspection, now you can identify the earliest place where rewording is more likely help. Repeat the reword-recompile cycle a couple times, and the page count will go down. Just be sure to take out \raggedbottom when you are done! :P

P.S. The two-page mode in your previewer can make the inspection more effective.

It’s All Text! Add-on for Firefox

It’s All Text! is one of my most-used Firefox add-ons and recently it’s been upgraded to run on 3.0b4.

Edit textareas using an external editor, because it’s all text!

Right click on a textarea, select “It’s All Text!” and edit the text in the editor of your choice.

Alternatively, click on the edit buttons added for your convenience. Right click on the edit buttons for even more options, including preferences.

There are good reasons why you want to use your own favorite text editor to do text editing, and this add-on makes the process extremely easy (no cut and paste needed). But my initial reason was to avoid the “back” button: on my ThinkPad, it’s right next to the arrow keys and if you happen to hit it by mistake, whoosh, all your text is gone…

Highly recommended.

P.S. Of course this post and many others are written using it. :P

PGF Version 2 is Released

From the project homepage:

PGF is a TeX macro package for generating graphics. It is platform- and format-independent and works together with the most important TeX backend drivers, including pdftex and dvips. It comes with a user-friedly syntax layer called TikZ.

I have been a happy user of PGF ever since 2006. For certain types of graphics like data structures and geometry, it really makes more sense to “code it” then to “draw it” (interactively). The package is very rich in features, as you can witness just by flipping through the 560 page manual.

560 pages for a package? I know it’s long, but of course you don’t need to learn every single option of every single feature before you can use PGF productively. (Actually, you will use a high-level abstraction layer called TikZ as explained in the manual.) The manual provides several tutorials to help you start.

Lastly, I note that the package is written by fellow Theory researcher Till Tantau. Thank you Till!

P.S. Version 2.0 is in the MiKTeX distribution already. Just do an automatic update.

SumatraPDF 0.8 Released

SumatraPDF has just become a very strong contender as an everyday PDF viewer on Windows. The reason: it finally supports searching and bookmarks in version 0.8.

Its interface is still a bit over simplistic, but it’s already quite good for everyday uses. At the moment, the keyboard shortcuts are not very well-documented. Looking at the source code, I noticed some missing entries that are noteworthy:

  • The search interface: / starts a search, so as Ctrl-F. Ctrl-G and F3 is next, and Shift-F3 is previous. Note that the toolbar doesn’t have to be visible for the search keys to work.
  • Ctrl-L toggles full screen mode.
  • F12 toggles the bookmark panel.

(Update: Also note that Ctrl-Drag will select a region and copy its text to clipboard.)

I don’t have a list of the numerous PDF viewers on Windows here: a google search will get you many hits. Personally, I have “switched” to SumatraPDF on my browsers a few months ago, while spending most of my “PDF time” in PDF-XChange Viewer (see this post about its annotation capability).

I still keep Adobe Reader 8 as the default PDF handler: in terms of printing, anti-aliasing and javascript support, I have yet to see any competition to Adobe. However, now that PDF is in the process of becoming an ISO standard and FSF is declaring the GNU PDF project as one of the few high priority projects, hopefully we will see some change in a few years (see this article).

I should note that SumatraPDF 0.8 is still missing hyperlink support. Also, none of Windows PDF viewers seems to support pdfsync (round-tripping between PDF and TeX source). I know the former is being worked on. The latter, hmm…

P.S. Common PDF viewers on Windows also include Ghostview and Foxit Reader.

Protect Your Email Address in PS and PDF

The randtext package is a great random find in CTAN. Here is its description in full, but with an emphasis added by me:

The package provides a single macro \randomize{TEXT} that typesets the characters of TEXT in random order, such that the resulting output appears correct, but most automated attempts to read the file will misunderstand it.

This function allows one to include an email address in a TeX document and publish it online without fear of email address harvesters or spammers easily picking up the address.

The author is Charles Duan.

While you most certainly want to use this package for some protection, you should not rely solely on it. For a historical reason(*) , Adobe’s PDF library can easily extract an email address protected by this package. I don’t know about the top search engines, but I would expect their extractors to perform no worse.

(*) Basically, space characters need not exist after the TeX phase. They may instead exist as kerning and spacing information. Therefore, Adobe have an extraction routine that guesses the word breaks based on how the characters are spaced. In other words, the routine is literally “reading” the text from the rendering, just like any human!

Ipe 6.0pre30 works with pdfTeX 1.4

A month ago I wrote about how to install MiKTeX 2.5 concurrently with 2.6 so that I can run Ipe 6.0pre28 on my main production machine.

Well, Ipe 6.0pre30 has just been released yesterday. From the announcement email, the major features of this release include:

* Ipe now works with pdftex 1.40 (in MikTeX 2.6 and texlive 2007).

* Pascal-Nicolas Becker, Frederik Hermans, and Damian Schmidt
implemented the missing forms of intersection snapping (for arcs
and Bezier curves), with bug fix by Jonathan Backer.

* Fixed the broken user interface (fields were too small to contain
the text) on Unix (removed a static QFont) (bug #191).

* Figtoipe now distributed separately.

I note that the source and the windows packages are already available at the LuaForge download site.

Thanks Otfried!

Changing PDF Margins With The pdfpages Package

Sometimes I am given a PDF and I wish I could change its margins. For example, when I print out a conference version of a paper to study in detail, usually there isn’t much space on the sides to write my own ideas. I heard Fermat had a solution for this type of issue :P , but in the modern days, I use sticky notes. The same situation surprisingly arises even if you use PDF annotating softwares. Free or not free (no link for them), they simply do not support the “enlarge canvas” feature yet. All you can do is to insert electronic sticky notes. So much for the metaphor!

Now there is actually a technology called “reflowable PDFs”, which are PDFs that contain enough information to support reflowing its content to fit any width. You can see this page for a screenshot of a reflowed document. Reflowing works wonder for text-dominant documents like novels, but the PDF has to be specially prepared for reflowing to really work well. (Try View->Zoom->Reflow in Adobe Reader 8.)

But if the given PDF is not reflowable, we can still use some graphics editor and edit the PDF interactively. After all, a PDF is mostly a vector graphics file, modulo some potential embedded bitmaps, and so you can edit it like any vector graphics file. I’ve seen it done in Illustrator, and I guess some of the free software competitors like Inkscape or Scribus can do this kind of editing too. But using a command line tool would be far easier.

For a long while, I actually know how to change the margins of a PDF. (Turns out lawyers have essentially the same problem.) The trick is to use the pdfpages package with pdfLaTeX. You may recall that this package allows us to include specific pages of a PDF into our own document. Magically, it has a scale option (that is really inherited from graphicx)… This gives us the first batch file: pdf-rescale.bat. Execute

pdf-rescale.bat foo.pdf 0.8

and you will get foo-0.8.pdf, which is foo.pdf shrunk to 80%. I’ve found that 80% is a good default and so the third argument is actually optional. You can also specify a scale of larger than 1 for some journal articles formatted for smaller paper sizes. I can also imagine fancier applications in which you combine this idea with the geometry package (see this post) to control of the final outcome.

But since we are not changing the actual size of the paper, shrinking the content for a larger margin actually means, well, shrunk content. Conference proceedings are already typeset in a small enough font. Since the proceedings are in two columns, I had the idea to print each column on its own page. That will definitely give us ample space. After a lot of different attempts since last year, I finally managed to get the second batch file: pdf-1c.bat. Execute

pdf-1c.bat foo.pdf

and you will get foo-1c.pdf, which is foo.pdf but with one column per page. No kidding.

The following PNG illustrates these scripts using the title page of an old paper. The upper-left shows the original, and the upper-right is after shrinking to 80%. The lower-left and lower-right are the two pages from the one-column version. I have also attached the source PDF from which I generated the PNG. The key feature is that this PDF retains the text of the original—try search for the word “degree” and you will see. (At one point my solution was to assemble a bunch of PNGs representing each single column into a huge PDF. Although you can annotate on it electronically, you cannot search in it. It also prints slowly.)

Finally, I also note that it is in fact possible to prepare reflowable PDFs using pdfLaTeX or dvipdfm (there seems to be trouble if going through a PS), but I will save it for a later story. For now, you can experience reflowing a LaTeX PDF with this PracTeX article, which is actually on the use of the pdfpages package. Having played with reflowing for a while, I would say that the real deal-breaker for reflowable PDFs lies in the mathematical expressions. You can see this TUGboat article for some excellent macros on fine-tuning mathematical expressions. Now, try to reflow it… :P

P.S. If you write the corresponding bash scripts, please send them to me so that I can, with full acknowledgement, post them here. The only reason why I stick to batch files is to avoid extra dependencies.

Change PDF Margin Scripts: pdf-rescale.bat pdf-1c.bat

Update: Joshua Dunfield has ported the rescaling script to Linux. See the comments.

Word Capitalization in Emacs and PowerPoint

One of my favorite keyboard shortcuts in PowerPoint is Shift-F3. It rotates the capitalization of the current word among lowercased, Capitalized and UPPERCASED. Note that you do not have to select the word, and the cursor does not have to be at the beginning of the word either(*).

But the title of this post clearly said Emacs, didn’t it? Well, since I missed this feature in Emacs, I just implemented it in a pinch and bound it to Shift-F3. :P The code is in this page in EmacsWiki. I have only tested it on GNU Emacs, and so I can only hope that it works in XEmacs.

(*) Actually, you rarely have to select a word in PowerPoint in order to format it. Commands like Bold Ctrl-B and Italic Ctrl-I will act on the current word when there is no selection. Also, similar behavior is in fact present in all Office applications. I just picked PowerPoint.

Continuous LaTeX Compilation Using latexmk

Now that we know how to precompile the preamble to cut down the running time of latex, here is a tool that furthers the goal of saving time in the document production process—latexmk.

As its name suggests, latexmk is a “make” utility for LaTeX files. In particular, it understands when a particular document requires varying number of runs to resolve all references, with a bibtex and/or makeindex throw in at the right moment in-between the runs. Recent versions even support multiple bibliographies and the like. In short, assuming no source errors, if you execute latexmk foo.tex, you will get a fully compiled foo.dvi without any manual intervention. (PDF users: add the -pdf option. nomencl(ature) and glossaries package users: see below.)

Now latexmk would be a great piece of software to recommend just for the features I have mentioned above. Indeed, over the years I have seen various Makefile solutions using the make utility, some of which are fairly sophisticated. There are also direct competitors like texify and the like. (See this article in EmacsWiki.) While I find that latexmk fits my workflow in terms of ease of use and customizability, you may also want to check out these other intelligent options too. They all beat the “latex, latex, bibtex, latex, latex” batch script.

But latexmk is better than that—it has support for continuous/automatic compilation: if you run latexmk -pvc main.tex, then whenever it detects that one of the dependent source files of main.tex has been changed—be that a TeX, bib, an included graphics, or any file you declare to be a source, latexmk will automatically recompile it for you. That means you don’t need to start the compilation manually after changes and an oven-fresh dvi/pdf will be delivered to your previewer as soon as it is ready.

Finally, here are some notes on latexmk:

  • You really want the latest version, even though the version number may say “beta”. The script is very mature. Also note that MiKTeX ships with latexmk.exe, which is a wrapper to call Perl on TEXROOT\scripts\latexmk\perl\
  • , which is the script you want to replace.

  • You can set up your .latexmkrc to override defaults or even define new dependencies. Below I have attached some interesting bits of my .latexmkrc just for an example. For instance, you can avoid launching a previewer even though you are using the -pvc option, and you can support the nomencl package and the like by declaring a custom dependency. And since this is a Perl script, you can use any Perl constructs. You can read the documentation for more possibilities.

    $latex = 'latex -src-specials -parse-first-line -c-style-errors';
    $pdflatex = 'pdf' . $latex;
    $dvi_previewer = 'exit'; # don't start a previewer for me
    @default_files = ('main');
    $clean_ext = # space separated string
    join(' ', qw( fmt acn acr alg gls glo glg ist nls nlo nlg brf out pdfsync rel));
    push @cus_dep_list, "nlo nls 0 nlo2nls"; # nomenclature
    sub nlo2nls { system("makeindex $_[0].nlo -s -o $_[0].nls -t $_[0].nlg"); }
    push @cus_dep_list, "acn acr 0 acn2acr"; # glossaries and acronym hack
    sub acn2acr { system("makeindex $_[0].acn -s -o $_[0].acr -t $_[0].alg"); }
    push @cus_dep_list, "glo gls 0 glo2gls"; #MiKTeX 2.6 has a broken makeglossaries.exe
    sub glo2gls { system("makeindex $_[0].glo -s -o $_[0].gls -t $_[0].glg"); }

  • The -silent option suppresses the output of latex and show you only the errors in a succinct format. Here is an example transcript when I run latexmk -silent foo.tex with two planted errors.

    No specific requests made, so default to dvi by latex
    Latexmk: Run number 1 of rule 'latex'
    Latexmk: Running 'latex -src-specials -parse-first-line -c-style-errors -interaction=batchmode -c-style-errors "foo.tex"'
    This is pdfTeX, Version 3.141592-1.40.4 (MiKTeX 2.6)
    entering extended mode
    foo.tex:3: Undefined control sequence
    foo.tex:4: Undefined control sequence
    Latexmk: Use the -f option to force complete processing.

Have fun with latexmk!

P.S. I should note one fine point: if you have the habit of saving your file after every single sentence, then perhaps continuous compilation can be a bit counterproductive. Emacs users can consider tuning their auto-save-timeout and auto-save-interval instead.

Precompiled Preamble for LaTeX

If you can save six seconds every time you run LaTeX, would you do it?

Indeed, I have been pondering on this issue for quite some time now. Every time I compile “a large document that shall not be named”, I notice that the first six seconds are used to process the code before \begin{document}. But this code—known as the preamble—hardly sees any changes between runs. The preamble for this particular document may be a bit longer than usual, but considering that I am usually working on a chapter at a time using the \includeonly facility (see a tutorial here), these six seconds actually represent over 50% of the running time. Computationally and environmentally, this is horribly inefficient.

But a few days ago, I have finally stumbled upon a solution—it’s called “custom format file”. However, let me call it precompiled preamble, borrowing the concept from C compilers that support precompiled headers. Assuming your source file is main.tex, here is how you may use this method:

  1. Rearrange your preamble so that its static part precedes any dynamic part. What in the preamble can be “dynamic”? For example, if you use \includeonly, you probably want to change its argument rather frequently and so it is not static. Another example is the svninfo package, which introduces a command \svnInfo whose arguments get updated every time you commit. While you can certainly load svninfo.sty in the precompiled preamble, you also want the \svnInfo to remain in main.tex. Finally, some packages read and write auxiliary files when you issue a command that you should put in the preamble (eg, nomencl uses \makenomenclature). Clearly, you have to run these commands in every run.
  2. Extract the static part of the preamble into, say, preamble.tex. At this point, main.tex no longer contains the static part. It should start with the dynamic part, or simply \begin{document} if you have nothing dynamic.
  3. Execute latex -ini -job-name="main" "&latex preamble.tex\dump". You will notice that a new file main.fmt has been generated in the same directory, along with other auxiliary files. PDF users can replace latex with pdflatex in both occurrences and the same applies to the steps below. Also, in some distributions, the options could be “-jobname”. Make sure you get main.fmt and not preamble.fmt in this step.
  4. Edit the first line of main.tex so that it starts with %&main. There can be other stuff on that line too, for example

    %&main -*- mode: latex; TeX-master: "main.tex"; -*-

    works for me. (See this post if you are not familiar with Emacs local variables.)

  5. (Drum beats) Execute latex main.tex as usual. You may get an error about the class file immediately, or you may notice that latex finishes as usual. But if you have paid attention to the output, or if you inspect the the log file, then you will see that the preamble gets processed in “no time” at all. At this point, cheers!
  6. If you happen to hit an error, you will need to run latex -parse-first-line main.tex instead. The extra option will force latex to parse the first line of main.tex where we have asked for main.fmt to be used instead of the default format. (In Linux, you can try to locate texmf.cnf and change the option parse_first_line from f to t.)

To make things slightly fancier, here is an modification of my own. First, add this to the end of preamble.tex:

\def\preambleloaded{Precompiled preamble loaded.}

Then, before the dynamic preamble (or \begin{document} if there is none) of main.tex, add:


The idea is to define a macro in the precompiled preamble and use it to detect if the precompiled preamble has been loaded or not. If not, \input{preamble} will be used to pull the static preamble back in and you will not see any error at all.

Of course, the actual amount of time saved will depend on your computer and your preamble. But in my case of long preamble and short document, the saving has been truly tremendous. (Hence I took some time to write this post in the hope that it would help someone down the road.)

Updated 2007/11/04: Changed the format file name to main.fmt and expanded on the dynamic preamble note.

File 2007/11/11: Attached beamer preamble test files in a zip, as referred to in my comment.

Updated 2007/11/11: Added comments for Linux users, after resolving the issue raised by Suresh’s comment.

Have You Encrypted Your Flash Drive Yet?

My key case got stolen from the gym a while ago. The theft caused me about several nights of sleep and several hundred dollars… cash, CMU ID, driver’s license (showing my address), keys (the subsequent lock replacement), and the key case itself!

And the thief also got my Sandisk SD Plus card. That’s the only thing that makes me “feel good” about the whole incident: the card has been encrypted using TrueCrypt, which is a free open-source disk encryption software for Windows and Linux. I can only hope that TrueCrypt doesn’t have any security flaw in its implementation and that whoever gets my card does not want my data badly enough to crack AES and Twofish. Oh well…

The situation could have been very different had I not used TrueCrypt… So, have you encrypted your flash drive yet?

P.S. I highly recommend the SD Plus cards. These are SD cards with a built-in USB interface and so they are as universal as USB thumb drives. Their speed is reasonable, even though it is not very good. There are faster devices for the same money (like the Ultra series from Buffalo), but not in this stamp-sized form factor. I store my card together with coins!

Free PDF Annotation Softwares

Given the amount of documents that I deal with, I’ve had many opportunities to save paper if only I could annotating on a PDF directly. Until recently, Jarnal has been the only free solution on Windows. However, I would say that Jarnal is not exactly the most polished piece of software I have used… (But I am not complaining against its price.)

Well, Jarnal has some serious competition now. PDF-XChange Viewer is a free (as in beer) PDF viewer that supports a full suite of native PDF annotation capabilities. By “native”, I mean if you insert a “sticky note” comment into the PDF, it shows up as a sticky note in Adobe Reader and so you can open, close and move the note, just like the stickies created by Acrobat Professional. In comparison, the interface is not very customizable and the keyboard shortcuts are not quite “there” yet, but it is certainly looking very good for a version-1 product. The font rendering is not as good as well, but it is comparable to other free solutions. Its performance on graphics intensive PDF is very good on too! There is even a button that allows you to quickly open the current PDF using Adobe Reader, just in case.

I wish it has better ink support, but again, I am not complaining against its price. :P

P.S. Not that I really want to destroy any sales, but I note that PDFCreator is a very good Distiller replacement. Together with PDF-XChange Viewer, they cover most of my PDF needs.

How to Install MiKTeX 2.5 Today

(Updated on 2007-10-31 with simpler steps. This post assumes you are running Windows, but it’s actually applicable to Unix users if you replace the MiKTeX terms with their TeX Live counterparts. )

The most recent release of MiKTeX is 2.6 and it ships with pdfLaTeX 1.4. Unfortunately, it is incompatible with Ipe‘s latest release 6.0pre28 because this version of Ipe cannot cope with the PDF generated by pdfLaTeX 1.4. As the next version of Ipe is not coming very soon (Otfried says “Certainly not before spring 2008.”), one solution would be to downgrade to MiKTeX 2.5 so that Ipe can use the pdfLaTeX 1.3 that ships with MiKTeX 2.5. But if you have upgraded to pdfLaTeX 1.4 with a reason (like having fun with microtype), then you can also keep the two installations side-by-side with some storage overhead (~100MB). Assuming that your MiKTeX 2.6 is installed in C:\texmf-2.6, here is how you might do the MiKTeX 2.5 installation:

  1. Get a copy of basic-miktex-2.5.2580.exe. It’s the self-contained “basic installer” for MiKTeX 2.5 and contains some basic packages. This file does not seem to be available at the official MiKTeX download page any more, but Google can help you find a copy, or you can get a local copy hosted on this server.
  2. Launch the basic installer and install MiKTeX 2.5 to, say, C:\texmf-2.5.
  3. After the installation finishes, remove C:\texmf-2.5 from the PATH environment variable. That way, whenever you run latex, you are still running pdfLaTeX 1.4.
  4. Run Yap 2.6 once and you will be prompted to associate .dvi files with it. (The 2.5 installer associates .dvi files with Yap 2.5, of course. And frankly, I recommend dviout over Yap.)
  5. Set up an environment variable called IPEPDFLATEX to override IPE’s default pdflatex command, eg, IPEPDFLATEX=C:\texmf-2.5\miktex\bin\pdflatex.exe if that’s where you installed it to. At this moment, you may also be interested to set up something like IPELATEXDIR=C:\temp\iperun to control where Ipe generates the temp files.
  6. If you don’t use any special packages in your Ipe files, then you can skip this step. But for completeness, we can let MiKTeX 2.5 know about the extra packages installed in MiKTeX 2.6. From the Start menu, run MiKTeX 2.5->Settings. In the Roots tab, add C:\texmf-2.6 to the bottom of the search list. Click OK and the filename database will be refreshed. (Unix users: this is the Kpathsea step. See here.)

At this point, the side-by-side installation is complete. Have fun!

Goto Last Change in Emacs

From an interesting idea in gnu.emacs.bug…

How many times have you found yourself mosying thru a file when you wonder, where the heck was I just editing? Well, the best you can do is hit undo, ^F, and undo again, to get back.

… comes a very handy function in Emacs—get this elisp file and bind a key to goto-last-change-with-auto-marks. (I bind it to F4, but of course it’s up to you.)

I note that my typical usage is a bit different from the post above: I usually remember what I was just editing, but I am reviewing a different part of the file. This feature allows me to jump back to my editing point quickly.

I must have used it so frequently that I just pressed F4 in another editor… and that’s how I realize I should share it here.

P.S. You may also be interested in this bit of advice for a slightly different experience:

(defadvice goto-last-change-with-auto-marks (before mav-goto-last-change activate)
"Split the window beforehand to retain the current view"
(unless (eq last-command 'goto-last-change-with-auto-marks)

Current Ipe and pdfLaTeX Incompatibility

I upgraded my MiKTeX installation to version 2.6 because I want to use pdfLaTeX 1.4 for microtyping. But it turns out that upgrading to MiKTeX 2.6 breaks the current release of Ipe:

Ipe cannot currently cope with the PDF output generated by the new version 1.40 of Pdflatex. This version is included in MikTeX 2.6 and in TexLive 2007. Therefore, Ipe does not currently work with MikTeX 2.6 or TexLive 2007. This will be fixed in Ipe 7.0.0, but since I’m changing many other things at the same time, do not expect this version before September 2007.

Thankfully, I also have an older laptop and with Subversion, it is not difficult to work on both simultaneously.

The Microtype Package

The short of this post is: if you use a recent LaTeX distribution, then by simply adding \usepackage{microtype} to the preamble, your document will look subtly nicer and the number of overfull/underfull hboxes will go down. In two-column publications, this package is really wonderful.

The tricks implemented in this package are called “microtypography”, which refers to techniques that enhance typography at a very small scale. (Tweaking \baselinestretch doesn’t count. :P )

One such technique is character protrusion—the ability to slightly extend certain characters, like punctuations, into the right margin. When used properly, the right margin will actually look “more justified” than justified. (The example above protrudes the hyphens completely. See below for a more moderate protrusion example that demonstrates the “more justified” look.)

Another technique is font expansion—the ability to dynamically tweak the width of the fonts within a line very slightly. The effect of this technique is more even density across a page due to better line breaking, but it is by design meant to be virtually imperceptible. (You can see it in before-after comparisons below.)

Aesthetics aside, these two techniques can cut down on the number of bad hboxes because they give extra flexibility to the line-breaking algorithm in TeX. Their effectiveness clearly varies from document to document, but the extra elbow room cannot hurt and so you may as well use it in every document. I especially like it in two-column publications based on my experiments.

A whole thesis has been written about the techniques that lead to this package, and the package also comes with an extensive manual that describes other microtypographic techniques implemented by the package. I must note that if you use a PDF viewer that supports PDF 1.5 (current Foxit and Sumatra fans may need Adobe Reader), you can even interact with a “live demo” of character protrusion and font expansion on page 4 of the manual. This is a highly recommended exercise. The manual itself is, of course, typeset with both features turned on as an example of the package, and so at least you get to see character protrusion in action if you look for it.

Finally, system requirements: first of all, the package is smart and simply adding \usepackage{microtype} will “just work”. But you really want a recent pdfTeX backend, and you can upgrade to version 1.4 to reap all the benefits in your PDFs. Note that pdfTeX can also generate DVIs. I know, it sounds weird, but for instance, recent versions of MiKTeX actually generate DVIs via pdfTeX. (microtype was a big part of the reason I upgraded from 2.4, and that led me to undergo the conversion from Yap to dviout.) Font expansion is not available in DVI though, but character protrusion does work.

Debugging Bad \hboxes with AUCTeX

When you use AUCTeX to compile a LaTeX document that contains an error, the compilation will fail and AUCTeX will remind you in the minibuffer area: LaTeX errors in `*foo output*'. Use C-c ` to display. By pressing C-c `, which invokes the next-error function, you can navigate to the source locations of the errors and fix them one by one. It surely is one of the most convenient features of AUCTeX.

But AUCTeX also has a lesser known feature in this regard: by pressing C-c C-w, which by default binds to TeX-toggle-debug-boxes, you can tell AUCTeX whether the debugger should consider underfull/overfull \hboxes as errors too. When preparing for the final(*) revision of a document, this feature really makes locating the bad \hboxes a breeze!

(What’s remaining are of course the \vboxes, but there doesn’t seem to be any good way to locate them using the output messages alone.)

(*) It is usually not a very productive idea to fix bad boxes before the document content is finalized.

Switching From Yap to Dviout

(Most recently updated on 2008-02-08, but I have kept the referenced MiKTeX version at 2.5. As far as I know, none of the changes in MiKTeX 2.6 and 2.7 matters to the topic of this post.)

I have recently upgraded my MiKTeX to the latest version 2.5 for some reason. And as much as I love MiKTeX, I have switched from YAP (Yet Another Previewer, the DVI previewer in MiKTeX) to Dviout.

Dviout may not be very familiar to non-Japanese users because, to my understanding, it is primarily developed to deal with Japanese usage (think about fonts). However, it works equally well in English too. I can recommend Dviout over YAP 2.5 for several reasons:

  • Dviout pretty much does everything YAP is capable of: color specials, HyperTeX jumps (you use the hyperref package, don’t you?), and perhaps most importantly, round-tripping using source specials (but see the note below).
  • Unlike YAP 2.5, it does not seem to have any DVI locking issue, at least not in my daily usage of working on a large document. (To me, this alone is worth the switch until YAP eliminates the lock issue.)
  • In my experience, Dviout is much faster than YAP ever since it had a major change in version 2.5. Unlike YAP, Dviout does not make you choose between “dvips” vs “pk font” rendering—the former is slow, and the latter cannot be used when your document has any graphics. There is really no good choice in YAP.
  • The particular document I am working with is also somewhat graphics intensive. Like YAP, Dviout is able to call Ghostscript to show the included graphics in the DVI preview. But it also caches the generated bitmaps and use them later for unmodified figures. This saves me a lot of time. (And this is the primary reason why I expect to stick with Dviout for a while. I sprinkle \parpics and wrapfigures quite liberally on my spaghetti.)
  • Dviout allows you to customize the shortcut keys. I like to exercise my left hand more often and so I set some shortcuts on my left hand.
  • Dviout can do a text search directly inside DVIs. This can be handy if all you have is a DVI file. (Package documentation comes to mind. And yes, you could have converted it to PS and then do the search in the PS…)

(Note: there is an issue that I am still puzzling on. In the forward search, sometimes Dviout will land on a few paragraphs earlier than the intended destination. I will update this post once I figure out the solution.

Update 2007-03-07: Nailed it. First, recall that source specials are implemented by inserting tags that specify the source file and the corresponding line number into the DVI file. The problem is that sometimes the line numbers in the tags are not in increasing order. Here is how the stream of tags might look like: {src:1003main.tex}{src:1055main.tex}{src:1015main.tex}{src:1019main.tex}. In this case, if you ask the DVI previewer to go to line 1015 of main.tex, a simple scan algorithm will hit the second tag and then incorrectly conclude that no further reading is necessary. This is exactly what happened. Workaround? I guess I will have to wait until I finish my current project and patch the source directly.)

Below I will show how to get Dviout working with MiKTeX 2.5. (Update 2007-11-15: The same instruction works for MiKTeX 2.6 because there is no change in directory layout.)

  1. Remove the directory C:\localtexmf\fonts if you have one. It contains your existing PK font files. We can afford to regenerate them. MiKTeX 2.5 by default put PK files in a different location too.
  2. Create a new file dviout.par and put it in the same directory with dviout.exe. It’s the preference file for Dviout.
  3. I have included the non-default parameters that I use at the end of this post. You can use it as your first dviout.par and start from there. As you can see, there are some hard-coded path names that you will need to change. The following is a list of parameters that you want to pay attention to, in the order of appearance in my dviout.par below:
    This means “On” with “Direct PS” turned off in the Graphic tab. Keeping Direct PS off can mitigate a class of problems due to dvi files prepared with source specials containing postscript. For instance, you can generate such a dvi file by using hyperref with the dvips driver, which is usually the default. The right driver for dviout is hypertex, used like this \usepackage[hypertex]{hyperref}.
    You may have installed Ghostscript somewhere else. I note that MiKTeX comes with Ghoscript these days, but I usually keep an installation of the most recent Ghoscript so I don’t use the one that comes with MiKTeX.
    All my documents store their figures in a figure subdirectory. The current setting tells Dviout to cache the preview bitmaps in the same subdirectory instead of the parent directory where the DVI is located.
    I installed my MiKTeX there. The default for 2.7 would be `C:\Progra~1\miktex~1.7\bin\makepk.exe ^s ^d ^D ^M. There should be no space in the path name and so you must use short path. Also, be careful with the backquote character.
    I have added four shortcut keys to my config. “z” and “x” are for back and forward, “-” and “=” are for zooming out and in. Also, note that “space” is by default mapped to next-page, and so the pair “z” and “space” is all I use most of the time. Remember, the shortcuts are fully configurable in the Option->Set Parameter->Key tab.
    BMP and scale
    I have made an unusual choice here because of my late-night TeXing. The negative numbers represent negative gamma, which is to say that the DVI text is displayed in white on black. If you want the normal black on white, change the -400 to 1100. The particular number depends largely on the font you use and your monitor, but 1100 is in the ball park. (This answers rmcd’s comment.)
    For MiKTeX 2.6, the current setting is a sensible choice. This is what ^r in the TEXPK option expands into.
    If you have installed MiKTeX 2.6 at its default destination, use TEXPK=”^r\fonts\pk\\dpi^d\^;C:\Program Files\MiKTeX 2.6\fonts\vf\\^s.vf” instead. You can read my comment on 2007-03-23 to understand what it does and how you can come up with the right setting for your machine with the help of YAP.
    According to the Dviout manual, this option is needed when you cannot generate a PK font but you want to replace the missing characters with spaces of the correct size, hence the need to locate the TFM (font metric) files. I would say that if you cannot generate an English PK font, then you want to resolve the issue completely instead of relying on this feature.
    I use GNU Emacs on Windows since a long time ago and I am still at version 21. That explains why I picked gnuclientw as my src editor. In the comments, rmcd explained how to use emacsclient instead. Dviout supports DDE as well and so you can use many other editors. See the help file for instructions.
    I use Ipe for most of my graphics. That explains the path in gsrc.
    With the GS option above, we have turned off Direct PS. This “ignore some source specials” setting further suppresses a whole bunch of (mostly harmless) warnings. There are pros and cons, but I think this together with the GS setting above is a sensible default.
    This is where you put dviout.par. Of course, you don’t really change this setting by changing it inside dviout.par, but this is a non-default setting with a hardcoded path. :P
  4. Finally, to make AUCTeX use Dviout instead of YAP, here is a snip from my tex-site.el. Note that I am showing you Emacs Lisp here and as rmcd pointed out in his comment, you do not want to enter the backslashes before the two inner double-quotes if you are using Emacs’s customize-variable command to change your TeX-view-style. The backslashes are only necessary in Emacs Lisp so that we escape the two inner double-quotes.

    (setq TeX-view-style
    '(("^a5$" "yap %d -paper a5")
    ("^landscape$" "yap %d -paper a4r -s 4")
    ("^epsf$" "gsview32 %f")
    ;;("." "yap -1 -s%n%b %d")
    ("." "dviout -1 %d \"# %n %b\"")))

Here are some usage tips on Dviout:

  • As much as I prefer not to ask you to touch the registry, you want to know that Dviout remembers some of its settings in HKCU\Software\SHIMA\DVIOUT. For instance, it stores the window dimensions there. (I set my xPos, yPos, Height and Width in the registry once and for all.) I believe that all options set outside of Option->Set Parameters, such as Option->Continuous Renew, are stored in the registry.
  • You may also want to disable Options->Check color specials from the menu in case Dviout complains about your DVI file. It happens when your color specials have certain issues as explained in the manual. I meet these issues too frequently.
  • Make sure you enable Options->Setup Parameters...->System->Auto Renew. (It’s on by default, but it’s worth checking in case you turned it off by accident.) It forces a update check when you switch into Dviout from another application. This behavior is shared among most, if not all, DVI previewers.
  • Options->Continuous Renew is a good thing if you have a large monitor or a dual monitor to let you see both your text editor and Dviout without overlap. This option will cause Dviout to pop into foreground when the DVI file is updated. Using Microsoft’s Tweak UI, in General->Focus, enable Prevent applications from stealing focus and set it to flash the taskbar button one time. That will make Dviout always show you the latest DVI without stealing the focus from your text editor. (I use this with the continuous mode in latexmk.)
  • Most importantly, once you have customized the options using Option->Setup Parameters to your own liking, select Option->Non-default Parameters. A small text box will pop up and you can copy and paste its content into your dviout.par. (That’s how I get the file below.)

Have fun with Dviout!

Finally here is my current dviout.par (last updated 2008-02-08). I have also uploaded it as a file to avoid line wrapping and other funny things due to quotes.

gen="`C:\texmf\miktex\bin\makepk.exe ^s ^d ^D ^M"
TEXROOT="C:\Documents and Settings\All Users\Application Data\MiKTeX\2.6"
src='gnuclientw^s+%d "%s"'

P.S. I should mention that staying with MiKTeX 2.4 would not be a bad choice if I could… You should also be reminded of potential issues if you decide to upgrade to Vista before MiKTeX 2.6 comes out.

Adjust the Slide Show Window

Sometimes you will encounter a projector screen that hangs so low, making the bottom of the slide way below anyone in the room can see. One way to avoid this annoying situation is to leave some space at the bottom of your slides. This works well when you know the room ahead of time. But what if you are visiting a new place? (Hmm… job talks come to mind.)

Turns out there are actually a couple of solutions.

My favorite is to use a rarely used feature of PowerPoint—you can in fact adjust the dimension of the slide show window through some minimal scripting. Here is a demo file as a proof of concept. (If you use Internet Explorer, please save the file and then open it locally. See below.) I can imagine many fancy mechanisms to integrate this into your slides.

Or you can open the PowerPoint file inside Internet Explorer, which will host the slide show inside its client area. (Try drag and drop the file into IE.) You can then resize the IE window as you go.

Or you can hold down the Alt key and then click that tiny “Slide Show from current slide” icon in the lower left corner. Your slide show will now be run in a windowed mode, similar to how it is being run when you open a PowerPoint file inside IE. You can then adjust this window like any other window.

All of these methods have issues though. If you use the first, you need to cover up the strip of desktop exposed due to a reduced window size. I bring a full-screen-sized black bitmap for this reason. But if you do this right, it does look very nice. The second and third bring unnecessary clutter like toolbars to the projector screen. Plus, you lose the ability to make pen annotations if you happen to be a tablet user.

P.S. I tested this in version 2003 only. I no longer have the older versions.

Two Patches for X41 Tablet

Recently I have finally switched to a ThinkPad X41 Tablet for my everyday computing need. I said “finally” because I actually had the machine since more than a year ago (Sept 2005), but it had more than a couple issues that kept me from relying on it solely. I remember being asked on a trip why I brought two laptops along. :P

The good news is that Microsoft has fixed two of my issues over the summer. If you are using a X41 tablet as well (already there are five in my group), here they are:

  • Insufficient System Resources Exist to Complete the API during hibernation: hot fix 909095
  • The mouse pointer or pen pointer behavior is irregular in Windows XP Tablet PC Edition 2005: hot fix 920295

The latter is particularly important since it makes the tablet a lot more responsive when the CPU is under load. I can’t imagine how I could have lived with a “jumpy” cursor for over a year…

Now if only someone makes a fast and reliable 1.8″ harddrive…