\documentclass[luatex,fontsize=8pt,paper=b5,twoside]{jlreq}%
\usepackage{amsmath,amssymb}
\usepackage{booktabs,caption}
\usepackage{luwa-ul}
\usepackage[most]{tcolorbox}
\usepackage{luatexja-ruby}
\usepackage{keisennote}

\usepackage{listings}
\lstset{
    basicstyle=\ttfamily\small,
    keywordstyle=\color{blue},
    commentstyle=\color{gray},
    stringstyle=\color{red},
    breaklines=true,
    breakatwhitespace=false,  
    columns=flexible           
}

% You can omit these font settings.
\makeatletter
\RequirePackage[no-math]{fontspec}
\RequirePackage[no-math,match,scale=1]{luatexja-fontspec}
\RequirePackage[hiragino-pro,deluxe,expert]{luatexja-preset}
\setmainfont{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
\setmainjfont{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
\newfontfamily{\sfhira@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6]
\newjfontfamily{\sfhiraj@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6]
\newfontfamily{\mchira@pre}{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
\newjfontfamily{\mchiraj@pre}{HiraMinPro-W3}[BoldFont=HiraMinPro-W6]
\newfontfamily{\gthira@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6,FontFace={eb}{\shapedefault}{HiraKakuStd-W8}]
\newjfontfamily{\gthiraj@pre}{HiraKakuPro-W3}[BoldFont=HiraKakuPro-W6,FontFace={eb}{\shapedefault}{HiraKakuStd-W8}]
\newfontfamily{\mghira@pre}{HiraMaruPro-W4}
\newjfontfamily{\mghiraj@pre}{HiraMaruPro-W4}
\renewcommand{\sffamily}{\sfhira@pre\sfhiraj@pre}
\renewcommand{\mcfamily}{\mchira@pre\mchiraj@pre}
\renewcommand{\gtfamily}{\gthira@pre\gthiraj@pre}
\renewcommand{\mgfamily}{\mghira@pre\mghiraj@pre}
\makeatother
%%%


\usepackage{hyperref} 
\hypersetup{
  luatex, pdfencoding=auto, 
  colorlinks=true,
  linkcolor=black,     
  citecolor=black,     
  urlcolor=DeepSkyBlue3,      
  pdfborder={0 0 0}, 
}

\colorlet{grayLight}{white!80!black} 

\NewTCBListing{SourceCode}{ m m !o !O{DeepSkyBlue3} }{%
  enhanced, colback=black!70, colframe=Snow4,
  toptitle=-1mm, bottomtitle=-1mm,
  righttitle=-1mm, lefttitle=-1mm,
  arc=.5mm, 
  title={\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt, top=1mm, bottom=0.8mm, left=2mm, right=2.2mm, colback=gray!80, coltext=white]{\raisebox{-0.1ex}{\vphantom{羅}\vphantom{j}#1}}},fonttitle=\gtfamily\footnotesize,boxrule=0.8pt,
  breakable,before upper={\color{white}},top=-0.5mm,bottom=-0.5mm,
  after title=\IfNoValueTF{#3}{}{{\hfill\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt, top=1mm, bottom=0.8mm, left=2mm, right=2.2mm, colback=white!80!black, coltext=#4]{\raisebox{-0.1ex}{\vphantom{羅}\vphantom{j}#3}}}},
  listing only,
  listing options={
    language={#2},
    basicstyle=\ttfamily,
    keywordstyle=\ttfamily\color{white},
    stringstyle=\itshape\color{white},
    commentstyle=\small\gtfamily\color{DeepSkyBlue2},
    showspaces=false,showtabs=false,
    breaklines=true,breakindent=0pt,
    showstringspaces=false,
    columns=fullflexible,
    tabsize=2,
    numbers=left,numbersep=1.5pt,
    numberstyle=\scriptsize\gtfamily\color{gray},
  }
}

\NewTColorBox{OutPut}{ m !o !O{DeepSkyBlue3} }{%
  enhanced, colframe=Snow4,
  toptitle=-1mm, bottomtitle=-1mm,
  righttitle=-1mm, lefttitle=-1mm,
  arc=.5mm, colback=white, 
  title={\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt, top=1mm, bottom=0.8mm, left=2mm, right=2.2mm, colback=gray!40, coltext=DeepSkyBlue3]{\raisebox{-0.1ex}{\vphantom{羅}\vphantom{j}#1}}},fonttitle=\gtfamily\footnotesize,boxrule=0.8pt,
  breakable,top=-0.5mm,bottom=-0.5mm,
  after title=\IfNoValueTF{#2}{}{{\hfill\tcbox[on line, arc=.5mm, boxsep=0pt, boxrule=0pt, top=1mm, bottom=0.8mm, left=2mm, right=2.2mm, colback=white!80!black, coltext=#3]{\raisebox{-0.1ex}{\vphantom{羅}\vphantom{j}#2}}}}, bottom=2mm, top=2mm, 
}


\title{\texttt{keisennote} Package Documentation}
\author{Kosei Kawaguchi a.k.a. KKTeX}
\date{Version 1.2.0 (2025/12/30)}

\begin{document}
\begin{titlepage}
  \maketitle
\end{titlepage}
\newpage
\tableofcontents
\newpage

\section{Acknowledgements / Credit}
This package is based on the code from \href{https://qiita.com/VoD/items/6849e63b978050218d2f}{VoD's Qiita article}, 
with some improvements. The original author has kindly granted permission 
to release this as a LaTeX package. Special thanks to VoD for their contribution to the TeX community.

\section{Installation}
Place \texttt{keisennote.sty} in a directory where LaTeX can find it.
Dependencies: \texttt{xcolor}, \texttt{tikz}, \texttt{zref}, \texttt{zref-savepos}, \texttt{fp}, \texttt{kvoptions}.

\section{Package options}
Set global defaults at load time using key-value style.

\bigskip
\begin{center}
  \begin{tabular}{l l p{.5\linewidth}}
    \toprule
    Option name & Default value & Description \\
    \midrule
    \texttt{linewidth} & \texttt{.5truept} & Width of the ruled lines. \\
    \texttt{radius}    & \texttt{.7truept} & Radius of dots on the lines. \\
    \texttt{distance}  & \texttt{6truemm} & Distance between lines (and dots). \\
    \texttt{triangle}  & \texttt{.7truept} & Scale of the center triangular markers. \\
    \bottomrule
  \end{tabular}
\end{center}
\bigskip

\section{Commands}
All commands below accept an optional argument in \texttt{pgfkeys} format:
\texttt{[color=..., show number=..., step=...]}.

\subsection{Notebook Style (\texttt{\textbackslash notefill}, \texttt{\textbackslash note})}
\begin{SourceCode}{Input}{TeX}
  \notefill[options]
  \note{<lines>}[options]
\end{SourceCode}

\texttt{\textbackslash notefill} automatically fills the remaining vertical space. \texttt{\textbackslash note} draws a block with the specified number of lines.

\bigskip
\textbf{Example with Line Numbers:}
\begin{SourceCode}{Input}{TeX}
  \note{5}[color=RoyalBlue, show number=true, step=1]
\end{SourceCode}
\note{5}[color=RoyalBlue, show number=true, step=1]

\subsection{Grid Style (\texttt{\textbackslash masumefill}, \texttt{\textbackslash masume})}
\begin{SourceCode}{Input}{TeX}
  \masumefill*[options]
  \masume*{<lines>}[options]
\end{SourceCode}

The starred version (\texttt{*}) draws a thick outer frame around the grid.

\bigskip
\textbf{Example with Frame:}
\begin{SourceCode}{Input}{TeX}
  \masume*{3}[color=Gray]
\end{SourceCode}
\masume*{3}[color=Gray]

\section{Dynamic Parameter Adjustment}
You can change the parameters in the middle of the document.

\begin{description}
  \item[\texttt{\textbackslash SetNoteLineWidth[dim]}] Sets the line width.
  \item[\texttt{\textbackslash SetNoteDotRadius[dim]}] Sets the dot radius.
  \item[\texttt{\textbackslash SetNoteLineDistance[dim]}] Sets the line spacing.
  \item[\texttt{\textbackslash SetNoteTriangleSize[dim]}] Sets the marker size.
\end{description}
If the optional argument is omitted, the parameter is reset to its package default.

\section{Technical Notes}
\begin{itemize}
  \item \textbf{Multiple Compilations:} Commands like \texttt{\textbackslash notefill} use \texttt{zref-savepos} to determine the available space. You must compile the document \textbf{at least twice} to ensure the lines are drawn correctly.
  \item \textbf{Line Numbers:} The \texttt{show number} option displays the line count. For \texttt{\textbackslash note}, it counts down to 1. For \texttt{\textbackslash notefill}, it calculates the total capacity of the space.
\end{itemize}

\section{Examples}

\subsection{Full Page Notebook Fill}
\begin{SourceCode}{Input}{TeX}
  \notefill[color=lightgray, show number=true]
\end{SourceCode}
(See the next page for the result.)
\newpage
\notefill[color=lightgray, show number=true]

\newpage

\section{License}
Released under the MIT License.

\section{Version History}
\begin{itemize}
  \item \textbf{v1.0.0 -- v1.0.4a} --- Initial versions, added grid commands and package options.
  \item \textbf{v1.2.0 (2025/12/30)} --- Added \texttt{pgfkeys} support for command options, improved \texttt{\textbackslash masume*} border logic, and changed license.
\end{itemize}

\section{Source Code}
  \begin{lstlisting}
    \ProvidesPackage{keisennote}[2025/12/30, v1.2.0]

    \RequirePackage[dvipsnames, svgnames, x11names]{xcolor}
    \RequirePackage{zref, zref-savepos, fp}
    \RequirePackage{tikz}

    \RequirePackage{kvoptions} 

    \SetupKeyvalOptions{
      family=kn,
      prefix=kn@
    }

    \newdimen\noteLineWidth@kn
    \newdimen\noteDotsRadius@kn
    \newdimen\noteLineDistance@kn
    \newdimen\noteTriangle@mag@kn

    % パッケージオプションの宣言
    \DeclareStringOption[.5truept]{linewidth}% 線の太さ
    \DeclareStringOption[.7truept]{radius}% ドットの大きさ
    \DeclareStringOption[6truemm]{distance}% ドットの間隔
    \DeclareStringOption[.7truept]{triangle}% 三角形の大きさ
    \ProcessKeyvalOptions* 


    % オプションの反映
    \setlength{\noteLineWidth@kn}{\kn@linewidth}
    \setlength{\noteDotsRadius@kn}{\kn@radius}
    \setlength{\noteLineDistance@kn}{\kn@distance}
    \setlength{\noteTriangle@mag@kn}{\kn@triangle}


    % 途中でパラメータ変更ができるように
    \NewDocumentCommand{\SetNoteLineWidth}{O{.5truept}}{%
      \setlength{\noteLineWidth@kn}{#1}
    }
    \NewDocumentCommand{\SetNoteDotRadius}{O{.8truept}}{%
      \setlength{\noteDotsRadius@kn}{#1}
    }
    \NewDocumentCommand{\SetNoteLineDistance}{O{6truemm}}{%
      \setlength{\noteLineDistance@kn}{#1}
    }
    \NewDocumentCommand{\SetNoteTriangleSize}{O{.5pt}}{%
      \setlength{\noteTriangle@mag@kn}{#1}
    }

    % 内部レジスタ
    \newdimen\VDNT@currentXPos
    \newdimen\VDNT@currentYPos
    \newdimen\VDNT@Xinterval
    \newdimen\VDNT@Yinterval
    \newdimen\VDNT@notegoal
    \def\VDNT@xscaler{.996}

    % \notefillで用いる座標管理用カウンタの準備
    \def\VDNT@pkgname{vodnote}
    \global\newcount\VDNT@uniqe


    % 行間算出
    \newcount\kn@linecount@internal
    \newcommand{\cal@kn@internal}{%
      \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
      \VDNT@Xinterval\dimexpr(\linewidth)/\VDNT@dotsNum\relax%
      \VDNT@Yinterval\VDNT@Xinterval%
    }


    % \notefill の定義
    % \notefill用内部マクロ
    \newcommand{\savepos@kn@internal@notefill}{%
      \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}% 上端の座標取得
      \leavevmode\vfill\leavevmode% 下まで移動→座標記憶
      \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}% 下端の座標取得
    }
    \newcommand{\cal@kn@internal@notefill}{%
      \VDNT@notegoal=\dimexpr
        \zposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}sp
        -\zposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}sp
      \relax%
    }
    \newif\ifVDNT@shownumber
    \pgfkeys{
      /VDNT/.is family, /VDNT,
      color/.estore in = \VDNT@color,
      step/.estore in = \VDNT@step,
      show number/.is if = VDNT@shownumber,
      default/.style = {color=white!70!black, step=5}
    }

    \NewDocumentCommand{\notefill}{ O{} }{%
      \par\bgroup%
      \pgfkeys{/VDNT, default, #1}%
      \parindent\z@%
      \@tempcnta\linewidth% 総横幅
      \@tempcntb\noteLineDistance@kn% 単位横幅
      \cal@kn@internal%
      \savepos@kn@internal@notefill%
      \cal@kn@internal@notefill%
      %%%行数算出
      \pgfmathtruncatemacro{\VDNT@totalLines}{floor(\VDNT@notegoal / \VDNT@Yinterval)}%
      %%%
      % ノート罫線描画本体
      \noindent\smash{%
        \begin{tikzpicture}[xscale=\VDNT@xscaler]
          \VDNT@currentYPos\z@
          %%%
          \kn@linecount@internal=\VDNT@totalLines\relax % 初期値を総行数に設定
          \advance\kn@linecount@internal by \@ne\relax %
          %%%
          % 上端の三角
          \coordinate (TopMarkerTip) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos+\noteTriangle@mag@kn*4pt);
          \fill[\VDNT@color] (TopMarkerTip) -- ++(\noteTriangle@mag@kn*3pt,-\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt,0) -- cycle;
          % 罫線とドットのループ描画 
          \@whiledim\VDNT@currentYPos<\VDNT@notegoal\do{%
            % 横線の左端(L)と右端(R)
            \coordinate (L) at (0, \VDNT@currentYPos);
            \coordinate (R) at (\linewidth, \VDNT@currentYPos);
            % --- 行番号の描画 ---
            \ifVDNT@shownumber
              \pgfmathtruncatemacro{\rem@notefill}{mod(\kn@linecount@internal,\VDNT@step)}
              \ifnum\rem@notefill=0
                \node[anchor=east, font=\scriptsize, text=\VDNT@color, overlay] at ([xshift=-\f@size/2pt]L) {\the\kn@linecount@internal};
              \fi
            \fi
            % --------------------
            % 罫線を引く
            \draw[\VDNT@color, line width=\noteLineWidth@kn] (L) -- (R);
            % ループ内のドット描画部分 
            \foreach \k in{0,1,...,\VDNT@dotsNum}{%
              \pgfmathtruncatemacro{\VDNT@halfNum}{\VDNT@dotsNum/2}%
              \def\do@draw@dot{1}% 描画フラグを立てる
              % 「現在の行が最初」かつ「kが真ん中」ならフラグを折る
              \ifdim\VDNT@currentYPos=0pt\relax 
                \ifnum\k=\VDNT@halfNum \def\do@draw@dot{0}\fi
              \fi
              % 「現在の行が最後（次がない）」かつ「kが真ん中」ならフラグを折る
              % \VDNT@notegoal との比較で行う
              \VDNT@currentXPos=\dimexpr\VDNT@currentYPos+\VDNT@Yinterval\relax
              \ifdim\VDNT@currentXPos<\VDNT@notegoal\else
                \ifnum\k=\VDNT@halfNum \def\do@draw@dot{0}\fi
              \fi
              \ifnum\do@draw@dot=1\relax
                \coordinate (Dot) at (\the\dimexpr\VDNT@Xinterval*\k\relax, \VDNT@currentYPos);
                \fill[\VDNT@color] (Dot) circle [radius=\noteDotsRadius@kn];
              \fi
            }
            % 次の行へ移動
            \advance\VDNT@currentYPos\VDNT@Yinterval\relax
            %%%カウントダウン
            \advance\kn@linecount@internal by -\@ne\relax 
            %%%
          }
          % 下端の三角
          % 座標を定義：(中心X, 最後の行Y - 4pt)
          \coordinate (BottomMarkerTip) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos-\VDNT@Yinterval-\noteTriangle@mag@kn*4pt);
          \fill[\VDNT@color] (BottomMarkerTip) -- ++(\noteTriangle@mag@kn*3pt,\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt,0) -- cycle;
        \end{tikzpicture}%
      }%
      \egroup%
      \global\advance\VDNT@uniqe\@ne% 描画番号を進める
      \par%
    }

    \NewDocumentCommand{\masumefill}{ s O{} }{%
      \par\bgroup%
      \pgfkeys{/VDNT, default, #2}%
      \parindent\z@%
      \@tempcnta\linewidth% 総横幅
      \@tempcntb\noteLineDistance@kn% 単位横幅
      \cal@kn@internal%
      \savepos@kn@internal@notefill%
      \cal@kn@internal@notefill%
      %%%行数算出
      \pgfmathtruncatemacro{\VDNT@totalLines}{floor(\VDNT@notegoal / \VDNT@Yinterval)}%
      %%%
      % ノート罫線描画本体
      \noindent\smash{%
        \begin{tikzpicture}[xscale=\VDNT@xscaler]
          \VDNT@currentYPos\z@
          %%%
          \kn@linecount@internal=\VDNT@totalLines\relax % 初期値を総行数に設定
          \advance\kn@linecount@internal by \@ne\relax %
          %%%
          % 上端の三角
          \coordinate (TopMarkerTip) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos+\noteTriangle@mag@kn*4pt);
          \fill[\VDNT@color] (TopMarkerTip) -- ++(\noteTriangle@mag@kn*3pt,-\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt,0) -- cycle;
          % 罫線とドットのループ描画 
          \@whiledim\VDNT@currentYPos<\VDNT@notegoal\do{%
            % 横線の左端(L)と右端(R)
            \coordinate (L) at (0, \VDNT@currentYPos);
            \coordinate (R) at (\linewidth, \VDNT@currentYPos);
            % --- 行番号の描画 ---
            \ifVDNT@shownumber
              \pgfmathtruncatemacro{\rem@notefill}{mod(\kn@linecount@internal,\VDNT@step)}
              \ifnum\rem@notefill=0
                \node[anchor=east, font=\scriptsize, text=\VDNT@color, overlay] at ([xshift=-\f@size/2pt]L) {\the\kn@linecount@internal};
              \fi
            \fi
            % --------------------
            % 罫線を引く
            \draw[\VDNT@color, line width=\noteLineWidth@kn] (L) -- (R);
            % ループ内のドット描画部分 
            \foreach \k in{0,1,...,\VDNT@dotsNum}{%
              \pgfmathtruncatemacro{\VDNT@halfNum}{\VDNT@dotsNum/2}%
              \def\do@draw@dot{1}% 描画フラグを立てる
              % 「現在の行が最初」かつ「kが真ん中」ならフラグを折る
              \ifdim\VDNT@currentYPos=0pt\relax 
                \ifnum\k=\VDNT@halfNum \def\do@draw@dot{0}\fi
              \fi
              % 「現在の行が最後（次がない）」かつ「kが真ん中」ならフラグを折る
              % \VDNT@notegoal との比較で行う
              \VDNT@currentXPos=\dimexpr\VDNT@currentYPos+\VDNT@Yinterval\relax
              \ifdim\VDNT@currentXPos<\VDNT@notegoal\else
                \ifnum\k=\VDNT@halfNum \def\do@draw@dot{0}\fi
              \fi
              % ------------------
              \coordinate (VBottom) at (\the\dimexpr\VDNT@Xinterval*\k\relax, \VDNT@currentYPos);
              \VDNT@currentXPos=\dimexpr\VDNT@currentYPos+\VDNT@Yinterval\relax
              \ifdim\VDNT@currentXPos<\VDNT@notegoal\relax
                \draw[\VDNT@color, line width=\noteLineWidth@kn] (VBottom) -- ++(0, \VDNT@Yinterval);
              \fi
              % ------------------
              \ifnum\do@draw@dot=1\relax
                \coordinate (Dot) at (\the\dimexpr\VDNT@Xinterval*\k\relax, \VDNT@currentYPos);
                \fill[\VDNT@color] (Dot) circle [radius=\noteDotsRadius@kn];
              \fi
            }
            % 次の行へ移動
            \advance\VDNT@currentYPos\VDNT@Yinterval\relax
            %%%カウントダウン
            \advance\kn@linecount@internal by -\@ne\relax 
            %%%
          }
          % 外枠描画
          \IfBooleanT{#1}{%
            \draw[\VDNT@color, line width=\noteLineWidth@kn*2.5] (0,0) rectangle (\linewidth, \the\dimexpr\VDNT@currentYPos-\VDNT@Yinterval\relax);
          }%
          % 下端の三角
          % 座標を定義：(中心X, 最後の行Y - 4pt)
          \coordinate (BottomMarkerTip) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos-\VDNT@Yinterval-\noteTriangle@mag@kn*4pt);
          \fill[\VDNT@color] (BottomMarkerTip) -- ++(\noteTriangle@mag@kn*3pt,\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt,0) -- cycle;
        \end{tikzpicture}%
      }%
      \egroup%
      \global\advance\VDNT@uniqe\@ne% 描画番号を進める
      \par%
    }


    % \note の定義（２以上の整数を引数に）
    \NewDocumentCommand{\note}{ m O{} }{%
      \par\bgroup%
      \pgfkeys{/VDNT, default, #2}%
      \@tempcnta\linewidth%
      \@tempcntb\noteLineDistance@kn%
      \cal@kn@internal%
      \noindent%
      \begin{tikzpicture}[xscale=\VDNT@xscaler]
        \VDNT@currentYPos\z@
        %%%
        \kn@linecount@internal=#1\relax 
        %%%
        \coordinate (TopMarker) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@Yinterval+\noteTriangle@mag@kn*4pt);
        \fill[\VDNT@color] (TopMarker) -- ++(\noteTriangle@mag@kn*3pt, -\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt, 0) -- cycle;
        \foreach \i in {1, 2, ..., #1} {%
          \xdef\tempY{\the\dimexpr\VDNT@Yinterval*\i\relax}
          \coordinate (LineL) at (0, \tempY);
          \coordinate (LineR) at (\linewidth, \tempY);
          % --- 行番号の描画 ---
          \ifVDNT@shownumber
            \pgfmathtruncatemacro{\VDNT@currentnum}{#1 - \i + 1 }
            \pgfmathtruncatemacro{\rem@notefill}{mod(\VDNT@currentnum,\VDNT@step)}
            \ifnum\rem@notefill=0
              \node[anchor=east, font=\scriptsize, text=\VDNT@color, overlay] at ([xshift=-\f@size/2pt]LineL) {\VDNT@currentnum};
            \fi
          \fi
          % --------------------
          \draw[\VDNT@color, line width=\noteLineWidth@kn] (LineL) -- (LineR);
          \foreach \k in {0, 1, ..., \VDNT@dotsNum} {%
            \pgfmathtruncatemacro{\VDNT@halfNum}{\VDNT@dotsNum/2}%
            \def\skipdot{0}%
            \ifnum\i=1 \ifnum\k=\VDNT@halfNum \def\skipdot{1}\fi\fi
            \ifnum\i=#1 \ifnum\k=\VDNT@halfNum \def\skipdot{1}\fi\fi
            \ifnum\skipdot=0
              \coordinate (DotPos) at (\the\dimexpr\VDNT@Xinterval*\k\relax, \tempY);
              \fill[\VDNT@color] (DotPos) circle [radius=\noteDotsRadius@kn];
            \fi
          }%
          % 最後に使ったY座標を記録
          \ifnum\i=#1 \global\VDNT@currentYPos=\tempY\relax \fi
        }%
        \coordinate (BottomMarker) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos-\noteTriangle@mag@kn*4pt);
        \fill[\VDNT@color] (BottomMarker) -- ++(\noteTriangle@mag@kn*3pt, \noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt, 0) -- cycle;
      \end{tikzpicture}%
      \egroup%
      \par%
    }

    \NewDocumentCommand{\masume}{ s m O{} }{%
      \par\bgroup%
      \pgfkeys{/VDNT, default, #3}%
      \@tempcnta\linewidth%
      \@tempcntb\noteLineDistance@kn%
      \cal@kn@internal%
      \noindent%
      \begin{tikzpicture}[xscale=\VDNT@xscaler]
        \VDNT@currentYPos\z@
        %%%
        \kn@linecount@internal=#1\relax 
        %%%
        \coordinate (TopMarker) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@Yinterval+\noteTriangle@mag@kn*4pt);
        \fill[\VDNT@color] (TopMarker) -- ++(\noteTriangle@mag@kn*3pt, -\noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt, 0) -- cycle;
        \foreach \i in {1, 2, ..., #2} {%
          \xdef\tempY{\the\dimexpr\VDNT@Yinterval*\i\relax}
          \coordinate (LineL) at (0, \tempY);
          \coordinate (LineR) at (\linewidth, \tempY);
          % --- 行番号の描画 ---
          \ifVDNT@shownumber
            \pgfmathtruncatemacro{\VDNT@currentnum}{#2 - \i + 1 }
            \pgfmathtruncatemacro{\rem@notefill}{mod(\VDNT@currentnum,\VDNT@step)}
            \ifnum\rem@notefill=0
              \node[anchor=east, font=\scriptsize, text=\VDNT@color, overlay] at ([xshift=-\f@size/2pt]LineL) {\VDNT@currentnum};
            \fi
          \fi
          % --------------------
          \draw[\VDNT@color, line width=\noteLineWidth@kn] (LineL) -- (LineR);
          \foreach \k in {0, 1, ..., \VDNT@dotsNum} {%
            \pgfmathtruncatemacro{\VDNT@halfNum}{\VDNT@dotsNum/2}%
            \def\skipdot{0}%
            \ifnum\i=1 \ifnum\k=\VDNT@halfNum \def\skipdot{1}\fi\fi
            \ifnum\i=#2 \ifnum\k=\VDNT@halfNum \def\skipdot{1}\fi\fi
            % ------------------
            \ifnum\i<#2\relax
              \draw[\VDNT@color, line width=\noteLineWidth@kn] (\the\dimexpr\VDNT@Xinterval*\k\relax, \tempY) -- ++(0, \VDNT@Yinterval);
            \fi
            % ------------------
            \ifnum\skipdot=0
              \coordinate (DotPos) at (\the\dimexpr\VDNT@Xinterval*\k\relax, \tempY);
              \fill[\VDNT@color] (DotPos) circle [radius=\noteDotsRadius@kn];
            \fi
          }%
          % 最後に使ったY座標を記録しておく（下の三角用）
          \ifnum\i=#2 \global\VDNT@currentYPos=\tempY\relax \fi
        }%
        \IfBooleanT{#1}{%
          \draw[\VDNT@color, line width=\noteLineWidth@kn*2.5] (0, \the\VDNT@Yinterval) rectangle (\linewidth, \VDNT@currentYPos);
        }%
        \coordinate (BottomMarker) at (\VDNT@Xinterval*\VDNT@dotsNum/2, \VDNT@currentYPos-\noteTriangle@mag@kn*4pt);
        \fill[\VDNT@color] (BottomMarker) -- ++(\noteTriangle@mag@kn*3pt, \noteTriangle@mag@kn*4pt) -- ++(-\noteTriangle@mag@kn*6pt, 0) -- cycle;
      \end{tikzpicture}%
      \egroup%
      \par%
    }

    \endinput
  \end{lstlisting}
\end{document}
