Tutorial by Examples

It is possible to use integer variables with latex. To create a new variable we need the \newcounter{name} command, where name is the name of the new counter. The name must contain only letters. This command creates a new one with name \thename. With this command we can print name variable onto the ...
This example shows how to use mathematical operations with counters. It may be useful for loops in latex. Addition: \addtocounter{num}{n} this command adds n to num, where num is a counter and n is a positive integer. Subtraction: \addtocounter{num}{-n} this command subtracts n from num, where n...
In latex we can use built-in commands to execute code whether the conditions are true or not. Comparing two integers: \ifnum\value{num}>n {A} \else {B}\fi This code executes A if num>n else B. We can substitute > with < and =. If a number is odd: \ifodd\value{num} {A}\else {B}\fi If ...
We can create loops in latex. They are similar but not as customizable as loops in other programming languages. One alternative to use loops are @loops. If we use a command which includes "@" in its name, we must be put it between \makeatletter and \makeatother. It is not allowed to use th...
Loops are useful in Tikz. The following code draws a clock without numbers: \documentclass{article} \usepackage{ifthen} \usepackage{intcalc} \usepackage{tikz} \newcounter{num} \begin{document} \begin{tikzpicture} \makeatletter \setcounter{num}{1} \newcounter{angle} ...

Page 1 of 1