Latex provides great tools for designing your documents. If you are writing a book, an article or a manual with code snippets, figures, and tables and you’d like to count and number them you can do it fairly easily.
First you can use built in listing tools like \equation \figure \table and so on. But let’s say you want to distinguish between Figures which are illustrations and Pictures which are real world picture, or lets say you want to number out code snippet in your document, or number out examples of solutions to exercises.
For this purpose comes the real power of Latex, custom commands. Here I’ll briefly show you how to create a custom command to count examples in your text book.
In the permeable of the document we’ll add a new counter, and add +1 to it, since Latex by default, starts counting from 0.
\newcounter{example}
\addtocounter{example}{1}
Now we have a new counter which can be accessed in the document with the call \arabic{example} or with the call \theexample. But that’s really something easy. Let’s say I want the numbering scheme to be: X.Y like before, X is the chapter and Y the example. For this will have to create a new command in the permeable of the document. Here is how it is easily done:
\newcommand{<\thenameofyournewcommand>}[<Number of variables the command takes>]{<a set of latex command to be executed in your new command>}
So we see a custom command is a little Macro or Latex script if you want to think about it like that.