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

% Copyright (c) 2025 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{luwa-ul}[2026/01/30, Version 1.2.5]

\RequirePackage{luatexja-adjust}
\RequirePackage{luacolor, lua-ul, calc, tikz}
\RequirePackage[dvipsnames, svgnames, x11names]{xcolor}


%%% colors
\definecolor{mygray@luwa-ul}{RGB}{60, 60, 60}
%%%


%%% horizontal-vertical adjust
\newlength{\underLine@KK@Adjust@tmp}
\newlength{\KKUL@bottom}
\newlength{\KKUL@height}
\NewDocumentCommand{\underLine@KK@Adjust@bottom}{m}{%
  \setlength{\underLine@KK@Adjust@tmp}{\zw}%
  \ifnum\ltjgetparameter{direction}=3%
    \def\underLine@KK@Adjust@use@bottom{\dimexpr -#1+\underLine@KK@Adjust@tmp/2\relax}%
  \else%
    \def\underLine@KK@Adjust@use@bottom{\dimexpr #1-\underLine@KK@Adjust@tmp/7\relax}%
  \fi%
}
\NewDocumentCommand{\underLine@KK@Adjust@height}{m}{%
  \ifnum\ltjgetparameter{direction}=3%
    \def\underLine@KK@Adjust@use@height{#1}%
  \else%
    \def\underLine@KK@Adjust@use@height{#1}%
  \fi%
}
%%%


%%% Auto Depth Adjust System 
\newlength{\temp@depth@kk}
\NewDocumentCommand{\getdepth@kk}{m}{%
  \ifnum\ltjgetparameter{direction}=3%
    \settoheight{\temp@depth@kk}{#1}%
    \addtolength{\temp@depth@kk}{-.5\zw}%
    \setlength{\temp@depth@kk}{-\temp@depth@kk}%
  \else%
    \settodepth{\temp@depth@kk}{#1}%
    \addtolength{\temp@depth@kk}{-.12\zw}%
  \fi%
}
%%%


%%% \underLineKK
% totally-plain
\define@key{KKUL}{bottom}{%
  \underLine@KK@Adjust@bottom{#1}%
  \setlength{\KKUL@bottom}{\underLine@KK@Adjust@use@bottom}%
}
\define@key{KKUL}{height}{%
  \underLine@KK@Adjust@height{#1}%
  \setlength{\KKUL@height}{\underLine@KK@Adjust@use@height}%
}
\define@key{KKUL}{color}{%
  \def\KKUL@color{#1}%
}
\NewDocumentCommand{\underLineKK@plain}{ O{} +m }{%
  \underLine@KK@Adjust@bottom{-.1\zw}%
  \underLine@KK@Adjust@height{0.3pt}%
  \setlength{\KKUL@bottom}{\underLine@KK@Adjust@use@bottom}%
  \setlength{\KKUL@height}{\underLine@KK@Adjust@use@height}%
  \def\KKUL@color{black}%
  \def\underLineKK@test@contents{#2}%
  \setkeys{KKUL}{#1}%
  \underLine[bottom=\KKUL@bottom, height=\KKUL@height, color=\KKUL@color]{#2}%
}

% Manual
\NewDocumentCommand{\underLineKK}{ O{} +m }{%
  \underLine@KK@Adjust@bottom{-.1\zw}%
  \underLine@KK@Adjust@height{0.3pt}%
  \setlength{\KKUL@bottom}{\underLine@KK@Adjust@use@bottom}%
  \setlength{\KKUL@height}{\underLine@KK@Adjust@use@height}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\KKUL@bottom}{-.1\zw}%
  \fi%
  \def\KKUL@color{black}%
  \def\underLineKK@test@contents{#2}%
  \setkeys{KKUL}{#1}%
  \underLine[bottom=\KKUL@bottom, height=\KKUL@height, color=\KKUL@color]{#2}%
}

% Auto
\NewDocumentCommand{\underLineKKAuto@make}{ O{} +m }{%
  \underLine@KK@Adjust@bottom{-.1\zw}%
  \underLine@KK@Adjust@height{0.3pt}%
  \setlength{\temp@depth@kk}{0pt}%
  \setlength{\KKUL@bottom}{\underLine@KK@Adjust@use@bottom}%
  \setlength{\KKUL@height}{\underLine@KK@Adjust@use@height}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\KKUL@bottom}{-.1\zw}%
  \fi%
  \def\KKUL@color{black}%
  \def\underLineKK@test@contents{#2}%
  \setkeys{KKUL}{#1}%
  \getdepth@kk{\underLineKK@test@contents}%
  \underLine[bottom=\KKUL@bottom-\temp@depth@kk, height=\KKUL@height, color=\KKUL@color]{#2}%
}
% mathmode-adjust
\NewDocumentCommand{\underLineKKAuto}{ O{} +m }{%
  \ifmmode%
    \mathchoice%
      {\mbox{\underLineKKAuto@make[#1]{$\displaystyle #2$}}}      % displaystyle
      {\mbox{\underLineKKAuto@make[#1]{$\textstyle #2$}}}         % textstyle (inline)
      {\mbox{\underLineKKAuto@make[#1]{$\scriptstyle #2$}}}       % scriptstyle
      {\mbox{\underLineKKAuto@make[#1]{$\scriptscriptstyle #2$}}} % scriptscriptstyle
  \else%
    \underLineKKAuto@make[#1]{#2}%
  \fi%
}
%%%


%%% \namiKK（元の名称はsnamiftだが、変更）
\newlength{\snamift@bottom}\setlength{\snamift@bottom}{0pt}
\define@key{snamift}{bottom}{%
  \setlength{\snamift@bottom}{#1}%
}
\define@key{snamift}{color}{%
  \def\snamift@color{#1}%
}

% 名称変更用のカウンター（グローバル変数）
\newcount\snamift@id

\NewDocumentCommand{\namiKK}{ O{} +m }{%
  % 1：キーを先にセットして \snamift@bottom を更新
  \setlength{\snamift@bottom}{0pt}%
  \def\snamift@color{black}%
  \def\snamift@test@contents{#2}%
  \setkeys{snamift}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\snamift@bottom}{-.1\zw}%
  \fi%
  % 2：IDを進める
  \global\advance\snamift@id by 1\relax%
  % 3：ユニーク名で下線タイプを定義（正しく展開されるように \expandafter と \number を使用）
  \expandafter\newunderlinetype\csname beginUnderWavyS\number\snamift@id\endcsname{%
    \cleaders\hbox{%
      \begin{tikzpicture}[xscale=.8,baseline=\zw/4 pt,
                          x=\zw/12 pt,y=\zw/25 pt]
        \clip[yshift=\snamift@bottom] (1,\zw/8 pt) rectangle (5,-\zw/8 pt);
        \draw[line width=\zw/24 pt,yshift=\snamift@bottom,\snamift@color]
          (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
          sin (5,1) cos (6,0);
      \end{tikzpicture}%
    }%
  }%
  \expandafter\newunderlinetype\csname beginUnderWavyState\number\snamift@id\endcsname{%
    \cleaders\hbox{%
      \begin{tikzpicture}[xscale=.8,baseline=\zw/4 pt,
                          x=\zw/12 pt,y=\zw/25 pt]
        \begin{scope}[yshift=\zw/1.2 pt]
          \clip[yshift=\snamift@bottom] (1,\zw/8 pt) rectangle (5,-\zw/8 pt);
          \draw[line width=\zw/24 pt,yshift=\snamift@bottom,\snamift@color]
            (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
            sin (5,1) cos (6,0);
        \end{scope}
      \end{tikzpicture}%
    }%
  }%
  % 4：使用（縦横の分岐；直接 csname を呼ぶ）
  {\ifnum\ltjgetparameter{direction}=3 %
    \csname beginUnderWavyState\number\snamift@id\endcsname{#2}%
  \else%
    \csname beginUnderWavyS\number\snamift@id\endcsname{#2}%
  \fi}%
}

\NewDocumentCommand{\namiKKAuto@make}{ O{} +m }{%
  \setlength{\snamift@bottom}{0pt}%
  \def\snamift@color{black}%
  \def\snamift@test@contents{#2}%
  \setkeys{snamift}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\snamift@bottom}{-.1\zw}%
  \fi%
  \setlength{\temp@depth@kk}{0pt}%
  \getdepth@kk{\snamift@test@contents}%
  \global\advance\snamift@id by 1\relax%
  \expandafter\newunderlinetype\csname beginUnderWavyS\number\snamift@id\endcsname{%
    \cleaders\hbox{%
      \begin{tikzpicture}[xscale=.8, baseline=\zw/4, x=\zw/12, y=\zw/25]
        \begin{scope}[yshift=-\temp@depth@kk]
          \clip[yshift=\snamift@bottom] (1,\zw/8) rectangle (5,-\zw/8);
          \draw[line width=\zw/24 , yshift=\snamift@bottom, \snamift@color]
            (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
            sin (5,1) cos (6,0);
        \end{scope}
      \end{tikzpicture}%
    }%
  }%
  \expandafter\newunderlinetype\csname beginUnderWavyState\number\snamift@id\endcsname{%
    \cleaders\hbox{%
      \begin{tikzpicture}[xscale=.8, baseline=\zw/4, x=\zw/12, y=\zw/25]
        \begin{scope}[yshift=\zw/1.2 - \temp@depth@kk]
          \clip[yshift=\snamift@bottom] (1,\zw/8) rectangle (5,-\zw/8);
          \draw[line width=\zw/24, yshift=\snamift@bottom, \snamift@color]
            (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
            sin (5,1) cos (6,0);
        \end{scope}
      \end{tikzpicture}%
    }%
  }%
  {\ifnum\ltjgetparameter{direction}=3 %
    \csname beginUnderWavyState\number\snamift@id\endcsname{#2}%
  \else%
    \csname beginUnderWavyS\number\snamift@id\endcsname{#2}%
  \fi}%
}
\NewDocumentCommand{\namiKKAuto}{ O{} +m }{%
  \ifmmode%
    \mathchoice%
      {\mbox{\namiKKAuto@make[#1]{$\displaystyle #2$}}}%
      {\mbox{\namiKKAuto@make[#1]{$\textstyle #2$}}}%
      {\mbox{\namiKKAuto@make[#1]{$\scriptstyle #2$}}}%
      {\mbox{\namiKKAuto@make[#1]{$\scriptscriptstyle #2$}}}%
  \else%
    \namiKKAuto@make[#1]{#2}%
  \fi%
}
%%%


%%% \tenKK, \dashKK（元の名称はstengthとsdashgthだが、変更）
\newlength{\sladj@tenKK@dashKK}
\sladj@tenKK@dashKK =.07\zw

\newlength{\stength@radius}
\newlength{\stength@distance}
\newlength{\stength@bottom}

\define@key{stength}{radius}{\setlength{\stength@radius}{#1}}
\define@key{stength}{distance}{\setlength{\stength@distance}{#1}}
\define@key{stength}{bottom}{\setlength{\stength@bottom}{#1}}
\define@key{stength}{color}{\def\stength@color{#1}}

\newcount\stength@id  

\NewDocumentCommand{\tenKK}{ O{} +m }{%
  \setlength{\stength@radius}{.1ex}%
  \setlength{\stength@distance}{.4ex}%
  \setlength{\stength@bottom}{0pt}%
  \def\stength@color{mygray@luwa-ul}%
  \def\stength@test@contents{#2}%
  \setkeys{stength}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\stength@bottom}{-.1\zw}%
  \fi%
  \global\advance\stength@id by 1\relax%
  \expandafter\newunderlinetype\csname beginUnderDot\number\stength@id\endcsname{%
  \xleaders\hbox{%
  \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
    \fill[\stength@color,yshift=\stength@bottom+\sladj@tenKK@dashKK] (0.3,0) circle (\stength@radius);
    \path[use as bounding box,yshift=\stength@bottom+\sladj@tenKK@dashKK] (0,0) rectangle (\stength@distance,0);
  \end{tikzpicture}%
  }%
  }%
  \expandafter\newunderlinetype\csname beginUnderDottate\number\stength@id\endcsname{%
  \xleaders\hbox{%
  \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
    \begin{scope}[yshift=\zw/1.1]
    \fill[\stength@color,yshift=\stength@bottom] (0.3,0) circle (\stength@radius);
    \path[use as bounding box,yshift=\stength@bottom] (0,0) rectangle (\stength@distance,0);
    \end{scope}
  \end{tikzpicture}%
  }%
  }%
  {\ifnum\ltjgetparameter{direction}=3 %
    \csname beginUnderDottate\number\stength@id\endcsname{#2}%
  \else%
    \csname beginUnderDot\number\stength@id\endcsname{#2}%
  \fi}%
}
\NewDocumentCommand{\tenKKAuto}{ O{} +m }{%
  \ifmmode%
    \mathchoice%
      {\mbox{\tenKKAuto@make[#1]{$\displaystyle #2$}}}% 
      {\mbox{\tenKKAuto@make[#1]{$\textstyle #2$}}}%
      {\mbox{\tenKKAuto@make[#1]{$\scriptstyle #2$}}}%
      {\mbox{\tenKKAuto@make[#1]{$\scriptscriptstyle #2$}}}%
  \else%
    \tenKKAuto@make[#1]{#2}%
  \fi%
}

\NewDocumentCommand{\tenKKAuto@make}{ O{} +m }{%
  \setlength{\stength@radius}{.05\zw}%
  \setlength{\stength@distance}{.2\zw}%
  \setlength{\stength@bottom}{0pt}%
  \def\stength@color{mygray@luwa-ul}%
  \def\stength@test@contents{#2}%
  \setkeys{stength}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\stength@bottom}{-.1\zw}%
  \fi%
  \setlength{\temp@depth@kk}{0pt}%
  \getdepth@kk{\stength@test@contents}%
  \global\advance\stength@id by 1\relax%
  \expandafter\newunderlinetype\csname beginUnderDot\number\stength@id\endcsname{%
  \xleaders\hbox{%
  \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
    \begin{scope}[yshift=-\temp@depth@kk]
      \fill[\stength@color,yshift=\stength@bottom+\sladj@tenKK@dashKK] (0.3,0) circle (\stength@radius);
      \path[use as bounding box,yshift=\stength@bottom+\sladj@tenKK@dashKK] (0,0) rectangle (\stength@distance,0);
    \end{scope}
  \end{tikzpicture}%
  }%
  }%
  \expandafter\newunderlinetype\csname beginUnderDottate\number\stength@id\endcsname{%
  \xleaders\hbox{%
  \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
    \begin{scope}[yshift=\zw/1.1 - \temp@depth@kk]
    \fill[\stength@color,yshift=\stength@bottom] (0.3,0) circle (\stength@radius);
    \path[use as bounding box,yshift=\stength@bottom] (0,0) rectangle (\stength@distance,0);
    \end{scope}
  \end{tikzpicture}%
  }%
  }%
  {\ifnum\ltjgetparameter{direction}=3 %
    \csname beginUnderDottate\number\stength@id\endcsname{#2}%
  \else%
    \csname beginUnderDot\number\stength@id\endcsname{#2}%
  \fi}%
}


\newlength{\underdash@length}
\newlength{\underdash@distance}
\newlength{\underdash@width}
\newlength{\underdash@bottom}

\define@key{underdashgth}{length}{\setlength{\underdash@length}{#1}}
\define@key{underdashgth}{distance}{\setlength{\underdash@distance}{#1}}
\define@key{underdashgth}{width}{\setlength{\underdash@width}{#1}}
\define@key{underdashgth}{bottom}{\setlength{\underdash@bottom}{#1}}
\define@key{underdashgth}{color}{\def\underdashgth@color{#1}}

\newcount\underdash@id 

\NewDocumentCommand{\dashKK}{ O{} +m }{%
  \setlength{\underdash@length}{.2\zw}%
  \setlength{\underdash@distance}{.15\zw}%
  \setlength{\underdash@width}{.2pt}%
  \setlength{\underdash@bottom}{0pt}%
  \def\underdashgth@color{black}%
  \def\sdashgth@test@contents{#2}%
  \setkeys{underdashgth}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\underdash@bottom}{-.1\zw}%
  \fi%
  \global\advance\underdash@id by 1\relax%
  \expandafter\newunderlinetype\csname beginUnderDash\number\underdash@id\endcsname{%
    \xleaders\hbox{%
      \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
        \draw[\underdashgth@color,line width=\underdash@width,xshift=.108\zw,yshift=\underdash@bottom+\sladj@tenKK@dashKK]%
        (0,0) -- (\underdash@length,0);%
        \path[use as bounding box,yshift=\underdash@bottom+\sladj@tenKK@dashKK] (0,0) rectangle (\underdash@length+\underdash@distance,0);%
      \end{tikzpicture}%
    }%
  }%
  \expandafter\newunderlinetype\csname beginUnderDashtate\number\underdash@id\endcsname{%
    \xleaders\hbox{%
      \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
        \begin{scope}[yshift=\zw/1.1]%
          \draw[\underdashgth@color,line width=\underdash@width,xshift=.043\zw,yshift=\underdash@bottom]%
          (0,0) -- (\underdash@length,0);%
          \path[use as bounding box,yshift=\underdash@bottom] (0,0) rectangle (\underdash@length+\underdash@distance,0);%
        \end{scope}%
      \end{tikzpicture}%
    }%
  }%
  {\ifnum\ltjgetparameter{direction}=3 %
    \csname beginUnderDashtate\number\underdash@id\endcsname{#2}%
  \else%
    \csname beginUnderDash\number\underdash@id\endcsname{#2}%
  \fi}%
}

\NewDocumentCommand{\dashKKAuto@make}{ O{} +m }{%
  \setlength{\underdash@length}{.4ex}%
  \setlength{\underdash@distance}{.3ex}%
  \setlength{\underdash@width}{.2pt}%
  \setlength{\underdash@bottom}{0ex}%
  \def\underdashgth@color{black}%
  \def\sdashgth@test@contents{#2}%
  \setkeys{underdashgth}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \addtolength{\underdash@bottom}{-.1\zw}%
  \fi%
  \setlength{\temp@depth@kk}{0pt}%
  \getdepth@kk{\sdashgth@test@contents}%
  \global\advance\underdash@id by 1\relax%
  \expandafter\newunderlinetype\csname beginUnderDash\number\underdash@id\endcsname{%
    \xleaders\hbox{%
      \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
        \begin{scope}[yshift=-\temp@depth@kk]
          \draw[\underdashgth@color,line width=\underdash@width,xshift=.108\zw,yshift=\underdash@bottom+\sladj@tenKK@dashKK] (0,0) -- (\underdash@length,0);%
          \path[use as bounding box,yshift=\underdash@bottom+\sladj@tenKK@dashKK] (0,0) rectangle (\underdash@length+\underdash@distance,0);%
        \end{scope}
      \end{tikzpicture}%
    }%
  }%
  \expandafter\newunderlinetype\csname beginUnderDashtate\number\underdash@id\endcsname{%
    \xleaders\hbox{%
      \begin{tikzpicture}[x=.344\zw,y=.086\zw,baseline=.301\zw]%
        \begin{scope}[yshift=\zw/1.1 - \temp@depth@kk]%
          \draw[\underdashgth@color,line width=\underdash@width,xshift=.043\zw,yshift=\underdash@bottom] (0,0) -- (\underdash@length,0);%
          \path[use as bounding box,yshift=\underdash@bottom] (0,0) rectangle (\underdash@length+\underdash@distance,0);%
        \end{scope}%
      \end{tikzpicture}%
    }%
  }%
  {\ifnum\ltjgetparameter{direction}=3%
    \csname beginUnderDashtate\number\underdash@id\endcsname{#2}%
  \else%
    \csname beginUnderDash\number\underdash@id\endcsname{#2}%
  \fi}%
}
\NewDocumentCommand{\dashKKAuto}{ O{} +m }{%
  \ifmmode%
    \mathchoice%
      {\mbox{\dashKKAuto@make[#1]{$\displaystyle #2$}}}%
      {\mbox{\dashKKAuto@make[#1]{$\textstyle #2$}}}%
      {\mbox{\dashKKAuto@make[#1]{$\scriptstyle #2$}}}%
      {\mbox{\dashKKAuto@make[#1]{$\scriptscriptstyle #2$}}}%
  \else%
    \dashKKAuto@make[#1]{#2}%
  \fi%
}
%%%


%%% \overLine
\define@key{overLine}{color}{%
  \def\overLineKK@color{#1}%
}

\newlength{\overLineKK@KK@Adjust}

\NewDocumentCommand{\overLineKK}{ O{} +m }{%
  \setlength{\overLineKK@KK@Adjust}{\zw}%
  \def\overLineKK@color{black}%
  \def\overLineKK@test@contents{#2}%
  \setkeys{overLine}{#1}%
  \underLineKK[bottom=\overLineKK@KK@Adjust-.05\zw,color=\overLineKK@color]{#2}%
  }

\newlength{\temp@depth@kk@over}

% overline専用の調整機構
\NewDocumentCommand{\getdepth@kk@over}{m}{%
  \ifnum\ltjgetparameter{direction}=3%
    \settodepth{\temp@depth@kk@over}{#1}%
    \addtolength{\temp@depth@kk@over}{-.45\zw}%
  \else%
    \settoheight{\temp@depth@kk@over}{#1}%
    \addtolength{\temp@depth@kk@over}{-.8\zw}%
    \setlength{\temp@depth@kk@over}{-\temp@depth@kk@over}%
  \fi%
}

\NewDocumentCommand{\overLineKKAuto}{ O{} +m }{%
  \setlength{\overLineKK@KK@Adjust}{\zw}%
  \setlength{\temp@depth@kk@over}{0pt}%
  \def\overLineKK@color{black}%
  \def\overLineKK@test@contents{#2}%
  \getdepth@kk@over{\overLineKK@test@contents}%
  \setkeys{overLine}{#1}%
  \underLineKK@plain[bottom=\overLineKK@KK@Adjust-\temp@depth@kk@over,color=\overLineKK@color]{#2}%
}
%%%


%%% hilighters
% 通常の細めの線
\newlength{\thinHighLight@KK@Adjust}
\newcommand{\thinHighLight@KK@Adjust@tmp}{%
  \ifnum\ltjgetparameter{direction}=3%
    \setlength{\thinHighLight@KK@Adjust}{-.3\zw}%
  \else%
    \setlength{\thinHighLight@KK@Adjust}{0pt}%
  \fi%
}

\DeclareDocumentCommand{\thinHighLight}{ O{color=gray} +m }{%
  \thinHighLight@KK@Adjust@tmp%
  \def\thinHighLight@test@contents{#2}%
  \underLineKK[#1,height=.25\underLine@KK@Adjust@tmp,%
  bottom=-.04\underLine@KK@Adjust@tmp+\thinHighLight@KK@Adjust]{#2}%
}

\DeclareDocumentCommand{\thinHighLightAuto}{ O{color=gray} +m }{%
  \thinHighLight@KK@Adjust@tmp%
  \def\thinHighLight@test@contents{#2}%
  \setlength{\temp@depth@kk}{0pt}%
  \getdepth@kk{\thinHighLight@test@contents}%
  \underLineKK[#1,height=.25\underLine@KK@Adjust@tmp,%
  bottom=-.04\underLine@KK@Adjust@tmp+\thinHighLight@KK@Adjust-\temp@depth@kk]{#2}%
}


% 通常の太めの線
\newlength{\thickHighLight@KK@Adjust}
\newcommand{\thickHighLight@KK@Adjust@tmp}{%
  \ifnum\ltjgetparameter{direction}=3%
    \setlength{\thickHighLight@KK@Adjust}{-1.1\zw}%
  \else%
    \setlength{\thickHighLight@KK@Adjust}{0pt}%
  \fi%
}

\DeclareDocumentCommand{\thickHighLight}{ O{color=gray} +m }{%
  \thickHighLight@KK@Adjust@tmp%
  \def\thickHighLight@test@contents{#2}%
  \underLineKK[#1,height=1.15\underLine@KK@Adjust@tmp,%
  bottom=-.04\underLine@KK@Adjust@tmp+\thickHighLight@KK@Adjust]{#2}%
}

% thickHighLightAuto専用の調整機構
\newlength{\temp@height@kk@thickHighLight}
\NewDocumentCommand{\getheight@kk@thickHighLight}{m}{%
  \ifnum\ltjgetparameter{direction}=3%
    \settodepth{\temp@height@kk@thickHighLight}{#1}%
    \addtolength{\temp@height@kk@thickHighLight}{-.5\zw}%
  \else%
    \settoheight{\temp@height@kk@thickHighLight}{#1}%
    \addtolength{\temp@height@kk@thickHighLight}{-.9\zw}%
  \fi%
}

\DeclareDocumentCommand{\thickHighLightAuto}{ O{color=gray} +m }{%
  \thickHighLight@KK@Adjust@tmp%
  \def\thickHighLight@test@contents{#2}%
  \setlength{\temp@depth@kk}{0pt}%
  \setlength{\temp@height@kk@thickHighLight}{0pt}%
  \getdepth@kk{\thickHighLight@test@contents}%
  \getheight@kk@thickHighLight{\thickHighLight@test@contents}%
  \ifnum\ltjgetparameter{direction}=3%
    \underLineKK[#1,height=1.15\underLine@KK@Adjust@tmp-\temp@depth@kk+\temp@height@kk@thickHighLight,%
    bottom=-.04\underLine@KK@Adjust@tmp+\thickHighLight@KK@Adjust-\temp@height@kk@thickHighLight]{#2}%
  \else%
    \underLineKK[#1,height=1.15\underLine@KK@Adjust@tmp+\temp@height@kk@thickHighLight+\temp@depth@kk,%
    bottom=-.04\underLine@KK@Adjust@tmp+\thickHighLight@KK@Adjust-\temp@depth@kk]{#2}%
  \fi%
}
%%%


%%% \nijyusen 
\newlength{\nijyusen@bottom}
\newlength{\nijyusen@bottom@adjust}

\define@key{nijyusen}{color}{\def\nijyusen@KK@color{#1}}
\define@key{nijyusen}{bottom}{\setlength{\nijyusen@bottom}{#1}}

\NewDocumentCommand\nijyusen{ O{} +m }{%
  \def\nijyusen@KK@color{black}%
  \setlength{\nijyusen@bottom}{0pt}%
  \setkeys{nijyusen}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \setlength{\nijyusen@bottom@adjust}{-\nijyusen@bottom}%
  \else%
    \setlength{\nijyusen@bottom@adjust}{\nijyusen@bottom}%
  \fi%
  \underLineKK[bottom=-.1\underLine@KK@Adjust@tmp+\nijyusen@bottom,color=\nijyusen@KK@color]%
  {\underLineKK[bottom=\nijyusen@bottom@adjust,color=\nijyusen@KK@color]{#2}}%
}

\NewDocumentCommand{\nijyusenAuto@make}{ O{} +m }{%
  \def\nijyusen@KK@color{black}%
  \def\nijyusen@test@contents{#2}%
  \setlength{\temp@depth@kk}{0pt}%
  \getdepth@kk{\nijyusen@test@contents}%
  \setlength{\nijyusen@bottom}{0pt}%
  \setkeys{nijyusen}{#1}%
  \ifnum\ltjgetparameter{direction}=3%
    \setlength{\nijyusen@bottom@adjust}{-\nijyusen@bottom}%
  \else%
    \setlength{\nijyusen@bottom@adjust}{\nijyusen@bottom}%
  \fi%
  \underLineKK@plain[bottom=-.1\underLine@KK@Adjust@tmp+\nijyusen@bottom-\temp@depth@kk,color=\nijyusen@KK@color]%
  {\underLineKK@plain[bottom=\nijyusen@bottom@adjust-\temp@depth@kk,color=\nijyusen@KK@color]{#2}}%
}
\NewDocumentCommand{\nijyusenAuto}{ O{} +m }{%
  \ifmmode%
    \mathchoice%
      {\mbox{\nijyusenAuto@make[#1]{$\displaystyle #2$}}}%
      {\mbox{\nijyusenAuto@make[#1]{$\textstyle #2$}}}%
      {\mbox{\nijyusenAuto@make[#1]{$\scriptstyle #2$}}}%
      {\mbox{\nijyusenAuto@make[#1]{$\scriptscriptstyle #2$}}}%
  \else%
    \nijyusenAuto@make[#1]{#2}%
  \fi%
}
%%%


%%% \keshinijyusen 
\newlength{\keshinijyuusen@KK@Adjust}
\newcommand{\keshinijyuusen@KK@Adjust@tmp}{%
  \ifnum\ltjgetparameter{direction}=3%
    \setlength{\keshinijyuusen@KK@Adjust}{0pt}%
  \else%
    \setlength{\keshinijyuusen@KK@Adjust}{.0646\zw}%
  \fi%
}

\define@key{keshinijyusen}{color}{\def\keshinijyusen@KK@color{#1}}
\NewDocumentCommand{\keshinijyusen}{ O{} +m }{%
  \def\keshinijyusen@KK@color{color=black}%
  \def\keshinijyusen@test@contents{#2}%
  \setkeys{keshinijyusen}{#1}%
  \keshinijyuusen@KK@Adjust@tmp%
  \underLineKK@plain[bottom=.57\underLine@KK@Adjust@tmp-\keshinijyuusen@KK@Adjust,#1]{%
    \underLineKK@plain[bottom=.47\underLine@KK@Adjust@tmp-\keshinijyuusen@KK@Adjust,#1]{#2}%
  }
}
%%%


%%% \LineNumbering
\newcommand{\linenumbering@luwa}[1]{\raisebox{-.43\zw}{\scalebox{.6}{#1}}}

\newdimen\overtline@f@size
\NewDocumentCommand{\tlinenumbering@luwa}{ s m }{%
  \setlength{\overtline@f@size}{\zw}%
  \raisebox{.6\overtline@f@size}{%
    \IfBooleanTF{#1}{%
      \tikz[baseline=(char.base)]{\node[inner sep=0pt, anchor=center, scale=.6] (char) {#2};}\nolinebreak%
    }{%
      \tikz[baseline=(char.base)]{\node[inner sep=0pt, anchor=center, scale=.6, rotate=90] (char) {#2};}\nolinebreak%
    }%
  }\hskip.0645\zw%
}

% horizontal-vertical
\NewDocumentCommand{\LineNumbering}{ s m O{0pt} }{%
  \ifnum\ltjgetparameter{direction}=3%
    \ltjghostbeforejachar%
    \IfBooleanTF{#1}{%
      \raisebox{#3}{\tlinenumbering@luwa*{#2}}\nolinebreak%
    }{%
      \raisebox{#3}{\tlinenumbering@luwa{#2}}\nolinebreak%
    }%
  \else%
    \ltjghostbeforejachar%
    \raisebox{#3}{\linenumbering@luwa{#2}\nolinebreak}%
  \fi%
}
%%%

\endinput