4

Is it possible to change the numeration base of LaTeX? Actually I am looking for base 6.

I would like this change to apply to all counters (TOC, pages, chapters..). I found this topic How can I make sure that all counters start at 0? which is almost exactly what I want but I have not a base 10 to base 6 function.

\makeatletter
\def\@arabic#1{\BASEVI\relax} 
\def\@roman#1{\romannumeral\BASEVI\relax}
\def\@Roman#1{\expandafter\@slowromancap\romannumeral\BASEVI\relax @}
\makeatother

BASEVI is just a placeholder.

To know more about the seximal system: seximal.net.

2 Answers2

5

A one liner:

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\cs_set:cpn {@arabic} #1 { \int_to_base:nn { #1 } { 6 } }
\ExplSyntaxOff

\setlength{\textheight}{2.5cm} % to keep the image small

\begin{document}

\newcounter{test}

\loop\ifnum\value{test}<100
  \arabic{test}%
  \stepcounter{test}%
  \space
\repeat

\end{document}

Every counter that's defined to use \arabic will print in base six, including page.

enter image description here

Beware: this will break all macros that abuse \the<counter> for obtaining the decimal representation of the counter instead of relying on its abstract value.

Better defining a suitable representation and choosing it for representing the counters you need.

\documentclass{article}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new:Npn \basesix_print:N #1 { \int_to_base:nn { #1 } { 6 } }
\cs_generate_variant:Nn \basesix_print:N {c}
\cs_new:Npn \basesix_start:n #1 { \basesix_print:c {c@#1} }
% user interface
\cs_new_eq:NN \basesix \basesix_start:n
% to keep \pagenumbering{basesix} happpy
\cs_new_eq:cN {@basesix} \basesix_print:N
\ExplSyntaxOff

\setlength{\textheight}{2.5cm} % to keep the image small
\pagenumbering{basesix}

\begin{document}

\setcounter{page}{6}

\newcounter{test}
\renewcommand{\thetest}{\basesix{test}}

\loop\ifnum\value{test}<100
  \thetest
  \stepcounter{test}%
  \space
\repeat

\end{document}

enter image description here

egreg
  • 1,121,712
4

enter image description here

\documentclass{article}

\usepackage{expl3}
\ExplSyntaxOn
\def\SIX#1{\expandafter\int_to_base:nn\csname c@#1\endcsname6}
\ExplSyntaxOff
\renewcommand\thesection{\SIX{section}}
\renewcommand\theenumi{\SIX{enumi}}
\begin{document}

\section{aa}

\begin{enumerate}
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\item aaa
\end{enumerate}

\section{zzz}
zz
\section{zzz}
zz
\section{zzz}
zz
\section{zzz}
zz
\section{zzz}
zz
\section{zzz}
zz

\end{document}
David Carlisle
  • 757,742