Math & Scienceunderstand a bit of code

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
stepec
Posts: 18
Joined: Fri Aug 06, 2010 11:36 pm

understand a bit of code

Post by stepec »

I've just lifted and slightly amended some code from a previous post which numbers some equations the way I want them to. It goes like this.

Code: Select all

\subsection*{Exercise 1}
\renewcommand{\theequation}{1.\arabic{equation}}
\begin{equation}
a
\end{equation}
\begin{equation}
b
\end{equation}

\subsection*{Exercise 2}

\renewcommand{\theequation}{2.\arabic{equation}}
\setcounter{equation}{0}
\begin{equation}
c
\end{equation}
\begin{equation}
d
\end{equation}
I'm not a programmer or even especially computerate, and I don't understand what the line

\renewcommand{\theequation}{2.\arabic{equation}}

actually does. Could somebody enlighten me?

stepec

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10359
Joined: Mon Mar 10, 2008 9:44 pm

understand a bit of code

Post by Stefan Kottwitz »

Hi stepec!
  • equation is the name of the counter for the equation-environment.
  • \theequation is the command that prints the equation counter.
  • \arabic is a command that takes a counter and outputs its value in arabic numbers.
  • \renewcommand redefines an existing command.
So,

Code: Select all

\renewcommand{\theequation}{2.\arabic{equation}}
redefines the output of the equation counter in that way: number 2, followed by a dot and by the number of the equation.

Stefan
LaTeX.org admin
stepec
Posts: 18
Joined: Fri Aug 06, 2010 11:36 pm

Re: understand a bit of code

Post by stepec »

Stefan

Thank you very much. I think I get most of that!

I've realised that I'm going to need to number some equations (actually, answers to questions) as question parts - eg 3.1(a), 3.1(b) etc. So I think I'm going to have to create a sub-subsection for the particular question, and use the same bit of code, except instead of {2.\arabic{equation}} I shall have to use {3.1\something{equation}}, where the something = whatever produces (a), (b) etc. I shall have a go, anyway, and see what transpires.

Thanks again.

stepec
Post Reply