A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia

Archive for March, 2008

Friday, March 21st, 2008

Xorg.conf configuration — solved font size problem

Awhile ago I started having problems with some of my fonts on my computer at work. Interestingly enough, it only seemed to affect a very small minority of programs and situations, namely on startup, when Fedora is going through and telling me all the services it is starting, the fonts were so tiny I could not read them. This also seemed to be the case for Matlab. For Matlab, I temporarily solved the problem by just changing the settings to use really big fonts (like 30 point or so). But today I wanted to run EEGlab, which is a Matlab toolbox to analyze EEG data. The toolbox has a GUI, and the GUI fonts were also tiny. I decided I needed to dig around some more, and I finally fixed the problem. Ultimately it was a misconfiguration in my xorg.conf file, that mysterious file that can cause so many things to go wrong on Linux. I discovered that Fedora uses the /etc/X11/Xresources file to specify the DPI (dots per inch), that your screen should have. It was set at 96 dpi, which seemed correct. And it must be the case that most programs use this value when calculating how to display fonts. However, there is also an option in the Monitor section of xorg.conf called DisplaySize, which is some sort of combination of the display resolution and the DPI. More precisely, the display size should be <pixelsize>/96*25.4. For the 1440×900 monitor I use at work, this turned out to be 381×238. Previously I had it set to 1440 x 900, which was why my fonts were so tiny.
To summarize, my xorg.conf looks like:

# Xorg configuration created by system-config-display

Section "ServerLayout"
    Identifier     "single head configuration"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
    Identifier  "Keyboard0"
    Driver      "kbd"
    Option      "XkbModel" "pc105"
    Option      "XkbLayout" "us"
EndSection

Section "Device"
    Identifier  "Videocard0"
    Driver      "radeon"
Option   "UseEdidDpi"   "FALSE"
        Option         "DPI" "100 x 100"
EndSection

Section "Monitor"
        Identifier            "Monitor0"
        HorizSync       30.0 - 82.0
        VertRefresh     50.0 - 85.0
        Option          "DPMS"
        Modeline        "1440x900_70.00" 126.98 1440 1536 1688 1936 900 901 904 937 -HSync +Vsync
        Modeline        "1440x900_60.00" 106.47 1440 1520 1672 1904 900 901 904 932 -HSync +Vsync
        #DisplaySize     1440 900
        DisplaySize     381 238
EndSection

Section "Screen"
        Identifier            "Screen0"
        Device        "VideoCard0"
        Monitor         "Monitor0"
        DefaultDepth    24
       SubSection            "Display"
        Depth           24
        Modes           "1440x900_70.00" "1440x900_60.00"
        EndSubSection
EndSection

Now I am very happy about my working fonts!

Wednesday, March 19th, 2008

Finally a better LaTeX to html converter

About a year ago I wrote a post about my frustration with the lack of a good LaTeX to html converter. Recently I found one. It is called plasTeX, so named because it is written in python. Finally a converter which works well with most any LaTeX package or macro you write, and produces sane, relatively standards-compliant html. Best of all, it comes with a built-in if \ifplastex, so you can specify that some things should be in the pdf version, while others should be in the html version. It also support some other formats like docbook, but I am not too interested in that, so I haven’t tested it all.

Though I discovered plasTeX a few months ago, I finally decided to play around with it some more this week, when I wasn’t feeling like working too much. So I decided to convert my CV from html to latex, so I can have both pretty pdf and html versions. So now I will update my CV only in latex, which is much nicer to write than html anyways.

To get both a pdf and an html version, this is what I do:

pdflatex cv
plastex -c cv.cfg cv
tidy --show-body-only true -asxhtml -utf8 -wrap 78 -indent cv/index.html > cv/index2.html

It took me awhile to figure out the syntax of the plasTeX config file. It is possible to specify these things on the command line, but I got tired of having too many things on the command line. The trick is that the plasTeX options are divided up into different sections. The sec-num-depth option, which tells plasTeX how many section levels deep to number, is in the document option section, while the split-level option is in the files section. The split-level option tells plasTeX how many different html pages to make. For my CV, I only wanted one. My plastex config file looks like:

[document]
sec-num-depth = 0
[files]
split-level = 0

Though plasTeX is pretty nice, there are 3 complaints I still have. One is that it uses <h1> tags for \section, which I can understand, but there is a long tradition in the web of having only one <h1> tag per page, which usually holds the title of the page. PlasTeX does have the ability to use different themes, so there might be a way to change this with a theme, but I haven’t figured that out yet. For the time being, I simply used \subsection tags instead.

My second complaint about plasTeX is that it doesn’t do any nice formatting of the html like indenting or line-wrapping. That is only a minor complaint though, since I can simply run it through htmltidy (as in the code above).

My third complaint is that plasTeX puts everything inside a <td> or <li> inside a <p>, which seems very strange to me, and creates some ugly formatting, so I used some CSS tricks to basically take away the standard effects of <p> tags inside these:

td > p {margin:0;padding:0;}
li > p {margin:0;padding:0;}

I am not completely finished yet, but you can check out the html and pdf results in: my new CV.

Tuesday, March 11th, 2008

convert pdf to png with imagemagick

Imagemagick is a swiss-army knife of command-line image conversion, but can be a bit complicated to actually use. I have been making most of my figures with R lately, and printing them to pdfs, which I can include very easily into documents with pdflatex. I like pdf because it is scalable, fairly small file size (smaller than .eps), and portable. But today a colleague wanted to include a few of my figures in her own powerpoint presentation, and powerpoint only likes bitmaps. She was just going to take screenshots of the figures, but I quickly said, “no, I will just convert them to pngs”. She replied: “I don’t want you to go to a bunch of trouble.” “No trouble at all,” I replied. Then I quickly wrote a bash for loop to convert all the pdf figures into pngs. Then an hour later when I went to zip them up and e-mail them to her, I realized that they looked like crap. After a bit of searching online, I found the flags I was looking for, and eventually used:

for file in *.pdf; do \
echo $file;\
convert -density 600x600 -resize 800x560 -quality 90 $file `echo $file|cut -f1 -d'.'`.png;\
done

And now the code explained:
-density 600×600 says treat the pdf as 600×600 dpi resolution
-quality 90 says use the highest compression level for png (9) and no filtering (0)
-resize 800×560 gives the dimensions in pixels of the resulting png file

Happy ImageMagicking!

Monday, March 10th, 2008

Seitan in a can

Sometime this past summer I made an interesting discovery in the international aisle of the local Food-Coop, Bloomingfoods — Seitan in a can. What is seitan you might ask? It is wheat gluten. And what is wheat gluten? It is the part of wheat that makes bread stick together. Glutinous means sticky, and that is exactly what gluten does in bread. Without gluten, all the carbon dioxide that yeast produces when it is eating the sugars would simply evaporate, but the gluten in the wheat binds the flour together, and causes the air to get trapped, making little bubbles, which makes your bread light and fluffy. Other grains have gluten too, but wheat has the most by far.

Seitan stirfry
Seitan stir-fry

If you get rid of the rest of the wheat and just leave the gluten, then you get a very sticky dough, which can be kneaded and cut into any shape you desire. Then the gluten is boiled, frequently in some sort of seasoned water, and then can be eaten, or can be further sauteéd, or baked. Seitan is 100% protein, and has a very nice texture which is surprising like meat. Lots of the commercially available meat substitutes contain seitan or wheat gluten, particularly in asian cooking (The Chinese invented it a long time ago). The only down side to seitan is that it is quite expensive. While living in Ann Arbor, I sometimes bought “Fajita strips” at the People’s Food Co-op, which were obviously made locally in someone’s kitchen, based on the ziploc bag and homemade label packaging. Boy were they tasty! Unfortunately, they cost about $5 for 12 oz. Needless to say, I was intrigued when I found seitan in a can for less than $2! Intrigued, but also skeptical. But as it turns out, it is very tasty. It can be a bit oily, so if you are making a stirfry, you might want to go light on the oil, or even drain the oil from the seitan to fry your vegetables. We have been able to find seitan in a can in a variety of flavors and shapes at the Co-op and at Asian grocery stores. Try it out!