2

How to use Mayan Numerals from 'BabelStone Mayan Numerals' font in math mode, with LuaLaTeX?

tatojo
  • 1,331
  • 11
  • 26

2 Answers2

2

With full conversion, so no computation necessary.

\documentclass{article}
\usepackage{amsmath}
\usepackage{fontspec}

\newfontface{\mayanumerals}{BabelStoneMayanNumerals}[
  Path=./,
  Extension=.ttf,
]

\ExplSyntaxOn

\NewDocumentCommand{\mayanumber}{sO{}m}
 {
  \IfBooleanTF { #1 }
   {
    \ensuremath { \mathrm { \tl_upper_case:n { \int_to_base:nn { #3 } { 20 } }\sb{20} } }
   }
   {
    \tatojo_maya_number:nn { #2 } { #3 }
   }
 }

\int_const:Nn \c__tatojo_maya_start_int { "1D2E0 }
\tl_new:N \l__tatojo_maya_converted_tl
\seq_new:N \l__tatojo_maya_digits_seq

\keys_define:nn { tatojo/maya }
 {
  align      .tl_set:N = \l__tatojo_maya_align_tl,
  align      .initial:n = c,
  horizontal .bool_set:N = \l__tatojo_maya_horizontal_bool,
  horizontal .default:n = true,
  vertical   .bool_set_inverse:N = \l__tatojo_maya_horizontal_bool,
  vertical   .default:n = true,
  scale      .code:n =
   {
    \fp_compare:nT { #1 != 1 } { \addfontfeatures{Scale=#1} }
   }
 }

\cs_new_protected:Nn \tatojo_maya_number:nn
 {
  \mbox
   {
    % choose the font and set spacing to 0.5
    \mayanumerals
    % evaluate options
    \keys_set:nn { tatojo/maya } { #1 }
    % clear the sequence containing the digits
    \seq_clear:N \l__tatojo_maya_digits_seq
    % convert the input to base 20
    \tl_set:Nx \l__tatojo_maya_converted_tl
     {
      \int_to_base:nn { #2 } { 20 }
     }
    % fill the digit sequence
    \tl_map_function:NN \l__tatojo_maya_converted_tl \__tatojo_maya_adddigit:n
    % print the digit sequence
    \bool_if:NTF \l__tatojo_maya_horizontal_bool
     {
      \seq_use:Nn \l__tatojo_maya_digits_seq { }
     }
     {
      \begin{tabular}[\l__tatojo_maya_align_tl]{@{}c@{}}
      \shortstack[c]{ \seq_use:Nn \l__tatojo_maya_digits_seq { \\ } }
      \end{tabular}
     }
   } % close the \mbox
 }

\cs_new:Nn \__tatojo_maya_adddigit:n
 {
  \seq_put_right:Nx \l__tatojo_maya_digits_seq
   {
    \tatojo_maya_digit:n { \int_from_base:nn { #1 } { 20 } }
   }
 }

\cs_new_protected:Nn \tatojo_maya_digit:n
 {
  \symbol { \int_eval:n { \c__tatojo_maya_start_int + #1 } }
 }

\ExplSyntaxOff

\begin{document}

$\mayanumber*{12414}=\mayanumber{12414}$\qquad
$\mayanumber[align=b]{12414}$\qquad
$\mayanumber[scale=0.5]{12414}$

\bigskip

\mayanumber*{123456} is \mayanumber[horizontal]{123456}

\end{document}

Remove the Path and Extension options if you have the font installed system-wise (possibly the name also).

As you see, one inputs \mayanumber{<number>} and the macros take care of the conversion. The number is converted to base 20, then each digit is converted back to base 10 in order to add it to the starting point corresponding to the Mayan digit 0.

The *-version is just a wrapper around the conversion to base 20.

The available options are

  • scale for scaling up or down the font;
  • align for the final alignment (in vertical aspect); default is c, it can be t or b
  • horizontal for printing in horizontal aspect (vertical is the default, which can also be specified for clarity)

enter image description here

egreg
  • 1,121,712
1

From this answer by @egreg,

\newfontface{\babm}{BabelStone Mayan Numerals}

\DeclareRobustCommand\mcero{%
    \mathrel{\text{\normalfont\babm\symbol{"01D2E0}}}%
}

A MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{fontspec}

\newfontface{\babm}{BabelStone Mayan Numerals}

\DeclareRobustCommand\mcero{%
    \mathrel{\text{\normalfont\babm\symbol{"01D2E0}}}%
}
\DeclareRobustCommand\muno{%
    \mathrel{\text{\normalfont\babm\symbol{"01D2E1}}}%
}
\DeclareRobustCommand\monce{%
    \mathrel{\text{\normalfont\babm\symbol{"01D2EB}}}%
}
\DeclareRobustCommand\mcatorce{%
    \mathrel{\text{\normalfont\babm\symbol{"01D2EE}}}%
}

\begin{document}

$${1\text B0\text E}_{20} = \begin{matrix}
\huge\muno\\
\huge\monce\\
\huge\mcero\\
\huge\mcatorce
\end{matrix}
$$
\end{document}

enter image description here

tatojo
  • 1,331
  • 11
  • 26
  • I just used this in a paper in spanish: "Mayan Numerals with LuaLateX", https://www.academia.edu/37478266/Numerales_mayas_con_LuaLaTeX – tatojo Sep 27 '18 at 15:44