\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.1 (2026/02/02)}

\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}, \texttt{pgfkeys}.

\section{Package options}
Set global defaults at load time using key-value style.
The same four keys can be changed in the middle of the document with
\texttt{\textbackslash SetKeisenNote}; see section~\ref{sec:setkeisennote}.

\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}\label{sec:setkeisennote}
You can change the layout parameters in the middle of the document with a single
command, using the same key-value style as the package options.

\begin{SourceCode}{Input}{TeX}
  \SetKeisenNote[<key>=<value>, ...]
\end{SourceCode}

\bigskip
\begin{center}
  \begin{tabular}{l l p{.5\linewidth}}
    \toprule
    Key name & Package default & 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

Only the keys you actually name are changed; the others keep their current values.
Calling \texttt{\textbackslash SetKeisenNote} without an optional argument therefore
does nothing. The assignments obey the usual \TeX{} grouping, so a change made
inside a group or an environment is undone when that group ends.

\bigskip
\textbf{Example:}
\begin{SourceCode}{Input}{TeX}
  \SetKeisenNote[distance=10mm, linewidth=1pt]
  \note{3}
\end{SourceCode}
{\SetKeisenNote[distance=10mm, linewidth=1pt]\note{3}}

\bigskip
Note that \texttt{color}, \texttt{show number} and \texttt{step} are \emph{not}
handled here: they are per-drawing settings and belong in the optional argument of
\texttt{\textbackslash notefill}, \texttt{\textbackslash note},
\texttt{\textbackslash masumefill} and \texttt{\textbackslash masume}.

\subsection{Migrating from v1.2.0}
Version 1.2.1 replaced the four separate setter commands with
\texttt{\textbackslash SetKeisenNote}. The old names are no longer defined, so
documents written for v1.2.0 or earlier have to be updated as follows.

\bigskip
\begin{center}
  \begin{tabular}{l l}
    \toprule
    Removed in v1.2.1 & Replacement \\
    \midrule
    \texttt{\textbackslash SetNoteLineWidth[<dim>]}    & \texttt{\textbackslash SetKeisenNote[linewidth=<dim>]} \\
    \texttt{\textbackslash SetNoteDotRadius[<dim>]}    & \texttt{\textbackslash SetKeisenNote[radius=<dim>]} \\
    \texttt{\textbackslash SetNoteLineDistance[<dim>]} & \texttt{\textbackslash SetKeisenNote[distance=<dim>]} \\
    \texttt{\textbackslash SetNoteTriangleSize[<dim>]} & \texttt{\textbackslash SetKeisenNote[triangle=<dim>]} \\
    \bottomrule
  \end{tabular}
\end{center}
\bigskip

One behavioural difference is worth noting: the old commands reset the parameter to
its package default when their optional argument was omitted. There is no equivalent
shorthand now --- to go back to a default, state the value explicitly, for example
\texttt{\textbackslash SetKeisenNote[distance=6truemm]}.

\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.
  \item \textbf{v1.2.1 (2026/02/02)} --- The four separate parameter setters were replaced by the single key-value command \texttt{\textbackslash SetKeisenNote} (see section~\ref{sec:setkeisennote}); internal clean-up of the package code.
\end{itemize}

\section{Source Code}
The complete package source is reproduced below, so that the listing can never
drift away from the code that is actually shipped.

\lstinputlisting[language=TeX]{keisennote.sty}
\end{document}
