Home | Mathematics | * Maxima |     Share This Page
A TeX Clipboard Daemon
P. Lutus Message Page

Copyright © 2007, P. Lutus

Overview

(double-click any word to see its definition)

 
Overview

User interface programs for programs like Maxima are getting better, but there are some perfectly obvious things they all lack, and you can't shake the feeling their developers are visiting from another planet.

For example, consider the steps presently required to get from a nice equation display in wxMaxima (or any other GUI program its class), to a common and useful graphic image like those used in this article:

  • in wxMaxima, point at the desired equation display.
  • Press the right mouse button.
  • Select "Copy TeX" (TeX is a special syntax for technical writing).
  • Open a text editor.
  • Select "Paste".
  • Strip off some delimiter characters that will cause the TeX processor to barf.
  • Wrap the remainder of the text in a document template acceptable to a TeX processor.
  • Save the result to a temporary file.
  • Run the "latex" utility to create a DVI file out of the TeX content.
  • Run the "dvips" utility to create a PostScript version of the DVI file.
  • Run "gs" to create an intermediate PNM format file from the PostScript data.
  • Run the utilities "pnmcrop", "pnmdepth", and "pnmscale" to process the image data into a suitable format.
  • Run "pnmtopng" to create a standard Portable Network Graphics file out of the image data.

That is no less than eight programs (not counting Maxima and wxMaxima) that must be run to convert a pretty equation rendering into an equally pretty, portable graphic image that can be put on a Web page or into an article. What a fantastic technical achievement — it staggers the mind to think of the efforts that must have been required to build this many pointless roadblocks between a source of useful information and a common destination.

All that aside, I wrote a daemon in Ruby that does this for you. Once set running, it waits patiently for clipboard content to appear, and if the clipboard seems to contain TeX-format content, the daemon creates a PNG graphic image and saves the result in a convenient location (the user's home directory).

You must have Ruby and the Ruby-GTK interface installed to run this daemon, as well as the netpbm graphic processing utilities (the netpbm utilities are present by default in a typical Linux distribution). It's likely this program will run on Windows, but I haven't tried it — I wrote it, and have only used it, on Linux systems.

If you are running a typical Linux distribution, you should be able to get this program up and running with this procedure:

  • First, because Linux distributions differ in this regard, try typing "yum" in a root command shell. If "yum" is not present, try "apt-get". Use the successful outcome in the next step (where I have presumed to use "yum").
  • In a root command shell, type "yum -y install ruby ruby-gtk2 netpbm". Chances are not all these installations will be needed — I included them all just to be sure.
  • Download this Ruby script of the daemon program, put it anywhere convenient, change its suffix from ".txt" to ".rb" (or to ".sh" if you want to be able to click it to start it), and make it executable.
  • Run the daemon. It will announce its present options and wait for the right kind of clipboard content.
  • Run wxMaxima, create a suitable equation, right-click it, and choose "Copy TeX".
  • If everything is working, the daemon will create a graphic image file named "tex_render0001.png" in your home directory.

Here are some program options that can be issued on the command line when executing the daemon:

  • -dpi (dpi, default 100, larger numbers make images larger)
  • -res (resolution number, default 0.25, smaller numbers improve antialiasing)
  • -pw (page width, default 16, bigger value renders large equations without truncation)
  • -png (select PNG output format (default))
  • -gif (select GIF output format)
  • -bold (boldfaces the TeX output)
  • -dest (destination path for graphic output, default (user home))
  • -keep (retain temporary files)
  • -debug (show detail and error messages)

A few program notes:

  • I am indebted to John Walker, http://www.fourmilab.ch/, an earlier developer of the basic algorithm (his version is called "textogif"), for about a third of the code I am using in my daemon script.
  • The daemon doesn't interfere with clipboard content, it only reads the content once per second and decides what to do. Therefore, if you copy the same TeX content to the clipboard more than once, the daemon won't create a new graphic image of content it has already read. This isn't likely to be a problem, I just thought I would mention it as potentially confusing behavior.
  • Click Here for a pretty-printed listing of the daemon.
 

Home | Mathematics | * Maxima |     Share This Page