latex Counter declaration, initialization and printing to pdf


Example

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 paper. The initial value of name is 0. To give value to "name" we can use \setcounter{name}{n} where n is an integer. \value{name} is a function which returns with the value of name.

\documentclass{article}
\begin{document}
\newcounter{num}                    %new counter, initial value is 0
\thenum                             %print 0
\setcounter{num}{3}                 %set num to 3
\thenum                             %print 3
\newcounter{number}
\setcounter{number}{\value{num}}    %set number to value of num
\thenumber                          %print 3

Latex provides some other formats to print a number.

Other types of printing:

\arabic{num}\\
\Roman{num}\\ %→ I, II, III, IV, . . . (num = 1, 2, 3, . . . )
\roman{num}\\ %→ i, ii, iii, iv, . . . (num = 1, 2, 3, . . . )
\Alph{num}\\  %→ A, B, C, D, . . . (num = 1, 2, 3, . . . , 26)
\alph{num}\\  %→ a, b, c, d, . . . (num = 1, 2, 3, . . . , 26)
\fnsymbol{num}\\ %→ ∗, †, ‡, §, ¶, k, ∗∗, ††, ‡‡ (num = 1, 2, 3, . . . , 9)
\end{document}

enter image description here