Created
November 30, 2012 14:51
-
-
Save zr-tex8r/4176211 to your computer and use it in GitHub Desktop.
LaTeX:「えるたそ」パッケージ:Lua から TeX への書き換えの例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- eltaso.lua | |
-- alpha_name : アルファベットの日本語読みの仮名表記 | |
alpha_name = { | |
--※ Luaは配列添字を普通は1から始めるので, 添字ゼロの要素を | |
-- 別に指定している. | |
[0] = "ぜっと", -- alpha_name[0] は「ぜっと」 | |
"えー", "びー", "しー", "でー", "いー", "えふ", "じー", | |
"えいち", "あい", "じぇー", "けー", "える", "えむ", "えぬ", | |
"おー", "ぴー", "きゅー", "あーる", "えす", "てぃー", "ゆー", | |
"ぶい", "だぶりゅー", "えっくす", "わい" | |
-- alpha_name[1] は「えー」, …… | |
} | |
-- digit : 漢数字(1~9) | |
digit = { | |
[0] = "", -- ゼロを空文字列にしておく | |
"一", "二", "三", "四", "五", "六", "七", "八", "九" | |
} | |
-- knumeral(n) : 整数n(1~9999)の漢数字表記 | |
function knumeral(n) | |
-- 整数nを4桁の十進表記で表し, それを文字毎に分割する | |
-- n=123 なら '0', '1', '2', '3' となる | |
local dm, dc, dx, di = | |
("%04d"):format(n):match("^(.)(.)(.)(.)$") | |
local km = knum_pos(dm, "千") | |
local kc = knum_pos(dc, "百") | |
local kx = knum_pos(dx, "十") | |
return km .. kc .. kx .. digit[tonumber(di)] | |
end | |
function knum_pos(d, u) | |
d = tonumber(d) | |
if d == 0 then return "" -- 0×百 は無出力 | |
elseif d == 1 then return u -- 1×百 は「百」 | |
else return digit[d] .. u -- 2×百 は「二百」 | |
end | |
end | |
-- eltaso_name(n) : 整数n(1~9999)に対する「えるたそ名」 | |
function eltaso_name(n) | |
return knumeral(n) .. "反田" .. alpha_name[n % 26] | |
end | |
-- eltaso_name(n) : 整数n(1~9999の範囲)に対して, 1からnの各整数 | |
-- に対する「えるたそ名」を出力する. | |
function eltaso(n) | |
if n > 9999 then n = 9999 end | |
for j = 1, n do | |
print(eltaso_name(j)) | |
end | |
end | |
-------- メイン | |
eltaso(1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% tceltaso.sty | |
\NeedsTeXFormat{LaTeX2e} | |
\ProvidesPackage{tceltaso} | |
%% 変数定義 | |
%(整数型) | |
\newcount\tclt@max | |
\newcount\tclt@j | |
\newcount\tclt@k | |
\newcount\tclt@ires % 戻り値 | |
%(文字列型) | |
%\tclt@dm / \tclt@dc / \tclt@dx / \tclt@di | |
%\tclt@km / \tclt@kc / \tclt@kx | |
%\tclt@x | |
%\tclt@sres % 戻り値 | |
%(配列型) | |
%\tclt@alpha@name/* | |
%\tclt@digit/* | |
%% \tclt@nameedef | |
\def\tclt@nameedef#1{\expandafter\edef\csname#1\endcsname} | |
%% \tclt@alpha@name/* : アルファベットの日本語読みの仮名表記 | |
\tclt@j=0 | |
\@for\tclt@x:=% | |
ぜっと,% | |
えー,びー,しー,でー,いー,えふ,じー,% | |
えいち,あい,じぇー,けー,える,えむ,えぬ,% | |
おー,ぴー,きゅー,あーる,えす,てぃー,ゆー,% | |
ぶい,だぶりゅー,えっくす,わい% | |
\do{% | |
\tclt@nameedef{tclt@alpha@name/\the\tclt@j}{\tclt@x}% | |
\advance\tclt@j 1 | |
} | |
%% \tclt@digit/* : 漢数字(1~9) | |
\tclt@j=0 | |
\@for\tclt@x:=,一,二,三,四,五,六,七,八,九\do{% | |
\tclt@nameedef{tclt@digit/\the\tclt@j}{\tclt@x}% | |
\advance\tclt@j 1 | |
} | |
%% \tclt@knumeral{<整数n>} | |
% 整数n(1~9999)の漢数字表記. | |
\def\tclt@knumeral#1{% | |
\tclt@split@digit{#1}% | |
% \edef\tclt@km{\tclt@sres} でもよいが \let が使える | |
\tclt@knum@pos{\tclt@dm}{千}\let\tclt@km\tclt@sres | |
\tclt@knum@pos{\tclt@dc}{百}\let\tclt@kc\tclt@sres | |
\tclt@knum@pos{\tclt@dx}{十}\let\tclt@kx\tclt@sres | |
\edef\tclt@sres{\tclt@km\tclt@kc\tclt@kx\@nameuse{tclt@digit/\tclt@di}}% | |
} | |
\def\tclt@split@digit#1{% | |
\edef\tclt@x{\noexpand\tclt@split@digit@a\the\tclt@j% | |
\noexpand\tclt@nil}% | |
\tclt@x | |
} | |
\def\tclt@split@digit@a#1\tclt@nil{% | |
\tclt@split@digit@b#1/000\tclt@nil | |
} | |
\def\tclt@split@digit@b#1#2#3#4#5#6\tclt@nil{% | |
\tclt@split@digit@c#1#2#3#4#5\tclt@nil | |
} | |
\def\tclt@split@digit@c#1/#2\tclt@nil{% | |
\tclt@split@digit@d#2#1% | |
} | |
\def\tclt@split@digit@d#1#2#3#4{% | |
\def\tclt@dm{#1}% | |
\def\tclt@dc{#2}% | |
\def\tclt@dx{#3}% | |
\def\tclt@di{#4}% | |
} | |
\def\tclt@knum@pos#1#2{% | |
\ifnum#1=0 \def\tclt@sres{}% | |
\else\ifnum#1=1 \def\tclt@sres{#2}% | |
\else \edef\tclt@sres{\@nameuse{tclt@digit/#1}#2}% | |
\fi\fi | |
} | |
%% \tclt@eltaso@name{<整数n>} | |
% 整数n(1~9999)に対する「えるたそ名」. | |
\def\tclt@eltaso@name#1{% | |
\tclt@knumeral{#1}% | |
\tclt@remainder{#1}{26}% | |
\edef\tclt@sres{\tclt@sres 反田\@nameuse{tclt@alpha@name/\the\tclt@ires}}% | |
} | |
\def\tclt@remainder#1#2{% | |
\tclt@k=#1\relax | |
\divide\tclt@k#2\relax | |
\multiply\tclt@k-#2\relax | |
\advance\tclt@k#1\relax | |
\tclt@ires=\tclt@k | |
} | |
%%(公開) \eltaso{<整数n>} | |
% 整数n(1~9999の範囲)に対して, 1からnの各整数 | |
% に対する「えるたそ名」を出力する. | |
\newcommand*\eltaso[1]{% | |
\tclt@max=#1\relax | |
\ifnum\tclt@max>9999 \tclt@max=9999 \fi | |
\par | |
\tclt@j=0 | |
\@whilenum\tclt@j<\tclt@max \do{% | |
\advance\tclt@j 1 | |
\tclt@eltaso@name{\tclt@j}% | |
\tclt@sres\par | |
}% | |
} | |
\endinput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[a4paper]{jsarticle} | |
\usepackage{tceltaso} | |
\begin{document} | |
\eltaso{1000} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment