\documentclass{article}
\begin{document}
\section{Testing LaTeX Counters}
\newcounter{foo}
Counter Foo [0] = \thefoo.


\stepcounter{foo}
Increment Foo[1] =  \thefoo.

\setcounter{foo}{2}
Set Foo to 2 = \thefoo.

\addtocounter{foo}{10}
Add 10 to Foo [12] = \thefoo.


\addtocounter{foo}{\value{foo}}
Double Foo [24] = \thefoo.

\subsection{Testing RefStep}
Define bar to be reset within foo.
\newcounter{bar}[foo]
Now (Foo,Bar)[24,0] is (\thefoo,\thebar)

Refstep bar: \refstepcounter{bar}
Now (Foo,Bar)[24,1] is (\thefoo,\thebar)

Refstep foo: \refstepcounter{foo}
Now (Foo,Bar)[25,0] is (\thefoo,\thebar)

\subsection{Number formatting}
\newcounter{fubar}
\setcounter{fubar}{6}
arabic[6] = \thefubar

\renewcommand{\thefubar}{\roman{fubar}}
roman [vi] = \thefubar


\renewcommand{\thefubar}{\Roman{fubar}}
Roman [VI] = \thefubar

\renewcommand{\thefubar}{\alph{fubar}}
alph [f] = \thefubar

\renewcommand{\thefubar}{\Alph{fubar}}
Alph [F] = \thefubar

\renewcommand{\thefubar}{\fnsymbol{fubar}}
fnsymbol [$\Vert$] = \thefubar

How far will \TeX\ go?
\renewcommand{\thefubar}{\roman{fubar}}
\setcounter{fubar}{9999}
Fubar is \thefubar

\section{Expanding LaTeX Counter Names}
\newcommand{\eff}{F}
\newcommand{\oh}{o}
\newcommand{\eww}{oo}
\newcounter{\eff\oh\oh}

Counter Foo [0] = \theFoo.

\stepcounter{\eff\oh\oh}
Increment Foo[1] =  \theFoo.

\setcounter{F\oh o}{2}
Set Foo to 2 = \theFoo.

\addtocounter{F\eww}{10}
Add 10 to Foo [12] = \theFoo.

\addtocounter{\eff oo}{\value{F\eww}}
Double Foo [24] = \theFoo.

\subsection{Testing RefStep}
\newcommand{\manchu}{Fu}
\newcommand{\pub}{Bar}

Define bar to be reset within Foo.
\newcounter{Bar}[Fo\oh]
Now (Foo,Bar)[24,0] is (\theFoo,\theBar)

Refstep Bar: \refstepcounter{\pub}
Now (Foo,Bar)[24,1] is (\theFoo,\theBar)

Refstep Foo: \refstepcounter{\eff\eww}
Now (Foo,Bar)[25,0] is (\theFoo,\theBar)

\subsection{Number formatting}
\newcounter{Fu\pub}
\setcounter{\eff uBar}{6}
arabic[6] = \theFuBar

\renewcommand{\theFuBar}{\roman{Fu\pub}}
roman [vi] = \theFuBar

\renewcommand{\theFuBar}{\Roman{\manchu Bar}}
Roman [VI] = \theFuBar

\renewcommand{\theFuBar}{\alph{\manchu\pub}}
alph [f] = \theFuBar

\renewcommand{\theFuBar}{\Alph{FuBar}}
Alph [F] = \theFuBar

\renewcommand{\theFuBar}{\fnsymbol{Fu\pub}}
fnsymbol [$\Vert$] = \theFuBar

\section{TeX Counters}
\subsection{Integers}
\countdef\two=2
\two=7\relax
7 = \the\two.

7 = \the\count2.

\subsection{Dimensions}
HFuzz is \the\hfuzz.
\hfuzz=2pt
Now HFuzz is \the\hfuzz.

HFuzz is \the\hfuzz.
\hfuzz=2ptNow HFuzz is \the\hfuzz.

%HFuzz is \the\hfuzz.
%\hfuzz=2Now HFuzz is \the\hfuzz.

%Linethickness: \the\linethickness
%\linethickness=2pt
%Now Linethickness: \the\linethickness

\dimen7= 1.23 pt\relax
Dimen 1.23pt = \the\dimen7.

Dimen 1.23pt = \the\dimen\two.

Dimen 1.23pt = \the\dimen\count2.

\two=65536\relax\multiply\two3\relax
count 2: 3*65536 = \the\two.

\dimen7= 1\count2\relax
Now dimen: 3pt = \the\dimen7

\dimen7 = 1em\relax
One em = \the\dimen7

\dimen7 = 1ex\relax
One ex = \the\dimen7

\dimendef\dseven7
Dimen: one ex = \the\dseven

\dseven1pt\relax
Dimen: 1pt = \the\dseven

Dimen: 1pt = \the\dimen7

\dseven'10pt\relax
8 pt = \the\dimen7

\dseven"Fpt\relax
15 pt = \the\dimen7

Catcodes?
{\catcode`\p=12\catcode`\t=12\gdef\undim#1pt{#1 POINTS}}
15.0 POINTS = \expandafter\undim\the\dimen7

\subsection{Glue}
\skip7 = 1pt plus 3pt\relax
1pt plus 3pt = \the\skip7

\skip7 = 1pt plus 3fil\relax
1pt plus 3fil = \the\skip7

\skip8 = 1pt plus 3fill\relax
1pt plus 3fill = \the\skip8

\advance\skip7\skip8
Skip: 2pt plus 3fill = \the\skip7

\skip8 = .1pt plus 3fill\relax
0.1pt plus 3fill = \the\skip8

Catcodes?
\skip7 = 1pt plus 3pt\relax
{\catcode`\p=12\catcode`\l=12\catcode`\u=12\catcode`\s=12\catcode`\t=12%
\gdef\oongoo#1pt#2plus#3pt{#1 POINTS #2 PLUS #3 POINTS}}
1.0 POINTS  PLUS 3.0 POINTS = \expandafter\oongoo\the\skip7

\subsection{Undefined?}

Unknown count: 0 = \the\count128\relax

Unknown dimen: 0pt = \the\dimen128\relax

Unknown skip: 0pt = \the\skip128\relax

\subsection{The}
% Let's hope 127 is safe?
\count127=99\relax
the count 127 [99] : \the\count127\relax

the two (countdef 2)[196608] : \the\two


\def\foo{FOO}
%the macro foo : \the\foo

%the primitive def : \the\def

\toks2={ab\foo cd}
Tokens: abFOOcd = \the\toks2

Catcode: 11 = \the\catcode`\A

Catcode: 12 = \the\catcode`\@


\subsection{New Count, etc}
\newcount\foo
\foo3\relax
3 = \the\foo

\subsection{\LaTeX\ style}
\newlength{\foolen}
\setlength{\foolen}{1em}
1em = \the\foolen
\addtolength{\foolen}{2em}
3em = \the\foolen

\subsection{Macrology}
\def\numthree{3}
\count2=1\relax 1=\the\count2

\count2=2\numthree\relax
[23=\the\count2]

\count2=2\ifnum20<\count2 9\else 8\fi
[29=\the\count2]

\count2=2\ifnum\count2<20 8\else 9\fi
[29=\the\count2]

\makeatletter
\count\tw@=\@M\relax
[10000=\the\count\tw@]
[\chardef\mydollar=36\relax
\$a\$ = \mydollar a\mydollar]

\makeatother

\subsection{Quirks}
Note that for toksdef and otheres, \TeX\ binds the token to relax
before reading the number, in case the definition is immediagely
followed by a usage or assignment (See TeX Program \S1224)

\toksdef\tooksa=1\tooksa={abc}\relax Tooks:\the\tooksa

\dimendef\dima=99\dima=1.0pt\relax dima:\the\dima

\skipdef\skipa=99\skipa=1.0pt plus 1pt\relax skipa:\the\skipa

\muskipdef\muskipa=99\muskipa=1.0mu\relax muskipa:\the\muskipa

\chardef\chara=64\chara

$\mathchardef\mathchara="1350\mathchara$

\end{document}
