12

I am looking for a way to draw Maya numerals using TikZ. What I want is a macro \maya{21} that gives me a graphical representation of the number 21 in the Mayan numeral system.

There is the package mathabx that provides something like this. But I can not use it, because I am using mnsymbol and there are some compatibility issues.

The following picture shows the symbols for each number in the maya system:

Maya numeral system

MWE:

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}

\begin{document}
  How to do it?
\end{document}
  • What about numbers above 19? What have you tried already yourself? Do you have an idea on how to get from 19 to three bars and four dots (mod and int functions)? The drawing with TikZ is really easy. – Qrrbrbirlbel Dec 02 '13 at 10:20
  • Have you considered doing this or this instead of drawing? – masu Dec 02 '13 at 10:34
  • 4
    –1: Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. Let me know when you edited your question and I’d be happy to redeem my downvote ;-) – Tobi Dec 02 '13 at 10:57
  • @Qrrbrbirlbel I understand how to calculate it (see below), but the coding to get it as TikZ-picture seems not straightforward to me (mixing TeX if statements with TikZ code). What I (mathematically) would do is 21:20=1 remainder 1 and 1:20=0 remainder 1. This means I would draw a dot at the "20" position and one at the "1" position. – Simon Schläpfer Dec 02 '13 at 14:15
  • @Tobi Your effort is really appreciable. But in cases like this, the OP may say I don't know where to start. In such scenario, shall we try to add some code just as an illustration? I will do it for this question. Pour in your opinions. :-) –  Dec 02 '13 at 23:41
  • @HarishKumar: Sure, it can be hard to find a starting point but in this case I'd expect that the OP at least had a look at the TikZ manual and drawing circles and lines isn't that complicated (the problems arise when you try to automate the numbering scheme) and he could explain how larger numbers should look like (He's explicitly asking for that but he tells how to do it only after Qrrbrbilbel asked in a comment …) – Tobi Dec 03 '13 at 06:12
  • @Tobi I agree. They can type at least the above code and in this case some dots and a bar additionally. –  Dec 03 '13 at 06:17

3 Answers3

14

You can copy the relevant code from mathabx.sty and mathabx.dcl to your document.

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnta%
\newcount\mayacntc%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

The definition of \mayaexpansion has been changed accordingly to this answer of Werner to have properly rotated numbers (requires graphicx).

So, using the command \mayadigit{<number>} you can obtain what you want, as with the following MWE

\documentclass{article}
\usepackage{graphicx,MnSymbol}

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnta%
\newcount\mayacntc%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

\begin{document}

$\mayadigit{0}\quad\mayadigit{9}\quad\mayadigit{19}$

\end{document} 

which yields

enter image description here


EDIT

I'm not really an expert in Maya numerals...

Try substituting the above code with this one to obtain numbers>20:

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnter%
\newcount\mayacnta%
\newcount\mayacntb%
\newcount\mayacntc%
\newdimen\mayawidth%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayarecurse{{%
    \mayacnta=\mayacnter \divide\mayacnter by 20
    \ifnum\mayacnter>0\mayarecurse\fi
    \mayacntb=\mayacnter
    \multiply\mayacntb by-20
    \advance\mayacnta by\mayacntb
    \hbox to\mayawidth{\hss\mayaexpansion\hss}}}%
%
\def\maya#1{%
    \mayacnter=#1
    \setbox0\hbox{\mathbfont 0}%
    \mayawidth=\wd0
    \left.
    \vcenter{\mayarecurse}
    \right.}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

and use the command \maya{<number>} instead of \mayadigit{<number>}, as in the following MWE:

\documentclass{article}
\usepackage{graphicx,MnSymbol}

\DeclareFontFamily{U}{mathb}{\hyphenchar\font45}
\DeclareFontShape{U}{mathb}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * mathb
      <10.95> mathb10 <12> <14.4> <17.28> <20.74> <24.88> mathb12
      }{}
\DeclareSymbolFont{mathb}{U}{mathb}{m}{n}

\newcommand\mathbfont{\usefont{U}{mathb}{m}{n}}

\newcount\mayacnter%
\newcount\mayacnta%
\newcount\mayacntb%
\newcount\mayacntc%
\newdimen\mayawidth%
%
\def\mayaexpansion{%
    \mayacntc=\mayacnta\mathbfont
    \ifnum\mayacntc=0 0\else
    \rotatebox[origin=c]{-90}{%
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5\repeat
    \the\mayacntc\mayacntc=\mayacnta
    \loop\ifnum\mayacntc>5\advance\mayacntc by -5 5\repeat}%
    \fi}%
\def\mayarecurse{{%
    \mayacnta=\mayacnter \divide\mayacnter by 20
    \ifnum\mayacnter>0\mayarecurse\fi
    \mayacntb=\mayacnter
    \multiply\mayacntb by-20
    \advance\mayacnta by\mayacntb
    \hbox to\mayawidth{\hss\mayaexpansion\hss}}}%
%
\def\maya#1{%
    \mayacnter=#1
    \setbox0\hbox{\mathbfont 0}%
    \mayawidth=\wd0
    \left.
    \vcenter{\mayarecurse}
    \right.}%
\def\mayadigit#1{%
    \mayacnta=#1\hbox{\mathbfont\mayaexpansion}}%

\begin{document}

$\maya{0}\quad\maya{9}\quad\maya{19}\quad\maya{49}$

\end{document} 

Result:

enter image description here

karlkoeller
  • 124,410
5

I think this does it:

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}

\newcount\mayannumber
\newcount\mayantmpa
\newcount\mayantmpb

\newcommand\mayan[2][]{%
\begin{scope}[#1,scale=1/4]%
    \mayannumber=#2\relax%
    \mayantmpb=20\relax
    \pgfmathloop
        \mayantmpa=\mayannumber
        \advance\mayantmpa by-\mayantmpb
        \ifnum\mayantmpa<0
        \else
        \multiply\mayantmpb by20
    \repeatpgfmathloop
    %
    \divide\mayantmpb by20\relax
    \tikzset{shift=(90:\pgfmathcounter*5-5)}
    \pgfmathloop
        \ifnum\mayantmpb=0
        \else
        \mayantmpa=\mayannumber\relax
        \divide\mayantmpa by\mayantmpb\relax
        {%
          \pgfmathloop%
          \ifnum5>\mayantmpa
            \ifnum0<\mayantmpa
              \foreach \i in {1,...,\mayantmpa}
                % Dot.
                  \fill (\i -\the\mayantmpa/2-1/2,1/4) circle [radius=1/4];
            \else%
              \ifnum\mayantmpa=\mayannumber
                % Shell
                \draw [thick, scale=5/4, shift=(90:2/3), line cap=round] 
                  (-60:1 and 2/3) 
                  \foreach \i in {-30,0,...,240}{ to [bend right, looseness=1.5] (\i:1 and 2/3)}
                  \foreach \i in {-60, -30,0,...,240}{ (0,-2/3) -- (\i:1 and 2/3)};
              \fi
           \fi
          \else%
            % Bar
            \fill (-2,0) rectangle (2,1/2);
            \tikzset{shift={(0,1)}}
            \advance\mayantmpa by-5
          \repeatpgfmathloop    
        }%
        \multiply\mayantmpa by\mayantmpb\relax
        \advance\mayannumber by-\mayantmpa
        \divide\mayantmpb by20
        \ifnum0<\mayantmpb
        \tikzset{shift={(0,-5)}}
        \path (-2,0) rectangle (2,1/2); % to enlarge bounding box
        \fi
    \repeatpgfmathloop
\end{scope}%
}
\begin{document}
%

\begin{tikzpicture}

\foreach \n [count=\i from 0, evaluate={\x=mod(\i, 5)/8*9; \y=int(\i/5)/8*12;}] in {0,...,19}{
 \mayan[shift={(\x,\y)}]{\n}
 \node [below] at (\x,\y) {\n};
}

\foreach \n [count=\i from 0, evaluate={\x=mod(\i, 5)/8*9; \y=-int(\i/5)/8*12-4;}] in {33, 56, 400, 429, 5425}{
 \mayan[shift={(\x,\y)}]{\n}
 \node [below] at (\x,\y) {\n};
}

\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
3

Just for fun with PGF.

Code

\documentclass[varwidth]{standalone}
\usepackage{pgf}
\makeatletter
\newcommand*\mayanumber[2][]{%
 \pgfpicture[#1]
  \pgftransformyscale{-1}
  \pgfmathdectobase\maya@{#2}{20}
  \expandafter\pgfutil@tfor\expandafter\maya@\expandafter:\expandafter=\maya@\do{
   \if0\maya@
     \maya@shell
     \pgftransformyshift{.5*(\pgfkeysvalueof{/pgf/maya digitty yshift})}
   \else
     \pgfmathbasetobase{\maya@}{\maya@}{20}{5}
     \expandafter\maya@number\maya@\@@
   \fi
   \pgftransformyshift{\pgfkeysvalueof{/pgf/maya digit yshift}}}
 \endpgfpicture}
\newcommand*\maya@shell{\pgfscope
  \pgfpathellipse{\pgfpointscale{.5}{\pgfpoint{\pgfkeysvalueof{/pgf/maya bar width}}{\pgfkeysvalueof{/pgf/maya bar height}}}}
    {\pgfpoint{.5*(\pgfkeysvalueof{/pgf/maya bar width})}{+0pt}}{\pgfpoint{+0pt}{\pgfkeysvalueof{/pgf/maya bar height}}}
  \pgfusepath{clip,stroke}%
  \pgfsetlinewidth{.5\pgflinewidth}
  \pgfutil@for\maya@@:=.2,.4,.6,.8\do{
    \pgfpathmoveto{\pgfpoint{\maya@@*(\pgfkeysvalueof{/pgf/maya bar width})}{-(\pgfkeysvalueof{/pgf/maya bar height})}}
    \pgfpathlineto{\pgfpoint{\maya@@*(\pgfkeysvalueof{/pgf/maya bar width})}{2*(\pgfkeysvalueof{/pgf/maya bar height})}}
    \pgfusepath{stroke}
  }\endpgfscope}
\def\maya@number#1#2\@@{%
  \def\pgf@temp{#2}%
  \ifx\pgf@temp\pgfutil@empty\expandafter\pgfutil@firstoftwo\else\expandafter\pgfutil@secondoftwo\fi
    {\maya@number0#1\@@}
    {\begingroup\pgftransformxshift{.5*(\pgfkeysvalueof{/pgf/maya bar width})}
        \pgftransformxshift{-.5*(#2-1)*(\pgfkeysvalueof{/pgf/maya bar height}+\pgfkeysvalueof{/pgf/maya circle seps})}
        \pgfmathloop\ifnum\pgfmathcounter>#2\else
          \pgfpathcircle{\pgfpoint{+0pt}{.5*(\pgfkeysvalueof{/pgf/maya bar height})}}{.5*(\pgfkeysvalueof{/pgf/maya bar height})}
          \pgfusepath{fill}
          \pgftransformxshift{\pgfkeysvalueof{/pgf/maya bar height}+\pgfkeysvalueof{/pgf/maya circle seps}}
        \repeatpgfmathloop
       \endgroup
      \pgfmathloop\ifnum\pgfmathcounter>#1\else
        \pgftransformyshift{\pgfkeysvalueof{/pgf/maya digitty yshift}}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\pgfkeysvalueof{/pgf/maya bar width}}{\pgfkeysvalueof{/pgf/maya bar height}}}
        \pgfusepath{fill}
      \repeatpgfmathloop}}
\pgfset{%
  maya digit yshift/.initial  =+.2em,
  maya digitty yshift/.initial=+.11em,
  maya bar height/.initial    =+.09em,
  maya bar width/.initial     =+.5em,
  maya circle seps/.initial   =+.03em}
\makeatother
\begin{document}
\begin{tabular}{rc}
  33 & \mayanumber{33}   \\
 429 & \mayanumber{429}  \\
2000 & \mayanumber{2000} \\
5125 & \mayanumber{5125}
\end{tabular}
\end{document}

Output

enter image description here

Moriambar
  • 11,466
Qrrbrbirlbel
  • 119,821