Friday, March 30, 2007

Suppressing a line number with the listings LaTeX package

Don't bother reading this post unless you are using the LaTeX listings package, have a code listing with line numbers, and want to suppress a line number in the listing.

By suppressing a line number, I mean something like the following:

Line 16 is split across two lines in the figure, but it's really one code statement, and I didn't want to have to refer to the statement using multiple line numbers in the text. Here is the LaTeX source for the key line:

String firstName = /*@\\@*/ /*@\underline{fullName.substring(0,spaceInd-1)};@*/

Note that since this snippet is used within the listings environment, the whitespace and the lack of a newline are significant. I used \lstset{escapeinside={/*@}{@*/}} before this listing to declare the escape sequence for adding other formatting. The {\*@\\@*/} inserts a linebreak, and then the spaces before the next characters appear as indentation in the figure.

Anyway, I googled around and couldn't find this trick, so hopefully this writeup will be useful to someone.

UPDATE (10/27/2008): In response to a request in a comment below, here is a minimal-ish full example that uses the technique. I've confirmed that this example works with the MacTex 2008 distribution (pdfTeXk, Version 3.1415926-1.40.9 and version 1.4 of the listings package).


\documentclass{article}
\usepackage{listings}

\lstset{escapeinside={/*@}{@*/}}

\begin{document}

\begin{figure}[t]
\begin{lstlisting}[numbers=left]
String firstName = /*@\\@*/ /*@\underline{fullName.substring(0,spaceInd-1)};@*/
\end{lstlisting}
\caption{Example illustrating suppression of line numbers.}
\end{figure}

\end{document}

Tuesday, March 27, 2007

Snitches in Baltimore

I read this article on witnesses being harassed and murdered in The Atlantic yesterday, and was absolutely infuriated. Everyone knows The Wire is a realistic show, but for some reason it was only after reading this article that it hit home for me how horrible that is. Is there any vaguely practical path to a sane drug policy in this country? Please let me know if one exists, as I'm eager to support it. Also, email me if you're not an Atlantic subscriber, and I'll email you access to the article.

Sunday, March 25, 2007

Rice and Keats

Just wanted to plug Rice and Keats, a blog well worth visiting; and I'm only a little biased :)

Friday, March 09, 2007

Times Reader again

I just wanted to recommend the New York Times reader again. They just updated it so that you can read any issue of the Times from the past week, a really useful feature. I've used the reader extensively on flights by syncing the articles before I leave, and it's been great.

Update (3/16): It looks like the Times reader will soon not be free, and for me, it's definitely not worth the price they are asking. On the other hand, Times Select is now free for students and faculty.

Thursday, March 01, 2007

News War

I wanted to recommend News War, a great Frontline documentary on the evolving role of the media that has been airing recently. You can watch it online, and the extended interviews are also really interesting.

Pipe for all my posts

Just for kicks, I made a pipe (as discussed previously) for all my posts here, on NewsDog, and on del.icio.us, and added a link to the feed.