Archive for November, 2006

Nifty Firefox extension - resizable textareas

Wednesday, November 22nd, 2006

I just found a very nifty little Firefox extension that will make all textareas resizable. In case you don’t know, a textarea is a text box that is longer than one line. With this extension enabled, simply hover the mouse over the bottom right corner until the cursor changes, then click and drag until you reach the desired size. Very handy for those times when you want to write a long message, and the website only gives you are very small textarea to do so, which means lots of scrolling.

You can get it here:
Resizable Textareas in Firefox

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

web + print frustrations

Tuesday, November 21st, 2006

Sometimes one wants to write a document that can be viewed both in print form and on the web. From my experiences so far, there does not yet exist a good way to do this from one document. I have tried several different methods, each with its own set of complications. I have not given up hope yet. Perhaps someone else can suggest a better method.

Firstly, why would someone want to do this? Well, I think there are a couple times where documents should be available in both formats

  1. Program documentation
  2. Short tutorials
  3. Curriculum Vitae

The last one is what I have been focusing on. Almost all academics have their CV online nowadays. Some have it in html format. Many have it in pdf format, and of course some only have it a terrible format like .doc or something. Personally, if I am going to view a CV online, I prefer it to be in html format. For very complex documents with lots of figures, graphics and such, pdf is usually better. A CV usually is not that complicated though, and it is much nicer to read them in html format. However, if one is applying for jobs (as I am), it is crucial to send a copy of your CV, and this should be either in hard copy or pdf format. Next I will describe the two different approaches I have taken to this conundrum.

starting with latex

As you may have gleaned, I like LaTeX quite a bit. It is quite simple in many ways, yet can also handle some really complicated documents. It produces really nice postscript and pdf files. As I write this, I am printing off a 3′ x 5′ poster that I made with LaTeX (I’ll make a separate post about making posters with LaTeX). LaTeX was designed well before the world wide web existed, so it was not designed with the web in mind. It was designed with print in mind. That being said, there are some packages and utilities that do a decent job of converting LaTeX to html. The two that I have found best so far are latex2html and tex4ht. They both have their disadvantages and advantages

latex2html
This program takes a direct latex to html approach. Essentially it tries to do all the same things standard LaTeX can do, but instead of producing a dvi, it produces html. The drawback from this approach is that it does not always handle all the packages that standard LaTeX does. It also produces some pretty ugly, out of date html. The latest html you can specify is 4.01. This is not very satisfactory if you try to adhere to web standards. It also uses some strange heading code. Using the article class, sections are coded with <h1> tags. Normally h1 is used as the title of a page, and only once, though see this article from A List Apart about why using h1 for the title text may be a bad idea
tex4ht
This program uses an entirely different approach. It acts more like other standard drivers, by converting dvi to html. The advantage of this is that it should work with any LaTeX package imaginable, as long as parseable dvi is still produced. This is nice, but the output is still too focused on print. It defines all sorts of extra classes, and specifies all sorts of font sizes, when this should really be done with CSS.

I recently read a very poorly written article about why to use LaTeX, which spurred me on to write my own, and as a proof of concept, I decided to write it in LaTeX, and convert it to html. I ended up using the tex4ht approach, and then wrote a perl script to clean up some of the code it produced. You can view the article on why to use LaTeX on my University of Michigan homepage

starting with html + css

It is possible to get pretty nice printed output using css today, but there are still some things missing. My wife has also been working on her résumé lately, and one thing I like about hers is that she had a header on each page with her name and info. This seems quite handy. Imagine especially if someone is printing off your CV from your webpage, and the pages get mixed up or something. All of a sudden they lost a page of your CV! That is no good. Using CSS 2.1, the current standard, one cannot specify such things. The same goes for page numbers. Most browsers will let you choose whether you want page numbers or not, but we don’t want to make more work for the user.

CSS 3 offers a glimpse of hope. CSS 3 offers many more possibilities, especially in terms of dealing with alternative media such as print or aural media. Unfortunately, it seems that CSS 3 support is still quite a ways off for most browsers.

Enter Prince.

Prince is a program that implements many features from CSS 3 and is designed to make quality pdf output from xml (or xhtml) documents. It can do some pretty neat stuff. I first learned about it from A List Apart, in an article about printing an entire book with xhtml and css. It has one major drawback though. It is not open-source. In fact it is quite expensive for a normal full license. It does offer a restricted license, which has full functionality but also sticks in a default page about Prince on the first page of your document. So this is not ideal. I have tried it out, and one can see the results of my experiment by looking at my CV
What you get in your browser is the normal stuff. If you click on the button at the bottom you get the nicely formatted version from prince. If you click on the print this page button, you get a very similar version using CSS 2 rules. It is nice too, but lacking the headers and page numbers.

The future

For my dissertation, I am definitely sticking to LaTeX, and will not attempt to convert it to html. I don’t think it is well suited for that. For most of my websites, I will stick to html. For my CV, and other documents for which I want the best of both worlds, I would like to go the LaTeX route, but I think that the tools available need some updating. Maybe I will work on that.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

Extreme TeX

Saturday, November 18th, 2006

While doing some searching around the internet for stuff about LaTeX, I ran across this snippet from a page on latex from stanford

The example is from the infamous David Carlisle, illustrating how much one can automate using TeX (plain TeX, not LaTeX). If you are in for a fun little surprise, copy the text and paste it into a file, then run

tex file
\\let~\\catcode~`76~`A13~`F1~`j00~`P2jdefA71F~`7113jdefPALLF
 PA''FwPA;;FPAZZFLaLPA//71F71iPAHHFLPAzzFenPASSFthP;A$$FevP
 A@@FfPARR717273F737271P;ADDFRgniPAWW71FPATTFvePA**FstRsamP
 AGGFRruoPAqq71.72.F717271PAYY7172F727171PA??Fi*LmPA&&71jfi
 Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx
 :76jelse&U76jfiPLAKK7172F71l7271PAXX71FVLnOSeL71SLRyadR@oL
 RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse
 B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI
 I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz;
 ;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,%
 s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G
 LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e
 doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye

Happy holidays

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

FileVault foibles

Saturday, November 18th, 2006

A little over a month ago I was having some font issues with LaTeX, and I wasn’t sure why. In fact, I never really figured out why. But basically I was getting some ugly bitmap fonts, and I wasn’t going to accept that. So I tried a bunch of things, including trying to re-install tetex. Eventually, I decided to totally re-install fink. In the process, I thought I could maybe just copy the whole /sw directory from my external hard-drive backup. I made one big mistake here though. Instead of copying backup/sw/* to /sw, I copied backup/sw/* to /, meaning that I unintentionally overwrote some important files. So I ended up reinstalling the whole OS. This took some time, but since pretty much everything was backed up, I was not too worried, and it seems like a fresh install is good every now and then anyways.

After, I reinstalled, I decided to try FileVault, which is a neat idea in theory. It encrypts your entire home directory as a sparse disk image, and when you log in, decrypts it on the fly. While you are logged in, it looks like a normal home directory. When you are logged out, it is one large password-protected and encrypted file. So, if you lose your laptop, your data is safe. Even if someone takes the hard-drive out of your computer. Your data is 128-bit AES encrypted, and unless they guess your password, it is very hard to crack.

Great in theory. In practice, after a month of testing it out, I decided to give up. Here were my problems:

  • slow
    While reading was not affected much, writing was severely slowed down. For my dissertation work I have some huge (9000+ rows) Excel files, and every time I went to save, it would take about 10 seconds. I read up some online about it, and found similar complaints from others. I also found suggestions to not store your pictures or music in your home directory. So I ended up moving a bunch of stuff around
  • Office crashing
    Although I generally hate Microsoft Office, I am not yet free from its reins. I noticed that while I had FileVault turned on, if I started to open a document from any Office program, and clicked on the dropdown list of recently used folders, the program would crash. Turned FileVault off, and voila! — problem solved
  • Graphic converter crippled
    Graphic Converter is an excellent Mac program that convert just about any image type into just about any other. It is shareware, but pretty good shareware. Without paying you get almost full functionality except customizing batch processing. I finally ponied up the $30 about a year ago, and it has definitely been worth it. So, batch processing. For batch processing Graphic Converter does not use the native file chooser, but uses its own. It would not recognize my home directory using FileVault. How crappy.

Finally, I decided that I didn’t really have that much sensitive data. I do store my bank statements on my computer, which I do not want to get stolen. So finally I decided to take the same approach that filevault does, but with only a very small subset of my hard drive. I found some great hints on the web to do this Mac OSX hints
It is also possible to use Apple’s Disk Utility, but that is obviously not as fun as the command line. So here are the two commands you need:

create an image

hdiutil create -size thesize -encryption -type SPARSE -fs HFS+ thename

shrink the image

hdiutil compact /some_path/your.sparseimage

There you have it. If you do have a bunch of sensitive data (on a laptop especially), I would nevertheless recommend using FileVault, in spite of the problems. If you recall, the last few major cases of personal data theft has been by stealing hard drives and laptops, not by hacking into computer systems. We need both physical and virtual security. Encrypting your data helps on both fronts.

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn

mediawiki and latex.fmt

Thursday, November 16th, 2006

Lately I have been fooling around with wikis and CMSes. As minister of technology for my friend Danny (basically I give him space on this server), I was commissioned by his fiancee Bethany to set up a wiki. I did a little more searching around on wikis, and decided on mediawiki. I also looked at DokuWiki, but I liked the interface of mediawiki a bit better, and supposedly it supported LaTeX, of which I am a big fan.

Supposedly.

Installing mediawiki was very easy. It really only took about five minutes. I downloaded the tarball, untarred it, then followed the instructions. It even had a nice convenient web interface, which led me through the steps of creating a database and populating it. It did take a little while to figure out how to create new accounts and such, but once that was done, Bethany was creating content within minutes.

Installing LaTeX support was not so easy. First I had to turn it on in some setting files. After testing, I got a few errors, went and checked some permissions and such, and it was working. Then I got this very uninformative error:

Failed to parse (PNG conversion failed; check for correct installation of latex, dvips, gs, and convert):

I fiddled around a bit more, then decided to call it quits for the day. At some point the next day, I had done some real schoolwork, and decided to fiddle around with computers. I had thought of some other ways to debug the LaTeX support for mediawiki. I read a somewhat helpful blog entry by Aaarre Laakso who suggested that it might not be permissions, but rather paths that was the problem. He was ultimately correct, though it was not the path that he was talking about. He suggest editing render.ml, which texvc uses, and hard-coding in the paths to latex, dvips, etc. I did that, and then recompiled texvc (which involved install an ocaml compiler — fortunately there was a yum package available for my Fedora Core 5 box). Still no luck.

So then I started digging around in the php code of mediawiki to try to find out what it was doing. In the process, I wrote a little bash script which will grep for certain words in certain types of files, and return the names of the files and the grep output for files which match. Here is that script, which I have dubbed grepme:

#!/bin/bash # this script will grep from all files matching the shell glob in $1 # and return files which contain the regexp in $2 if [ $# -ne 2 ]; then echo 'usage: ./grepme files pattern'>&2; exit 1; fi for file in $1 do return=`grep -c "$2" < "$file"` #echo $return if [ $return -gt 0 ] then echo '**' "$file" grep "$2" < "$file" echo fi done

Anyways, I found that there were only a couple files that I need to look at, the main one being includes/Math.php. I decided to copy that file and try to hack it on its own, and see what latex commands were being given. That didn’t work so well, but eventually, I just started trying my own latex commands, and finally I was getting some meaningful debugging info. It turns out that running as the apache user, LaTeX couldn’t find some files, most notably latex.fmt. So I tried copying that file to the images/tmp directory where the tmp .tex files are stored, and it finally worked!!!!. How nice. Only several hours of banging my head. Once that was done, it was late, and I went to bed, feeling that I had accomplished something. (Note that my solution is still a huge kludge, and if anyone can tell me how to properly set the path so latex can find the files while running as apache, I would be happy to hear them).

  • FriendFeed
  • Reddit
  • del.icio.us
  • Digg
  • Slashdot
  • Technorati
  • Facebook
  • Fark
  • TwitThis
  • LinkedIn