duodecimal page number

I would like to have page numbers in my document written in base 12. Here's an MWE

\documentclass[12pt]{article} \usepackage[paperheight=1.8in, textheight=0.8in]{geometry}  \newcommand{\sirdot}{$\odot$} \newcommand{\apple}{$\Delta$}  \begin{document}  The duodecimal numbers: \begin{center} 1, 2, \ldots, 8, 9, \sirdot,  \apple, 10, 11, \ldots, 19, 1\sirdot, 1\apple, 20, 21, \ldots, \apple 9, \apple\sirdot, \apple\apple, 100 \ldots \end{center}  \setcounter{page}{10} Set page counter to 10, so this should be page \sirdot. \newpage This should be page \apple. \newpage This should be page 10.  \end{document} 

duodecimal page number

Why those particular symbols for 10 and 11? See http://www.cs.umb.edu/~eb/sam/duodecimal/ssegm.pdf.

My document is unlikely to need three digit page numbers, which may allow for inelegant hack solutions.

Extra question: \sirdot seems to appear just a little too low on the line.

Replay

With expl3 it's quite easy (and there's no limit on numbers, other than the usual 2147483647, the maximum number in TeX)

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\basetwelve}{m}
  { \duodec_convert:n { #1 } }

\tl_new:N \l_duodec_string_tl
\cs_new_protected:Npn \duodec_convert:n #1
  {
   \tl_set:Nx \l_duodec_string_tl { \int_to_base:nn { #1 } { 12 } }
   \tl_replace_all:Nnn \l_duodec_string_tl { A } { $\odot$ }
   \tl_replace_all:Nnn \l_duodec_string_tl { B } { $\Delta$ }
   \tl_use:N \l_duodec_string_tl
 }
\ExplSyntaxOff

\renewcommand{\thepage}{\basetwelve{\arabic{page}}}

\begin{document}

\ExplSyntaxOn
\prg_stepwise_inline:nnnn { 1 } { 1 } { 145 }
  { \basetwelve{#1} ~ }
\ExplSyntaxOff

\end{document}

The code is in the preamble and after it is a test for showing that the numbers are correctly produced in the requested form.

duodecimal page number

The \int_to_base:nn function produces A for 10 and B for 11, so we have to replace the letters with the symbols.

The input \basetwelve{123456} produces 5∆540.



What do we do? We define a robust command, \basetwelve, that will wrap the call to the conversion, performed by \duodec_convert:n. This command takes as input something that ultimately expands to a decimal number (for instance \arabic{page} and stores away the number converted into duodecimal form, with digits 0123456789AB, through the function \int_to_base:nn. Then we replace all A's with $\odot$ and all B's with $\Delta$ and deliver the so converted token list.

When LaTeX wants to write a page number to the .aux file, it will expand \thepage, getting \basetwelve{\arabic{page}}. Since \basetwelve is robust (all commands defined with \NewDocumentCommand are), it will be written untouched. Instead \arabic{page} will be expanded to the current page number, so what's written in the .aux file is, for instance, \basetwelve{23}. When this is used by \pageref the conversion will be performed, giving 1∆.

Here's a solution using the fmtcount package plus a new \duodecimal macro that is modelled on fmtcount's \hexadecimal. (Actually, it's an example of cargo-cult programming: I basically took the fmtcount macro set and replaced "hexa" with "duo", "16" with "12", and "65536" [16^4] with "20736" [12^4].)

\documentclass[12pt]{article}
\usepackage[paperheight=1.8in, textheight=0.8in]{geometry}

\newcommand{\sirdot}{$\odot$}
\newcommand{\apple}{$\Delta$}

\usepackage{fmtcount}

\makeatletter

\newcommand*{\@@duodecimal}[1]{\ifcase#10\or1\or2\or3\or4\or5\or
6\or7\or8\or9\or $\odot$\or $\Delta$\fi}

\newcommand*{\@duodecimal}[1]{%
\@[email protected]
\@[email protected]=5\relax
\@strctr=\@[email protected]
\whiledo{\@strctr<\[email protected]}{0\advance\@strctr by 1}%
\@strctr=20736\relax
\@[email protected]=#1\relax
\loop
\@[email protected]=\@[email protected]
\divide\@[email protected] by \@strctr
\ifthenelse{\boolean{@[email protected]}\and\(\@[email protected]=0\)\and
\(\@[email protected]>\[email protected]\)}{}{\@@duodecimal\@[email protected]}%
\ifnum\@[email protected]=0\else\@[email protected]\fi
\multiply\@[email protected] by \@strctr
\advance\@[email protected] by -\@[email protected]
\divide\@strctr by 12\relax
\advance\@[email protected] by -1\relax
\ifnum\@strctr>1
\repeat
\@@duodecimal\@[email protected]}

\let\duodecimalnum=\@duodecimal

\providecommand*{\duodecimal}[1]{%
\expandafter\protect\expandafter\@duodecimal{%
\expandafter\the\csname [email protected]#1\endcsname}}

\makeatother

\renewcommand*{\thepage}{\duodecimal{page}}

\begin{document}

The duodecimal numbers:
\begin{center}
1, 2, \ldots, 8, 9, \sirdot,  \apple, 10, 11, \ldots, 19, 1\sirdot,
1\apple, 20, 21, \ldots, \apple 9, \apple\sirdot, \apple\apple, 100 \ldots
\end{center}

\setcounter{page}{10}
Set page counter to 10, so this should be page \sirdot.
\newpage
This should be page \apple.
\newpage
This should be page 10.

\end{document}

Here's a first stab at it and it relies on the fact that you only require two-digit page numbers. As such, this solution is only good up to 144 pages:

duodecimal page number

\documentclass{article}
\usepackage[paperheight=50pt,paperwidth=5em,footskip=-10em]{geometry}%
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
\newcommand{\basetwelve}[1]{%
  \vphantom{0}\ifcase#1
    0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or\smash{\raisebox{.2ex}{$\odot$}}\or\smash{$\Delta$}%
  \fi%
}
\newcounter{duo}%
\renewcommand{\thepage}{%
  \setcounter{duo}{\value{page}}%
  \FPeval\remainder{clip(\theduo-(12*round(\theduo/12-.5:0)))}%
  \FPeval\result{clip(round(\theduo/12-.5:0))}%
  \ifnum\result=0\else\basetwelve\result\fi\basetwelve\remainder%
}
\newcommand{\npage}{\mbox{}\newpage}
\pagestyle{plain}%
\begin{document}
\npage\npage\npage\npage\npage\npage\npage\npage\npage\npage
\npage\npage\npage\npage\npage\npage\npage\npage\npage\npage
\npage\npage\npage\npage\npage\npage\npage\npage\npage\npage
\npage\npage\npage\npage\npage\npage\npage\npage\npage\npage
\end{document}

\basetwelve{<num>} works like a lookup function, returning 0,1,...,9,"10","11" based on the input values. \result contains the first digit of the page number, and \remainder the second. fp was used to perform the modulo calculations for base 12.

Height adjustments for the non-numeric symbols is done using a combination of \smash and \raisebox, as well as a \vphantom{0} for numbers smaller than 12.

geometry settings is just for this example.

There is alredy a LaTeX2e implematation for a dozenal converter, \dozens, provided by the dozenal package, which can do the job of @egregs \basetwelve:

\documentclass{article}
\usepackage{dozenal}
  \renewcommand{\x}{$\odot$}
  \renewcommand{\e}{$\Delta$}
\renewcommand{\thepage}{\dozens{\arabic{page}}}

\let\sirdot\x
\let\apple\e

\begin{document}
\setcounter{page}{10}
Set page counter to $10_{10}$, so this should be page \sirdot.
\newpage
This should be page \apple.
\newpage
This should be page 10.
\end{document}

duodecimal page number
duodecimal page number
duodecimal page number

Category: page numbering Time: 2012-06-09 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.283 (s). 12 q(s)