| Start |
|---|
| Operations with counters This example shows how to use mathematical operations with counters. It may be useful for loops in latex. Addition: this command adds Subtraction: this command subtracts Multiplication: this command multiply Division this command divides
The result of the code: 13\10\11\121\242\4 (\ symbolizes new line) intcalc package adds some other integer operations e.g. mod, pow, sng, abs, inv ... |
| Counter declaration, initialization and printing to pdf It is possible to use integer variables with latex. To create a new variable we need the |
| If statements In latex we can use built-in commands to execute code whether the conditions are true or not. Comparing two integers: This code executes A if num>n else B. We can substitute > with < and =. If a number is odd: If num is odd then it executes A else B. If with condition: We have to load ifthen package to use this command. If condition are true then it executes A else B. It is possible to create complex condition with For example: This piece of code writes down "B" on the page. An example code: |
| Loops - repeating things 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 Wrong: Right: @for loop: Example: It creates the following text: The sun is rising. The sun is setting. @whilenum loop: Example: This code writes odd numbers from 1 to 9. "loop repeat" loop: Executes commands till condition is true. Example This code does the same as @whilenum loop. An example code: |
| Using loops in Tikz Loops are useful in Tikz. The following code draws a clock without numbers: The result: |
Read Article
https://develop.horje.com/learn/1434/reference