\documentclass[a4paper,12pt]{article}

\usepackage[dvipsnames, svgnames, x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning, shadows, shadows.blur, patterns, decorations.text, 
                decorations.pathmorphing, arrows.meta, calc, snakes, intersections}
\usepackage{xparse, calc, ifthen}
\usepackage{fp}
\usepackage{zref-savepos}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{keisennote}
\usepackage{listings}
\lstset{
    basicstyle=\ttfamily\small,
    keywordstyle=\color{blue},
    commentstyle=\color{gray},
    stringstyle=\color{red},
    breaklines=true,
    breakatwhitespace=false,  % 空白なしでも改行する
    columns=flexible           % 幅に応じて文字幅を調整
}

\usepackage{hyperref} %必ずラストに設定
\hypersetup{
  luatex, pdfencoding=auto, 
  colorlinks=true,
  linkcolor=black,     % \ref などの色
  citecolor=black,     % \cite の色
  urlcolor=DeepSkyBlue3,        % URL の色 
  pdfborder={0 0 0},  % 「幅 水平オフセット 垂直オフセット」をすべてゼロに
}



\title{\texttt{keisennote} Package Documentation}
\author{KKTeX}
\date{Version 1.0.0 (2025/09/13)}
\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.

\section{Installation}

Place \texttt{keisennote.sty} in a directory where LaTeX can find it, e.g., your local \texttt{texmf} tree or alongside your document.

Dependencies:
\begin{itemize}
    \item \texttt{xcolor} (options: \texttt{dvipsnames, svgnames, x11names})
    \item \texttt{tikz} (libraries: \texttt{shapes, positioning,...etc.})
    \item \texttt{xparse, calc, ifthen}
    \item \texttt{fp}
    \item \texttt{zref-savepos} (required for \texttt{\textbackslash notefill})
\end{itemize}

Load the package:

\begin{verbatim}
\usepackage{keisennote}
\end{verbatim}

\section{Commands}

\subsection{\texttt{\textbackslash notefill}}
\begin{verbatim}
\notefill[<scale>][<color>]
\end{verbatim}

Fills the current vertical space with ruled notebook lines and dots.

\begin{itemize}
    \item \texttt{<scale>} (optional, default: 0.5pt): size of triangular end markers.
    \item \texttt{<color>} (optional, default: white!70!black): color of lines and dots.
\end{itemize}

\textbf{Example:}
\begin{verbatim}
\notefill[0.6pt][Gray]
\end{verbatim}

\subsection{\texttt{\textbackslash note}}
\begin{verbatim}
\note{<lines>}[<scale>][<color>]
\end{verbatim}

Typesets a short ruled block with a specified number of lines.

\begin{itemize}
    \item \texttt{<lines>} (mandatory, integer $\ge$ 2): number of ruled lines.
    \item \texttt{<scale>} (optional, default: 0.5pt): size of triangular markers.
    \item \texttt{<color>} (optional, default: white!70!black): color of lines and dots.
\end{itemize}

\textbf{Example:}
\begin{verbatim}
\note{5}[0.4pt][NavyBlue]
\end{verbatim}

This produces the following output.

\note{5}[0.4pt][NavyBlue]

\section{Package Parameters}

These dimensions can be adjusted:

\begin{itemize}
    \item \texttt{\textbackslash noteLineWidth}: thickness of ruled lines (default: 0.5pt)
    \item \texttt{\textbackslash dotsRadius}: radius of intersection dots (default: 0.8pt)
    \item \texttt{\textbackslash noteLineDistance}: vertical distance between lines (default: 6mm)
\end{itemize}

Example:
\begin{verbatim}
\setlength{\noteLineDistance}{7truemm} % A-kei spacing
\end{verbatim}

\section{Examples}

\subsection{Short Note Block}
\begin{verbatim}
\note{4}
\end{verbatim}
\note{4}

\subsection{Full Page Fill}
\begin{verbatim}
\notefill
\end{verbatim}
\notefill

\newpage\section{Implementation Notes}

\begin{itemize}
    \item Notebook lines are drawn using TikZ, with dots placed at equal horizontal intervals.
    \item The number of dots per line is automatically calculated using the \texttt{fp} package.
    \item Triangular markers are added at the top and bottom of each ruled block.
    \item \texttt{\textbackslash notefill} measures available vertical space using \texttt{zref-savepos}.
\end{itemize}

\section{License}

Released under the \href{https://www.latex-project.org/lppl/}{LaTeX Project Public License (LPPL) 1.3c}.

\section{Version History}

\begin{itemize}
    \item \textbf{v1.0.0 (2025/09/13)} --- Initial public release.
\end{itemize}

\section{Source Code}
  \begin{lstlisting}
    \ProvidesPackage{keisennote}[2025/09/13, v1.0.0]

    \RequirePackage[dvipsnames, svgnames, x11names]{xcolor}
    \RequirePackage{tikz}
    \usetikzlibrary{shapes, positioning, shadows, shadows.blur, patterns, decorations.text, decorations.pathmorphing, arrows.meta, calc, snakes, intersections}
    \RequirePackage{xparse, calc, ifthen}\RequirePackage{fp}

    \newdimen\inv@mag
    \inv@mag=.5pt 
    \newdimen\noteLineWidth
    \newdimen\dotsRadius
    \newdimen\noteLineDistance
    \noteLineWidth.5truept\relax%  
    \dotsRadius.8truept\relax%     
    \noteLineDistance=6truemm\relax%

    %%%
    \newdimen\VDNT@currentXPos
    \newdimen\VDNT@currentYPos
    \newdimen\VDNT@Xinterval
    \newdimen\VDNT@Yinterval
    \newdimen\VDNT@notegoal


    %%% 
    \def\VDNT@pkgname{vodnote}
    \global\newcount\VDNT@uniqe


    %%% 
    \NewDocumentCommand{\notefill}{ O{.5pt} O{white!70!black} }{\par\bgroup
      \inv@mag=#1
      \parindent\z@
      %%
      \@tempcnta\linewidth
      \@tempcntb\noteLineDistance
      \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
      \VDNT@Xinterval\dimexpr(\linewidth)/\VDNT@dotsNum\relax
      \VDNT@Yinterval\VDNT@Xinterval
      %%
      \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}%
      %%
      \leavevmode\vfill\leavevmode
      \zsaveposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}%
      %%
      \VDNT@notegoal=\dimexpr
        \zposy{\VDNT@pkgname.\the\VDNT@uniqe.TopPos}sp
        -\zposy{\VDNT@pkgname.\the\VDNT@uniqe.BottomPos}sp
      \relax
      %%
      \noindent\smash{%
        \begin{tikzpicture}[xscale=0.996]
          \VDNT@currentYPos\z@
          \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\inv@mag*4pt) -- ++(\inv@mag*3pt,-\inv@mag*4pt) -- ++(-\inv@mag*6pt,0) -- cycle;
          \@whiledim\VDNT@currentYPos<\VDNT@notegoal\do{
            \VDNT@currentXPos\z@
            \draw[#2,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
            \foreach \k in{0,1,...,\VDNT@dotsNum}{%
              \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
              \fill[#2] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
            }
            \advance\VDNT@currentYPos\VDNT@Yinterval\relax
          }
          \fill[#2] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\VDNT@Yinterval-\inv@mag*4pt) -- ++(\inv@mag*3pt,\inv@mag*4pt) -- ++(-\inv@mag*6pt,0) -- cycle;
        \end{tikzpicture}%
      }%
      \egroup
      %%
      \global\advance\VDNT@uniqe\@ne
      \par
    }



    %%% 
    \NewDocumentCommand{\note}{ m O{.5pt} O{white!70!black} }{\par\bgroup
      %%
      \inv@mag=#2
      %%
      \@tempcnta\linewidth
      \@tempcntb\noteLineDistance
      \FPeval\VDNT@dotsNum{round(round(((\the)\@tempcnta/(\the)\@tempcntb)/2:0)*2:0)}%
      \VDNT@Xinterval\dimexpr\linewidth/\VDNT@dotsNum\relax
      \VDNT@Yinterval\VDNT@Xinterval
      %%
      \noindent
        \begin{tikzpicture}[xscale=0.996]
          \VDNT@currentYPos\z@
          \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos+\VDNT@Yinterval+\inv@mag*4pt) -- ++(\inv@mag*3pt,-\inv@mag*4pt) -- ++(-\inv@mag*6pt,0) -- cycle; 
          \foreach \i in{1,2,...,#1}{ 
            \VDNT@currentXPos\z@
            \global\VDNT@currentYPos=\dimexpr\VDNT@Yinterval*\i\relax
            \draw[#3,line width=\noteLineWidth] (0,\VDNT@currentYPos) -- (\linewidth,\VDNT@currentYPos);
            \foreach \k in{0,1,...,\VDNT@dotsNum}{
              \VDNT@currentXPos=\dimexpr\VDNT@Xinterval*\k\relax
              \fill[#3] (\VDNT@currentXPos,\VDNT@currentYPos) circle [radius=\dotsRadius];
            }
          }
          \fill[#3] (\VDNT@Xinterval*\VDNT@dotsNum/2,\VDNT@currentYPos-\inv@mag*4pt) -- ++(\inv@mag*3pt,\inv@mag*4pt) -- ++(-\inv@mag*6pt,0) -- cycle; 
        \end{tikzpicture}%
      \egroup
      \par
    }
  \end{lstlisting}
\end{document}
