diff options
Diffstat (limited to 'language/japanese/BX/bxwareki/bxwareki.sty')
-rw-r--r-- | language/japanese/BX/bxwareki/bxwareki.sty | 110 |
1 files changed, 94 insertions, 16 deletions
diff --git a/language/japanese/BX/bxwareki/bxwareki.sty b/language/japanese/BX/bxwareki/bxwareki.sty index d3dab98aca..f21d77a4ab 100644 --- a/language/japanese/BX/bxwareki/bxwareki.sty +++ b/language/japanese/BX/bxwareki/bxwareki.sty @@ -1,7 +1,7 @@ %% %% This is file 'bxwareki.sty'. %% -%% Copyright (c) 2018,2019 Takayuki YATO (aka. "ZR") +%% Copyright (c) 2018-2023 Takayuki YATO (aka. "ZR") %% GitHub: https://github.com/zr-tex8r %% Twitter: @zr_tex8r %% @@ -12,7 +12,7 @@ %% package declaration \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{bxwareki}[2019/06/01 v0.6] +\ProvidesPackage{bxwareki}[2023/07/07 v0.7] %% preparation \def\bxwy@pkgname{bxwareki} @@ -34,11 +34,18 @@ \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 +\bxwy@next\Omegaversion {\chardef\bxwy@engine=4 }% Omega +\bxwy@next\XeTeXversion {\chardef\bxwy@engine=5 }% XeTeX +\bxwy@next\luatexversion {\chardef\bxwy@engine=6 }% LuaTeX \newif\ifbxwy@eTeX@ok \bxwy@next\eTeXversion{\bxwy@eTeX@oktrue} +% if non-e-TeX and non-kanji-aware then fallback +\ifbxwy@eTeX@ok\else \ifnum\bxwy@engine=0 + \chardef\bxwy@engine=3 % fallback +\fi\fi +\ifx\WarekiForceFallback\@undefined\else + \chardef\bxwy@engine=3 +\fi \newif\ifbxwy@upTeX@ok \bxwy@next\forcecjktoken{\bxwy@upTeX@oktrue} \newif\ifbxwy@epTeXinputencoding@ok @@ -53,6 +60,7 @@ \else\ifbxwy@upTeX@ok \bxwy@customdate@oktrue \fi\fi \or % jTeX +\or % fallback \else \bxwy@customdate@oktrue \fi @@ -64,7 +72,7 @@ \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. + % pTeX/JTeX/Omega/fallback \def\bxwy@oncex#1{#1} \def\bxwy@twicex#1{#1} \fi @@ -88,6 +96,8 @@ \fi %--------------------------------------- options +% Note: This package will never have ordinary options. +% If it has options, they will be used only in special workflow. %% 'download' \DeclareOption{download2019}{}% now no-op @@ -111,6 +121,10 @@ \let\bxwy@normal@S\relax %% \bxwy@C : Japanese character printer for JTeX \let\bxwy@C\relax +%% \bxwy@U : Japanese character printer for fallback mode +\let\bxwy@U\relax +%% \bxwy@normal@U : the normal definition of \bxwy@U +\def\bxwy@normal@U#1{?} %% \bxwy@freeze@fragile : make fragile cs unexpandable \let\bxwy@freeze@fragile\relax @@ -162,27 +176,61 @@ \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 +\or %fallback + \def\bxwy@add@jchar@dec#1:#2:#3:#4:#5\bxwy@end{% + \bxwy@next{\bxwy@U{#2}}} + \def\bxwy@C#1#2#3{% + \mbox{\csname j#1\endcsname\char"#2#3}} + \def\bxwy@S{~} + \let\bxwy@org@tie\relax + \def\bxwy@freeze@fragile{% + \let\bxwy@org@U\bxwy@U \let\bxwy@U\relax + \let\bxwy@org@tie=~\let~=\relax} + \def\bxwy@restore@fragile{% + \let~=\bxwy@org@tie \let\bxwy@U\bxwy@org@U} +\else %Omega/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. +%--------------------------------------- Inter-ascii-kanji spaces + +%%<*> \WarekiUseNormalInterGlue +% Uses the normal definition of inter-ascii-kanji space. \newcommand*\WarekiUseNormalInterGlue{% \let\bxwy@S\bxwy@normal@S \bxwy@render@all} -%%<+> \WarekiUseCustomInterGlue{<text>} -% Uses the custom definition of inter-ascii-kanji skip. +%%<*> \WarekiUseNoInterGlue +% Disables inter-ascii-kanji skip. +\newcommand*\WarekiUseNoInterGlue{% + \let\bxwy@S\@empty + \bxwy@render@all} +\ifbxwy@eTeX@ok %<*eTeX> +%%<*> \WarekiUseCustomInterGlue{<text>} +% Uses the custom definition of inter-ascii-kanji space. \@ifdefinable\WarekiUseCustomInterGlue{% \def\WarekiUseCustomInterGlue#{% \afterassignment\bxwy@render@all \protected\def\bxwy@S}} \fi %</eTeX> +% default is \WarekiUseNormalInterGlue +\let\bxwy@normal@S\bxwy@S + +%--------------------------------------- Fallback handler + +%%<+> \WarekiResetUHandler +% Sets \bxwy@U to \bxwy@normal@U. +\newcommand*\WarekiResetUHandler{% + \let\bxwy@U\bxwy@normal@U} +%%<+> \WarekiSetUHandler{<text>} +% Redefines \bxwy@U. In <text> #1 means the codepoint in hex. +\@ifdefinable\WarekiSetUHandler{% + \def\WarekiSetUHandler#{% + \def\bxwy@U##1}} +% set default +\WarekiResetUHandler + %--------------------------------------- Japanese words %% \bxwy@@meiji : kanji string 'Meiji' @@ -242,11 +290,13 @@ \bxwy@set@jchar@digit{X}{E58D81:5341:3D3D:eE2}% ten \bxwy@set@jchar@digit{C}{E799BE:767E:4934:j41}% hundred -%%<+> \WarekiKansuji{<counter>} +%%<*> \WarekiKansuji{<counter>} %% \bxwy@kansuji{<number>} % The kansuji representation of the number. \newcommand*\WarekiKansuji[1]{% - \expandafter\bxwy@kansuji\csname c@#1\endcsname} + \expandafter\@WarekiKansuji\csname c@#1\endcsname} +\newcommand*\@WarekiKansuji{% + \bxwy@counter@fun\bxwy@kansuji} \def\bxwy@kansuji#1{% \ifnum#1<\z@\else \expandafter\bxwy@kansuji@a\number#1\bxwy@mk @@ -257,9 +307,14 @@ \expandafter\bxwy@kansuji@a \fi} +%%<*> \WarekiJKansuji{<counter>} %% \bxwy@jkansuji{<number>} % The kansuji-by-reading representation of the number. % NB. Only valid in range 0..999; otherwise fallback to \bxwy@kansuji. +\newcommand*\WarekiJKansuji[1]{% + \expandafter\@WarekiJKansuji\csname c@#1\endcsname} +\newcommand*\@WarekiJKansuji{% + \bxwy@counter@fun\bxwy@jkansuji} \def\bxwy@jkansuji#1{% \expandafter\bxwy@jkansuji@a\number#1\bxwy@mk} \chardef\bxwy@jk@x=10 @@ -283,6 +338,18 @@ \ifnum#2>\z@ \bxwy@twicex{\csname bxwy@jcd/X\endcsname}\fi \ifnum#3>\z@ \bxwy@twicex{\csname bxwy@jcd/#3\endcsname}\fi} +%% \bxwy@counter@fun +\let\bxwy@tmpa=f +\ifcase\bxwy@engine \or +\or \let\bxwy@tmpa=t %jTeX +\or \let\bxwy@tmpa=t %fallback +\fi +\ifx t\bxwy@tmpa + \def\bxwy@counter@fun#1#2{% + \expandafter\protect\expandafter#1\expandafter{\number#2}} +\else \let\bxwy@counter@fun\@empty +\fi + %--------------------------------------- calculate wareki year %% errors @@ -434,6 +501,17 @@ \let\bxwy@today@year\relax \let\bxwy@today@yearstr\relax +%%<*> \WarekiIfAvailable{<true>}{<false>} +\ifnum\bxwy@engine=3 + \newcommand*\WarekiIfAvailable{% + \ifx\bxwy@U\bxwy@normal@U \expandafter\@secondoftwo + \else \expandafter\@firstoftwo + \fi} +\else + \newcommand*\WarekiIfAvailable{% + \@firstoftwo} +\fi + %%<*> counter 'warekiyear' : number of wareki year \bxwy@newcounter{warekiyear} %%<*> \warekigengo : kanji string of the current gengo |