LaTeX Tip of the Day – equation numbering by section or chapter

March 11th, 2009

Let’s say you have a nice LaTeX document with sections, and it’s full of numbered equations. Normally, the equation numbers will start at 1 and keep counting up. If your document gets long, though, you may find yourself with hundreds of equations, and when a reader tries to look one up, they have to search around for a while.
To fix this problem, you can number your equations within sections (so the numbers will go (1.1), (1.2),…, (2.1),(2,2),… instead of (1),(2),…), just add

\usepackage{amsmath}
\numberwithin{equation}{section}


to the preamble of your document.
Of course, if you want numbering by chapter or subsection, just replace section with the relevant name.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon

Typesetting , ,

LaTeX Tip of the Day – \fbox, \mbox, \makebox, \framebox

March 4th, 2009

When typesetting with LaTeX, sometimes you need to take a little control back from the automatic routines that determine linebreaks. Or perhaps you want to manually control the placement of text on a line.
The latex command \makebox[w][position]{content} inserts an unbreakable box of width w (10pt, 2cm, 0.23in, \textwidth will work), where the content is positioned flush left (use the letter l), flush right (r), centered (c), or will fill the box (s). The square brackets mean that those arguments are optional (if you only specify one, LaTeX assumes you’re giving the width). The default positioning is (c), and the default width is just big enough to fit the content (if you specify a width that is too small, the text will overflow onto text outside the box.

examples of \makebox in LaTeX

The command \framebox is exactly the same, except it draws a solid line around the box:

examples of \framebox in LaTeX

The commands \mbox{content} and \fbox{content} are equivalent to \makebox{content} and \framebox{content}, respectively (\mbox and \fbox are robust, so you should use them if possible). To change the thickness of the outline drawn by \fbox to 2pt, add the command \renewcommand{\fboxrule}{2pt} anywhere before the \fbox.

examples of \mbox and \fbox in LaTeX

Note how the boxes make the line overflow.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon

Typesetting , ,

Apple iTunes skip and play counts explained

February 9th, 2009

A of iTunes 7 (download here), music aficionados and meta-data junkies have been able to track the Skip Count of the songs in their music library. This data complements the ages-old Play Count statistic.

Along with the skip and play counts, iTunes records the last time a user played or skipped a song (this is useful if you want to know when you listen to music most during the day/week/month, or if you want to know when you’re most choosy about your music).

What, then, merits a Skip or a Play?

Using iTunes 8.02 on OS X 10.4, I set out to find out exactly how to (and how not to) get iTunes to increment the skip and play counts on a song. You can’t manually change these counts in iTunes unless you resort to changing the iTunes library xml file, or if you use one of Doug’s Applescripts. If you prefer not to cheat, and beat iTunes at its own game, here’s how:

  • The play count is incremented by 1 if the song is completed, or if the track timer is within 10 seconds of the end of the track when the Forward command is sent.
  • The skip count is incremented by 1 if the track timer is between 2 and 20 seconds when the Forward command is sent.
  • The two above rules apply whether the song is playing or paused.
  • iTunes doesn’t care how you got the progress in the track: listening to the first 21 seconds is the same as manually moving the timer to 0:24. This means you can easily get play counts on songs by placing the timer within 10 second of the song’s finish, then hitting Forward.
  • Play counts take precedence over skip counts. This means you will never get a nonzero skip count for any track of duration less than 12 seconds.

I assume the rules are the same for other versions of iTunes, and for playback on iPods (I’ve heard iPod firmware needs to have been updated sometime since september 2006, and it won’t work in very old iPods). Now go out and get some sweet play/skip data!
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon

iTunes , ,

LaTeX Tip of the Day – paragraph styles

February 5th, 2009

There are two really quick commands to change the way new paragraphs begin. In the preamble (before begin{document}), add:

setlength{parindent}{0.0in}
setlength{parskip}{0.1in}

and set the two lengths to suit your needs. Acceptable units are: in, cm, mm, pt, ex, em (ex and em are approximately the width of the letters x and m, and scale with the font size), or you can use setlength{parskip}{1.0baselineskip} to get a full blank line before each new paragraph (the baseline skip is the vertical distance from one line of text to the next), or replace 1.0 with some other number for bigger or smaller spacing (which also scales properly if you increase the line spacing).
If you have a paragraph with special needs, you can specify noindent right before the text. You can also insert a space equal to th paragraph indent with indent.

You can also change line spacing with

renewcommand{baselinestretch}{1.2}

where the numerical factor is 1 for single spacing, 2 for double spacing, etc.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon

Typesetting , ,

LaTeX Tip of the Day – cases

January 30th, 2009

If you want to define a piecewise equation in your typeset math, or if you want to express a conditional statement, or just group a set of related equations in math mode, then you’re looking for the cases environment. It’s the way to get that big curly brace on the left of a couple of lines of math. In math mode, the code

f(x,y)=\begin{cases}
0 &\text{for~}x\leq 0\,,\\
\sin x+\phi &\text{for~}x > 0\,.
\end{cases}


will produce the output:
$$f(x,y)=\begin{cases}0 &\text{for }x\leq 0\,,\\ \sin x+\phi &\text{for }x > 0\,. \end{cases}$$

Note that you use an alignment character (&) on each line, and the first character after it on each line will align vertically (it’s as if you’re making a 2-column table). Each line ends with \\ save the last one.

This entire construct only gets one equation number (if you have equation numbering on), and you can’t specify the alignment of the first part of each line. Both of these problems are solved by the cases package.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon

Typesetting , ,