%%% License %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This package is licensed under the terms of the MIT License.

% Copyright (c) 2025-2026 Kosei Kawaguchi

% 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{KKsymbols}[2026/08/20, Version 2.3.0]
\RequirePackage{luatexja-adjust, luacode, kvoptions}
\RequirePackage{calc}
\RequirePackage{tikz}
  \usetikzlibrary{shapes}

%%% package options
\SetupKeyvalOptions{%
  family=kksymbols,%
  prefix=kksymbols@%
}
\DeclareStringOption[1]{tsumesuji}
\DeclareStringOption[1]{autolowercase}
% `auto` preserves each command's historical line width.  A global value is
% used by every TikZ-drawn frame unless a command-specific value overrides it.
\DeclareStringOption[auto]{linewidth}
\DeclareStringOption[auto]{marulinewidth}
\DeclareStringOption[auto]{kuromarulinewidth}
\DeclareStringOption[auto]{nmarulinewidth}
\DeclareStringOption[auto]{jegglinewidth}
\DeclareStringOption[auto]{seihoulinewidth}
\DeclareStringOption[auto]{kuroseihoulinewidth}
\DeclareStringOption[auto]{seimarulinewidth}
\DeclareStringOption[auto]{kuroseimarulinewidth}
\DeclareStringOption[auto]{hishilinewidth}
\DeclareStringOption[auto]{kurohishilinewidth}
\DeclareStringOption[auto]{maruhishilinewidth}
\DeclareStringOption[auto]{kuromaruhishilinewidth}
\ProcessKeyvalOptions*
%%%

%%% KKsymbols.lua
\directlua{require("KKsymbols")}%%%
%%%


%%% tsumesuji
\ExplSyntaxOn
% l3text の \text_expand:n / \text_purify:n は、引数にフォントサイズ命令
% (\Large, \tiny 等) が含まれると無限ループに陥る（expl3 側の既知の挙動）。
% 本パッケージは「引数が数字列か」を判定するため引数を \text_expand:n にかけるので、
% サイズ命令を展開時に空へ畳んで安全化する。描画には #1 をそのまま使うため、
% 実際の出力サイズ（\maru{\Large A} 等）には影響しない。
\tl_map_inline:nn
  { \tiny \scriptsize \footnotesize \small \normalsize
    \large \Large \LARGE \huge \Huge }
  { \text_declare_expand_equivalent:Nn #1 { } }
\str_new:N \kks@tmp@str
\bool_new:N \kks@autolowercase@bool

\msg_new:nnn { KKsymbols } { invalid-autolowercase }
  {
    The~input~of~the~`autolowercase`~option~should~be~0~or~1.
  }

\str_case_e:nnF { \kksymbols@autolowercase }
  {
    { 0 } { \bool_gset_false:N \kks@autolowercase@bool }
    { 1 } { \bool_gset_true:N  \kks@autolowercase@bool }
  }
  {
    \bool_gset_true:N \kks@autolowercase@bool
    \msg_error:nn { KKsymbols } { invalid-autolowercase }
  }

\msg_new:nnn { KKsymbols } { negative-linewidth }
  {
    The~`#1`~option~must~be~`auto`~or~a~non-negative~TeX~dimension.
  }

% Parse every explicit line-width value once at package load time.  The value
% itself is not stored, so relative dimensions such as .04\zw remain dynamic
% when a symbol is used at another font size or in another direction.
\cs_new_protected:Npn \kks@linewidth@validate:nn #1#2
  {
    \str_if_eq:eeF { #2 } { auto }
      {
        \group_begin:
          \dim_set:Nn \l_tmpa_dim { #2 }
          \dim_compare:nNnT { \l_tmpa_dim } < { 0pt }
            { \msg_error:nnn { KKsymbols } { negative-linewidth } { #1 } }
        \group_end:
      }
  }
\kks@linewidth@validate:nn { linewidth } { \kksymbols@linewidth }
\kks@linewidth@validate:nn { marulinewidth } { \kksymbols@marulinewidth }
\kks@linewidth@validate:nn { kuromarulinewidth } { \kksymbols@kuromarulinewidth }
\kks@linewidth@validate:nn { nmarulinewidth } { \kksymbols@nmarulinewidth }
\kks@linewidth@validate:nn { jegglinewidth } { \kksymbols@jegglinewidth }
\kks@linewidth@validate:nn { seihoulinewidth } { \kksymbols@seihoulinewidth }
\kks@linewidth@validate:nn { kuroseihoulinewidth } { \kksymbols@kuroseihoulinewidth }
\kks@linewidth@validate:nn { seimarulinewidth } { \kksymbols@seimarulinewidth }
\kks@linewidth@validate:nn { kuroseimarulinewidth } { \kksymbols@kuroseimarulinewidth }
\kks@linewidth@validate:nn { hishilinewidth } { \kksymbols@hishilinewidth }
\kks@linewidth@validate:nn { kurohishilinewidth } { \kksymbols@kurohishilinewidth }
\kks@linewidth@validate:nn { maruhishilinewidth } { \kksymbols@maruhishilinewidth }
\kks@linewidth@validate:nn { kuromaruhishilinewidth } { \kksymbols@kuromaruhishilinewidth }

\prg_new_protected_conditional:Npnn \kks@if@lowercase:n #1 { T, F, TF }
  {
    % KKran's public commands are protected.  Replace them only inside this
    % classification group, if present, so either package load order works and
    % unrelated l3text expansion elsewhere in the document is not changed.
    \group_begin:
    \@ifpackageloaded { KKran }
      {
        \cs_if_exist:NT \Rrnum
          { \cs_set_eq:NN \Rrnum \kks@Rrnum@expand: }
        \cs_if_exist:NT \alphabetarray
          { \cs_set_eq:NN \alphabetarray \kks@alphabetarray@expand: }
      }
      { }
    \str_set:Nx \kks@tmp@str { \text_expand:n { #1 } }
    \int_compare:nNnTF
      {
        \directlua{
          tex.sprint(
            KKsymbols.lowercase_ascii_flag(
              "\luaescapestring{\kks@tmp@str}"
            )
          )
        }
      }
      = { 1 }
      { \group_end: \prg_return_true: }
      { \group_end: \prg_return_false: }
  }

\cs_new_protected:Npn \kks@autolowercase@select:nnn #1#2#3
  {
    \bool_if:NTF \kks@autolowercase@bool
      { \kks@if@lowercase:nTF { #3 } { #1 { #3 } } { #2 { #3 } } }
      { #2 { #3 } }
  }
\cs_new_eq:NN \kks@autolowercase@select \kks@autolowercase@select:nnn

% Resolve a command-specific line width, then the global line width, then the
% command's historical default.  Keep this expandable so TikZ receives the
% final dimension directly and nested enclosure commands cannot leak state.
\cs_new:Npn \kks@linewidth@resolve:nnn #1#2#3
  {
    \str_if_eq:eeTF { #1 } { auto }
      {
        \str_if_eq:eeTF { #2 } { auto }
          { #3 }
          { #2 }
      }
      { #1 }
  }
\cs_new_eq:NN \kks@linewidth \kks@linewidth@resolve:nnn

% Expandable, classification-only equivalents for KKran's protected commands.
% They are installed locally by \kks@if@lowercase:n only when the corresponding
% public command exists; neither KKran command is redefined globally.
\NewExpandableDocumentCommand \kks@Rrnum@expand: { s m }
  {
    \IfBooleanTF { #1 }
      { \uppercase \expandafter { \romannumeral #2 } }
      { \romannumeral #2 }
  }
\NewExpandableDocumentCommand \kks@alphabetarray@expand: { s m }
  {
    \IfBooleanTF { #1 }
      { \seq_item:Nn \g_alphabet_upper_seq { #2 } }
      { \seq_item:Nn \g_alphabet_lower_seq { #2 } }
  }

\DeclareRobustCommand{\kks@ShrinkedNumber@internal}[1]{
  \str_set:Nx \kks@tmp@str { \text_expand:n { #1 } }
  \regex_match:nVTF { \A \d+ \Z } \kks@tmp@str
    % 先頭・末尾が数字かつ1桁以上
    {
      \directlua{KKsymbols.narrow_ones("\luaescapestring{\kks@tmp@str}")}
    }
    {
      #1
    }
}


\msg_new:nnn { KKsymbols } { invalid-tsumesuji }
  { 
    The~input~of~the~`tsumesuji`~option~should~be~0~or~1. 
  }
\int_compare:nNnTF {\number\kksymbols@tsumesuji} = { 1 } 
  {
    \tl_set_eq:NN {\kks@ShrinkedNumber} {\kks@ShrinkedNumber@internal} 
  }
  {
    \int_compare:nNnTF {\number\kksymbols@tsumesuji} = {0}
      {
        \tl_set_eq:NN {\kks@ShrinkedNumber} {\relax} 
      }
      {
        \msg_error:nnn { KKsymbols } { invalid-tsumesuji } { #1 }
      }
  }
\ExplSyntaxOff
%%%


%%% interface commands
\DeclareRobustCommand{\maru}{%
  \@ifstar{\maru@new@no}{\kks@autolowercase@select{\maru@new@no}{\maru@new}}%
}

\DeclareRobustCommand{\kuromaru}{%
  \@ifstar{\kuromaru@new@no}{\kks@autolowercase@select{\kuromaru@new@no}{\kuromaru@new}}%
}

\DeclareRobustCommand{\nmaru}{%
  \@ifstar{\nmaru@new@no}{\kks@autolowercase@select{\nmaru@new@no}{\nmaru@new}}%
}

\DeclareRobustCommand{\jegg}{%
  \@ifstar
    {\kks@autolowercase@select{\jegg@new@black@no}{\jegg@new@black}}
    {\kks@autolowercase@select{\jegg@new@no}{\jegg@new}}%
}

\DeclareRobustCommand{\seihou}{%
  \@ifstar{\seihou@new@no}{\kks@autolowercase@select{\seihou@new@no}{\seihou@new}}%
}

\DeclareRobustCommand{\kuroseihou}{%
  \@ifstar{\kuroseihou@new@no}{\kks@autolowercase@select{\kuroseihou@new@no}{\kuroseihou@new}}%
}

\DeclareRobustCommand{\seimaru}{%
  \@ifstar{\seimaru@new@no}{\kks@autolowercase@select{\seimaru@new@no}{\seimaru@new}}%
}

\DeclareRobustCommand{\kuroseimaru}{%
  \@ifstar{\kuroseimaru@new@no}{\kks@autolowercase@select{\kuroseimaru@new@no}{\kuroseimaru@new}}%
}

\DeclareRobustCommand{\hishi}{%
  \@ifstar{\hishi@new@no}{\kks@autolowercase@select{\hishi@new@no}{\hishi@new}}%
}

\DeclareRobustCommand{\kurohishi}{%
  \@ifstar{\kurohishi@new@no}{\kks@autolowercase@select{\kurohishi@new@no}{\kurohishi@new}}%
}

\DeclareRobustCommand{\maruhishi}{%
  \@ifstar{\maruhishi@new@no}{\kks@autolowercase@select{\maruhishi@new@no}{\maruhishi@new}}%
}

\DeclareRobustCommand{\kuromaruhishi}{%
  \@ifstar{\kuromaruhishi@new@no}{\kks@autolowercase@select{\kuromaruhishi@new@no}{\kuromaruhishi@new}}%
}

\DeclareRobustCommand{\ichimoji}{%
  \@ifstar{\ichimoji@new@no}{\kks@autolowercase@select{\ichimoji@new@no}{\ichimoji@new}}%
}

\DeclareRobustCommand{\kakko@y@internal}[1]{\kakko@byouga@internal{（}{）}{#1}}
\DeclareRobustCommand{\kakko@y@internal@no}[1]{\kakko@byouga@internal@no{（}{）}{#1}}
\DeclareRobustCommand{\kakko@t@internal}[1]{\kakko@byouga@internal@tate{（}{）}{#1}}
\DeclareRobustCommand{\kakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{（}{）}{#1}}
\DeclareRobustCommand{\kakko}{%
  \@ifstar{\kakko@star}{\kks@autolowercase@select{\kakko@star}{\kakko@nostar}}% 
}
\newcommand{\kakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kakko@t@internal@no{#1}%
  \else
    \kakko@y@internal@no{#1}%
  \fi
}
\newcommand{\kakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kakko@t@internal{#1}%
  \else
    \kakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\sumikakko@y@internal}[1]{\kakko@byouga@internal{【}{】}{#1}}
\DeclareRobustCommand{\sumikakko@y@internal@no}[1]{\kakko@byouga@internal@no{【}{】}{#1}}
\DeclareRobustCommand{\sumikakko@t@internal}[1]{\kakko@byouga@internal@tate{【}{】}{#1}}
\DeclareRobustCommand{\sumikakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{【}{】}{#1}}
\DeclareRobustCommand{\sumikakko}{%
  \@ifstar{\sumikakko@star}{\kks@autolowercase@select{\sumikakko@star}{\sumikakko@nostar}}% 
}
\newcommand{\sumikakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \sumikakko@t@internal@no{#1}%
  \else
    \sumikakko@y@internal@no{#1}%
  \fi
}
\newcommand{\sumikakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \sumikakko@t@internal{#1}%
  \else
    \sumikakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\kakukakko@y@internal}[1]{\kakko@byouga@internal{［}{］}{#1}}
\DeclareRobustCommand{\kakukakko@y@internal@no}[1]{\kakko@byouga@internal@no{［}{］}{#1}}
\DeclareRobustCommand{\kakukakko@t@internal}[1]{\kakko@byouga@internal@tate{［}{］}{#1}}
\DeclareRobustCommand{\kakukakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{［}{］}{#1}}
\DeclareRobustCommand{\kakukakko}{%
  \@ifstar{\kakukakko@star}{\kks@autolowercase@select{\kakukakko@star}{\kakukakko@nostar}}% 
}
\newcommand{\kakukakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kakukakko@t@internal@no{#1}%
  \else
    \kakukakko@y@internal@no{#1}%
  \fi
}
\newcommand{\kakukakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kakukakko@t@internal{#1}%
  \else
    \kakukakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\kikakko@y@internal}[1]{\kakko@byouga@internal{〔}{〕}{#1}}
\DeclareRobustCommand{\kikakko@y@internal@no}[1]{\kakko@byouga@internal@no{〔}{〕}{#1}}
\DeclareRobustCommand{\kikakko@t@internal}[1]{\kakko@byouga@internal@tate{〔}{〕}{#1}}
\DeclareRobustCommand{\kikakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{〔}{〕}{#1}}
\DeclareRobustCommand{\kikakko}{%
  \@ifstar{\kikakko@star}{\kks@autolowercase@select{\kikakko@star}{\kikakko@nostar}}% 
}
\newcommand{\kikakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kikakko@t@internal@no{#1}%
  \else
    \kikakko@y@internal@no{#1}%
  \fi
}
\newcommand{\kikakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kikakko@t@internal{#1}%
  \else
    \kikakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\ykakko@y@internal}[1]{\kakko@byouga@internal{〈}{〉}{#1}}
\DeclareRobustCommand{\ykakko@y@internal@no}[1]{\kakko@byouga@internal@no{〈}{〉}{#1}}
\DeclareRobustCommand{\ykakko@t@internal}[1]{\kakko@byouga@internal@tate{〈}{〉}{#1}}
\DeclareRobustCommand{\ykakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{〈}{〉}{#1}}
\DeclareRobustCommand{\ykakko}{%
  \@ifstar{\ykakko@star}{\kks@autolowercase@select{\ykakko@star}{\ykakko@nostar}}% 
}
\newcommand{\ykakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \ykakko@t@internal@no{#1}%
  \else
    \ykakko@y@internal@no{#1}%
  \fi
}
\newcommand{\ykakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \ykakko@t@internal{#1}%
  \else
    \ykakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\nykakko@y@internal}[1]{\kakko@byouga@internal{《}{》}{#1}}
\DeclareRobustCommand{\nykakko@y@internal@no}[1]{\kakko@byouga@internal@no{《}{》}{#1}}
\DeclareRobustCommand{\nykakko@t@internal}[1]{\kakko@byouga@internal@tate{《}{》}{#1}}
\DeclareRobustCommand{\nykakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{《}{》}{#1}}
\DeclareRobustCommand{\nykakko}{%
  \@ifstar{\nykakko@star}{\kks@autolowercase@select{\nykakko@star}{\nykakko@nostar}}% 
}
\newcommand{\nykakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \nykakko@t@internal@no{#1}%
  \else
    \nykakko@y@internal@no{#1}%
  \fi
}
\newcommand{\nykakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \nykakko@t@internal{#1}%
  \else
    \nykakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\namikakko@y@internal}[1]{\kakko@byouga@internal{｛}{｝}{#1}}
\DeclareRobustCommand{\namikakko@y@internal@no}[1]{\kakko@byouga@internal@no{｛}{｝}{#1}}
\DeclareRobustCommand{\namikakko@t@internal}[1]{\kakko@byouga@internal@tate{｛}{｝}{#1}}
\DeclareRobustCommand{\namikakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{｛}{｝}{#1}}
\DeclareRobustCommand{\namikakko}{%
  \@ifstar{\namikakko@star}{\kks@autolowercase@select{\namikakko@star}{\namikakko@nostar}}% 
}
\newcommand{\namikakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \namikakko@t@internal@no{#1}%
  \else
    \namikakko@y@internal@no{#1}%
  \fi
}
\newcommand{\namikakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \namikakko@t@internal{#1}%
  \else
    \namikakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\kagikakko@y@internal}[1]{\kakko@byouga@internal{「}{」}{#1}}
\DeclareRobustCommand{\kagikakko@y@internal@no}[1]{\kakko@byouga@internal@no{「}{」}{#1}}
\DeclareRobustCommand{\kagikakko@t@internal}[1]{\kakko@byouga@internal@tate{「}{」}{#1}}
\DeclareRobustCommand{\kagikakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{「}{」}{#1}}
\DeclareRobustCommand{\kagikakko}{%
  \@ifstar{\kagikakko@star}{\kks@autolowercase@select{\kagikakko@star}{\kagikakko@nostar}}% 
}
\newcommand{\kagikakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kagikakko@t@internal@no{#1}%
  \else
    \kagikakko@y@internal@no{#1}%
  \fi
}
\newcommand{\kagikakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \kagikakko@t@internal{#1}%
  \else
    \kagikakko@y@internal{#1}%
  \fi
}

\DeclareRobustCommand{\nkagikakko@y@internal}[1]{\kakko@byouga@internal{『}{』}{#1}}
\DeclareRobustCommand{\nkagikakko@y@internal@no}[1]{\kakko@byouga@internal@no{『}{』}{#1}}
\DeclareRobustCommand{\nkagikakko@t@internal}[1]{\kakko@byouga@internal@tate{『}{』}{#1}}
\DeclareRobustCommand{\nkagikakko@t@internal@no}[1]{\kakko@byouga@internal@tate@no{『}{』}{#1}}
\DeclareRobustCommand{\nkagikakko}{%
  \@ifstar{\nkagikakko@star}{\kks@autolowercase@select{\nkagikakko@star}{\nkagikakko@nostar}}% 
}
\newcommand{\nkagikakko@star}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \nkagikakko@t@internal@no{#1}%
  \else
    \nkagikakko@y@internal@no{#1}%
  \fi
}
\newcommand{\nkagikakko@nostar}[1]{%
  \ifnum\ltjgetparameter{direction}=3\relax
    \nkagikakko@t@internal{#1}%
  \else
    \nkagikakko@y@internal{#1}%
  \fi
}
%%%


% 全体で使用
\NewDocumentCommand{\shukushou@adj@new}{ m m m }{%
  \ifdim #1 < #2%
    \resizebox*{\width}{#2}{#3}%
  \else%
    \resizebox*{#2}{#2}{#3}%
  \fi%
}
\NewDocumentCommand{\shukushou@adj@new@no}{ m m m }{%
  \ifdim #1 < #2%
    #3%
  \else%
    \resizebox*{!}{#2}{#3}%
  \fi%
}
\NewDocumentCommand{\RotYoko}{O{0}}{%
  \def\KKsymbolsRot@val@y{#1}%
}
\NewDocumentCommand{\RotTate}{O{90}}{%
  \def\KKsymbolsRot@val@t{#1}%
}
\def\KKsymbolsRot@val@t{90}
\def\KKsymbolsRot@val@y{0}
\NewDocumentCommand{\rot@or@not@kksym}{}{%
  \ifnum\ltjgetparameter{direction}=3
    \def\rot@kksym@tateyoko{\KKsymbolsRot@val@t}%
  \else
    \def\rot@kksym@tateyoko{\KKsymbolsRot@val@y}%
  \fi
}
%%%


%%% 中央寄せ基準ボックス (reference box)
% 囲みコマンドは、引数の高さ・深さを基準に中身のサイズと中央位置を決める。
% 引数自身の寸法を使うと、ローマ数字小文字 (\Rrnum{n}) のように字ごとに高さが
% ばらつく内容で大きさ・上下位置が不揃いになり、さらにフォントによっても中央が
% ずれる。そこで「基準ボックス」を内部の \vphantom として注入し、寸法を一定化する。
%
% 既定は【自動】: 現在フォントの x ハイト相当を基準にする（\kks@autoref）。
%   これは短い内容の基準を安定させるための既定値であり、
%   \vphantom{\Rrnum{6}} と同一ではない。ローマ数字小文字を厳密に揃える場合は
%   \kksref{\Rrnum{6}} のように基準を明示する。漢字・かな・大文字・数字は基準より
%   背が高いので max を取るだけで影響せず、従来どおりになる。
%
% \kksref{<material>} : 基準を <material> の寸法で明示上書き（スコープ依存）。
% \kksrefauto        : 自動基準（既定）に戻す。
% \kksrefoff         : 基準を解除＝引数自身の寸法を使う旧来動作。
% \kksrefreset       : \kksrefauto の別名（後方互換）。
\newcommand{\kks@autoref}{x}% 現在フォントの x（= x ハイト, 深さ0）を基準にする
\let\kks@ref@material\kks@autoref
\DeclareRobustCommand{\kksref}[1]{\def\kks@ref@material{#1}}
\DeclareRobustCommand{\kksrefauto}{\let\kks@ref@material\kks@autoref}
\DeclareRobustCommand{\kksrefoff}{\def\kks@ref@material{}}
\DeclareRobustCommand{\kksrefreset}{\kksrefauto}
% 内容に基準ボックスの高さ・深さを与える（手書きの \vphantom{ref}#1 と等価）。
% 基準が空（\kksrefoff）なら何もしない。\vphantom は幅0なので水平方向には影響しない。
\newcommand{\kks@withref}[1]{%
  \ifx\kks@ref@material\@empty
    #1%
  \else
    \vphantom{\kks@ref@material}#1%
  \fi
}
%%%


% \maru
\NewDocumentCommand{\vertical@adj@maru@new}{}{%
  \ifnum\ltjgetparameter{direction}=3
    -.5\zw%
  \else
    -.12\zw%
  \fi
}
\newlength{\maru@boxwidth@new}
\newlength{\maru@boxwidth@inner}
\newlength{\maru@var@yokohaba}

\ExplSyntaxOn
\newcommand{\kks@chech@maru@onedigit}[1]{
  \str_set:Nx \l_tmpa_str { \text_expand:n { #1 } }
  \str_if_eq:VnTF \l_tmpa_str { 0 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 1 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 2 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 3 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 4 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 5 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 6 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 7 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 8 } { \kksdigit@maru@newtrue } {
  \str_if_eq:VnTF \l_tmpa_str { 9 } { \kksdigit@maru@newtrue } {
    \kksdigit@maru@newfalse
  }}}}}}}}}}
}
\ExplSyntaxOff

\NewDocumentCommand{\shukushou@adj@new@maru@onedigit}{ m m m }{%
  \resizebox*{!}{#2}{#3}%
}

% ---- Uniform fit for the star (safe-sizing) routes ------------------------
% A star route has to size arbitrary material, not just one lowercase letter,
% so it may only ever apply a single uniform scale, and that scale has to keep
% the material's whole box -- width and height plus depth -- inside the shape
% that is actually drawn.  Two limits are combined:
%
%   * the inner box each command hands TikZ.  It is the design's own padding
%     and is what gives lowercase letters their familiar size and the visible
%     gap to the frame, so it stays the primary limit;
%   * the interior of the drawn outline, i.e. the TikZ path taken in by half
%     the stroke.  The stroke width is a package option (`linewidth' and the
%     per-command keys), so a thick enough frame eats into the interior; the
%     limits below are therefore derived from the very expressions the drawing
%     nodes hand to TikZ.
%
% Each limit is expressed in the shape's own metric -- a radius for the circle,
% half-extents for the rectangles, half-diagonals for the diamond -- so that
% flat material may use the shape's full chord instead of being squeezed into
% the inscribed square, and so that the diamond's slanted edges are honoured
% rather than approximated by an outer rectangle.
%
% A shape may add a third limit, the band: the total height it allots to the
% material whatever its width.  Only the circle sets one.  A box touches a
% circle at its corners, and for tall narrow material those corners are where
% the ink is not: the ink extremes of a letter such as `j' -- the dot and the
% descender -- sit at the horizontal centre, that is at the circle's poles,
% where a corner fit leaves no clearance at all and the letter reads as
% crowding the stroke even though its box is inside the path.  The circle's
% band is therefore the side of the square inscribed in the usable circle,
% which at the default stroke is exactly the inner box the command hands TikZ
% and reproduces the historical sizing of a lowercase letter.  The band can
% only lower a limit that already proves containment, and it never binds for
% material at least as wide as it is tall, so flat and multi-character
% material keeps the shape's full chord.
\newbox\kks@fit@box
\newlength{\kks@fit@wd}
\newlength{\kks@fit@ht}
\newlength{\kks@fit@lw}   % the line width the drawing node is given
\newlength{\kks@fit@path} % half-extent of the drawn path itself
\newlength{\kks@fit@a}    % usable half-width, radius, or half-diagonal
\newlength{\kks@fit@b}    % usable half-height (equal to \kks@fit@a for every
                          % enclosure here, kept separate for readability)
\newlength{\kks@fit@rc}   % radius of the drawn corner arc (0 = sharp corner)
\newlength{\kks@fit@cx}   % centre of that arc, measured from the shape centre
\newlength{\kks@fit@cy}
\newlength{\kks@fit@band} % total height the shape allots to the material,
                          % whatever its width (0pt = the shape sets no band)
\newlength{\kks@fit@wide} % width above which the design settles for the wide
                          % base below (0pt = the shape has no such width)
% Material wider than the shape's own inner box has never been given the full
% base size: the historical routes stepped down to this factor instead, which
% is what keeps a wide letter such as `m' or `w' clear of the frame at the
% sides.  It applies as one more upper bound, so it can only ever make a fit
% smaller than the geometry already allows.
\newcommand{\kks@fit@widebase}{.85}
% Whether this enclosure lets a single glyph take that wide base outright.
% Only the two routes that also run the ink guard do: a lone glyph's width is
% bounded by the em and its ink stops short of its own box corners, so the box
% corner crossing the stroke does not put ink there -- which is exactly how the
% historical routes sized `m' and `w'.  A string has no such bound, so it keeps
% the geometric limit.  0 = off, 1 = on; every setup clears it.
\newcommand{\kks@fit@widefree}{0}
% 1 when that allowance was actually taken, for the fixtures to read.
\newcommand{\kks@fit@widetaken}{0}
% The size lowercase material keeps whenever it already fits; this is the
% factor the star routes have always applied to a letter that needs no
% shrinking, and it is what keeps \maru*{m} the same size as \maru{m}.
\newcommand{\kks@fit@base}{.9}

% A vanishing dimension carries no constraint of its own.  The floor keeps the
% divisions below finite without changing any measurement that exists.
\newcommand{\kks@fit@measure}[1]{%
  \setbox\kks@fit@box=\hbox{#1}%
  \setlength{\kks@fit@wd}{\wd\kks@fit@box}%
  \setlength{\kks@fit@ht}{\dimexpr\ht\kks@fit@box+\dp\kks@fit@box\relax}%
  \ifdim\kks@fit@wd<.01pt\setlength{\kks@fit@wd}{.01pt}\fi
  \ifdim\kks@fit@ht<.01pt\setlength{\kks@fit@ht}{.01pt}\fi
}
% #1 is the largest scale the shape allows, or 0 when the enclosure has no
% interior left to fit into (a stroke thick enough to swallow it).  In that
% case there is nothing to compute from and the plain lowercase size is used,
% exactly as \jegg's own scaler does.
\newcommand{\kks@fit@emit}[2]{%
  \ifdim #1pt>\z@
    \pgfmathsetmacro{\kks@fit@scale}{min(#2,#1)}%
  \else
    \def\kks@fit@scale{#2}%
  \fi
  \scalebox{\kks@fit@scale}{\copy\kks@fit@box}%
}

% Largest uniform scale that keeps the measured box inside a rounded rectangle
% with half-extents a and b whose corner arcs have radius rc about (cx,cy).
% A sharp rectangle is the case rc = 0, and a circle of radius r the case
% a = b = rc = r with the arc centred on the shape centre.  The material is
% centred on the shape, so one corner decides everything: the ray from the
% centre through that corner leaves the rectangle through a straight side
% unless the exit point lies beyond both arc centres, and only then does the
% arc itself become the limit.  Solving on the ray normalised by its longer
% component keeps every quantity in the quadratic within pgfmath's range.
\NewDocumentCommand{\kks@fit@into@box}{ m m }{%
  \begingroup
    % Read the limits before the material is typeset: a nested enclosure would
    % otherwise overwrite them while it sizes its own contents.
    \edef\kks@fit@aa{\the\kks@fit@a}%
    \edef\kks@fit@bb{\the\kks@fit@b}%
    \edef\kks@fit@rr{\the\kks@fit@rc}%
    \edef\kks@fit@ccx{\the\kks@fit@cx}%
    \edef\kks@fit@ccy{\the\kks@fit@cy}%
    \edef\kks@fit@bband{\the\kks@fit@band}%
    \edef\kks@fit@wwide{\the\kks@fit@wide}%
    \gdef\kks@fit@widetaken{0}%
    \kks@fit@measure{#2}%
    \def\kks@fit@limit{0}%
    \ifdim\kks@fit@aa>\z@
      \ifdim\kks@fit@bb>\z@
        \pgfmathsetmacro{\kks@fit@limit}{%
          min(2*\kks@fit@aa/\kks@fit@wd, 2*\kks@fit@bb/\kks@fit@ht)}%
        % The same limit read on the axes rather than at the corner: how far
        % the material may go before its widest and tallest points leave the
        % shape.  The corner solution below overwrites the limit, so keep it.
        \let\kks@fit@side\kks@fit@limit
        \pgfmathsetmacro{\kks@fit@px}{.5*\kks@fit@limit*\kks@fit@wd}%
        \pgfmathsetmacro{\kks@fit@py}{.5*\kks@fit@limit*\kks@fit@ht}%
        \ifdim\kks@fit@px pt>\kks@fit@ccx
          \ifdim\kks@fit@py pt>\kks@fit@ccy
            % The exit point lies past both arc centres, so the arc is what
            % the material actually meets.  Solve on the ray, normalised by
            % its longer component, and take the larger root: the ray starts
            % outside the arc's circle and leaves it there.
            \pgfmathsetmacro{\kks@fit@qn}{max(\kks@fit@wd,\kks@fit@ht)}%
            \pgfmathsetmacro{\kks@fit@qx}{\kks@fit@wd/\kks@fit@qn}%
            \pgfmathsetmacro{\kks@fit@qy}{\kks@fit@ht/\kks@fit@qn}%
            \pgfmathsetmacro{\kks@fit@qa}{%
              \kks@fit@qx*\kks@fit@qx + \kks@fit@qy*\kks@fit@qy}%
            \pgfmathsetmacro{\kks@fit@qb}{%
              \kks@fit@qx*\kks@fit@ccx + \kks@fit@qy*\kks@fit@ccy}%
            \pgfmathsetmacro{\kks@fit@qc}{%
              \kks@fit@ccx*\kks@fit@ccx + \kks@fit@ccy*\kks@fit@ccy
                - \kks@fit@rr*\kks@fit@rr}%
            \pgfmathsetmacro{\kks@fit@limit}{%
              2 * (\kks@fit@qb
                   + sqrt(max(0, \kks@fit@qb*\kks@fit@qb
                                   - \kks@fit@qa*\kks@fit@qc)))
                / (\kks@fit@qa * \kks@fit@qn)}%
          \fi
        \fi
        % Wide material settles for the wide base, as it always has.  Where
        % the enclosure allows it, a single glyph takes that base outright
        % rather than the corner limit, which is what the historical routes
        % did and what keeps `m' and `w' their familiar size.
        \ifdim\kks@fit@wwide>\z@
          \ifdim\kks@fit@widebase\kks@fit@wd>\kks@fit@wwide\relax
            \def\kks@fit@single{0}%
            \ifnum\kks@fit@widefree=1
              \edef\kks@fit@single{%
                \directlua{tex.sprint(KKsymbols.glyph_count(%
                  \number\kks@fit@box))}}%
            \fi
            \ifnum\kks@fit@single=1
              % A lone glyph is judged on the axes, the way the ink guard
              % judges it: its ink does not reach its own box corners, so the
              % corner solution understates what fits, while the widest and
              % tallest points of the box are what must stay inside the shape.
              % This still tightens with the stroke, so a heavy frame shrinks
              % such a glyph exactly as it shrinks everything else.
              \gdef\kks@fit@widetaken{1}%
              \pgfmathsetmacro{\kks@fit@limit}{%
                min(\kks@fit@widebase, \kks@fit@side)}%
            \else
              \pgfmathsetmacro{\kks@fit@limit}{%
                min(\kks@fit@limit, \kks@fit@widebase)}%
            \fi
          \fi
        \fi
        % The band, where the shape sets one.  It comes last so that it also
        % holds the wide allowance above: it can only lower whatever limit
        % has been reached, so containment stays proved by that limit.
        \ifdim\kks@fit@bband>\z@
          \pgfmathsetmacro{\kks@fit@limit}{%
            min(\kks@fit@limit, \kks@fit@bband/\kks@fit@ht)}%
        \fi
      \fi
    \fi
    \kks@fit@emit{\kks@fit@limit}{#1}%
  \endgroup
}

% Largest uniform scale that keeps the measured box inside a diamond with
% half-diagonals a and b.  A box of width w and total height h centred on such
% a diamond touches its edges exactly when w/2a + h/2b = 1, which is the true
% inscribed fit; treating the diamond as its bounding rectangle would waste
% most of the room a wide, flat string needs.
\NewDocumentCommand{\kks@fit@into@diamond}{ m m }{%
  \begingroup
    \edef\kks@fit@aa{\the\kks@fit@a}%
    \edef\kks@fit@bb{\the\kks@fit@b}%
    \edef\kks@fit@bband{\the\kks@fit@band}%
    \edef\kks@fit@wwide{\the\kks@fit@wide}%
    \gdef\kks@fit@widetaken{0}%
    \kks@fit@measure{#2}%
    \def\kks@fit@limit{0}%
    \ifdim\kks@fit@aa>\z@
      \ifdim\kks@fit@bb>\z@
        \pgfmathsetmacro{\kks@fit@limit}{%
          1 / (.5*\kks@fit@wd/\kks@fit@aa + .5*\kks@fit@ht/\kks@fit@bb)}%
        % Wide material settles for the wide base, as it always has.  No
        % diamond sets a wide width, so this is inert; it is kept so that both
        % fit routines state the same rule.
        \ifdim\kks@fit@wwide>\z@
          \ifdim\kks@fit@widebase\kks@fit@wd>\kks@fit@wwide\relax
            \pgfmathsetmacro{\kks@fit@limit}{%
              min(\kks@fit@limit, \kks@fit@widebase)}%
          \fi
        \fi
        % No diamond sets a band -- its slanted edges already leave the top
        % and bottom clear -- but the capture and this guard keep the rule
        % identical in both fit routines, including when a banded enclosure
        % is nested inside diamond material.
        \ifdim\kks@fit@bband>\z@
          \pgfmathsetmacro{\kks@fit@limit}{%
            min(\kks@fit@limit, \kks@fit@bband/\kks@fit@ht)}%
        \fi
      \fi
    \fi
    \kks@fit@emit{\kks@fit@limit}{#1}%
  \endgroup
}

% The setup commands run in the enclosure's own context, never inside the TikZ
% node, because \zw there need not be the enclosure's Japanese em.  Each takes
% the inner box, the inner separation, the minimum size and the corner radius
% exactly as its drawing node states them, and \kks@fit@lw must already hold
% the line width that node is given.
%
% pgf gives a circle node the radius sqrt(xa^2+ya^2) of its text box plus the
% inner separation, raised to half the minimum size, and strokes that path
% centred.  The inner box is square, hence the sqrt(2).  Its circumscribed
% circle is the historical limit.  #1 inner box, #2 inner sep, #3 minimum
% size, #4 how far the stroke reaches inwards.
\newcommand{\kks@fit@setup@circle}[4]{%
  \pgfmathsetlength{\kks@fit@a}{%
    min(0.5*sqrt(2)*(#1),
        max(0.5*(#3), sqrt(2)*(0.5*(#1)+(#2))) - (#4))}%
  \setlength{\kks@fit@b}{\kks@fit@a}%
  \setlength{\kks@fit@rc}{\kks@fit@a}%
  \setlength{\kks@fit@cx}{\z@}%
  \setlength{\kks@fit@cy}{\z@}%
  % The side of the square inscribed in the usable circle.  At the default
  % stroke the usable radius is the inner box over sqrt(2), so the band is the
  % inner box itself; a heavier stroke tightens it in step with the outline.
  \pgfmathsetlength{\kks@fit@band}{1.4142136*\kks@fit@a}%
  % Wider than that same inner box is what `wide' has always meant here.
  \setlength{\kks@fit@wide}{\kks@fit@band}%
  \def\kks@fit@widefree{0}%
}
% A rectangle node is as wide as its text box plus twice the inner separation,
% raised to the minimum size, and `rounded corners' bends its corners on arcs
% of the given radius.  Taking the stroke in by half its width leaves those
% arcs concentric, so only their radius shrinks.  #5 is the corner radius.
\newcommand{\kks@fit@setup@rect}[5]{%
  \pgfmathsetlength{\kks@fit@path}{0.5*max((#3), (#1)+2*(#2))}%
  \pgfmathsetlength{\kks@fit@a}{min(0.5*(#1), \kks@fit@path - (#4))}%
  \setlength{\kks@fit@b}{\kks@fit@a}%
  \pgfmathsetlength{\kks@fit@rc}{max(0, (#5) - (#4))}%
  \pgfmathsetlength{\kks@fit@cx}{\kks@fit@path - (#5)}%
  \setlength{\kks@fit@cy}{\kks@fit@cx}%
  % A rectangle's own half-height already is the band.
  \setlength{\kks@fit@band}{\z@}%
  \setlength{\kks@fit@wide}{\z@}%
  \def\kks@fit@widefree{0}%
}
% An opening with nothing drawn around it: the material simply has to stay
% inside the box the enclosure reserves for it.
\newcommand{\kks@fit@setup@plain}[2]{%
  \setlength{\kks@fit@a}{.5#1}%
  \setlength{\kks@fit@b}{.5#2}%
  \setlength{\kks@fit@rc}{\z@}%
  \setlength{\kks@fit@cx}{\kks@fit@a}%
  \setlength{\kks@fit@cy}{\kks@fit@b}%
  \setlength{\kks@fit@band}{\z@}%
  \setlength{\kks@fit@wide}{\z@}%
  \def\kks@fit@widefree{0}%
}
% With the default aspect a diamond node's half-diagonal is the sum of the two
% half-extents of its text box plus the inner separation, raised to half the
% minimum size, and its background path then pulls the tips in by .414 of the
% outer separation, which pgf initialises to half the line width.  Taking that
% path in by half the stroke moves each slanted edge .707 of a line width along
% the diagonal, and a rounded tip costs a further .414 of the arc radius the
% inner edge is left with.  A square inner box of side s is inscribed exactly
% in a diamond of half-diagonal s, which is the historical limit.  #4 is the
% line width itself here, since the diamond needs it in more than one place.
\newcommand{\kks@fit@setup@diamond}[5]{%
  \pgfmathsetlength{\kks@fit@path}{%
    max(0.5*(#3), 2*(0.5*(#1)+(#2))) - 0.4142136*0.5*(#4)}%
  \pgfmathsetlength{\kks@fit@a}{%
    min((#1),
        \kks@fit@path - 0.7071068*(#4)
          - 0.4142136*max(0, (#5) - 0.5*(#4)))}%
  \setlength{\kks@fit@b}{\kks@fit@a}%
  % The slanted edges already keep the top and bottom of a tall box clear.
  \setlength{\kks@fit@band}{\z@}%
  \setlength{\kks@fit@wide}{\z@}%
  \def\kks@fit@widefree{0}%
}
% A negative line width is already reported when the package loads; ignore its
% sign here so that a stroke can never widen an interior.
\newcommand{\kks@fit@linewidth}[1]{%
  \setlength{\kks@fit@lw}{#1}%
  \ifdim\kks@fit@lw<\z@\setlength{\kks@fit@lw}{\z@}\fi
}

% Shrink-only visual overflow guard.  The raw material and the exact legacy
% star-path result are measured in dedicated local boxes.  When the actual
% glyph ink is already inside the visible frame, #5 is emitted verbatim with no
% graphic wrapper; only an overflow receives one additional uniform scale.
\newbox\kks@visual@rawbox
\newbox\kks@visual@legacybox
\newbox\kks@visual@leftbox
\newbox\kks@visual@rightbox
\newlength{\kks@visual@radius}
\newcommand{\kks@bracket@xscale}{.63}
\newcommand{\kks@bracket@overlap}{.1\zw}
\NewDocumentCommand{\kks@visual@guard@circle}{ m m m m m m }{%
  \begingroup
    \pgfmathsetlength{\kks@visual@radius}{%
      max(0.5 * (#3), sqrt(2) * (0.5 * (#1) + (#2))) + 0.5 * (#4)}%
    \setbox\kks@visual@rawbox=\hbox{#6}%
    \def\kks@visual@material{\copy\kks@visual@rawbox}%
    \setbox\kks@visual@legacybox=\hbox{#5}%
    \edef\kks@visual@scale{%
      \directlua{tex.sprint(KKsymbols.visual_scale(
        \number\kks@visual@rawbox,
        \number\kks@visual@legacybox,
        "circle",
        \number\kks@visual@radius,
        0))}}%
    \ifx\kks@visual@scale\@empty
      \copy\kks@visual@legacybox
    \else
      \scalebox{\kks@visual@scale}{\copy\kks@visual@legacybox}%
    \fi
  \endgroup
}

\NewDocumentCommand{\kks@visual@guard@bracket}{ m m m m m m }{%
  \begingroup
    \setbox\kks@visual@leftbox=\hbox{#1}%
    \setbox\kks@visual@rightbox=\hbox{#2}%
    \setbox\kks@visual@rawbox=\hbox{#6}%
    \def\kks@visual@material{\copy\kks@visual@rawbox}%
    \setbox\kks@visual@legacybox=\hbox{#5}%
    \pgfmathparse{#4}%
    \edef\kks@visual@angle{\pgfmathresult}%
    \edef\kks@visual@scale{%
      \directlua{tex.sprint(KKsymbols.visual_bracket_scale(
        \number\kks@visual@rawbox,
        \number\kks@visual@legacybox,
        \number\kks@visual@leftbox,
        \number\kks@visual@rightbox,
        \number#3,
        \number\dimexpr\kks@bracket@overlap\relax,
        \kks@bracket@xscale,
        \kks@visual@angle))}}%
    \ifx\kks@visual@scale\@empty
      \copy\kks@visual@legacybox
    \else
      \scalebox{\kks@visual@scale}{\copy\kks@visual@legacybox}%
    \fi
  \endgroup
}

\newif\ifkksdigit@maru@new

\DeclareRobustCommand{\maru@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \settowidth{\maru@var@yokohaba}{#1}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        line width=\kks@linewidth{\kksymbols@marulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum size=.9\maru@boxwidth@new, 
        draw,
        inner sep=.02\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\maru@var@yokohaba}{\maru@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\maru@var@yokohaba}{\maru@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\maru@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@marulinewidth}{\kksymbols@linewidth}%
    {.04\maru@boxwidth@new}}%
  \kks@fit@setup@circle{\maru@boxwidth@inner}{.02\maru@boxwidth@new}
    {.9\maru@boxwidth@new}{.5\kks@fit@lw}%
  % This route runs the ink guard below, so a single wide glyph may take the
  % historical wide size; anything the ink really oversteps is caught there.
  \def\kks@fit@widefree{1}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        line width=\kks@linewidth{\kksymbols@marulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum size=.9\maru@boxwidth@new, 
        draw,
        inner sep=.02\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \kks@visual@guard@circle
            {\maru@boxwidth@inner}{.02\maru@boxwidth@new}{.9\maru@boxwidth@new}
            {-\kks@linewidth{\kksymbols@marulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new}}
            {\kks@fit@into@box{\kks@fit@base}{\kks@visual@material}}
            {\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\kuromaru@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \settowidth{\maru@var@yokohaba}{#1}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        fill=black,%%%
        line width=\kks@linewidth{\kksymbols@kuromarulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum size=.9\maru@boxwidth@new, 
        draw,
        inner sep=.02\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\maru@var@yokohaba}{\maru@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \else%
            \shukushou@adj@new{\maru@var@yokohaba}{\maru@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kuromaru@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@kuromarulinewidth}{\kksymbols@linewidth}%
    {.04\maru@boxwidth@new}}%
  \kks@fit@setup@circle{\maru@boxwidth@inner}{.02\maru@boxwidth@new}
    {.9\maru@boxwidth@new}{.5\kks@fit@lw}%
  % This route runs the ink guard below, so a single wide glyph may take the
  % historical wide size; anything the ink really oversteps is caught there.
  \def\kks@fit@widefree{1}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        fill=black,%%%
        line width=\kks@linewidth{\kksymbols@kuromarulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum size=.9\maru@boxwidth@new, 
        draw,
        inner sep=.02\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \kks@visual@guard@circle
            {\maru@boxwidth@inner}{.02\maru@boxwidth@new}{.9\maru@boxwidth@new}
            {\kks@linewidth{\kksymbols@kuromarulinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new}}
            {\kks@fit@into@box{\kks@fit@base}{\kks@visual@material}}
            {\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\nmaru@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \settowidth{\maru@var@yokohaba}{#1}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.85 * \maru@boxwidth@new / sqrt(2)}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        line width=\kks@linewidth{\kksymbols@nmarulinewidth}{\kksymbols@linewidth}{.03\maru@boxwidth@new},
        minimum size=.88\maru@boxwidth@new, 
        draw, double, double distance=.03\zw,%%%
        inner sep=.06\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko,
        scale=.87
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\maru@var@yokohaba}{\maru@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\maru@var@yokohaba}{\maru@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\nmaru@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.82 * \maru@boxwidth@new / sqrt(2)}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@nmarulinewidth}{\kksymbols@linewidth}%
    {.03\maru@boxwidth@new}}%
  % The doubled outline strokes a band of twice the line width plus the double
  % distance, and pgf transforms the path but not the stroke, so `scale' leaves
  % that band measured in the node's own, unscaled units.
  \kks@fit@setup@circle{\maru@boxwidth@inner}{.06\maru@boxwidth@new}
    {.88\maru@boxwidth@new}{(\kks@fit@lw + .015\maru@boxwidth@new) / 0.9}%
  \def\kks@fit@widefree{1}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=circle,
        line width=\kks@linewidth{\kksymbols@nmarulinewidth}{\kksymbols@linewidth}{.03\maru@boxwidth@new},
        minimum size=.88\maru@boxwidth@new, 
        draw, double, double distance=.03\zw,%%%
        inner sep=.06\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko,
        scale=.9
      ] (char){%
      \vbox to \maru@boxwidth@inner{%
        \vss%
        \hbox to \maru@boxwidth@inner{%
        \hss%
          \kks@fit@into@box{\kks@fit@base}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\newlength{\jegg@boxwidth@inner@cal}%%%
\DeclareRobustCommand{\jegg@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \settowidth{\maru@var@yokohaba}{#1}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \pgfmathsetlength{\jegg@boxwidth@inner@cal}{0.77 * \maru@boxwidth@inner}%%%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=ellipse,
        line width=\kks@linewidth{\kksymbols@jegglinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum height=.9\maru@boxwidth@new, 
        minimum width=.7\maru@boxwidth@new, 
        draw,
        inner sep=0\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \jegg@boxwidth@inner@cal{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\maru@var@yokohaba}{\jegg@boxwidth@inner@cal}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\maru@var@yokohaba}{\jegg@boxwidth@inner@cal}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\jegg@new@black}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\maru@boxwidth@new}{\zw}%
  \settowidth{\maru@var@yokohaba}{#1}%
  \pgfmathsetlength{\maru@boxwidth@inner}{0.87 * \maru@boxwidth@new / sqrt(2)}%
  \pgfmathsetlength{\jegg@boxwidth@inner@cal}{0.77 * \maru@boxwidth@inner}%%%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \maru@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \maru@boxwidth@new{%
  \vss%
  \hbox to \maru@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        shape=ellipse,
        line width=\kks@linewidth{\kksymbols@jegglinewidth}{\kksymbols@linewidth}{.04\maru@boxwidth@new},
        minimum height=.9\maru@boxwidth@new, 
        minimum width=.7\maru@boxwidth@new, 
        draw,
        fill=black!70,
        inner sep=0\maru@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \maru@boxwidth@inner{
        \vss%
        \hbox to \jegg@boxwidth@inner@cal{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\maru@var@yokohaba}{\jegg@boxwidth@inner@cal}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\maru@var@yokohaba}{\jegg@boxwidth@inner@cal}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}

% \jegg reserves its public star for the gray background, so the lowercase
% sizing path needs private wrappers instead of another user-visible star.
% The wrappers locally replace only the generic scaler used by \jegg; the
% drawing code and the starred background remain exactly the same.
%
% The egg also needs a scaler of its own.  Every other enclosure fits its
% material to a shape the \kks@fit@ helpers can describe, but \jegg's inner box
% (\jegg@boxwidth@inner@cal) is only the width limit of a much taller ellipse.
% Sizing lowercase from that single length made `c' as tall as the enclosed
% `C' and left wide `m'/`w' at a natural width that ran straight through the
% outline.  Scale uniformly instead: start from the size
% the circle enclosures give lowercase (.9 of the natural size), taken down by
% the .77 ratio between the egg's and the circle's inner boxes so that `c'
% keeps its familiar x-height-to-cap-height look next to \jegg{C}, and shrink
% further only when the glyph box does not fit inside the drawn ellipse.
%
% Both `minimum' keys win over the node contents and `inner sep' is 0, so the
% ellipse path is always .7\zw wide and .9\zw high, and TikZ centres the stroke
% on that path.  The usable half-axes are therefore .35\zw and .45\zw less half
% of the drawn line width.  That width is not always the historical .04\zw any
% more: `jegglinewidth' and `linewidth' can make the egg's stroke arbitrarily
% thicker, which eats into the interior, so the half-axes are derived from the
% very expression both drawing nodes hand to TikZ.  A box of width w and total
% height h centred on that ellipse fits exactly when (w/2a)^2 + (h/2b)^2 <= 1,
% so the square root below (call it the reach) must stay under 2; dividing the
% padding factor by it yields the largest aspect-preserving scale in one step.
\newbox\kks@jegg@lower@box
\newlength{\kks@jegg@lower@width}
\newlength{\kks@jegg@lower@height}
\newlength{\kks@jegg@lower@linewidth}
\newlength{\kks@jegg@lower@hradius}
\newlength{\kks@jegg@lower@vradius}
% Half of the ellipse path itself, before the stroke is taken into account.
\newcommand{\kks@jegg@lower@hradius@ratio}{.35}% .7\zw wide
\newcommand{\kks@jegg@lower@vradius@ratio}{.45}% .9\zw high
\newcommand{\kks@jegg@lower@base}{.69}% .9 (circle lowercase) * .77 (inner box)
\newcommand{\kks@jegg@lower@pad}{.92}% visual gap between glyph and outline
% #1 (natural width) and #2 (the inner box) only complete \shukushou@adj@new's
% signature; the egg takes its limits from the ellipse the wrapper measured.
\NewDocumentCommand{\kks@jegg@lowercase@scale}{ m m m }{%
  \begingroup
    \setbox\kks@jegg@lower@box=\hbox{#3}%
    \setlength{\kks@jegg@lower@width}{\wd\kks@jegg@lower@box}%
    \setlength{\kks@jegg@lower@height}{%
      \dimexpr\ht\kks@jegg@lower@box+\dp\kks@jegg@lower@box\relax}%
    % A stroke thick enough to swallow the ellipse leaves no interior to fit
    % into, and an empty argument has nothing to fit; in both cases there is no
    % reach to divide by, so fall back to the plain lowercase size.
    \ifdim\kks@jegg@lower@hradius>\z@
      \ifdim\kks@jegg@lower@vradius>\z@
        \pgfmathsetmacro{\kks@jegg@lower@reach}{%
          sqrt((\kks@jegg@lower@width / \kks@jegg@lower@hradius)^2
             + (\kks@jegg@lower@height / \kks@jegg@lower@vradius)^2)}%
      \else
        \def\kks@jegg@lower@reach{0}%
      \fi
    \else
      \def\kks@jegg@lower@reach{0}%
    \fi
    \ifdim\kks@jegg@lower@reach pt>\z@
      \pgfmathsetmacro{\kks@jegg@lower@scale}{%
        min(\kks@jegg@lower@base,
            2 * \kks@jegg@lower@pad / \kks@jegg@lower@reach)}%
    \else
      \let\kks@jegg@lower@scale\kks@jegg@lower@base
    \fi
    \scalebox{\kks@jegg@lower@scale}{\copy\kks@jegg@lower@box}%
  \endgroup
}
% The half-axes are measured here, in the surrounding text context, because the
% scaler itself runs inside the TikZ node where \zw need not be the enclosure's
% own Japanese em.  \maru@boxwidth@new is set exactly as \jegg@new sets it, so a
% relative line width resolves against the same em the outline is drawn with.
\newcommand{\kks@jegg@lower@setup}{%
  \setlength{\maru@boxwidth@new}{\zw}%
  \setlength{\kks@jegg@lower@linewidth}{%
    \kks@linewidth{\kksymbols@jegglinewidth}{\kksymbols@linewidth}%
      {.04\maru@boxwidth@new}}%
  % A negative option value is already reported when the package loads; ignore
  % its sign here so a stroke can never widen the interior past the path.
  \ifdim\kks@jegg@lower@linewidth<\z@
    \setlength{\kks@jegg@lower@linewidth}{\z@}%
  \fi
  \setlength{\kks@jegg@lower@hradius}{\kks@jegg@lower@hradius@ratio\zw}%
  \addtolength{\kks@jegg@lower@hradius}{-.5\kks@jegg@lower@linewidth}%
  \setlength{\kks@jegg@lower@vradius}{\kks@jegg@lower@vradius@ratio\zw}%
  \addtolength{\kks@jegg@lower@vradius}{-.5\kks@jegg@lower@linewidth}%
  \let\shukushou@adj@new\kks@jegg@lowercase@scale
}
\DeclareRobustCommand{\jegg@new@no}[1]{%
  \leavevmode
  \begingroup
    \kks@jegg@lower@setup
    \jegg@new{#1}%
  \endgroup
}
\DeclareRobustCommand{\jegg@new@black@no}[1]{%
  \leavevmode
  \begingroup
    \kks@jegg@lower@setup
    \jegg@new@black{#1}%
  \endgroup
}
%%%


% \seihou
\NewDocumentCommand{\vertical@adj@seihou@new}{}{%
  \ifnum\ltjgetparameter{direction}=3
    -.5\zw%
  \else
    -.12\zw%
  \fi
}
\newlength{\seihou@boxwidth@new}
\newlength{\seihou@boxwidth@inner}
\newlength{\seihou@var@yokohaba}

\DeclareRobustCommand{\seihou@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@seihoulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\seihou@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@seihoulinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@rect{\seihou@boxwidth@inner}{.1\seihou@boxwidth@new}
    {.85\seihou@boxwidth@new}{.5\kks@fit@lw}{0pt}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@seihoulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@box{\kks@fit@base}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\kuroseihou@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuroseihoulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \else%
            \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kuroseihou@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@kuroseihoulinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@rect{\seihou@boxwidth@inner}{.1\seihou@boxwidth@new}
    {.85\seihou@boxwidth@new}{.5\kks@fit@lw}{0pt}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuroseihoulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@box{\kks@fit@base}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\seimaru@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@seimarulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        rounded corners=.13\zw,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \else%
            \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\seimaru@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@seimarulinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@rect{\seihou@boxwidth@inner}{.1\seihou@boxwidth@new}
    {.85\seihou@boxwidth@new}{.5\kks@fit@lw}{.13\seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@seimarulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        rounded corners=.13\zw,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@box{\kks@fit@base}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\kuroseimaru@new}[1]{%
  \kks@chech@maru@onedigit{#1}%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuroseimarulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        rounded corners=.13\zw,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \ifkksdigit@maru@new%
            \shukushou@adj@new@maru@onedigit{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \else%
            \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
          \fi%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kuroseimaru@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.68 * \seihou@boxwidth@new}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@kuroseimarulinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@rect{\seihou@boxwidth@inner}{.1\seihou@boxwidth@new}
    {.85\seihou@boxwidth@new}{.5\kks@fit@lw}{.13\seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuroseimarulinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.85\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        rounded corners=.13\zw,%%%
        inner sep=.1\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@box{\kks@fit@base}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\hishi@new}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@hishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\hishi@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@hishilinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@diamond{\seihou@boxwidth@inner}{.03\seihou@boxwidth@new}
    {.5\seihou@boxwidth@new}{\kks@fit@lw}{0pt}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@hishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@diamond{\kks@fit@base}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\maruhishi@new}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@maruhishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        rounded corners=.06\zw,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\maruhishi@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@maruhishilinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@diamond{\seihou@boxwidth@inner}{.03\seihou@boxwidth@new}
    {.5\seihou@boxwidth@new}{\kks@fit@lw}{.06\seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@maruhishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        rounded corners=.06\zw,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@diamond{\kks@fit@base}{\kks@withref{\kks@ShrinkedNumber{#1}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\kurohishi@new}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kurohishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kurohishi@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@kurohishilinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@diamond{\seihou@boxwidth@inner}{.03\seihou@boxwidth@new}
    {.5\seihou@boxwidth@new}{\kks@fit@lw}{0pt}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kurohishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@diamond{\kks@fit@base}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}


\DeclareRobustCommand{\kuromaruhishi@new}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \settowidth{\seihou@var@yokohaba}{#1}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuromaruhishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        rounded corners=.06\zw,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{%
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \shukushou@adj@new{\seihou@var@yokohaba}{\seihou@boxwidth@inner}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kuromaruhishi@new@no}[1]{%
  \rot@or@not@kksym%
  \setlength{\seihou@boxwidth@new}{\zw}%
  \pgfmathsetlength{\seihou@boxwidth@inner}{0.85 * \seihou@boxwidth@new / 2}%
  \kks@fit@linewidth{\kks@linewidth{\kksymbols@kuromaruhishilinewidth}{\kksymbols@linewidth}%
    {.04\seihou@boxwidth@new}}%
  \kks@fit@setup@diamond{\seihou@boxwidth@inner}{.03\seihou@boxwidth@new}
    {.5\seihou@boxwidth@new}{\kks@fit@lw}{.06\seihou@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
  \hbox to \seihou@boxwidth@new{%
  \raisebox{\vertical@adj@maru@new}{%
  \vbox to \seihou@boxwidth@new{%
  \vss%
  \hbox to \seihou@boxwidth@new{%
    \hss%
    \tikz[baseline=(char.base)]{%
      \node[
        line width=\kks@linewidth{\kksymbols@kuromaruhishilinewidth}{\kksymbols@linewidth}{.04\seihou@boxwidth@new},
        minimum size=.5\seihou@boxwidth@new, 
        draw,
        fill=black,%%%
        rounded corners=.06\zw,%%%
        shape=diamond,
        inner sep=.03\seihou@boxwidth@new,
        rotate=\rot@kksym@tateyoko
      ] (char){%
      \vbox to \seihou@boxwidth@inner{
        \vss%
        \hbox to \seihou@boxwidth@inner{%
        \hss%
          \kks@fit@into@diamond{\kks@fit@base}{%
            \textcolor{white}{\kks@withref{\kks@ShrinkedNumber{#1}}}}%
        \hss%
        }%
        \vss%
      }%
      };
    }%
    \hss%
  }%
  \vss%
  }%
  }%
  }%
  \ltjghostafterjachar%
}
%%%


% \kakko
\newlength{\kakko@boxwidth@new}
\newlength{\kakko@boxwidth@inner}
\newlength{\kakko@var@yokohaba}

\DeclareRobustCommand{\kakko@byouga@internal}[3]{% 横の方
  \rot@or@not@kksym%
  \setlength{\kakko@boxwidth@new}{\zw}%
  \settowidth{\kakko@var@yokohaba}{#3}%
  \pgfmathsetlength{\kakko@boxwidth@inner}{0.8 * \kakko@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
    \hbox to \zw{\hss%
      \scalebox{\kks@bracket@xscale}[1]{#1}\hspace*{-\kks@bracket@overlap}%
      \raisebox{-.03\zw}{%
        \vbox to \kakko@boxwidth@inner{%
          \vss%
          \hbox to \kakko@boxwidth@inner{%
          \hss%
            \rotatebox[origin=c]{\rot@kksym@tateyoko}{%
              \shukushou@adj@new{\kakko@var@yokohaba}{\kakko@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#3}}}}%
          \hss%
          }%
          \vss%
        }%
      }%
      \hspace*{-\kks@bracket@overlap}\scalebox{\kks@bracket@xscale}[1]{#2}%
    \hss}%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kakko@byouga@internal@no}[3]{% 横の方
  \rot@or@not@kksym%
  \setlength{\kakko@boxwidth@new}{\zw}%
  \pgfmathsetlength{\kakko@boxwidth@inner}{0.8 * \kakko@boxwidth@new}%
  \kks@fit@setup@plain{\kakko@boxwidth@inner}{\kakko@boxwidth@inner}%
  \leavevmode%
  \ltjghostbeforejachar%
    \hbox to \zw{\hss%
      \scalebox{\kks@bracket@xscale}[1]{#1}\hspace*{-\kks@bracket@overlap}%
      \raisebox{-.03\zw}{%
        \vbox to \kakko@boxwidth@inner{%
          \vss%
          \hbox to \kakko@boxwidth@inner{%
          \hss%
            \rotatebox[origin=c]{\rot@kksym@tateyoko}{%
              \kks@visual@guard@bracket{#1}{#2}{\kakko@boxwidth@inner}{\rot@kksym@tateyoko}{%
                \kks@fit@into@box{\kks@fit@base}{\kks@visual@material}}{%
                \kks@withref{\kks@ShrinkedNumber{#3}}}}%
          \hss%
          }%
          \vss%
        }%
      }%
      \hspace*{-\kks@bracket@overlap}\scalebox{\kks@bracket@xscale}[1]{#2}%
    \hss}%
  \ltjghostafterjachar%
}

\DeclareRobustCommand{\kakko@byouga@internal@tate}[3]{% 縦の方
  \rot@or@not@kksym%
  \ifnum\ltjgetparameter{direction}=3\pgfmathsetmacro{\rot@kksym@tateyoko}{\rot@kksym@tateyoko - 90}\fi%
  \setlength{\kakko@boxwidth@new}{\zw}%
  \settowidth{\kakko@var@yokohaba}{#3}%
  \pgfmathsetlength{\kakko@boxwidth@inner}{0.8 * \kakko@boxwidth@new}%
  \leavevmode%
  \ltjghostbeforejachar%
    \raisebox{-.5\zw}{%
    \rotatebox[origin=c]{90}{%
    \hbox to \zw{\hss%
    \vbox to \zw{\vss%
      \hbox to \zw{\hss%
      \scalebox{\kks@bracket@xscale}[1]{#1}\hspace*{-\kks@bracket@overlap}%
        \vbox to \kakko@boxwidth@inner{%
        \vss%
        \hbox to \kakko@boxwidth@inner{%
        \hss%
          \raisebox{-1.2\zw}{%
            \rotatebox[origin=c]{\rot@kksym@tateyoko}{%
              \shukushou@adj@new{\kakko@var@yokohaba}{\kakko@boxwidth@inner}{\kks@withref{\kks@ShrinkedNumber{#3}}}%
            }%
          }%
        \hss%
        }%
        \vss%
      }%
      \hspace*{-\kks@bracket@overlap}\scalebox{\kks@bracket@xscale}[1]{#2}\vspace*{.3\zw}%
    \hss}%
    \vss}%
    \hss}%
    }%
    }%
  \ltjghostafterjachar%
}
\DeclareRobustCommand{\kakko@byouga@internal@tate@no}[3]{% 縦の方
  \rot@or@not@kksym%
  \ifnum\ltjgetparameter{direction}=3\pgfmathsetmacro{\rot@kksym@tateyoko}{\rot@kksym@tateyoko - 90}\fi%
  \setlength{\kakko@boxwidth@new}{\zw}%
  \pgfmathsetlength{\kakko@boxwidth@inner}{0.8 * \kakko@boxwidth@new}%
  \kks@fit@setup@plain{\kakko@boxwidth@inner}{\kakko@boxwidth@inner}%
  \leavevmode%
  \ltjghostbeforejachar%
    \raisebox{-.5\zw}{%
    \rotatebox[origin=c]{90}{%
    \hbox to \zw{\hss%
    \vbox to \zw{\vss%
      \hbox to \zw{\hss%
      \scalebox{\kks@bracket@xscale}[1]{#1}\hspace*{-\kks@bracket@overlap}%
        \vbox to \kakko@boxwidth@inner{%
        \vss%
        \hbox to \kakko@boxwidth@inner{%
        \hss%
          \raisebox{-1.6\zw}{%
            \vbox to \kakko@boxwidth@inner{%
            \vss%
            \hbox to \kakko@boxwidth@inner{%
            \hss%
            \rotatebox[origin=c]{\rot@kksym@tateyoko}{%
              \kks@visual@guard@bracket{#1}{#2}{\kakko@boxwidth@inner}{\rot@kksym@tateyoko}{%
                \kks@fit@into@box{\kks@fit@base}{\kks@visual@material}}{%
                \kks@withref{\kks@ShrinkedNumber{#3}}}%
            }\hss}\vss}%
          }%
        \hss%
        }%
        \vss%
      }%
      \hspace*{-\kks@bracket@overlap}\scalebox{\kks@bracket@xscale}[1]{#2}\vspace*{.3\zw}%
    \hss}%
    \vss}%
    \hss}%
    }%
    }%
  \ltjghostafterjachar%
}
%%%


% \ichimoji
% \ichimoji draws no frame, but its star route still has to keep arbitrary
% material inside the one em it reserves.  It used to squeeze the width alone,
% which distorted anything wider than an em; scale uniformly instead, and, as
% before, leave material that already fits at its natural size.
\DeclareRobustCommand{\ichimoji@scaling}[1]{%
  \kks@fit@setup@plain{\zw}{\zw}%
  \kks@fit@into@box{1}{#1}%
}
\DeclareRobustCommand{\ichimoji@new}[1]{%
  \ifnum\ltjgetparameter{direction}=3%
    \leavevmode%
    \ltjghostbeforejachar%
    \raisebox{-.5\zw}{%
      \hbox to \zw {\hss%
      \vbox to \zw {\vss%
      \hbox to \zw {\hss%
        \resizebox*{\zw}{\zw}{#1}%
      \hss}%
      \vss}%
      \hss}%
    }%
    \ltjghostafterjachar%
  \else%
    \leavevmode%
    \ltjghostbeforejachar%
    \raisebox{-.12\zw}{%
      \hbox to \zw {\hss%
      \vbox to \zw {\vss%
      \hbox to \zw {\hss%
        \resizebox*{\zw}{\zw}{#1}%
      \hss}%
      \vss}%
      \hss}%
    }%
    \ltjghostafterjachar%
  \fi%
}
\DeclareRobustCommand{\ichimoji@new@no}[1]{%
  \ifnum\ltjgetparameter{direction}=3%
    \leavevmode%
    \ltjghostbeforejachar%
    \raisebox{-.5\zw}{%
      \hbox to \zw {\hss%
      \vbox to \zw {\vss%
      \hbox to \zw {\hss%
        \ichimoji@scaling{#1}%
      \hss}%
      \vss}%
      \hss}%
    }%
    \ltjghostafterjachar%
  \else%
    \leavevmode%
    \ltjghostbeforejachar%
    \raisebox{-.12\zw}{%
      \hbox to \zw {\hss%
      \vbox to \zw {\vss%
      \hbox to \zw {\hss%
        \ichimoji@scaling{#1}%
      \hss}%
      \vss}%
      \hss}%
    }%
    \ltjghostafterjachar%
  \fi%
}
%%%


% \zenkakuhabafixer
\newlength{\zenkakuhabafixer@yk@new}
\DeclareRobustCommand{\zenkakuhabafixer}[1]{%
  \leavevmode%
  \settowidth{\zenkakuhabafixer@yk@new}{#1}%
  \ifdim\zenkakuhabafixer@yk@new>\zw%
    \ltjghostbeforejachar%
    \hbox to \zw {%
      \resizebox{\zw}{\height}{#1}%
    }%
    \ltjghostafterjachar%
  \else%
    \ltjghostbeforejachar%
    \hbox to \zw {%
      \hss #1\hss%
    }%
    \ltjghostafterjachar%
  \fi%
}
%%%
\endinput
