A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia

Archive for September, 2009

Thursday, September 24th, 2009

Vim regex-fu for LaTeX

When writing a beamer presentation with LaTeX, I organize my presentation into sections and subsections. Frequently, the title of the first frame (slide) in a subsection has the same name as the subsection. Let’s say I start off with the following structure:

\section[corpora]{Accessing text corpora}
\subsection[gutenberg]{The Gutenberg Corpus}
\subsection[chat]{The web and chat Corpus}
\subsection[brown]{The Brown Corpus}
\subsection[reuters]{The Reuters Corpus}
\subsection[inaugural]{The Inaugural address Corpus}
\subsection[annotated]{Annotated corpora}
\subsection[foreign]{Corpora in other languages}
\subsection[DIY]{Loading your own corpora}

For each subsection, I want to put in one frame, with the name of the subsection being the name of the frame. Regular expressions to the rescue! In vim, all I have to is use V to select each line with subsection, then I hit :, which allows me to operate on those lines only.

'<,'>

is automatically inserted after the colon, which stands for “from the beginning of the highlighted section to the end of it”. Then I use s to perform my substitution. \r inserts a new line.

:'<,'>s/{\(.*\)}/{\1}\r\\begin{frame}\r\\frametitle<presentation>{\1}\r\\end{frame}/

The result is:

\section[corpora]{Accessing text corpora}
\begin{frame}
\frametitle<presentation>{Accessing text corpora}
\end{frame}
\subsection[gutenberg]{The Gutenberg Corpus}
\begin{frame}
\frametitle<presentation>{The Gutenberg Corpus}
\end{frame}
\subsection[chat]{The web and chat Corpus}
\begin{frame}
\frametitle<presentation>{The web and chat Corpus}
\end{frame}
\subsection[brown]{The Brown Corpus}
\begin{frame}
\frametitle<presentation>{The Brown Corpus}
\end{frame}
\subsection[reuters]{The Reuters Corpus}
\begin{frame}
\frametitle<presentation>{The Reuters Corpus}
\end{frame}
\subsection[inaugural]{The Inaugural address Corpus}
\begin{frame}
\frametitle<presentation>{The Inaugural address Corpus}
\end{frame}
\subsection[annotated]{Annotated corpora}
\begin{frame}
\frametitle<presentation>{Annotated corpora}
\end{frame}
\subsection[foreign]{Corpora in other languages}
\begin{frame}
\frametitle<presentation>{Corpora in other languages}
\end{frame}
\subsection[DIY]{Loading your own corpora}
\begin{frame}
\frametitle<presentation>{Loading your own corpora}
\end{frame}
Friday, September 11th, 2009

Energy usage myth

Phone charger plugged into the killawatt

Phone charger plugged into the killawatt

Recently I heard some sort of public service announcement about energy usage. I don’t recall where I heard it, but I was struck by one part of it. Two kids were talking about energy usage, and one mentioned that your cell phone charger still draws power, even if your cell phone is not plugged in. That is, if you leave the charger plugged into the outlet when not charging, which many people do. I was very suspicious of this claim, so I decided to do a little test with my Sanyo S1 phone charger, and my kill a watt, which is a small device which measures energy usage. You simply plug the kill a watt into an outlet, and then plug a device into the kill a watt.

I left my phone charger plugged in for 5 days without plugging in my phone. During this time, the killawatt reported 0.00 kilowatt hours of energy usage. This does not conclusively mean that it used no power. There is a precision limitation. If I left a charger in for a whole year, and it registered 0.00 killowatt hours, I would be confident that the charger draws at most 0.0099 kilowatt hours per year. Since I only left it in for five days, I have to imagine that it could use 0.0099 kilowatt hours per five days, which is 0.7227 kilowatt hours per year (.0099*(365/5)). In comparison, running a single 13 watt compact flourescent light bulb for 1 hour a day for a year uses 4.745 kilowatt hours of electricity (13*365/1000), or 6.5 times as much energy.

In summary, does leaving your cell phone charger plugged in waste electricity? Maybe. But in the case of my Sanyo S1 charger, it uses very little electricity. If you want to conserve electricity, you would be much more effective by turning off lights when you don’t need them.

Another note – I have also tested out how much power my iPod Photo (circa 2005) uses. When plugged in all the time, it uses about 2-3 kilowatt hours per year. Once again, less than running a 13W bulb one hour a day.

Wednesday, September 2nd, 2009

Black bean quesadillas

Black bean quesadilla with pico de gallo

Black bean quesadilla with pico de gallo

Black bean quesadillas with pico de gallo

Black bean quesadillas with pico de gallo

Last week we had lots of fresh tomatoes, so Clare told me I should make pico de gallo, and some mexican food. We make burritos fairly frequently, so I thought it would be fun to make something slightly different. We happened to have a bunch of pepper jack cheese, so I decided to try my hand at quesadillas. I made them in a pan, spraying a bit of canola oil onto a nonstick griddle, then I added a flour tortilla, topped half with the shredded cheese, and a mixture of black beans, onions, red peppers, cumin and coriander. After about 2 minutes I folded over the rest of the tortilla. I would have flipped the whole thing, except I overfilled them a bit.

For the pico de gallo, I finely chopped tomatoes, and let them drain in a colander a bit, so it wouldn’t be too soupy. I added some finely chopped onion, and a couple hot peppers from the garden. I put one clove of garlic in and a little salt. The combo turned out to be very tasty.