Thursday, November 27, 2008

For the front of my 209 final exam...

For the front of the ECE 209 (Circuits and Electronics Laboratory) final exam I'm giving this Tuesday...

Thursday, October 16, 2008

Fixing bug in hyperref's autoref: amsmath-type equations under items get "item" label

Earlier this year, in a comp.text.tex posting, I discussed a bug I found in hyperref. That bug was then fixed in hyperref 6.77a, but there are still plenty of old packages hanging around that have this bug (for example, the hyperref from TeXLive 2007 on my system that I still haven't upgraded to TeXLive 2008).

The problem happens when
  • amsmath (or mathtools) is loaded.
  • An equation (or any other type of displayed-math environment) environment with labels occurs INSIDE an enumerated item.
  • You try to use \autoref to generate a reference to one of those equation labels later.
The \autoref macro will not properly return an "Equation" label (e.g., "Equation 1"). Instead, it will return an "item" label (e.g., "item 1").

To fix this problem, I use these lines of code just after I load hyperref in my preamble:
\makeatletter
\newcommand{\AMShreffix}[1]{%
    \expandafter\let\csname old#1\expandafter\endcsname%
        \csname #1\endcsname%
    \expandafter\renewcommand\csname #1\endcsname{%
        \@hyper@itemfalse\csname old#1\endcsname}}
\makeatother
\AMShreffix{equation}
\AMShreffix{align}
\AMShreffix{gather}
The \AMShreffix (i.e., AMS-href-fix) macro "fixes" the displayed-math environment that you pass it. This example fixes equation, align, and gather. If you want to fix alignat too, add a \AMShreffix{alignat} at the end of those lines. Make similar changes for your other displayed-math environments (e.g., flalign and multline too).

That fix changes all of the improper "item" labels back into proper "Equation" labels.

Monday, October 06, 2008

Big bug in the bathroom

A very large bug was spotted in the men's restroom...
Check out how huge those mandibles are! That thing could take out an eyeball!
For scale, I got this shot of it next to my shoe. The bug is about an inch long.
I didn't step on the bug, but after I noticed it, someone else did. That didn't kill the bug, but it made it less mobile. I couldn't get a shot of it near my shoe when it was more mobile because it kept walking toward my shoe, and I was afraid it would eat through my shoe and eventually eat through me...

Officemate's bee research on NPR

The graduate school research of my officemate (Kevin Schultz) was featured on NPR All Things Considered on Saturday during the "Science out of the Box" segment:

"Bees Follow Their Leaders"
When a swarm of bees takes flight, it can form a cloud as big as a school bus. But who's driving? And how do they know which way to go? Professor Thomas Seeley of Cornell University talks about how swarms of honeybees decide who's at the wheel and who's a backseat flier.
The audio story is streamable from the NPR link.

Professor Passino is our shared adviser, but my research has nothing to do with bee swarms. :) Professor Seeley is a collaborator of Passino/Schultz; he's from Cornell.

Saturday, October 04, 2008

Terra-Fi/Tera-Fi was my idea!

Someday they'll come out with terabit/s wireless networking (similar to 802.11... maybe 802.11t or something), and they'll need a name for it. It came to me this week that a great name would be "TeraFi" (or "TerraFi" or "Tera-Fi" or a similar spelling). That is, combine "terabit" and "wi-fi" to make a word that sounds like "terrify."

So that's my idea.

I wanted to put it out there before someone else did.

Tera-Fi. It's so fast it's scary.

Monday, September 29, 2008

My Brother Kenny on YouTube

A YouTube video of my brother Kenny and his family is now available. It is an interview segment with them for the MDA telethon held on Labor Day. My brother has ALS, which is also known as "Lou Gehrig's disease."

The MDA is one of many organizations fighting this disease, and yet the general public knows very little about it and researchers are having a hard time getting positive results from animal models to perform equally as well in human tests.

PLEASE help support my brother and ALS research in general by donating to my d'Feet ALS walk page.

Friday, September 26, 2008

Ben Folds and Regina Spektor together

Today's NPR Song of the Day: Ben Folds: Cynicism Meets Sweetness
  • Song: "You Don't Know Me"
  • Artist: Ben Folds (featuring Regina Spektor)
  • CD: Way to Normal
  • Genre: Pop-Rock
It's a good track. It's funny. It's witty. It's catchy. Oh, and its got some bitter realism mixed in there. Speaking of mixing, it's interesting combining Spektor and Folds. You can stream the track at the NPR page. The music video is embedded below...
The explicit lyrics go something like... (where Spektor's lyrics are in parentheses)
I wanna ask you —
Do you ever sit and wonder,
It's so strange
That we could be together for
So long, and never know, never care
What goes on in the other one's head?

Things I've felt but I've never said
You said things that I never said
So I'll say something that I should have said long ago:

(You don't know me)
You don't know me at all
(You don't know me)
You don't know me at all (at all)

You could have just propped me up on the table like a mannequin
Or a cardboard stand-up and paint me (paint me)
Any face that you wanted me
To be seen.
We're
Damned by the existential moment where
We saw the couple in the coma and
It was we were the cliché,
But we carried on anyway.

So, sure, I could just close my eyes.
Yeah, sure, trace and memorize,
But can you go back once you know

(You don't know me)
You don't know me at all
(You don't know me)
You don't know me at all (at all)

(You don't know me)
You don't know me at all
(You don't know me)
You don't know me

If I'm the person that you think I am (Ah ah ahh)
Clueless chump you seem to think I am (Ah ah ahhh)
So easily led astray,
An errant dog who occasionally escapes and needs a shorter leash, then
Why the fuck would you want me back?!

Maybe it's because

(You don't know me at all)

Ahhh ah
Ahhh ah

(You don't know me,
you don't know me.)

Ahhh ah
Ahhh ah

So, what I'm trying to say is
What (What?)
I'm trying to tell you
It's not gonna come out like I wanna say it cause I know you'll only change it.
(Say it.)

(You don't know me)
You don't know me at all
(You don't know me)
You don't know me at all (at all)

(You don't know me)
You don't know me at all
(You don't know me)
You don't know me at all (at all)

What?

(Mmmm, ohh oh
Ah ah ah ah ah
Aha ah ah ah
Ah-ah-ah-ah-ah
Oh-oh-oh-oh-oh
Aha ah
Ah ah
Ah-ah-ah-ah-ah-ah-ah-ah-ah
Oh-oh-oh-oh oh ohh)
What?

Tuesday, September 23, 2008

Fixing natbib: Adding tie between author and citation

Something that bugs me about natbib is that \citet puts a formal SPACE between the authors and the citation list, and so LaTeX like...
. . . as discussed by \citet{SK86}.
that shows up near the end of a typeset line can turn into
as discussed by Stephens and Krebs
[1].
Not only does this put a number at the beginning of a line, which is a typography no-no when you aren't starting a numerical item in a list, but it separates the citation list from its neighbors. If natbib would just us a TIE (~ in TeX) instead, then the "Krebs" in the example above would never get separated from the "[1]."

The best solution is to fix natbib so that this character is configurable. That would really help when using superscript references because you could get rid of the character all together (right now superscripts get a space before them, and that looks a little silly (especially when superscripts show up on the next line!)). However, that could take a while to get fixed (CTAN isn't quite SourceForge)... So I put together the following fix, which should work OK for \citet, \citet*, \Citet, and \Citet* regardless of how many optional arguments (0, 1, or 2) are present.

(note: the \makeatletter and \makeatother commands are not needed if these lines are put into a .sty file or in a natbib.cfg file (in the same directory as your TeX document source).
% Unfortunately, natbib does not TIE textual 
% references to their citations. So authors
% sometimes get separated from citations when
% they come at the end of the line. The following
% lines attempt to fix this problem.
%
% The lines below do the equivalent of . . .
%
% \renewcommand\citet[1]%
% {\citeauthor{#1}~\citep{#1}}
%
% but they handle the star and capitalization and
% optional argument cases too.
%
% (the \makeatletter and \makeatother are not needed if
% these lines are put into a .sty file or in a natbib.cfg
% file)
\makeatletter
%
%%% These lines test for star and number of arguments
%%% and call the workhorses below
%
% Test for star (mid-sentence and start-sentence forms)
\def\citet{\@ifstar{\citetstar}{\citetnostar}}
\def\Citet{\@ifstar{\Citetstar}{\Citetnostar}}
%
% No star found. Now test for argument count.
\def\citetnostar%
{\@ifnextchar[{\squarecitet}{\simplecitet}}
\def\squarecitet[#1]%
{\@ifnextchar[{\twocitet[#1]}{\onecitet[#1]}}
\def\Citetnostar%
{\@ifnextchar[{\squareCitet}{\simpleCitet}}
\def\squareCitet[#1]%
{\@ifnextchar[{\twoCitet[#1]}{\oneCitet[#1]}}
%
% Star found. Now test for argument count.
\def\citetstar%
{\@ifnextchar[{\squarecitetstar}{\simplecitetstar}}
\def\squarecitetstar[#1]%
{\@ifnextchar[{\twocitetstar[#1]}{\onecitetstar[#1]}}
\def\Citetstar%
{\@ifnextchar[{\squareCitetstar}{\simpleCitetstar}}
\def\squareCitetstar[#1]%
{\@ifnextchar[{\twoCitetstar[#1]}{\oneCitetstar[#1]}}
%
\makeatother
%
%%% The following actually do the \cite work
%
% The \citet cases (no arg, one arg, and two args)
\def\simplecitet#1%
{\citeauthor{#1}~\citep{#1}}
\def\onecitet[#1]#2%
{\citeauthor{#2}~\citep[#1]{#2}}
\def\twocitet[#1][#2]#3%
{\citeauthor{#3}~\citep[#1][#2]{#3}}
%
% The \citet* cases (no arg, one arg, and two args)
\def\simplecitetstar#1%
{\citeauthor*{#1}~\citep{#1}}
\def\onecitetstar[#1]#2%
{\citeauthor*{#2}~\citep[#1]{#2}}
\def\twocitetstar[#1][#2]#3%
{\citeauthor*{#3}~\citep[#1][#2]{#3}}
%
% The \Citet cases (no arg, one arg, and two args)
\def\simpleCitet#1%
{\Citeauthor{#1}~\citep{#1}}
\def\oneCitet[#1]#2%
{\Citeauthor{#2}~\citep[#1]{#2}}
\def\twoCitet[#1][#2]#3%
{\Citeauthor{#3}~\citep[#1][#2]{#3}}
%
% The \Citet* cases (no arg, one arg, and two args)
\def\simpleCitetstar#1%
{\Citeauthor*{#1}~\citep{#1}}
\def\oneCitetstar[#1]#2%
{\Citeauthor*{#2}~\citep[#1]{#2}}
\def\twoCitetstar[#1][#2]#3%
{\Citeauthor*{#3}~\citep[#1][#2]{#3}}
Even if this problem gets fixed within natbib, it still might serve as a good example of how to deal with TWO or more optional arguments in macros...

UPDATE: For author-year citations (i.e., "Harvard style citations"), you must replace the \citep with \citeyearpar. That is, replace the final section of the code above with this section:
%%% The following actually do the \cite work
%
% The \citet cases (no arg, one arg, and two args)
\def\simplecitet#1%
{\citeauthor{#1}~\citeyearpar{#1}}
\def\onecitet[#1]#2%
{\citeauthor{#2}~\citeyearpar[#1]{#2}}
\def\twocitet[#1][#2]#3%
{\citeauthor{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \citet* cases (no arg, one arg, and two args)
\def\simplecitetstar#1%
{\citeauthor*{#1}~\citeyearpar{#1}}
\def\onecitetstar[#1]#2%
{\citeauthor*{#2}~\citeyearpar[#1]{#2}}
\def\twocitetstar[#1][#2]#3%
{\citeauthor*{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \Citet cases (no arg, one arg, and two args)
\def\simpleCitet#1%
{\Citeauthor{#1}~\citeyearpar{#1}}
\def\oneCitet[#1]#2%
{\Citeauthor{#2}~\citeyearpar[#1]{#2}}
\def\twoCitet[#1][#2]#3%
{\Citeauthor{#3}~\citeyearpar[#1][#2]{#3}}
%
% The \Citet* cases (no arg, one arg, and two args)
\def\simpleCitetstar#1%
{\Citeauthor*{#1}~\citeyearpar{#1}}
\def\oneCitetstar[#1]#2%
{\Citeauthor*{#2}~\citeyearpar[#1]{#2}}
\def\twoCitetstar[#1][#2]#3%
{\Citeauthor*{#3}~\citeyearpar[#1][#2]{#3}}
Those lines seem to work for me.

Friday, September 19, 2008

Pretty analog docs

Lately, I've noticed more hits on my website for documents that I put together for some classes that I've taught. So I decided to collect all the substantial ones and list them in one place. I figured I'd do the same here...

My attempt at a "public domain" license declaration

Many lawyers will tell you that it is impossible for an author to explicitly release a new work into the public domain, but many authors would like to do such a thing. Normally the advice is to acknowledge retaining the copyright and then explicitly grant permission for public use of the work for every possible use.

So here's my attempt (taken from something I had to put into the public domain today:
Copyright (c) YEARS by AUTHORS
No rights reserved. All rights granted.

This work is licensed to the public domain. All persons
are permitted to use, copy, modify, distribute, and
publicly perform or display this work without restriction.

To view a copy of this license, visit
http://creativecommons.org/licenses/publicdomain/
or send a letter to Creative Commons, 171 Second Street,
Suite 300, San Francisco, California, 94105, USA.
I think much of that is redundant. You probably don't need that second half linking to CC's explanation of public domain. You probably don't need the "No rights reserved" and "All rights granted" crap either. Anyway, for the moment, I don't think they're doing any harm.

Yes, I realize I could just ask the civil law attorney in my family who handles this type of thing daily, but I'm afraid he'd just think I was being silly.