May 2, 2014

Typesetting LATEX in Grace

After such a long hiatus, I'm back (:
Finally I found something I deem to be quite worthy to be (b)logged here. *peace

I've been writing my undergraduate thesis (skripsi) using LATEX. It's a convenient way to produce sophisticated formulae. And I produce graphs using Grace (a.k.a. xmgrace, formerly xmgr), which has been long used for publication quality graphs. Then, why not combine the two?


A Google search brought me to this solution:
http://plasma-gate.weizmann.ac.il/Grace/phpbb/viewtopic.php?p=2446

It's a tool called grtexstr, which in turn uses dvi2gr to convert LATEX DVI output to a string in Grace escape syntax. Alternatively, it can also output into a pipe, which will show up directly in Grace, if run with the appropriate command line option.

Here goes a simple guide for installing grtexstr in Ubuntu 12.04 LTS. As it involves installing packages, you'll need superuser access.
(Yes, I know Ubuntu 14.04 LTS is out, but I still haven't upgraded my installation yet due to various reasons.)
  1. Obviously, install Grace and TeX Live first. The simplest way to do that is using the following command in a terminal window:
    sudo apt-get install grace texlive-full

    (Caution: Installing texlive-full requires a fast and stable internet connection. It needs to download around ~1GiB of data!)
  2. Open a terminal window and type the following command to install the required dependencies:
    sudo apt-get install python-qt3 libt1-dev
  3. Download the tar package file for grtexstr (as of the time of writing, the latest version is 0.6).
    You won't need to download dvi2gr and the fonts separately, as they're already included in the package.
  4. Extract the contents to a folder, say, ~/grtexstr-0.6
  5. Now we'll compile dvi2gr. Navigate to Extras folder, then extract dvi2gr-0.3a.tar.gz to a folder, say, ~/dvi2gr-0.3a
  6. Open a terminal window (or use the one you opened earlier), then navigate to the dvi2gr folder and start compiling.
    cd ~/dvi2gr-0.3a
    make
  7. Return to the Extras folder within the grtexstr folder, and extract all afm and pfb files from the two font packages (amsps-unix.tar.gz and cmps-unix.tar.gz) to a temporary folder, say, ~/grtexstr-0.6/fonts
    You should have 256 files in total inside that folder.
  8. Copy the font files into Grace font folder.
    sudo cp ~/grtexstr-0.6/fonts/* /usr/share/grace/fonts/type1/
  9. Open the supplied font database in ~/dvi2gr-0.3a/fonts/FontDatabase and your current Grace font database in /usr/share/grace/fonts/FontDatabase
    You'll need to open the latter file with superuser access.
  10. In your Grace font database, add 49 to the number in the first line.
    Find a line that starts with cmb10 in the supplied database, then append everything from that line downwards into your Grace font database. Save  and exit.
  11. Now test dvi2gr. Issue the following commands in a terminal window:
    cd ~/dvi2gr-0.3a
    make check

    This will open several Grace windows in succession. (When you close the first one, the next one will appear.)
    If the LaTeX output shows up as expected, then you've been doing it right.
  12. Copy dvi2gr and grtexstr into a folder included in your PATH environment variable. I personally use /usr/local/bin
    sudo cp ~/dvi2gr-0.3a/dvi2gr /usr/local/bin/dvi2gr
    sudo cp ~/grtexstr-0.6/grtexstr.py /usr/local/bin/grtexstr.py
  13. Add execute bit to both files.
    sudo chmod +x /usr/local/bin/dvi2gr
    sudo chmod +x /usr/local/bin/grtexstr.py
  14. grtexstr.py is now ready to use by issuing the command in a terminal window. 
  15. If you want to use pipe feature, create the pipe in your home folder,
    mkfifo ~/.grace_pipe
    then execute Grace using the following command line option:
    xmgrace -npipe ~/.grace_pipe &
I'll upload screenshots later.

1 comment:

  1. Hi. I've tried this procedure, but when I do the make for div2gr I get this error:

    make
    gcc -g -ansi -Wall -W -pedantic -c -o dvi2gr.o dvi2gr.c
    dvi2gr.c:29:10: fatal error: t1lib.h: No such file or directory
    #include
    ^~~~~~~~~
    compilation terminated.
    : recipe for target 'dvi2gr.o' failed
    make: *** [dvi2gr.o] Error 1

    ReplyDelete