\documentclass[12pt]{amsart}
\usepackage{tikz,xcolor,ifthen,rotating}

\usetikzlibrary{math}

\definecolor{liteBlue}{rgb}{0, 0.5, 1}
\definecolor{liteRed}{rgb}{1, 0, 0.5}

\newcommand{\drawCogs}[2]{
\def\m{#1}\def\n{#2}
\tikzmath{\p=36/(\m+\n);}\tikzmath{\r=max(\n*\n-(\m+4)*(\m+4),0);}
\tikzmath{\z=int(sqrt(\r)+1);}
\ifthenelse{\m>\z}{\tikzmath{\z=2*\m;}}{\tikzmath{\z=\z+\z;}}

\begin{tikzpicture}[x=\p mm, y=\p mm,
declare function={rx(\x,\y,\t)={\x*cos(\t)+\y*sin(\t)}; ry(\x,\y,\t)={\y*cos(\t)-\x*sin(\t)};}]

\ifthenelse{\m<\n \AND \m>7 \AND \n<37}{
\foreach \i in {1,...,\m}
{\draw ({-\m-2+rx(\m*sin(0),\m*cos(0),360*\i/\m)},{-\n+\m+ry(\m*sin(0),\m*cos(0),360*\i/\m)}) -- ({-\m-2+rx(\m*sin(180/\m),\m*cos(180/\m),360*\i/\m)},{-\n+\m+ry(\m*sin(180/\m),\m*cos(180/\m),360*\i/\m)}) -- ({-\m-2+rx((\m+2)*sin(225/\m),(\m+2)*cos(225/\m),360*\i/\m)},{-\n+\m+ry((\m+2)*sin(225/\m),(\m+2)*cos(225/\m),360*\i/\m)}) -- ({-\m-2+rx((\m+2)*sin(315/\m),(\m+2)*cos(315/\m),360*\i/\m)},{-\n+\m+ry((\m+2)*sin(315/\m),(\m+2)*cos(315/\m),360*\i/\m)}) -- ({-\m-2+rx(\m*sin(360/\m),\m*cos(360/\m),360*\i/\m)},{-\n+\m+ry(\m*sin(360/\m),\m*cos(360/\m),360*\i/\m)});%blue cog (on left)
\filldraw[white, fill=liteBlue!15!] ({-\m-2+rx((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)},{-\n+\m+ry((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)},{-\n+\m+ry((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)},{-\n+\m+ry((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)},{-\n+\m+ry((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)},{-\n+\m+ry((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)}) -- cycle;%blue spoke shading (on left)
\draw ({-\m-2+rx((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)},{-\n+\m+ry((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)},{-\n+\m+ry((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)},{-\n+\m+ry((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)}) -- ({-\m-2+rx((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)},{-\n+\m+ry((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)});%blue spokes (on left)
\filldraw[white, fill=liteBlue!15!] ({2*\n-\m+4+rx((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)},{\n+\m+ry((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)}) -- ({2*\n-\m+4+rx((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)},{\n+\m+ry((\m-2)*sin(180/\m),(\m-2)*cos(180/\m),360*\i/\m)}) -- ({2*\n-\m+4+rx((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)},{\n+\m+ry((\m-2)*sin(360/\m),(\m-2)*cos(360/\m),360*\i/\m)}) -- ({2*\n-\m+4+rx((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)},{\n+\m+ry((\m-4.2)*sin(330/\m),(\m-4.2)*cos(330/\m),360*\i/\m)}) -- ({2*\n-\m+4+rx((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)},{\n+\m+ry((\m-4.2)*sin(210/\m),(\m-4.2)*cos(210/\m),360*\i/\m)}) -- cycle;%blue hubcap shading (on right)
}
\draw ({2*\n-\m+4},{\m+\n}) circle ({\m-2});%blue hubcap outline (on right)

\foreach \i in {1,...,\n}
{\draw ({\n+2+rx(\n*sin(0),\n*cos(0),360*\i/\n)},{ry(\n*sin(0),\n*cos(0),360*\i/\n)}) -- ({\n+2+rx(\n*sin(180/\n),\n*cos(180/\n),360*\i/\n)},{ry(\n*sin(180/\n),\n*cos(180/\n),360*\i/\n)}) -- ({\n+2+rx((\n+2)*sin(225/\n),(\n+2)*cos(225/\n),360*\i/\n)},{ry((\n+2)*sin(225/\n),(\n+2)*cos(225/\n),360*\i/\n)}) -- ({\n+2+rx((\n+2)*sin(315/\n),(\n+2)*cos(315/\n),360*\i/\n)},{ry((\n+2)*sin(315/\n),(\n+2)*cos(315/\n),360*\i/\n)}) -- ({\n+2+rx(\n*sin(360/\n),\n*cos(360/\n),360*\i/\n)},{ry(\n*sin(360/\n),\n*cos(360/\n),360*\i/\n)});%red cog (on right)
\filldraw[white, fill=liteRed!15!] ({\n+2+rx((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)},{ry((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)}) -- ({\n+2+rx((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)},{ry((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)}) -- ({\n+2+rx((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)},{ry((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)}) -- ({\n+2+rx((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)},{ry((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)}) -- ({\n+2+rx((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)},{ry((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)}) -- cycle;%red spoke shading (on right)
\draw ({\n+2+rx((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)},{ry((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)}) -- ({\n+2+rx((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)},{ry((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)}) -- ({\n+2+rx((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)},{ry((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)}) -- ({\n+2+rx((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)},{ry((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)});%red spokes (on right)
\filldraw[white, fill=liteRed!15!] ({-2*\m+\n-6+rx((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)},{\z+ry((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)}) -- ({-2*\m+\n-6+rx((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)},{\z+ry((\n-2)*sin(180/\n),(\n-2)*cos(180/\n),360*\i/\n)}) -- ({-2*\m+\n-6+rx((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)},{\z+ry((\n-2)*sin(360/\n),(\n-2)*cos(360/\n),360*\i/\n)}) -- ({-2*\m+\n-6+rx((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)},{\z+ry((\n-4.2)*sin(330/\n),(\n-4.2)*cos(330/\n),360*\i/\n)}) -- ({-2*\m+\n-6+rx((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)},{\z+ry((\n-4.2)*sin(210/\n),(\n-4.2)*cos(210/\n),360*\i/\n)}) -- cycle;%red hubcap shading (on left)
}
\draw ({-2*\m+\n-6},{\z}) circle ({\n-2});%red hubcap outline (on left)

\draw ({-2*\m},{-\n-2}) -- ({2*\n},{-\n-2}) -- ({2*\n},{-3*\n-10}) -- ({-2*\m},{-3*\n-10}) -- cycle;%card base
\draw[dotted] (0,{-\n-2}) -- (0,{-3*\n-10});%fold line
\draw ({-\m},{-2*\n-6}) circle ({\m-4});%left axle
\draw ({\n},{-2*\n-6}) circle ({\n-4});%right axle
}
{\node at (0,0) {Use \textcolor{red}{$\backslash$drawcogs(m,n)} with $7<m<n<37$.};}
\end{tikzpicture}}

%%%%%%%%%%%%%%%%%%%%
\begin{document}
\title{Supplementary material for ``Clockwork Mathematics''}
\maketitle
\thispagestyle{empty}

\noindent Use this file to generate gears with $m$ and $n$ teeth ($8\le m<n\le 36$). In the \LaTeX\ code, set the number of teeth by modifying this line: \\

\noindent \texttt{{\textbackslash}drawCogs\{m\}\{n\}}\\

\noindent For more information, see the article ``Clockwork Mathematics,'' by Daniel Heath (\emph{Math Horizons}, April 2019).
\vfill

%%%%%%%%%%%%%%%%%%%%%
%
% Enter the number of teeth below as 
%
% \drawCogs{m}{n}
%
% where 7<m<n<37.
%
%%%%%%%%%%%%%%%%%%%%%
\begin{center}
\drawCogs{10}{13} 
\end{center}

\end{document}