How to Make LaTeX use a Hanging Indent

Ah, LaTeX. The programmer’s text processing system, in which you have to compile your document before it turns into something viewable. It gives us the joys of truly beautiful equation typesetting and the agonies of obscure commands, crazy “badness” rules, and sometimes obstreperous auto-figure placement.

Today was a case in point. I’m typesetting the index for a book and I wanted to get entries to have hanging indents, like this:

This is my paragraph, which I am writing to demonstrate what it looks like to have a paragraph that wraps and uses a hanging indent.

The only problem is that LaTeX only lets you specify how much to indent the first line of a paragraph, not the rest. The assumption is that the “typical” sort of indentation you want is to get paragraphs like this:

This is another paragraph, which shows what it looks like to have a paragraph that wraps but indents the first line instead of the following lines.

The solution turns out to be to set your left margin in to where you want the hanging lines to be, and then use a negative offset to specify the indentation of the first line. Here’s an example:

\leftskip 0.1in
\parindent -0.1in

Thank you, google! Talk about thinking outside the box.

P.S. What’s funny is that HTML has the same limitation, so to show the first example above, I had to set a negative text indentation.

Changing the Battery on Your Motherboard

I’d noticed recently that astra (my ancient Ubuntu machine) was getting forgetful; she couldn’t remember what time it was when booting up. Almost certainly, the battery on her motherboard had finally run out (I bought astra in 2000). The first hit on google was this great article on battery replacement; astra turned out to have the “lateral socket” type of lithium battery.

Here’s what the computer looked like when I opened it up. Can you spot the battery?
That’s right, it’s under the video card!

Popping it out was as easy as the above link suggested, and then I went to Radio Shack and bought a replacement ($4.99). I booted up and told astra to sync with a network time server (yep, my Ubuntu wireless card installation continues to work). You can imagine how pleased I was with the easy fix, until I rebooted the machine and it failed to find the primary master hard drive. Guess how far you get without one of those?

I re-opened the case and checked the seating on all of my drive cables (I have it stuffed full with a floppy drive, two CD drives, and two hard drives), which possibly had come loose between boots? Nothing felt loose, but the next reboot was successful. And the time was right! Whew!

What to do with the old battery? Rechargeable batteries can be recycled (you can search for a local dropoff site), and California regulations require that all batteries be recycled (they are categorized as hazardous waste). Conveniently, there’s a pickup for batteries at my workplace. Otherwise, the preceding link has suggestions for other ways to get rid of your old batteries.

How to embed fonts in a PDF file

This is an issue that comes up every now and then, for example when you create a PDF file that’s designed for actual printing (like in a book). The fonts used by PDF (or PS) files can be either embedded or simply “linked” to fonts already installed on the system. The advantage to linking is that the file size can be a lot smaller; the PDF file doesn’t need to carry around a full description of how to render each font. Unfortunately, the destination system doesn’t always have the fonts you want. The safest solution is to embed every font description in the PDF file.

But how do you make this magic happen? There are two important steps I learned about today. (These apply to linux/unix/Mac systems.)

1. Tell pdflatex, dvips, and dvipdf to embed the fonts.

The best instructions I’ve seen for this are here. Basically, you run `updmap` to find out where your config file is, then edit it to indicate that you want the fonts to be embedded. Re-run `updmap` to make those config settings stick, and then you can do pdflatex or dvips or dvipdf (as desired) to create files with embedded fonts.

That will get you most of the way there. However, if you’re including figures (say, .eps files) that also have their own fonts that weren’t embedded, and those font names aren’t recognized, you may get an error like:

dvips: Font Helvetica used in file fancy_widget.eps is not in the mapping file.

You can’t embed the font if your system doesn’t have a mapping for it. Oops! This usually happens with fonts like Helvetica, Times, and Symbol; these are proprietary font names, so their mappings aren’t found in most open source systems. But you can fix this problem, as described in this excellent font reference, by replacing the font names with their open-source equivalents:

2. Replace proprietary font names with their open-source equivalents.

Since .eps is a text format, you can just open the .eps file in a text editor and search/replace the font names. Markus Neteler makes this even easier with a handy bit of sed:

cat original_graphics.eps | sed 's+Times-Bold+NimbusSanL-Bold+g' |\
sed 's+Times-Roman+NimbusSanL-Regu+g' |\
sed 's+Times+NimbusSanL-Regu+g' |\
sed 's+Helvetica-BoldOblique+NimbusSanL-BoldItal+g' |\
sed 's+Helvetica-Oblique+NimbusSanL-ReguItal+g' |\
sed 's+Helvetica-Bold+NimbusSanL-Bold+g' |\
sed 's+Helvetica-Bold-iso+NimbusSanL-Bold+g' |\
sed 's+Helvetica+NimbusSanL-Regu+g' |\
sed 's+Helvetica-iso+NimbusSanL-Regu+g' |\
sed 's+Symbol+StandardSymL+g' > new_graphics.eps

For the particular file I was working on today, a couple of additional fonts didn’t show up on Markus’s list. They were all variants on the Courier font. After some hunting around, I figured out that Courier is “Nimbus Mono L”, so here’s the translation:

Courier NimbusMonL-Regu
Courier-Bold NimbusMonL-Bold
Courier-Oblique NimbusMonL-ReguObli
Courier-BoldOblique NimbusMonL-BoldObli

Finally, you may want to check the file to confirm that the fonts were embedded. It seems that you can use a utility called ‘pdffonts’ to do this from the command-line, but I don’t have it on my system. Alternatively, you can fire up Adobe Reader, go to “File->Document Properties”, click on the “Fonts” tab, and browse to see that each font is marked “embedded.”

Programming by Platonic Ideal

I am teaching a programming class on Data Structures: lists, arrays, trees, heaps, stacks, queues, and other fun things. This is my first time teaching at this particular university, and I’ve had to successively ratchet down my expectations of the students as it became clear that their preparation was not, well, adequate for the topics this course covers. Or rather, they do well catching on to the concepts, but struggle mightily when it comes to implementing them in code. I’ve been somewhat puzzled by this, since even students who have the prerequisite course under their belts seem to be having trouble.

Today, I got my first glimpse into why.

I scheduled a brief post-midterm conference with each student, to give them feedback on their current progress and to answer privately any concerns they might have about the course. One student today launched into a description of what that prerequisite course was like.

“I don’t want to say anything bad about the professor, but I don’t think I learned much. He just showed PowerPoint slides, and never ran any of the code, and we never had to write any code. He said it was more important to know the concepts, and he didn’t want us to write code because then we might get too used to the syntax of one language. You know, each language is different.”

I was flabbergasted, but tried to hide it. Sure, programming languages differ. And it’s great to get to a point where you have a solid grasp of the abstract ideal of an iterative loop, or a recursive method, or, heck, a list or an array or a tree or… all the stuff we’re covering–without being tied to one language’s syntax. But it’s staggeringly unfair to expect a student to get to that point without having worked in any languages at all.

It’s possible that this student’s view of his professor’s pedagogical opinions has been filtered or changed from what the professor actually intended; we don’t always communicate effectively. But the sad fact is that many of these students lack basic programming skills in the language in which these courses are taught, and that leaves them handicapped when facing all of the rest of the courses in the department. I can hope that they’ve gained some skill from the battery of assignments I’ve given them (and knowing what I know now, if I started the course over, I’d reduce the volume of that battery significantly), but any skills have been gained at quite a cost. I continue to be impressed at the amazing amount of energy and hours these students invest to keep up with what I give them.

Interestingly enough, six students (one from my current class) have already signed up for the class I will teach starting in January (Machine Learning!). You’d think they’d be sick of me by now. :)

How to fix your own printer

Now that I have my linux machine, astra, up and running again, one of the next things is to set it up to serve access to my printer, nova, over my local wireless network. (Nova is just as old as astra, and can only be accessed via parallel port, which my Mac laptop lacks.) But when I tried a test-print from astra, just using the regular parallel cable connection, to my dismay I discovered that nova had degraded due to neglect and age: it wouldn’t feed paper correctly. I couldn’t print. Argh!

After some googling, I determined that it would cost on the order of $50 + parts to have someone fix the printer. Not *bad*, but at that price it’s time to start thinking about just buying a new printer. But I’m stubborn, and I kept googling. And what do you know — I found fixyourownprinter.com (in contrast to fixyourprinter.com, which redirects to xerox.com).

Apparently, my particular problem (bad feeding for an HP 1100 LaserJet) is one of their most common items (It turns out your printer here is only *mostly* dead!), and they sell a kit to solve it. Could it be? $19.95 + shipping, and I could not only save money, but achieve the moral victory of having fixed my own printer? The testimonials raved about success after success with this kit, many emphasizing how useful the accompanying video was.

So I went ahead and ordered one. I got it the next day (priority mail) and eagerly ripped open the envelope to find… four sheets of paper. A receipt, an ad for other kits, a half-sheet of instructions, and one page containing 3 photographs of some steps in the process, with a replacement “separation pad” stapled to the sheet. No video. Had I been duped?

With little expectation of success, I followed the instructions and replaced this little pad that the printer uses to pick up sheets. And ten minutes later, I kid you not, I sent a print job to nova… and it worked! As good as new! It’s practically magical!

So my apologies to fixyourownprinter.com for doubting them. Their kit worked like a charm and I did, in fact, manage to fix my very own printer. Whee!

NB: I googled the separation pad and found that you can order it for $4 + shipping online. Now that I know how to replace it, that’s what I’d do in the future. But hey, $10-15 extra for the experience of learning a new repair skill? So worth it.

« Newer entries · Older entries »