Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r zr-tex8r/grcnum.tex
Created Dec 15, 2018

Embed
What would you like to do?
LaTeX: TeXでもイオニア式記数法したい件
\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmainfont{GentiumPlus}
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN
%---------------------------------------補助マクロ
%% ユニークトークン
% \my@nil : 値がないことを表す.
% ※デバッグの便宜のため保護付にする.
\protected\def\my@nil{\my@nil@}
% \my@mt : \my@if@empty 専用.
\def\my@mt{\my@mt@}
% \my@b : リストの空判定のため.
\def\my@b{\my@b@}
% \my@mk : 展開不能なマーカトークン.
% ※"ユニーク"ではないので, 専らマクロ引数の区切りトークンとして使う.
\let\my@mk\indent
%% \my@cond\ifXXX...\fi{<真>}{<偽>}
% \ifXXX... の判定結果により<真>と<偽>の何れかに展開される.
% TeXのif-トークンを末尾呼出で使うための機構.
\@gobbletwo\if\if \def\my@cond#1\fi{%
#1\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}
%% \my@if@empty{<入力>}{<真>}{<偽>}
% 入力が空であるかを判定する.
\def\my@if@empty#1{%
\my@cond\ifx\my@mt#1\my@mt\fi}
%% \my@iexpanded{<トークン列>}
% edef中で一回展開の結果を置く.
\def\my@iexpanded#1{%
\unexpanded\expandafter{#1}}
%---------------------------------------継続渡しの機構
%% \my@return{<値v>}{<継続>}
% 継続渡しの恒等写像関数.
% ※関数の中で値を返すのに用いる.
\def\my@return#1#2{#2{#1}}
%% \my@get{<値v>}
% 恒等写像のマクロ.
% ※継続渡しの一連の計算の結果を取得するのに用いる.
\def\my@get#1{#1}
%% \my@num@eval{<整数式>}{<継続>}
% 整数式の評価結果を返す.
\def\my@num@eval#1{%
\expandafter\my@num@eval@a\the\numexpr#1\my@mk}
\def\my@num@eval@a#1\my@mk{\my@return{#1}}
%% \my@expand{<トークン列>}{<継続>}
% 一回展開する.
\def\my@expand#1{%
\expandafter\my@return\expandafter{#1}}
%% \my@unpack{<リスト>}{<継続>}
% リストの要素を順に返す多値関数.
\def\my@unpack#1#2{#2#1}
%% \my@pack@two{<値x>}{<値y>}{<継続>}
% xとyからなるリストを返す.
\def\my@pack@two#1#2{\my@return{{#1}{#2}}}
%% \my@compose{<継続のリスト>}{<値>}{<継続>}
% 継続の"合成"みたいなやつ.
\def\my@compose#1#2{\my@return{#2}#1}
%---------------------------------------Listモジュールの関数
%% \my@map{<関数f>}{<リストxs>}{<継続>}
\def\my@map#1#2{%
\my@map@a{#1}{}#2\my@b\my@mk}
\def\my@map@a#1#2#3#4\my@mk{%
\my@cond\ifx\my@b#3\fi{\my@return{#2}}{%else
#1{#3}{\my@map@b{#1}{#2}{#4}}}}
\def\my@map@b#1#2#3#4{%
\my@map@a{#1}{#2{#4}}#3\my@mk}
%% \my@mapi{<関数f>}{<リストxs>}{<継続>}
\def\my@mapi#1#2{%
\my@mapi@a{#1}{}{0}#2\my@b\my@mk}
\def\my@mapi@a#1#2#3#4#5\my@mk{%
\my@cond\ifx\my@b#4\fi{\my@return{#2}}{%else
#1{#3}{#4}{\my@num@eval{#3+1}{\my@mapi@b{#1}{#2}{#5}}}}}
\def\my@mapi@b#1#2#3#4#5{%
\my@mapi@a{#1}{#2{#5}}{#4}#3\my@mk}
%% \my@nth{<整数n>}{<リストxs>}{<継続>}
\def\my@nth#1{%
\my@num@eval{#1}{\my@nth@a}}
\def\my@nth@a#1#2{%
\my@nth@b{#1}#2\my@b\my@mk}
\def\my@nth@b#1#2#3\my@mk{%
\my@cond\ifx\my@b#2\fi{\my@return{\my@nil}}{%else
\my@cond\ifnum#1=\z@\fi{\my@return{#2}}{%else
\my@num@eval{#1-1}{\my@nth@c{#3}}}}}
\def\my@nth@c#1#2{%
\my@nth@b{#2}#1\my@mk}
%% \my@reverse{<リストxs>}{<継続>}
\def\my@reverse#1{%
\my@reverse@a{}#1\my@b\my@mk}
\def\my@reverse@a#1#2#3\my@mk{%
\my@cond\ifx\my@b#2\fi{\my@return{#1}}{%else
\my@reverse@a{{#2}#1}#3\my@mk}}
%---------------------------------------ユーティリティー関数
%% \my@apply@non@empty{<関数f>}{<値s>}{<継続>}
\def\my@apply@non@empty#1#2{%
\my@if@empty{#2}{\my@return{}}{#1{#2}}}
%% \my@zip{<リストxs>}{<リストys>}{<継続>}
\def\my@zip#1#2{%
\my@zip@a#1\my@b\my@mk#2\my@b\my@mk{}}
\def\my@zip@a#1#2\my@mk#3#4\my@mk#5{%
\my@cond\ifx\my@b#1\fi{\my@return{#5}}{%else
\my@cond\ifx\my@b#3\fi{\my@return{#5}}{%else
\my@zip@a#2\my@mk#4\my@mk{#5{{#1}{#3}}}}}}
%% \my@split@by{<整数n>}{<リストys>}{<継続>}
\def\my@split@by#1{%
\my@num@eval{#1}{\my@split@by@a}}
\def\my@split@by@a#1#2{%
\my@split@by@b{#1}{}{}{#1}#2\my@b\my@mk}
\def\my@split@by@b#1#2#3#4#5#6\my@mk{%
\my@cond\ifx\my@b#5\fi{\my@return{#2{#3}}}{%else
\my@cond\ifnum#4=\z@\fi{\my@split@by@b{#1}{#2{#3}}{}{#1}{#5}#6\my@mk}{%
\my@num@eval{#4-1}{\my@split@by@c{#1}{#2}{#3}{#5}{#6}}}}}
\def\my@split@by@c#1#2#3#4#5#6{%
\my@split@by@b{#1}{#2}{#3{#4}}{#6}#5\my@mk}
%% \my@repeat{<整数n>}{<リストxs>}{<継続>}
\def\my@repeat#1{%
\my@num@eval{#1}{\my@repeat@a}}
\def\my@repeat@a#1#2{%
\my@repeat@b{#1}{#2}{}}
\def\my@repeat@b#1#2#3{%
\my@cond\ifnum#1=\z@\fi{\my@return{#3}}{%else
\my@num@eval{#1-1}{\my@repeat@c{#2}{#3}}}}
\def\my@repeat@c#1#2#3{%
\my@repeat@b{#3}{#1}{#2#1}}
%% \my@concat@maybe{<リストxs>}{<継続>}
\def\my@concat@maybe#1{%
\my@concat@maybe@a{}#1\my@b\my@mk}
\def\my@concat@maybe@a#1#2#3\my@mk{%
\my@cond\ifx\my@b#2\fi{\my@return{#1}}{%else
\my@cond\ifx\my@nil#2\fi{\my@concat@maybe@a{#1}#3\my@mk}{%else
\my@concat@maybe@a{#1{#2}}#3\my@mk}}}
%% \my@intersparse{<値c>}{<リストxs>}{<継続>}
\def\my@intersparse#1#2{%
\my@if@empty{#2}{\my@return{}}{%else
\my@intersparse@a{#1}#2\my@b\my@mk}}
\def\my@intersparse@a#1#2{%
\my@intersparse@b{#1}{{#2}}}
\def\my@intersparse@b#1#2#3#4\my@mk{%
\my@cond\ifx\my@b#3\fi{\my@return{#2}}{%else
\my@intersparse@b{#1}{#2{#1}{#3}}#4\my@mk}}
%% \my@implode{<リストxs>}{<継続>}
% リストの各々の文字列を連接した文字列.
\def\my@implode#1{%
\my@implode@a{}#1\my@b\my@mk}
\def\my@implode@a#1#2#3\my@mk{%
\my@cond\ifx\my@b#2\fi{\my@return{#1}}{%else
\my@implode@a{#1#2}#3\my@mk}}
%---------------------------------------1,0000未満の表記
%% 定数
\def\my@s@keraia{ʹ}
\def\my@s@gnls{͵}
\def\my@ones{{}{α}{β}{γ}{δ}{ε}{ϛ}{ζ}{η}{θ}}
\def\my@tens{{}{ι}{κ}{λ}{μ}{ν}{ξ}{ο}{π}{ϟ}}
\def\my@hundreds{{}{ρ}{σ}{τ}{υ}{φ}{χ}{ψ}{ω}{ϡ}}
%% \my@thousands
\def\my@tmpa#1{\my@expand{\my@s@gnls#1}}
\my@expand{\my@ones}{\my@map{\my@apply@non@empty{\my@tmpa}}}{%
\def\my@thousands}
%% \my@number@symbols
\edef\my@number@symbols{%
{\my@iexpanded{\my@ones}}{\my@iexpanded{\my@tens}}%
{\my@iexpanded{\my@hundreds}}{\my@iexpanded{\my@thousands}}}
%% \my@simple@digits{<リストxs>}{<継続>}
\def\my@simple@digits#1{%
\my@expand{\my@number@symbols}{\my@zip{#1}}{\my@reverse}{%
\my@map{\my@compose{{\my@unpack}{\my@nth}}}}{\my@implode}}
%%<*> \greeknumber{<整数n>}
\newcommand*{\greeknumber}[1]{%
\my@num@eval{#1}{\my@reverse}{\my@simple@digits}{%
\my@greeknumber@a}{\my@get}}
\def\my@greeknumber@a#1{%
\my@expand{\my@s@keraia}{\my@pack@two{#1}}{\my@implode}}
%---------------------------------------おしまい
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END
\newcommand*{\Test}[1]{%
#1 = \greeknumber{#1}}
\begin{document}
\begin{itemize}
\item\Test{1}
\item\Test{2}
\item\Test{3}
\item\Test{5}
\item\Test{8}
\item\Test{13}
\item\Test{21}
\item\Test{34}
\item\Test{55}
\item\Test{89}
\item\Test{144}
\item\Test{233}
\item\Test{377}
\item\Test{610}
\item\Test{987}
\item\Test{1597}
\item\Test{2584}
\item\Test{4181}
\item\Test{6765}
\end{itemize}
\end{document}
@zr-tex8r

This comment has been minimized.

Copy link
Owner Author

zr-tex8r commented Dec 15, 2018

記事:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.