Friday, April 30, 2010

A sed one-liner for LaTeX

Sometime in the near past, I posted my regex cheat sheet. With "sed" you can make regex work. For those not in the know:
sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
But that doesn't really tell you much. Here is an excellent tutorial by Bruce Barnett. Here are explanations to some great one liners.

Today, I had to do something to a LaTeX manuscript, I have been working on for a few months: I finally made up my mind on which journal to send it to. While LaTeX in conjunction with natbib and BiBTeX is great for re-formatting, there was one issue that needed to be weeded out.

I wrote the manuscript using Nature citation style (compressed numerical superscripts) by using \cite commands after punctuation marks like commas and periods. The new place I wanted to send it to required author-year formatting before punctuation marks. Basically transform something like
This is known from previous studies.1-3
This is known from previous studies (Smart and Boss, 1990; Smarter et al., 2005; Smartass 2011).

Normally, this would be a fairly tedious manual exercise. But sed reduces the task into a one liner.

sed 's/\([,.;:]\)\\cite{\([a-z0-9, ]*\)}/ \\citep{\2}\1/g' doc0.tex > doc1.tex

Let me parse the command.

sed 's/xxx/yyy/g' doc0.tex > doc1.tex

substitutes (the s/) all matches (the /g' at the end for global substitution) of "xxx" in the file doc0.tex with "yyy" and writes it into a new file doc1.tex. So far it is a simple find and replace, which could have been done easily in most editors.

The real magic is the "xxx" and "yyy" in the original command. The [,.;:] matches any of the usual punctuation marks that precede a \cite declaration. Parenthesis \( and \) mark stuff to be remembered and \1, \2 etc puke it out. Thus,
echo abcd123 | sed 's/\([a-z][a-z]*\).*/\1/'

The \\ is required to protect the \, which has special meaning. The rest is plain old regex matching.

Saturday, April 24, 2010

Should teachers be judged based on student evaluations?

The case certainly can be made for including student surveys as one part of a teacher's overall evaluation. I understand and respect student opinion, as an important component for designing a continuous improvement strategy. Nevertheless, I have a problem, when they are used as the primary source of a teacher's evaluation.

One of my colleagues emailed me this story.
Dominique G. Homberger won't apologize for setting high expectations for her students. The biology professor at Louisiana State University at Baton Rouge gives brief quizzes at the beginning of every class, to assure attendance and to make sure students are doing the reading. On her tests, she doesn't use a curve, as she believes that students must achieve mastery of the subject matter, not just achieve more mastery than the worst students in the course. For multiple choice questions, she gives 10 possible answers, not the expected 4, as she doesn't want students to get very far with guessing.
Students in introductory biology don't need to worry about meeting her standards anymore. LSU removed her from teaching, mid-semester, and raised the grades of students in the class. In so doing, the university's administration has set off a debate about grade inflation, due process and a professor's right to set standards in her own course.

My state of Florida even tried to take the idea too far: directly connect teachers pay increases to students performance. Thankfully, the governor vetoed it.

As I read somewhere, how would law-makers like it if their pay increases were connected to the performance of the laws they passed (how many laws were successfully obeyed, or any such metric)?

Sunday, April 18, 2010

Diligence v/s Intelligence?

As a product of the JEE myself, I have been reading both positive, and negative reactions to changes proposed for admitting students into the IITs, with much interest.

Board Exams = Diligence?
Many years ago, I used to think doing well on board exams had to do with being diligent. Putting in long hours redoing fairly standard problems/questions, committing large amounts of data to memory (processing it was completely optional), learning to present material neatly etc. The exam paper itself, was never a surprise.

JEE = Intelligence?
The JEE on the other hand was quite the opposite (I suspect that coaching classes changed the equation somewhat). Very few problems were standard, and clearly required some degree of processing. No amount of sheer practice could substitute for the "think on your feet" aspect of the exam. Clearly, I use the label "intelligence" quite loosely to describe this quality of the selection criteria.

I don't want to imply that diligence and intelligence are orthogonal in any sense. And a completely different issue (and one that my colleagues and I talk about quite a bit, in the context of what makes for good grad-student/scientists) is what is more desirable?

One fairly important person said something about "99% perspiration", and while I could bicker about the percentages, my thoughts are in alignment.

Thursday, April 8, 2010

Detaching from terminals using GNU screen

GNU screen is a Linux utility, that I did not know much about it, until a couple of years ago. It is a very handy program, and I'll start with my most frequent use of the utility.

If you use Linux, you like terminals. Let's say you start a program like Firefox or emacs from the terminal, by issuing a command like

$ emacs &

The program runs in the background and let you do other work in the terminal. However, when you exit the terminal, by either typing exit or closing the terminal window, your program (emacs in this case) is also killed.

GNU screen allows you to detach the program from the particular terminal from which it was invoked, thereby letting the program persist beyond the life-time of the terminal.

It is very simple to use. Fire your program from a terminal, in background mode.

$ emacs &

Then invoke screen (preinstalled on pretty much all Unix like systems)

$ screen

You may see that the title of your terminal window has changed somewhat, but that is not important.

You now type Ctrl-A d. You should see something like [detached] echoed on your screen.

Now go ahead, and kill your terminal.

Your emacs window persists!


There are several other good uses for screen. You could fire programs like Thunderbird, Firefox, emacs etc. from a terminal and leave them running for months. If you've logged into a remote server, screen can function as a multiplexer (multiple tabs).

There are a number of places to learn more about screen. Here are some of them.

Monday, April 5, 2010

Easy scheduling

One of the hardest things about scheduling a one-off meeting, thesis defense, or coordinating volunteers for an event is reaching a consensus.

A typical method of dealing with the problem is via email, where everyone sends available/non-available slots to a person coordinating the event. The time required to converge to a "solution" is governed by the slowest responder.

If this time is too long (unfortunately all too frequent), it is possible that some of the originally available timeslots have been booked for something else, and have hence been rendered unavailable.

The process often needs iteration, and finding consensus can be a nerve-racking problem.

One of my colleagues, Peter Beerli, recently alerted me (the department really) to a nifty (but really simple) tool called doodle.

Give it a spin.

It is really easy to set up, and people can mark available timeslots for everyone to see, which is a big help. One can also add comments like "I can do this time, but that time is preferable."

It also integrates nicely with other calendar programs, if required.