Leedberg.com

The online home for Greg Leedberg, since 1995.

Friday, November 18, 2005

How-To: Printing in Emacs Under Windows

For those who don't know, Emacs is one of the most popular text editors available for Unix-based operating systems. Emacs, and its competitor vi, have both been around almost as long as Unix itself, and most users of Unix can barely get through a day without using one of them. They are both excellent, in their own ways.

There is also a surpisingly good port of Emacs for Windows operating systems, sometimes called NTEmacs. Emacs is one of the first programs I install in a new Windows installation -- the regular Windows Notepad editor just doesn't cut it for people used to working in Linux.

But, I always had one problem with Emacs under Windows -- printing. I could not for the life of me figure out how to print text files from Emacs. With a little research, I was able to print black-and-white documents, but one of the nice things about Emacs is the syntax highlighting for programming languages. I really wanted to be able to print source code files, with colored syntax highlighting in tact.

After a lot of research and experimentation, I now am able to do this, and will document the steps here.

First, download and install Emacs for Windows, if you don't already have it. It comes in a tarball, so you'll need a decompression program such as WinZip in order to open it.

Now, open up a file you want to print. If you don't know how to use Emacs, I'm not going to cover that here. Emacs has an excellent tutorial that comes with it; the tutorial should be your first reference for the basics of Emacs.

Once you have a file open, press Alt-X. This allows you to enter a command directly into Emacs.

The command we want to enter is:

ps-spool-buffer-with-faces

so type that, and press enter. What this does is create a new buffer in Emacs, which contains the Postscript version of the current buffer. Postscript is a language used by printers, which actually allows you to represent anything that can be printed, including text, colored text, and graphics. If you click on "Buffers" in Emacs, there should now be a Postscript buffer. Click on that, and you'll see the Postscript data that would be used to represent the document you wanted to print. This includes all formatting and color as well!

Now what you need to do is save this Postscript buffer. You can name it whatever you want, but give it a .ps file extension. For example, source.ps.

Now, you have a Postscript file. What you need now are two programs, Ghostscript and GSView. Ghostscript is a system for manipulating Postscript files, and GSView is a graphical program which uses Ghostscript in order to view Postscript files. Download and install them both, if you don't already have them.

Once installed, you can use GSView to open up the .ps file you created. It should open up and look just like it did in Emacs! Success!

Almost.

It may seem that you can now use GSView to print this, but in my experience this doesn't seem to always be the case. I always found that if there was color in the .ps file, GSView would print it in black and white. But, this is fixable!

With the file open in GSView, click on File, Convert to PDF. This will allow you to create a PDF version of this file. PDF is similar in idea to Postscript, but was developed exclusively by Adobe.

Once you have a PDF file, open it using Adobe Acrobat Reader. If you don't already have it, download and install it. It's a useful program that you should get if you don't already have it!

Once opened in Acrobat, it can now be printed, and should retain all color and formatting of the original.

Not a straightforward process, but once you've done it, it's not too bad. I hope it helps other people!

Saturday, November 12, 2005

On Turning 24 and Growing Up

So, today is my birthday, and I turn 24!

For a while, I've been intending on writing an entry on growing up, so this seems as good an opportunity as any.

Generally, when my birthday comes around, I don't feel like I'm any older than I was a year ago. Some things have probably changed in that year, and I probably am a little more mature, but I don't feel like that's the case. When I turned 23 last year, I was in grad school, and my biggest concern in the world was still trying to get assignments done on time and make sure I didn't oversleep in the morning.

Even prior to my birthday today, I feel like I've grown up a lot since I graduated. It's a strange feeling, for sure. I look at my life, and no longer am I studying and learning about how to do something... I'm actually doing it. And I think that's how you know when you're an adult. Not that college is easy or anything. But there's a world of difference when you realize that you're actually doing stuff, forging the way ahead.

And then there's responsibility. In most cases, one doesn't have much responsibility while in college, except for yourself. Suddenly you're being paid money to do something because it needs to be done. It's not a case where if you don't do it or you're late in doing it, you get a bad grade. Suddenly, actions you take can amount to large sums of money being traded -- and you have to work hard they're being traded in the right direction.

And it's not just responsibility with respect to the company you work for. There's responsibility for your family. Even if you don't have a family when you start working, you feel the responsibility on your shoulders for the "ghosts" of your family to come. I don't have a wife or children now, but chances are good that I will at some point in the future. I'm working now to provide a good life for them later. And once you actually have a spouse and children, I'd imagine that the responsibility takes on a whole new dimension.

And with this responsibility, you suddenly are forced to have financial responsibility, which is the primary form in which one can start working for their future family. I never was one to needlessly spend money, but I also didn't have terribly much to manage. All of a sudden I have actual amounts of money, and I need to make sure that those amounts are preserved, grown, and that I have enough money down the line to achieve the things I want. Before getting a job, I really didn't know anything about mutual funds, 401ks, money market funds, inflation, and so on. But now a large percentage of my mental processes are devoted to making sure that my finances beat inflation, that there is enough money to secure the happiness of my family. I'm already starting to save for retirement, a house, and my kids' college education -- even though I have no idea at all when I will actually need the money for those things. Nor do I even know who my kids are!

Well, all I can say is that now I am 24, and for the first time in 24 years, I feel older on my birthday. If you haven't already hit that point, you will too. But, that's not to say that this scares me or that I wish I was back in college. I don't. Now I get up every day and am paid to do something I absolutely love to do. I look forward to have a chance to leave my mark on the world, and to live a happy life with a family -- a life that will be supported by the decisions I make now. I think it's a good thing to feel responsibility, and to feel older, because it means that you have something to look forward to, and a reason to exist.

So have some cake in honor of me. :-)

Sunday, November 06, 2005

Linux / WiFi / USB / FireWire: A Deadly Combination

For all two of you that read my My Computers blog, you'll know that I recently built a third computer, "Waldorf", out of parts that have been recycled out of other computers. There was one new component to Waldorf -- a Linksys 802.11g wireless LAN card. In the process of building this computer, I ran into a massive, confusing, week-long problem. Surprisingly, the problem had nothing to do with the process of setting up the WiFi card itself. I've done this before (in my laptop), and now know the secret process of getting a wireless LAN connection to work under Linux. The problem here was much more enigmatic.

Upon first boot, all was well. Wireless was working, USB was working, everything was working. I had no sound card installed, since I don't have a spare sound card currently. But everything that was installed worked fine.

Then I rebooted. Suddenly, weird things start happening. During bootup I got "IRQ #11 disabled" messages, then various error messages related to the WiFi card. Once booted, the wireless connection no longer worked, nor did USB. I tinkered around with lots of settings, kept rebooting, but after each boot the same strange problems would occur.

The next day, I booted up from a cold start, and everything worked fine again. Phew, problem must have been transient. Then I played with some settings, and rebooted.

And the problems came right back.

The problem, it appears, only occurs on reboots -- not cold starts. Very strange. But this is only the first strange thing to occur.

I did some Googling and found that this specific problem ("Disabling IRQ #11") is frequently caused by ACPI in the BIOS, and so you should disable it when booting the Linux kernel. I tried this, but discovered that since my BIOS is pre-2000, the ACPI support in the kernel was being disabled by default, so this wasn't the problem.

I tried 2 different distributions of Linux -- Fedora Core 3 and Fedora Core 4. Same problem on both. I tried several different kernels for both. Same problem on every kernel I tried.

Upon more Googling (I was now on page ~30 of the results), I learned that IRQ 11 is shared between all of the PCI devices, as well as USB and Firewire. In many cases this is caused by having a Wireless card and sound card. I don't have a sound card, so this simplified my debugging.

From what I could gather, what was probably happening was that the USB driver was loading, and grabbing IRQ 11, seemingly randomly. Since my WiFi card is PCI, it needs IRQ 11 as well, so when the WiFi driver tries to load, it can't communicate with the device, which ends up disabling the WLAN connection and also degrading USB performance.

I disabled USB in my BIOS. On first try, this seemed to work. However, on subsequent boots, the problem kept appearing. I tried to disable the USB subsystem from loading by playing around with the boot scripts for Linux, but no matter what I tried, it seemed that the USB system would try and load.

I tried to do the same thing for FireWire (I don't have any FireWire devices). However, as with USB, it seemed that nothing I did would prevent the driver from loading.

I was able to look at the system boot messages and actually see the ohci (usb/ firewire) system loading and outputting the fact that it was grabbing IRQ 11. I've never been so stressed out -- seeing it do it, but not being able to stop it.

In the end, I'm sorry to say that I have no solution to offer here -- I certainly was hoping this would be a "how-to" post, not a "I have no idea what just happened" post. I decided to just not reboot the machine. It's a secondary machine anyways, so I'll just turn it on and turn it off. I find it completely inexplicable that this problem only happens on reboots.

I'm posting this with two hopes. One, so that anyone else who runs into this problem will at least have an idea of what I tried, what didn't work, and what information on possible causes I was able to collect online. Two, so that if anyone else has this problem and finds a way around it, they can let me know!

I love Linux, but it's partially because of things like this that I took Linux off of Fozzie, my primary machine.