Wednesday, April 16, 2008

LaTeX example - creating a lecture note

This LaTeX example will create an automatic exercises numbering as well as the problems in each exercise. It is useful for creating lecture notes.

Example

\documentclass[a4paper,12pt]{book}

\newcounter{exercisenum}[section]
\renewcommand{theexercisenum}{\arabic{exercisenum}}
\newenvironment{exercise}
\stepcounter{exercisenum}

\vspace{1pc}\par\noindent\textbf{Exercise thesection.theexercisenum}\par

\newcounter{problemnum}[exercisenum]
\renewcommand{theproblemnum}{\arabic{problemnum}}
\newcommand{problem}
{
\stepcounter{problemnum}
\theproblemnum.
}

\newcounter{secondproblemnum}[problemnum]
\renewcommand{thesecondproblemnum}{\alph{secondproblemnum}}
\newcommand{secondproblem}
{
\stepcounter{secondproblemnum}
\thesecondproblemnum)
}

\begin{document}

\chapter{Introduction}

\section{Function}

\begin{exercise}

\begin{tabular}{lll}
\multicolumn{3}{l}{Solve for $x$.}
\problem $x + 3 = 4$ & \problem $x + 3 = 4$ & \problem $x + 3 = 4$
\multicolumn{3}{l}{
\problem \secondproblem $x + 11 = 0$
\secondproblem $x + 11 = 0$
\secondproblem $x + 11 = 0$
}
\problem $x + 3 = 4$ & \problem $x + 3 = 4$ & \problem $x + 3 = 4$
\problem $x + 3 = 4$ & \problem $x + 3 = 4$ & \problem $x + 3 = 4$
\end{tabular}

\end{exercise}

\begin{exercise}

\problem
Cras egestas rhoncus mi. Donec sed orci rhoncus risus consequat
posuere. Maecenas ut lorem at neque imperdiet varius. Mauris imperdiet
arcu a eros. Proin elementum elementum nibh.

\problem Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In eget magna.

\end{exercise}

\end{document}