diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/bxwareki/LICENSE | 21 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/bxwareki/README.md | 176 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def | 126 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty | 520 |
4 files changed, 843 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/bxwareki/LICENSE b/Master/texmf-dist/doc/latex/bxwareki/LICENSE new file mode 100644 index 00000000000..fbe40a0146b --- /dev/null +++ b/Master/texmf-dist/doc/latex/bxwareki/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2018 Takayuki YATO (aka. "ZR") + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Master/texmf-dist/doc/latex/bxwareki/README.md b/Master/texmf-dist/doc/latex/bxwareki/README.md new file mode 100644 index 00000000000..637f814a7b7 --- /dev/null +++ b/Master/texmf-dist/doc/latex/bxwareki/README.md @@ -0,0 +1,176 @@ +BXwareki Package +================ + +LaTeX: Support for Japanese calendar + +This package provides commands to convert from the Gregorian calendar +(2018/8/28) to the Japanese rendering of the Japanese calendar (Heisei +30 nen 8 gatsu 28 nichi; actually with kanji characters). You can choose +whether the numbers are written in Western numerals or kanji numerals. + +Note that the package only deals with dates in the year 1873 or later, +where the Japanese calendar is really a Gregorian calendar with the +different notation of years. + +### System requirement + + * TeX format: LaTeX. + * TeX engine: pdfTeX, LuaTeX, XeTeX, pTeX, upTeX, ApTeX (pTeX-ng), + and NTT-jTeX. (The e-TeX extension is not needed.) + +### Installation + + - `*.sty`, `*.def` → $TEXMF/tex/latex/BXwareki + +### License + +This package is distributed under the MIT License. + + +The bxwareki Package ― main +---------------------------- + +Note: The modern (post-1873) Japanese calendar (*wareki*; 和暦) can be +regarded as a variant of Gregorian calendar where only the notation of +years differs from the original. To avoid confusion, this document refers +to the original Gregorian calendar as the *Western calendar*, which +corresponds to the Japanese term *seireki* (西暦). + +### Package Loading + + \usepackage{bxwareki} + +### Usage + +#### Conversion from the given date + + * `\warekisetdate{<year>}{<month>}{<day>}`: Converts from the specified + Western date. The result will be rendered by the commands described + at the following items, where the result for the invocation + `\warekisetdate{2018}{8}{28}` will be shown as example. + + Note: Although the Japanese calendar differs from the Western calendar + only in the notation of years, the value of months and days are still + required, since the notation of the year in which *kaigen* (改元; + change of gengo) occurs depends on months and days. + + * `\warekisettoday`: Does `\warekisetdate` with the current date. + + * Counter `warekiyear`: The year number (within the gengo); e.g. 30. + + Note: Unlike ordinary counters, the assignment to `warekiyear` by + `\warekisetdate` is *local*. Moreover, manual assignment to this + counter is not supported. + + * `\warekigengo`: The gengo in kanji, e.g. “平成”. + + * `\warekiyear`: The full notation of the year (without ‘年’), + e.g. “平成30”. + + Note: When the year number is one, the kanji ‘元’ is used instead + of the numeral ‘1’. + + * `\warekidate`: The date string, e.g. “平成30年8月28日”. + + * `\warekikanjidate`: The date string using kansuji (kanji numerals), + e.g. “平成三〇年八月二八日”. + + * `\warekijkanjidate`: The date string using “kansuji-by-reading” + (that is, kanji rendering of numbers in the Japanese language), + e.g. “平成三十年八月二十八日”. + + * `\warekicustomdate{<option>}`: The date string in the form specified + with the option. The option is a string of letters such as `wk` and + each letter means a specific setting. When the option is empty, the + date is rendered in the form “2018年8月28日” (using the Western + calendar). The available option letters are: + + - `w`: uses Japanese calendar (2018年 → 平成30年) + - `k`: uses kansuji (28 → 二八) + - `j`: uses kansuji-by-reading (28 → 二十八) + Note: Western years does not support kansuji-by-reading and thus + `k` will be applied instead (二〇一八, not 二千十八) + - `J`: variant of `j` where “ten’s multiple” kanji characters + (廿 and 卅) are employed (28 → 廿八) + - `o`: uses *imyo* (異名) for months (8月 → 葉月) + (Don’t ask me if this form is ever used in LaTeX document!) + + Note: This command is supported only on pdfLaTeX, XeLaTeX, LuaLaTeX, + upLaTeX, ApLaTeX and recent versions of pLaTeX. On other engines it + simply falls back to `\warekidate`. + + * `\WarekiIfCustomDateAvailable{<true>}{<false>}`: Tests if the command + `\warekicustomdate` is supported on the engine in use. + +#### Current date + +These commands always represent the current date, and are not affected +by `\warekisetdate` (or `\warekisettoday`). + + * `\warekitoday`: The `\warekidate` form of the current date. + * `\warekikanjitoday`: The `\warekikanjidate` form. + * `\warekijkanjitoday`: The `\warekijkanjidate` form. + +#### Inter-alphabet-kanji glues + +In quality Japanese typesetting, a thin space (*shibuaki*; 四分空き) +must be inserted between an alphabet letter and a kanji letter. This +package by default inserts a command suitable for the most prevalent +Japanese-typesetting environment for the engine in use. + + * On pLaTeX, upLaTeX and ApLaTeX: Nothing is inserted, since the engine + can automatically insert shibuaki spaces. + * On LuaLaTeX and XeLaTeX: Nothing is inserted, on the assumption that + the package for Japanese typesetting (such as LuaTeXja and xeCJK) + will automatically insert shibuaki spaces. + * On LaTeX and pdfLaTeX: `~` is inserted, on the assumption that the + CJK package is employed and `\CJKtilde` is in effect. + +On the engines with e-TeX extension, the command for shibuaki can be +changed with the following commands: + + * `\WarekiUseCustomInterGlue{<text>}`: Uses `<text>` for making shibuaki + spaces. + * `\WarekiUseNormalInterGlue`: Reverts `\WarekiUseCustomInterGlue` and + uses the normal setting. + +### Support for the kaigen planned in 2019 + +In Japan a kaigen (due to the abdication of the Emperor) is planned on +2019/05/01, but the new gengo is not yet announced. Thus in the current +version of the package, the date of the day or later is not supported +(the Western year will be printed instead). +. +This package will be updated to support the new gengo and uploaded to +CTAN, as soon as the new gengo is announced. + +### Notices for TeX programmers + + * On the engines with support for native kanji/Unicode characters + (i.e. LuaLaTeX, XeLaTeX, pLaTeX, upLaTeX, and ApLaTeX), the content + (one-level expansion) of `\wareki…date` (except `\warekicustomdate`) + and `\wareki…today` is a simple string of character tokens, unless + `\WarekiUseCustomInterGlue` is in effect. The same holds for LaTeX + and pdfLaTeX, except that each kanji character is represented by the + sequence of activated byte tokens and `~` is inserted as shibuaki + spaces. + * On the engines with native kanji/Unicode support, `\warekicustomdate` + fully expands to a simple string of character tokens (again without + `\WarekiUseCustomInterGlue`), and the situation on LaTeX and pdfLaTeX + is parallel to that described at the item above. + * The use of `\WarekiUseCustomInterGlue` does not break the full + expandability of `\wareki…date` and `\wareki…today` on the engines + with native kanji/Unicode support. + + +Revision History +---------------- + + * Version 0.3 ‹2018/09/24› + - The total rewrite. + * Version 0.2 ‹2018/04/08› + - The first public version. + +-------------------- +Takayuki YATO (aka. "ZR") +http://zrbabbler.sp.land.to/ diff --git a/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def b/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def new file mode 100644 index 00000000000..ac08ea1e031 --- /dev/null +++ b/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def @@ -0,0 +1,126 @@ +%% +%% This is file 'bxwareki-cd.def'. +%% +%% Copyright (c) 2018 Takayuki YATO (aka. "ZR") +%% GitHub: https://github.com/zr-tex8r +%% Twitter: @zr_tex8r +%% +%% This package is distributed under the MIT License. +%% + +% Note: This file must be encoded in UTF-8. + +%% file declaration +\NeedsTeXFormat{LaTeX2e} +\ProvidesFile{bxwareki-cd.def}[2018/09/24 v0.3] + +\ifbxwy@epTeXinputencoding@ok + \epTeXinputencoding utf8 +\fi + +%--------------------------------------- helpers + +%% \bxwy@burst-`>... +\let\bxwy@burst\romannumeral + +%% \bxwy@cond\ifXXX...\fi{<true>}{<false>} +\@gobbletwo\if\if \def\bxwy@cond#1\fi{% + #1\expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi} + +%% \bxwy@catch@mk...\bxwy@mk +\def\bxwy@catch@mk#1\bxwy@mk{#1} + +%--------------------------------------- kanji numerals + +%% \bxwy@Jkansuji{<number>} +% The kansuji-by-reading with use of ten-composites (廿, 卅). +% NB. Only valid in range 0..99; otherwise fallback to \bxwy@jkansuji. +\def\bxwy@Jkansuji#1{% + \expandafter\bxwy@Jkansuji@a\number#1\bxwy@mk} +\def\bxwy@Jkansuji@a#1\bxwy@mk{% + \ifnum#1<\bxwy@jk@x + \bxwy@jkansuji@a#1\bxwy@mk + \else\ifnum#1<\bxwy@jk@c + \bxwy@Jkansuji@b#1% + \else + \bxwy@jkansuji@a#1\bxwy@mk + \fi\fi} +\def\bxwy@Jkansuji@b#1#2{% + \ifcase#1\relax \or 十\or 廿\or 卅% + \else \csname bxwy@jcd/#1\endcsname 十% + \fi + \ifnum#2>\z@ \csname bxwy@jcd/#2\endcsname \fi} + +%--------------------------------------- custom date format + +%% \warekicustomdate{<options>} +% Renders the date in the form specified by the options. +% [calendar] def. seireki; w = wareki; +% [numerals] def. western numerals; k = kansuji; j = kansuji-by-reading; +% J = kansuji-by-reading, with ten-composites (廿, 卅); +% [month names] def. by numbers; o = 異名 (old month names); +% O = Izumo-style 異名 (use 神在月 instead of 神無月); +\def\warekicustomdate#1{% + \bxwy@custom@date@parse@opt{#1}\bxwy@custom@date@a} +\def\bxwy@custom@date@a#1{% + \expandafter\bxwy@custom@date@b\bxwy@date#1} +\def\bxwy@custom@date@b#1#2#3#4#5#6{% + % y,m,d,calendar,numerals,monthname + \if \ifx\warekigengo\@empty-\else#4\fi w% wareki + \warekigengo + \ifnum\c@warekiyear=\@ne 元% + \else \bxwy@custom@date@number#5\c@warekiyear + \fi + \else % seireki + \if#5-#1\bxwy@S% western + \else \bxwy@kansuji{#1}% kansuji/-j/-J + \fi + \fi + 年% + \if#6-\bxwy@custom@date@number#5{#2}月% month by number + \else \bxwy@custom@date@month#6{#2}% month name + \fi + \bxwy@custom@date@number#5{#3}日} +\def\bxwy@custom@date@number#1#2{% + \if#1k\bxwy@kansuji{#2}% kansuji + \else\if#1j\bxwy@jkansuji{#2}% kansuji-j + \else\if#1J\bxwy@Jkansuji{#2}% kansuji-J + \else % western + \bxwy@S \expandafter\bxwy@catch@mk\number#2\bxwy@mk \bxwy@S + \fi\fi\fi} +\def\bxwy@custom@date@month#1#2{% + \ifnum#2=\z@\else\ifcase#2\relax + \or 睦月\or 如月\or 弥生\or 卯月\or 皐月\or 水無月% + \or 文月\or 葉月\or 長月% + \or \if#1O神在月\else 神無月\fi + \or 霜月\or 師走% + \fi\fi} + +%% \bxwy@custom@date@parse@opt{<options>}\CScont +\def\bxwy@custom@date@parse@opt#1{% + \bxwy@cd@parse@opt@a#1\bxwy@mk---} +\def\bxwy@cd@parse@opt@a{% + \expandafter\bxwy@cd@parse@opt@b\bxwy@burst-`>} +\def\bxwy@cd@parse@opt@b#1{% + \bxwy@cond\ifx#1\bxwy@mk\fi{\bxwy@cd@parse@opt@f}{% + \expandafter\bxwy@cd@parse@opt@c\csname bxwy@cdpo@@#1\endcsname}} +\def\bxwy@cd@parse@opt@c#1{% + \bxwy@cond\ifx#1\relax\fi{\bxwy@cd@parse@opt@a}{% + \bxwy@cd@parse@opt@d#1}} +\def\bxwy@cd@parse@opt@d#1#2\bxwy@mk#3#4#5{% + \expandafter\bxwy@cd@parse@opt@e\bxwy@burst-`>#1#3#4#5{#2}} +\def\bxwy@cd@parse@opt@e#1#2#3#4{% + \bxwy@cd@parse@opt@a#4\bxwy@mk#1#2#3} +\def\bxwy@cd@parse@opt@f#1#2#3#4{% + #4{#1#2#3}} +% +\def\bxwy@cdpo@@w#1#2#3{w#2#3} +\def\bxwy@cdpo@@k#1#2#3{#1k#3} +\def\bxwy@cdpo@@j#1#2#3{#1j#3} +\def\bxwy@cdpo@@J#1#2#3{#1J#3} +\def\bxwy@cdpo@@o#1#2#3{#1#2o} +\def\bxwy@cdpo@@O#1#2#3{#1#2O} + +%--------------------------------------- all done +\endinput +%% EOF diff --git a/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty b/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty new file mode 100644 index 00000000000..2509ccf7522 --- /dev/null +++ b/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty @@ -0,0 +1,520 @@ +%% +%% This is file 'bxwareki.sty'. +%% +%% Copyright (c) 2018 Takayuki YATO (aka. "ZR") +%% GitHub: https://github.com/zr-tex8r +%% Twitter: @zr_tex8r +%% +%% This package is distributed under the MIT License. +%% + +% Note: This file is encoded entirely in us-ascii. + +%% package declaration +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{bxwareki}[2018/09/24 v0.3] + +%% preparation +\def\bxwy@pkgname{bxwareki} +\providecommand\bxDebug[1]{} + +%--------------------------------------- general + +%% unique tokens +\def\bxwy@end{\noexpand\bxwy@end@} +\def\bxwy@mt{\noexpand\bxwy@mt@} +\let\bxwy@mk\indent + +%% \bxwy@engine : engine type +%% \ifbxwy@eTeX@ok : have e-TeX extension? +%% \ifbxwy@epTeXinputencoding@ok : have \epTeXinputencoding? +\def\bxwy@next#1#2{% + \edef\bxwy@tmpa{\string#1}\edef\bxwy@tmpb{\meaning#1}% + \ifx\bxwy@tmpa\bxwy@tmpb #2\fi} +\chardef\bxwy@engine=0 % 8-bit TeX +\bxwy@next\kanjiskip {\chardef\bxwy@engine=1 }% pTeX (or upTeX) +\bxwy@next\jintercharskip{\chardef\bxwy@engine=2 }% NTT-jTeX +\bxwy@next\Omegaversion {\chardef\bxwy@engine=3 }% Aleph +\bxwy@next\XeTeXversion {\chardef\bxwy@engine=4 }% XeTeX +\bxwy@next\luatexversion {\chardef\bxwy@engine=5 }% LuaTeX +\newif\ifbxwy@eTeX@ok +\bxwy@next\eTeXversion{\bxwy@eTeX@oktrue} +\newif\ifbxwy@upTeX@ok +\bxwy@next\forcecjktoken{\bxwy@upTeX@oktrue} +\newif\ifbxwy@epTeXinputencoding@ok +\bxwy@next\epTeXinputencoding{\bxwy@epTeXinputencoding@oktrue} + +%% switch 'bxwy@customdate@ok' +% NB. It is "whether or not UTF-8 files can be safely loaded". +\newif\ifbxwy@customdate@ok +\ifcase\bxwy@engine \bxwy@customdate@oktrue % 8-bit +\or % pTeX + \ifbxwy@epTeXinputencoding@ok \bxwy@customdate@oktrue + \else\ifbxwy@upTeX@ok \bxwy@customdate@oktrue + \fi\fi +\or % jTeX +\else \bxwy@customdate@oktrue +\fi + +%% \bxwy@oncex{...} +% The once-expander, used in \edef. +%% \bxwy@twicex{...} +% The twice-expander, used in \edef. +\ifbxwy@eTeX@ok + \def\bxwy@oncex#1{\unexpanded\expandafter{#1}} + \def\bxwy@twicex#1{\unexpanded\expandafter\expandafter\expandafter{#1}} +\else + % Here it is assumed that the engine is (u)pTeX or JTeX. + \def\bxwy@oncex#1{#1} + \def\bxwy@twicex#1{#1} +\fi + +%% \bxwy@newcounter{<name>} +%% \bxwy@setcounter{<name>}{<value>} +% Declares a pseudo-counter (if not on e-TeX). +\@onlypreamble\bxwy@newcounter +\ifbxwy@eTeX@ok + \let\bxwy@newcounter\newcounter + \def\bxwy@setcounter#1#2{% assign locally + \csname c@#1\endcsname#2\relax} +\else + \def\bxwy@newcounter#1{% + \expandafter\@ifdefinable\csname c@#1\endcsname{% + \expandafter\mathchardef\csname c@#1\endcsname\z@ + \expandafter\gdef\csname the#1\expandafter\endcsname\expandafter{% + \expandafter\@arabic\csname c@#1\endcsname}}} + \def\bxwy@setcounter#1#2{% assign locally + \expandafter\mathchardef\csname c@#1\endcsname#2\relax} +\fi + +%--------------------------------------- Japanese string maker + +% The "combo-code" represents a single Japanese character and has +% the form such like: +% E698AD:662D:3E3C:f3F +% where +% - E698AD is hex dump of UTF-8 bytes; +% - 662D is hex of Unicode point; +% - 3E3C is hex dump of JIS-encoding bytes; +% - f3F is something for jTeX. + +%% \bxwy@S : inter-ascii-kanji skip +\let\bxwy@S\@empty +%% \bxwy@normal@S : the normal definition of \bxwy@S +\let\bxwy@normal@S\relax +%% \bxwy@C : Japanese character printer for JTeX +\let\bxwy@C\relax + +%% \bxwy@freeze@fragile : make fragile cs unexpandable +\let\bxwy@freeze@fragile\relax +%% \bxwy@restore@fragile : revoke \bxwy@freeze@fragile +\let\bxwy@restore@fragile\relax + +%% \bxwy@add@jchar\CS{<combo-code>} +% Adds a character with given combo-code to the macro \CS. +\@onlypreamble\bxwy@add@jchar +\def\bxwy@add@jchar#1#2{% + \begingroup + \bxwy@freeze@fragile + \def\bxwy@next##1{\xdef#1{\bxwy@oncex#1\bxwy@oncex{##1}}}% + \edef\bxwy@tmpa{#2}% + \expandafter\bxwy@add@jchar@dec\bxwy@tmpa::::\bxwy@end + \endgroup} +\@onlypreamble\bxwy@add@jchar@dec +\@onlypreamble\bxwy@add@jchar@dec@a +\@onlypreamble\bxwy@add@jchar@dec@b +% engine-dependent parts +\ifcase\bxwy@engine %8-bit + \def\bxwy@add@jchar@dec#1:#2:#3:#4:#5\bxwy@end{% + \bxwy@add@jchar@dec@a#1000000\bxwy@end} + \def\bxwy@add@jchar@dec@a#1#2#3#4#5#6#7\bxwy@end{% + \let\do\bxwy@add@jchar@dec@b + \do{#1#2}\do{#3#4}\do{#5#6}} + \def\bxwy@add@jchar@dec@b#1{% + \lccode`\~="#1\relax\lowercase{\bxwy@next{\noexpand~}}} + \def\bxwy@S{~}% \bxwy@S expands to ~, and ~ is protected. + \let\bxwy@org@tie\relax + \def\bxwy@freeze@fragile{\let\bxwy@org@tie=~\let~=\relax} + \def\bxwy@restore@fragile{\let~=\bxwy@org@tie} +\or %pTeX + \def\bxwy@add@jchar@dec#1:#2:#3:#4:#5\bxwy@end{% + \kansujichar\@ne=\jis"#3\relax \bxwy@next{\kansuji\@ne}} +\or %jTeX + \def\bxwy@add@jchar@dec#1:#2:#3:#4:#5\bxwy@end{% + \bxwy@next{\bxwy@C#4}} + \def\bxwy@C#1#2#3{% + \mbox{\csname j#1\endcsname\char"#2#3}} + \def\bxwy@@S{% standard inter-ascii-kanji skip + \hskip \ifdim\jasciikanjiskip=\z@ \fontdimen7\ja\@minus\fontdimen9\ja + \else \jasciikanjiskip \fi + \relax} + \def\bxwy@S{\bxwy@@S}% \bxwy@S expands to \bxwy@@S, which is protected. + \let\bxwy@org@@S\relax \let\bxwy@org@C\relax + \def\bxwy@freeze@fragile{% + \let\bxwy@org@@S\bxwy@@S \let\bxwy@@S\relax + \let\bxwy@org@C\bxwy@C \let\bxwy@C\relax} + \def\bxwy@restore@fragile{% + \let\bxwy@@S\bxwy@org@@S \let\bxwy@C\bxwy@org@C} +\else %Aleph/XeTeX/LuaTeX + \def\bxwy@add@jchar@dec#1:#2:#3:#4:#5\bxwy@end{% + \lccode`\Z="#2\relax \lowercase{\bxwy@next{\noexpand Z}}} +\fi +% set \bxwy@normal@S +\let\bxwy@normal@S\bxwy@S + +\ifbxwy@eTeX@ok %<*eTeX> +%%<+> \WarekiUseNormalInterGlue +% Uses the normal definition of inter-ascii-kanji skip. +\newcommand*\WarekiUseNormalInterGlue{% + \let\bxwy@S\bxwy@normal@S + \bxwy@render@all} +%%<+> \WarekiUseCustomInterGlue{<text>} +% Uses the custom definition of inter-ascii-kanji skip. +\@ifdefinable\WarekiUseCustomInterGlue{% + \def\WarekiUseCustomInterGlue#{% + \afterassignment\bxwy@render@all + \protected\def\bxwy@S}} +\fi %</eTeX> + +%--------------------------------------- Japanese words + +%% \bxwy@@meiji : kanji string 'Meiji' +\let\bxwy@@meiji\@empty +\bxwy@add@jchar\bxwy@@meiji{E6988E:660E:4C40:k67} +\bxwy@add@jchar\bxwy@@meiji{E6B2BB:6CBB:3C23:e6A} +%% \bxwy@@taisho : kanji string 'Taisho' +\let\bxwy@@taisho\@empty +\bxwy@add@jchar\bxwy@@taisho{E5A4A7:5927:4267:gE2} +\bxwy@add@jchar\bxwy@@taisho{E6ADA3:6B63:4035:fF4} +%% \bxwy@@showa : kanji string 'Showa' +\let\bxwy@@showa\@empty +\bxwy@add@jchar\bxwy@@showa{E698AD:662D:3E3C:f3F} +\bxwy@add@jchar\bxwy@@showa{E5928C:548C:4F42:l83} +%% \bxwy@@heisei : kanji string 'Heisei' +\let\bxwy@@heisei\@empty +\bxwy@add@jchar\bxwy@@heisei{E5B9B3:5E73:4A3F:jAA} +\bxwy@add@jchar\bxwy@@heisei{E68890:6210:402E:fED} +%% \bxwy@@nen : kanji for 'year' +\let\bxwy@@nen\@empty +\bxwy@add@jchar\bxwy@@nen{E5B9B4:5E74:472F:i80} +%% \bxwy@@gatsu : kanji for 'month' +\let\bxwy@@gatsu\@empty +\bxwy@add@jchar\bxwy@@gatsu{E69C88:6708:376E:cDF} +%% \bxwy@@nichi : kanji for 'day' +\let\bxwy@@nichi\@empty +\bxwy@add@jchar\bxwy@@nichi{E697A5:65E5:467C:i6F} +%% \bxwy@@gan : kanji for 'origin' +\let\bxwy@@gan\@empty +\bxwy@add@jchar\bxwy@@gan{E58583:5143:3835:d04} + +%--------------------------------------- kanji numerals + +%% \bxwy@set@jchar@digit{<n>}{<combo-code>} +\@onlypreamble\bxwy@set@jchar@digit +\def\bxwy@set@jchar@digit#1{% + \expandafter\bxwy@set@jchar@digit@a\csname bxwy@jcd/#1\endcsname} +\@onlypreamble\bxwy@set@jchar@digit@a +\def\bxwy@set@jchar@digit@a#1#2{% + \let#1\@empty \bxwy@add@jchar#1{#2}} + +%% \[bxwr@jcd/<n>] : kanji digit for n +\bxwy@set@jchar@digit{0}{E38087:3007:213B:{sy}1B} +\bxwy@set@jchar@digit{1}{E4B880:4E00:306C:a4B} +\bxwy@set@jchar@digit{2}{E4BA8C:4E8C:4673:i66} +\bxwy@set@jchar@digit{3}{E4B889:4E09:3B30:e19} +\bxwy@set@jchar@digit{4}{E59B9B:56DB:3B4D:e36} +\bxwy@set@jchar@digit{5}{E4BA94:4E94:385E:d2D} +\bxwy@set@jchar@digit{6}{E585AD:516D:4F3B:l7C} +\bxwy@set@jchar@digit{7}{E4B883:4E03:3C37:e7E} +\bxwy@set@jchar@digit{8}{E585AB:516B:482C:iDB} +\bxwy@set@jchar@digit{9}{E4B99D:4E5D:3665:c78} +\bxwy@set@jchar@digit{X}{E58D81:5341:3D3D:eE2}% ten +\bxwy@set@jchar@digit{C}{E799BE:767E:4934:j41}% hundred + +%%<+> \WarekiKansuji{<counter>} +%% \bxwy@kansuji{<number>} +% The kansuji representation of the number. +\newcommand*\WarekiKansuji[1]{% + \expandafter\bxwy@kansuji\csname c@#1\endcsname} +\def\bxwy@kansuji#1{% + \ifnum#1<\z@\else + \expandafter\bxwy@kansuji@a\number#1\bxwy@mk + \fi} +\def\bxwy@kansuji@a#1{% + \ifx#1\bxwy@mk\else + \bxwy@twicex{\csname bxwy@jcd/#1\endcsname}% + \expandafter\bxwy@kansuji@a + \fi} + +%% \bxwy@jkansuji{<number>} +% The kansuji-by-reading representation of the number. +% NB. Only valid in range 0..999; otherwise fallback to \bxwy@kansuji. +\def\bxwy@jkansuji#1{% + \expandafter\bxwy@jkansuji@a\number#1\bxwy@mk} +\chardef\bxwy@jk@x=10 +\chardef\bxwy@jk@c=100 +\def\bxwy@jkansuji@a#1\bxwy@mk{% + \ifnum#1<\z@ + \bxwy@kansuji{#1}% + \else\ifnum#1<\bxwy@jk@x + \bxwy@twicex{\csname bxwy@jcd/#1\endcsname}% + \else\ifnum#1<\bxwy@jk@c + \bxwy@jkansuji@b0#1% + \else\ifnum#1<\@m + \bxwy@jkansuji@b#1% + \else + \bxwy@kansuji@a#1\bxwy@mk + \fi\fi\fi\fi} +\def\bxwy@jkansuji@b#1#2#3{% + \ifnum#1>\@ne \bxwy@twicex{\csname bxwy@jcd/#1\endcsname}\fi + \ifnum#1>\z@ \bxwy@twicex{\csname bxwy@jcd/C\endcsname}\fi + \ifnum#2>\@ne \bxwy@twicex{\csname bxwy@jcd/#2\endcsname}\fi + \ifnum#2>\z@ \bxwy@twicex{\csname bxwy@jcd/X\endcsname}\fi + \ifnum#3>\z@ \bxwy@twicex{\csname bxwy@jcd/#3\endcsname}\fi} + +%--------------------------------------- load the new gengo + +%% \bxwy@new@gengo@file +% The external data file for the new gengo. +\def\bxwy@new@gengo@file{bxwareki2019.def} + +%% \bxwy@new@gengo +% The kanji string for the new gengo if available; otherwise empty. +\let\bxwy@new@gengo\@empty + +%% read the file +\endlinechar\m@ne +\openin\@inputcheck=\bxwy@new@gengo@file\relax +\ifeof\@inputcheck\else % if available + \read\@inputcheck to\bxwy@tmpa + \ifeof\@inputcheck\else + \edef\bxwy@next{\noexpand\bxwy@new@gengo{\bxwy@tmpa}} + \expandafter\bxwy@add@jchar\bxwy@next + \read\@inputcheck to\bxwy@tmpa + \ifeof\@inputcheck + \global\let\bxwy@new@gengo\@empty + \else + \edef\bxwy@next{\noexpand\bxwy@new@gengo{\bxwy@tmpa}} + \expandafter\bxwy@add@jchar\bxwy@next + \fi + \fi +\fi +\endlinechar=13 % + +%--------------------------------------- calculate wareki year + +%% errors +\def\bxwy@err@ivnum#1{% + \PackageError\bxwy@pkgname + {Bad number form: #1}{\@ehc}} +\def\bxwy@err@ivrng#1#2#3#4{% + \PackageError\bxwy@pkgname + {The #4 value #1 is out of range (#2..#3)}{\@ehc}} + +%% variables +\let\bxwy@g@gengo\relax +\let\bxwy@g@year\relax +\let\bxwy@g@date\relax + +%% \bxwy@assign@date{<year>}{<month>}{<day>} +\def\bxwy@assign@date#1#2#3{% + \bxwy@assign@date@a\year {#1}{0}{9999}{year}% + \bxwy@assign@date@a\month{#2}{1}{99}{}% + \bxwy@assign@date@a\day {#3}{1}{99}{}} +\def\bxwy@assign@date@a#1#2#3#4#5{% + \afterassignment\bxwy@assign@date@b\@tempcnta=#2\bxwy@mk{#2}% + \@tempswatrue + \edef\bxwy@tmpb{\the\@tempcnta}% + \ifnum#3>\@tempcnta \@tempswafalse \@tempcnta#3\relax \fi + \ifnum#4<\@tempcnta \@tempswafalse \@tempcnta#4\relax \fi + \if@tempswa\else \ifx\bxwy@mt#5\bxwy@mt\else + \bxwy@err@ivrng\bxwy@tmpb{#3}{#4}{#5}% + \fi\fi + #1=\ifnum\@tempcnta=\z@ \@ne \else \@tempcnta \fi} +\def\bxwy@assign@date@b#1\bxwy@mk#2{% + \ifx\bxwy@mk#1\bxwy@mk\else + \@tempcnta\z@ + \bxwy@err@ivnum{#2}% + \fi} + +%% \bxwy@calc@wareki@year +% Sets \bxwy@g@gengo and \bxwy@g@year. +\def\bxwy@calc@wareki@year{% + \@tempcnta=\the\year\two@digits\month\two@digits\day\relax + \let\bxwy@tmpb\@empty \@tempcntb\year + \ifnum\@tempcnta<18730101 % ancient times (non-Gregorian) + \else\ifnum\@tempcnta<19120730 % meiji era + \let\bxwy@tmpb\bxwy@@meiji + \advance\@tempcntb-1867\relax + \else\ifnum\@tempcnta<19261225 % taisho era + \let\bxwy@tmpb\bxwy@@taisho + \advance\@tempcntb-1911\relax + \else\ifnum\@tempcnta<19890108 % showa era + \let\bxwy@tmpb\bxwy@@showa + \advance\@tempcntb-1925\relax + \else\ifnum\@tempcnta<20190501 % heisei era + \let\bxwy@tmpb\bxwy@@heisei + \advance\@tempcntb-1988\relax + \else % the new era + \ifx\bxwy@new@gengo\@empty\else + \let\bxwy@tmpb\bxwy@new@gengo + \advance\@tempcntb-2018\relax + \fi + \fi\fi\fi\fi\fi + % + \global\let\bxwy@g@gengo\bxwy@tmpb + \xdef\bxwy@g@year{\the\@tempcntb}% + \xdef\bxwy@g@date{{\the\year}{\the\month}{\the\day}}} + +%--------------------------------------- render wareki date + +%% \bxwy@render@for\CSIdate\CSIgengo\CSIyear +% \CSOyear\CSOdate\CSOkanjidate\CSOjkanjidate +\def\bxwy@render@for{% + \expandafter\bxwy@render@for@a} +\def\bxwy@render@for@a#1#2#3#4#5#6#7#8#9{% + %y,m,d,Igengo,Iyear,Oyaer,Odate,Okanjidate,Ojkanjidate + \bxwy@freeze@fragile + % \CSOyear + \edef#6{% + \ifx#4\@empty \number#1%(y) + \else + \bxwy@oncex{#4}%(\CSIgengo) + \ifnum#5=\@ne \bxwy@oncex{\bxwy@@gan}% + \else \bxwy@S\number#5%(\CSIyear) + \fi + \fi}% + % \CSOdate + \edef#7{% + \bxwy@oncex{#6}%(\CSOyear) + \ifx#4\@empty \bxwy@S + \else\ifnum#5=\@ne %nix + \else \bxwy@S + \fi\fi + \bxwy@oncex{\bxwy@@nen}% + \bxwy@S#2\bxwy@S \bxwy@oncex{\bxwy@@gatsu}%(m) + \bxwy@S#3\bxwy@S \bxwy@oncex{\bxwy@@nichi}}%(d) + % \CSOkanjidate + \edef#8{% + \ifx#4\@empty \bxwy@kansuji{#1}%(y) + \else + \bxwy@oncex{#4}%(\CSIgengo) + \ifnum#5=\@ne \bxwy@oncex{\bxwy@@gan}% + \else \bxwy@kansuji{#5}% + \fi + \fi + \bxwy@oncex{\bxwy@@nen}% + \bxwy@kansuji{#2}\bxwy@oncex{\bxwy@@gatsu}%(m) + \bxwy@kansuji{#3}\bxwy@oncex{\bxwy@@nichi}}%(d) + % \CSOjkanjidate + \edef#9{% + \ifx#4\@empty \bxwy@jkansuji{#1}%(y) + \else + \bxwy@oncex{#4}%(\CSIgengo) + \ifnum#5=\@ne \bxwy@oncex{\bxwy@@gan}% + \else \bxwy@jkansuji{#5}% + \fi + \fi + \bxwy@oncex{\bxwy@@nen}% + \bxwy@jkansuji{#2}\bxwy@oncex{\bxwy@@gatsu}%(m) + \bxwy@jkansuji{#3}\bxwy@oncex{\bxwy@@nichi}}%(d) + % done + \bxwy@restore@fragile} + +%% \bxwy@render@date +\def\bxwy@render@date{% + \bxwy@render@for\bxwy@date\warekigengo\c@warekiyear + \warekiyear\warekidate\warekikanjidate\warekijkanjidate} +%% \bxwy@render@today +\def\bxwy@render@today{% + \bxwy@render@for\bxwy@today@date\bxwy@today@gengo\bxwy@today@year + \bxwy@today@yearstr\warekitoday\warekikanjitoday\warekijkanjitoday} +%% \bxwy@render@all +\def\bxwy@render@all{% + \bxwy@render@date + \bxwy@render@today} + +%--------------------------------------- user interface + +%% variables +\let\bxwy@date\relax +\let\bxwy@today@date\relax +\let\bxwy@today@gengo\relax +\let\bxwy@today@year\relax +\let\bxwy@today@yearstr\relax + +%%<*> counter 'warekiyear' : number of wareki year +\bxwy@newcounter{warekiyear} +%%<*> \warekigengo : kanji string of the current gengo +\newcommand*\warekigengo{} +%%<*> \warekiyear : string of the wareki year +\newcommand*\warekiyear{} +%%<*> \warekidate : string of the wareki date +\newcommand*\warekidate{} +%%<*> \warekikanjidate : string of the wareki date (kansuji) +\newcommand*\warekikanjidate{} +%%<*> \warekijkanjidate : string of the wareki date (kansuji-by-reading) +\newcommand*\warekijkanjidate{} +%%<*> \warekitoday : \warekidate string of today +\newcommand*\warekitoday{} +%%<*> \warekikanjitoday : \warekikanjidate string of today +\newcommand*\warekikanjitoday{} +%%<*> \warekijkanjitoday : \warekijkanjidate string of today +\newcommand*\warekijkanjitoday{} + +%%<*> \warekisetdate{<year>}{<month>}{<day>} +\newcommand*\warekisetdate[3]{% + \begingroup + \bxwy@assign@date{#1}{#2}{#3}% + \bxwy@calc@wareki@year + \endgroup + \let\warekigengo\bxwy@g@gengo + \bxwy@setcounter{warekiyear}{\bxwy@g@year}% + \let\bxwy@date\bxwy@g@date + \bxwy@render@date} + +%%<*> \warekisettoday +\newcommand*\warekisettoday{% + \warekisetdate\year\month\day} + +%%<+> \WarekiSetToday +\newcommand*\WarekiSetToday{% + \begingroup + \bxwy@assign@date\year\month\day + \bxwy@calc@wareki@year + \endgroup + \let\bxwy@today@gengo\bxwy@g@gengo + \let\bxwy@today@year\bxwy@g@year + \let\bxwy@today@date\bxwy@g@date + \bxwy@render@today} + +%%<+> WarekiIfCustomDateAvailable{<true>}{<false>} +\newcommand*\WarekiIfCustomDateAvailable{% + \ifbxwy@customdate@ok \expandafter\@firstoftwo + \else \expandafter\@secondoftwo + \fi} + +%%<*> \warekicustomdate +\newcommand*\warekicustomdate[1]{% + \warekidate}% fallback + +%--------------------------------------- start up + +%% load submodules +\ifbxwy@customdate@ok + \input{bxwareki-cd.def} +\fi + +%% set 'date' to today +\warekisettoday +% copy 'date' to 'today' +\let\bxwy@today@gengo\warekigengo +\edef\bxwy@today@year{\the\c@warekiyear} +\let\bxwy@today@date\bxwy@date +\let\warekitoday\warekidate +\let\warekikanjitoday\warekikanjidate +\let\warekijkanjitoday\warekijkanjidate + +%--------------------------------------- all done +\endinput +%% EOF |