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

\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{gckanbun} Package Documentation (Reworked)}
\author{%
\parbox[r]{8cm}{%
  Original ver. : Munehiro Yamamoto\\
  Modified ver. : Kosei Kawaguchi a.k.a. KKTeX
}}
\date{Version 2.2.7 (2026/01/05)}


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

\section{概要}
このリワークは、gckanbunパッケージを、日本における漢文組版においてより高い品質を担保できるように改変したものです。オリジナルの作者様である山本宗宏（Munehiro Yamamoto）さんとの協議により、メンテナーを形式上私川口晃世（KKTeX）が引き継ぐこととなりました。

gckanbunパッケージはそのルビや返り点の制御構造において非常に優れていたため、大枠はオリジナルのそれを踏襲し、必要最低限の拡張及び変更にとどめています。また、本パッケージに関する山本さんの記事として、
\begin{quotation}
  \url{https://qiita.com/munepi/items/5e6ac49fa5c025123305}
\end{quotation}
\noindent もぜひご参照ください。

\section{変更点}
私は本パッケージを作成するにあたり、既存のgckanbunパッケージを以下を満たすように改変しました。

\begin{itemize}
  \item[\seihou{1}] \hspace{\zw}再読文字に対応するコマンドの提供。
  \item[\seihou{2}] \hspace{\zw}横書き環境でも正しく動くようにする。
  \item[\seihou{3}] \hspace{\zw}一レ点などの特別な返り点に対処するためのコマンドを提供する。
  \item[\seihou{4}] \hspace{\zw}行間に対してルビの「大きさ」が反映されるように変更。（それに伴い、オリジナルで生じていた文字サイズ変更に伴うルビと本文の被りが生じる問題を解消。）
  \item[\seihou{5}] \hspace{\zw}筆者の作成した（TeX Live にも収録されている）luwa-ul パッケージと併用し易い仕様にする。
\end{itemize}

\section{設置・依存性}
\subsection{読み込み}
適切な場所に\texttt{gckanbun.sty}のファイルを設置し、\verb|\usepackage{gckanbun}|とかけば読み込みは完了です。

本パッケージはLuaLaTeXでも(u)pLaTeXでも使用が可能です。

ただし、\namiKK{推奨はLuaLaTeX+jlreq}です。LuaLaTeX以外で扱う場合、内部で使用している\verb|\ltjghostbeforejachar|と\verb|\ltjghostafterjachar|の恩恵を受けることができず、bxghostパッケージを用いた和文ゴーストの挿入に切り替わります。その際に出力が劣化し得るため、LuaLaTeXが望ましいのです。

\subsection{オプション}
パッケージオプションは\verb|prefix=<prefix>|（デフォルト値：\verb|gckanbun|）となっていて、\texttt{gckanbun}パッケージが提供する3つのコマンド\verb|\gckanbunruby|、\verb|\gckanbunokurigana|、\verb|\gckanbunkaeriten| をそれぞれ\verb|<prefix>ruby|、\verb|<prefix>okurigana|、\verb|<prefix>kaeriten| として提供します。このオプションにより、他のパッケージで提供されるルビ振りコマンド \verb|\ruby| との衝突を避けられます。

\namiKK{以下の説明においては、\texttt{prefix}を空白として指定したものと仮定してコマンド名を表記しています。必要に応じて補って読んでください。}

\section{各種コマンド}
\subsection{概観}
漢文組版において必要十分であるコマンドは、

\begin{itemize}
  \item 返り点
  \item 振り仮名
  \item 送り仮名
  \item 再読振り仮名
  \item 再読送り仮名
  \item 一レ点、上レ点、甲レ点、天レ点
  \item ハイフン
\end{itemize}

\noindent です。これらに対し、本パッケージでは、それぞれ

\begin{itemize}
  \item \verb|\<prefix>kaeriten|、\verb|\返り|
  \item \verb|\<prefix>furigana|、\verb|\振り|
  \item \verb|\okurigana|、\verb|\送り|
  \item \verb|\<prefix>furigana|、\verb|\振り|のオプショナル引数
  \item \verb|\<prefix>okurigana|、\verb|\送り|のオプショナル引数
  \item \verb|\IchiRe|、\verb|\JyouRe|、\verb|\KouRe|、\verb|\TenRe|
  \item \verb|\KanHyphen|
\end{itemize}

\noindent が対応しています。

このうち、\texttt{prefix}が適用されるのは\verb|\<prefix>kaeriten|、\verb|\<prefix>furigana|、\verb|\<prefix>okurigana|のみであることに注意が必要です。

\subsection{追記：LuaTeX-ja v20260107.0に伴って}
gckanbunパッケージは、v2.2.7以降より、\verb|\振り|、\verb|\送り|、\verb|\返り|などの各種コマンドの後に、適切なkanjiskipが挿入されるような設計を導入しました。ただし、この設計の重要な要素である\verb|\ltjghostbeforejachar|と\verb|\ltjghostafterjachar|の仕組みは、LuaTeX-jaにおけるv20260107.0より前のバージョンを使用する場合機能しません。したがって、本パッケージをv2.2.7以降のものにアップデートする場合には、LuaTeX-jaも同時にv20260107.0以後のものにアップデートされている必要があります。

\subsection{使用方法}

\subsubsection{\textbackslash kaeriten、\textbackslash 返り}
これらの２種類のコマンドは全く同一のコマンドです。

\begin{SourceCode}{Input}{TeX}
  雖\返り{\IchiRe}鬼

  雖\返り{\JyouRe}鬼

  雖\返り{\KouRe}鬼

  雖\返り{\TenRe}鬼
\end{SourceCode}

\begin{OutPut}{Output}[横書き]
  雖\返り{\IchiRe}鬼

  雖\返り{\JyouRe}鬼

  雖\返り{\KouRe}鬼

  雖\返り{\TenRe}鬼
\end{OutPut}

のような出力になります。

\subsubsection{\textbackslash furigana、\textbackslash 振り、\textbackslash okurigana、\textbackslash 送り}

\verb|\furigana|、\verb|\振り|は同一、\verb|\okurigana|、\verb|\送り|は同一です。

\begin{SourceCode}{Input}{TeX}
  \振り{雖}{いへど}\送り{モ}\\
  \振り{所}{ゆ}\返り[intrusion=post]{二}\振り{\KanHyphen}{ゑ}\振り{以}{ん}\\
  \振り{猶}{な}[ごと]\送り{ホ}[キヲ]
\end{SourceCode}

\begin{OutPut}{Output}[横書き]
  \振り{雖}{いへど}\送り{モ}\\
  \振り{所}{ゆ}\返り[intrusion=post]{二}\振り{\KanHyphen}{ゑ}\振り{以}{ん}\\
  \振り{猶}{な}[ごと]\送り{ホ}[キヲ]
\end{OutPut}

v2.1.0以前では、各コマンドにはスターオプションがありましたが、現在では別の仕様に変更されました\footnote{以前は、スターオプションをつけると振り仮名や送り仮名の部分が行間計算に影響を与えなくなるという仕様を設けていましたが、使用されることがほぼないため削除しました。}。

ちなみに、「所以」のようなハイフンを含んだ熟語を打つ場合、\verb|\返り[intrusion=post]{二}|のように\verb|[intrusion=post]|のオプションを入れると出力は綺麗になります。

\section{局所縦書き}
このパッケージによって提供されるコマンドは局所的な縦書きにも対応しています（v2.2.0以降限定ですので、それ以前のものだと出力が壊れることに注意してください。）。

局所縦書きを開始する際には、\verb|\GCKTateOn|を入れます。もし、通常が縦書き環境の中で局所横書きをする場合には\verb|\GCKTateOff|となります。

\begin{SourceCode}{Input}{TeX}
  \parbox<t>{8\zw}{\GCKTateOn%
    \振り{雖}{いへど}\送り{モ}\\
    \振り{所}{ゆ}\返り[intrusion=post]{二}\振り{\KanHyphen}{ゑ}\振り{以}{ん}\\
    \振り{猶}{な}[ごと]\送り{ホ}[キヲ]
  \par}

  \parbox<t>{8\zw}{\GCKTateOn%
  今夫\送り{レ}江戸\振り{者}{は}、世之所\送り{ノ}\返り{レ}称\送り{スル}名都\振り{大}{だい}\振り{邑}{いふ}、%
  冠蓋之所\返り{レ}集\送り{マル}\LineNumbering*{\kakko{2}}\dashKK{舟車之\振り{所}{ところ}\送り{ニシテ}\返り{レ}\振り{湊}{あつ}\送り[intrusion=post]{マル}}、%
  実\送り{ニ}\振り{為}{た}\送り{ル}\返り{二}天下之大都会\返り{一}也。%
  而\送り{レドモ}\LineNumbering{C}\nolinebreak\underLineKKAuto{其地之為名、訪之於古、未之聞}。%
  豈\送り{ニ}非\送り{ズ}\返り{三}古今相\送り{ヒ}去\送り{ルコト}\振り{日}{ひび}\送り{ニ}遠\送り{ク}、%
  事之相\送り{ヒ}変\送り{ズルコト}愈多\送り{ク}、%
  求\送り{ムルモ}\返り{二}其\送り{ノ}所\送り{ヲ}\返り{\IchiRe}欲\送り{スル}\返り{レ}聞\送り{カント}而不\送り{ルコト}可\送り{カラ}\返り{レ}得、%
  亦\送り{タ}\振り{猶}{な}[ごと]\送り{ホ}[キヲ]\返り{二}今之於\送り{ケルガ}\返り{\JyouRe}古\送り{ニ}也。\par%
  }
\end{SourceCode}

\begin{OutPut}{Output}[局所縦書き]
  \parbox<t>{8\zw}{\GCKTateOn%
    \振り{雖}{いへど}\送り{モ}\\
    \振り{所}{ゆ}\返り[intrusion=post]{二}\振り{\KanHyphen}{ゑ}\振り{以}{ん}\\
    \振り{猶}{な}[ごと]\送り{ホ}[キヲ]
  \par}

  \parbox<t>{8\zw}{\GCKTateOn%
  今夫\送り{レ}江戸\振り{者}{は}、世之所\送り{ノ}\返り{レ}称\送り{スル}名都\振り{大}{だい}\振り{邑}{いふ}、%
  冠蓋之所\返り{レ}集\送り{マル}\LineNumbering*{\kakko{2}}\dashKKAuto{舟車之\振り{所}{ところ}\送り{ニシテ}\返り{レ}\振り{湊}{あつ}\送り[intrusion=post]{マル}}、%
  実\送り{ニ}\振り{為}{た}\送り{ル}\返り{二}天下之大都会\返り{一}也。%
  而\送り{レドモ}\LineNumbering{C}\nolinebreak\underLineKKAuto{其地之為名、訪之於古、未之聞}。%
  豈\送り{ニ}非\送り{ズ}\返り{三}古今相\送り{ヒ}去\送り{ルコト}\振り{日}{ひび}\送り{ニ}遠\送り{ク}、%
  事之相\送り{ヒ}変\送り{ズルコト}愈多\送り{ク}、%
  求\送り{ムルモ}\返り{二}其\送り{ノ}所\送り{ヲ}\返り{\IchiRe}欲\送り{スル}\返り{レ}聞\送り{カント}而不\送り{ルコト}可\送り{カラ}\返り{レ}得、%
  亦\送り{タ}\振り{猶}{な}[ごと]\送り{ホ}[キヲ]\返り{二}今之於\送り{ケルガ}\返り{\JyouRe}古\送り{ニ}也。\par%
  }
\end{OutPut}

\section{通常の漢文}
通常の漢文を打つ際には、

\begin{itemize}
  \item ルビはモノルビ仕様
  \item 必ず\verb|\振り|→\verb|\送り|→\verb|\返り|の順番にコマンドを配置
\end{itemize}

\noindent の２点に注意します。

縦書き環境における出力は以下のようになります。\namiKK{漢詩でなければ}、通常の文章と同様の打ち方で問題ありません。

漢文に傍線を引く場合、luwa-ulパッケージが最適です。自動でルビを検出\footnote{luwa-ulパッケージの提供する``Auto Series''の機能を使用することで可能となります。}し、下線を適切に持ち上げてくれます。詳しい仕様は、luwa-ulのマニュアルをご参照ください。

\begin{SourceCode}{Input}{TeX}
  \documentclass[luatex,fontsize=8pt,paper=b5,tate]{jlreq}
  \usepackage{luwa-ul,KKsymbols}
  \usepackage{gckanbun}

  \begin{document}
  
  今夫\送り{レ}江戸\振り{者}{は}、世之所\送り{ノ}\返り{レ}称\送り{スル}名都\振り{大}{だい}\振り{邑}{いふ}、冠蓋之所\返り{レ}集\送り{マル}\LineNumbering*{\kakko{2}}\dashKKAuto{舟車之\振り{所}{ところ}\送り{ニシテ}\返り{レ}\振り{湊}{あつ}\送り[intrusion=post]{マル}}、実\送り{ニ}\振り{為}{た}\送り{ル}\返り{二}天下之大都会\返り{一}也。
  而\送り{レドモ}\LineNumbering{C}\nolinebreak\underLineKKAuto{其地之為名、訪之於古、未之聞}。
  豈\送り{ニ}非\送り{ズ}\返り{三}古今相\送り{ヒ}去\送り{ルコト}\振り{日}{ひび}\送り{ニ}遠\送り{ク}、事之相\送り{ヒ}変\送り{ズルコト}愈多\送り{ク}、求\送り{ムルモ}\返り{二}其\送り{ノ}所\送り{ヲ}\返り{\IchiRe}欲\送り{スル}\返り{レ}聞\送り{カント}而不\送り{ルコト}可\送り{カラ}\返り{レ}得、亦\送り{タ}\振り{猶}{な}[ごと]\送り{ホ}[キヲ]\返り{二}今之於\送り{ケルガ}\返り{\JyouRe}古\送り{ニ}也。

  \end{document}
\end{SourceCode}

\begin{OutPut}{Output}[縦書き]
  \begin{center}
    \parbox<t>{12\zw}{\GCKTateOn%
      今夫\送り{レ}江戸\振り{者}{は}、世之所\送り{ノ}\返り{レ}称\送り{スル}名都\振り{大}{だい}\振り{邑}{いふ}、%
      冠蓋之所\返り{レ}集\送り{マル}\LineNumbering*{\kakko{2}}\dashKKAuto{舟車之\振り{所}{ところ}\送り{ニシテ}\返り{レ}\振り{湊}{あつ}\送り[intrusion=post]{マル}}、%
      実\送り{ニ}\振り{為}{た}\送り{ル}\返り{二}天下之大都会\返り{一}也。%
      而\送り{レドモ}\LineNumbering{C}\nolinebreak\underLineKKAuto{其地之為名、訪之於古、未之聞}。%
      豈\送り{ニ}非\送り{ズ}\返り{三}古今相\送り{ヒ}去\送り{ルコト}\振り{日}{ひび}\送り{ニ}遠\送り{ク}、%
      事之相\送り{ヒ}変\送り{ズルコト}愈多\送り{ク}、%
      求\送り{ムルモ}\返り{二}其\送り{ノ}所\送り{ヲ}\返り{\IchiRe}欲\送り{スル}\返り{レ}聞\送り{カント}而不\送り{ルコト}可\送り{カラ}\返り{レ}得、%
      亦\送り{タ}\振り{猶}{な}[ごと]\送り{ホ}[キヲ]\返り{二}今之於\送り{ケルガ}\返り{\JyouRe}古\送り{ニ}也。\par%
    }
  \end{center}
\end{OutPut}

また、通常の文章の中にいきなり「過\送り{ギタルハ}\振り{猶}{な}[ごと]\送り{ホ}[シ]\返り{レ}不\送り{ルガ}\返り{レ}及\送り{バ}」と漢文を打ち込むことも可能です。和文TeX一般に見られる\verb|\ruby|と類似の挙動をとるため、組版を壊さずに出力することが可能です。

\section{漢詩}
\subsection{基本の打ち方}
漢詩を打つ場合には、\verb|\makebox|と\verb|intrusion|オプションを使います。\verb|intrusion|オプションを指定すると、ルビ文字が親文字の幅を超えた時に前後の領域に「侵入」する形で配置されます。

しかし、漢文はほとんどの文字に何らかのルビが振られるため、普段から侵入を許可する仕様にするとかえって読みづらいです。したがって、本当に必要な時にだけこのオプションを使うべきです。

漢詩において、各句の最初と最後の字が水平方向に揃っていないと見栄えを損なってしまいます。そこで、gckanbunパッケージでは\verb|\GCKanshiBox|と\verb|intrusion|オプションを用意しています。

\begin{description}
  \item[\texttt{\textbackslash 振り}] \verb|intrusion=pre/post/both| の３種類
  \item[\texttt{\textbackslash 送り}] \verb|intrusion=post/both| の２種類
  \item[\texttt{\textbackslash 返り}] \verb|intrusion=post/both| の２種類
\end{description}

\noindent が各コマンドで提供されるオプションであることに注意し、

\begin{SourceCode}{Input}{TeX}
  % 構文
  \GCKanshiBox{<１句の長さ>}{<句>}

  % 使用例
  \GCKanshiBox{10\zw}{%
    \振り[intrusion=both]{春}{しゅん}%
    \振り[intrusion=both]{眠}{みん}%
    不\返り[intrusion=both]{レ}%
    \振り{覚}{おぼ}\送り{エ}\返り[intrusion=both]{レ}%
    \振り{暁}{あかつき}\送り[intrusion=post]{ヲ}%
  }

  \GCKanshiBox{10\zw}{%
    \振り[intrusion=both]{処}{しょ}%
    \振り[intrusion=both]{処}{しょ}%
    聞\送り{ク}\返り[intrusion=both]{二}%
    \underLineKKAuto{\振り[intrusion=both]{啼}{てい}%
    鳥\送り{ヲ}\返り[intrusion=post]{一}}%
  }

  \GCKanshiBox{10\zw}{%
    \振り[intrusion=both]{夜}{や}%
    \振り[intrusion=both]{来}{らい}%
    風%
    雨\送り[intrusion=both]{ノ}%
    声%
  }

  \GCKanshiBox{10\zw}{%
    花%
    \振り{落}{お}\送り[intrusion=both]{ツルコト}%
    知\送り[intrusion=both]{ル}%
    \振り[intrusion=both]{多}{た}%
    \振り[intrusion=both]{少}{しょう}%
  }
\end{SourceCode}

\begin{OutPut}{Output}[縦書き（漢詩）]
  \parbox<t>{12\zw}{\GCKTateOn%
    \GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{春}{しゅん}%
      \振り[intrusion=both]{眠}{みん}%
      不\返り[intrusion=both]{レ}%
      \振り{覚}{おぼ}\送り{エ}\返り[intrusion=both]{レ}%
      \振り{暁}{あかつき}\送り[intrusion=post]{ヲ}%
    }

    \GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{処}{しょ}%
      \振り[intrusion=both]{処}{しょ}%
      聞\送り{ク}\返り[intrusion=both]{二}%
      \underLineKKAuto{\振り[intrusion=both]{啼}{てい}%
      鳥\送り{ヲ}\返り[intrusion=post]{一}}%
    }

    \GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{夜}{や}%
      \振り[intrusion=both]{来}{らい}%
      風%
      雨\送り[intrusion=both]{ノ}%
      声%
    }

    \GCKanshiBox{10\zw}{%
      花%
      \振り{落}{お}\送り[intrusion=both]{ツルコト}%
      知\送り[intrusion=both]{ル}%
      \振り[intrusion=both]{多}{た}%
      \振り[intrusion=both]{少}{しょう}%
    }
  }
\end{OutPut}

内部実装としては、

\begin{SourceCode}{Input}{TeX}
  \makebox[<幅>][s]{<引数>}
\end{SourceCode}

\noindent をベースにしており、挿入される\verb|kanjiskip|に反応して等幅に伸縮するという仕組みとなっています。

\subsection{エンジンによる注意}
この漢詩用のインターフェースは基本的には\namiKK{LuaLaTeX推奨}となっています。uplatexでも動くものの、\verb|\GCKanshiBox|の引数が適切に伸縮しない場合がある\footnote{utarticleクラスとは相性が良いが、uplatexとjlreqの併用は相性が良くない。}ので注意が必要です。

もし、何らかのの原因で適切に漢字の間にアキが入らない場合には、手動で\verb|\hfill|を入力して対処することになります。

\section{GCKEnv}
v2.2.7以降、\verb|GCKEnv|という環境が新規追加されました。この環境は、本パッケージを用いて漢文を、完全に統一された行間、より広い字間のもとに組版するために設けられたものです。

構文は

\begin{SourceCode}{Input}{TeX}
  \begin{GCKEnv}{<baselineskip>}[<kanjiskip>]
    <内容>
  \end{GCKEnv}
\end{SourceCode}

\noindent となります。

\begin{description}
  \item[<baselineskip>] 行間をどの程度にするか指定します。
  \item[<kanjiskip>] 字間をどの程度にするか指定します。 
\end{description}

\noindent 以上が各引数の説明ですが、具体例を見ていただく方が早いでしょう。

\begin{SourceCode}{Input}{TeX}
  \LARGE
  \begin{GCKEnv}{2\zw}[.5\zw plus .15\zw minus .15\zw]
    今夫\送り{レ}江戸\振り{者}{は}、世之所\送り{ノ}\返り{レ}称\送り{スル}名都\振り{大}{だい}\振り{邑}{いふ}、冠蓋之所\返り{レ}集\送り{マル}\LineNumbering*{\kakko{2}}\dashKKAuto{舟車之\振り{所}{ところ}\送り{ニシテ}\返り{レ}\振り{湊}{あつ}\送り[intrusion=post]{マル}}、実\送り{ニ}\振り{為}{た}\送り{ル}\返り{二}天下之大都会\返り{一}也。
    而\送り{レドモ}\LineNumbering{C}\underLineKKAuto{其地之為名、訪之於古、未之聞}。
    豈\送り{ニ}非\送り{ズ}\返り{三}古今相\送り{ヒ}去\送り{ルコト}\振り{日}{ひび}\送り{ニ}遠\送り{ク}、事之相\送り{ヒ}変\送り{ズルコト}愈多\送り{ク}、求\送り{ムルモ}\返り{二}其\送り{ノ}所\送り{ヲ}\返り{\IchiRe}欲\送り{スル}\返り{レ}聞\送り{カント}而不\送り{ルコト}可\送り{カラ}\返り{レ}得、亦\送り{タ}\振り{猶}{な}[ごと]\送り{ホ}[キヲ]\返り{二}今之於\送り{ケルガ}\返り{\JyouRe}古\送り{ニ}也。
  \end{GCKEnv}

  \bigskip

  \begin{GCKEnv}{3\zw}
    \fbox{\GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{春}{しゅん}%
      \振り[intrusion=both]{眠}{みん}%
      不\返り[intrusion=both]{レ}%
      \振り{覚}{おぼ}\送り{エ}\返り[intrusion=both]{レ}%
      \振り{暁}{あかつき}\送り[intrusion=post]{ヲ}%
    }}

    \GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{処}{しょ}%
      \振り[intrusion=both]{処}{しょ}%
      聞\送り{ク}\返り[intrusion=both]{二}%
      \underLineKKAuto{\振り[intrusion=both]{啼}{てい}%
      鳥\送り{ヲ}\返り[intrusion=post]{一}}%
    }

    \GCKanshiBox{10\zw}{%
      \振り[intrusion=both]{夜}{や}%
      \振り[intrusion=both]{来}{らい}%
      風%
      雨\送り[intrusion=both]{ノ}%
      声%
    }

    \GCKanshiBox{10\zw}{%
      花%
      \振り{落}{お}\送り[intrusion=both]{ツルコト}%
      知\送り[intrusion=both]{ル}%
      \振り[intrusion=both]{多}{た}%
      \振り[intrusion=both]{少}{しょう}%
    }
  \end{GCKEnv}
\end{SourceCode}

\begin{OutPut}{Output}[縦書き]
  \begin{center}
    \includegraphics[width=.8\linewidth]{
      gckanbun-test.pdf
    }
  \end{center}
\end{OutPut}

\section{ライセンス}
本パッケージをMITライセンスで配布します。条件なども全て以下のライセンス表記に準拠します。

\noindent This package is licensed under the terms of the MIT License.

\noindent Copyright (c) 2017-2026 Munehiro Yamamoto <munepixyz@gmail.com>\\
\noindent Copyright (c) 2025-2026 Kosei Kawaguchi <p.c.aces1056@gmail.com>

\noindent 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:

\noindent The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

\noindent 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.


\section{Version History}
\begin{itemize}
  \item \textbf{v2.0.0 (2025/11/04)} --- Initial public release as a reworked version.
  \item \textbf{v2.1.0 (2025/11/12)} --- Modefied package documentation. Also, KKTeX added some options for KANSHI typesetting.
  \item \textbf{v2.2.0 (2025/12/26)} --- Fixed a problem in which a previous \verb|\送り| has an effect on the next \verb|\返り[intrusion=post]{arg}|. Also, make every commands can be used in partly-vertical-mode with the new \verb|\GCKTateOn|.
  \item \textbf{v2.2.7 (2025/01/05)} --- Added \verb|GCKEnv| in order to typeset in more sophisticated way. Also, adjusted kanjiskip to be applied in the same manner as standard Japanese characters. This update also optimizes the layout logic for Chinese poetry (Kanshi), eliminating the need for manual \verb|\hfill| commands.
\end{itemize}

\section{Source Code}
\begin{lstlisting}
  \NeedsTeXFormat{LaTeX2e}
  \ProvidesPackage{gckanbun}[2026/01/05, Version 2.2.7]

  %% package errors
  \def\gcknbn@error{\PackageError{gckanbun}}
  \def\gcknbn@warning{\PackageWarning{gckanbun}}
  \def\gcknbn@warningnoline{\PackageWarningNoLine{gckanbun}}
  \def\gcknbn@info{\PackageInfo{gckanbun}}

  %% package options
  \RequirePackage{keyval,etoolbox}
  \DeclareOption*{\gcknbn@setkey}
  \def\gcknbn@setkey{\expandafter\@gcknbn@setkey\expandafter{\CurrentOption}}
  \def\@gcknbn@setkey{\setkeys{gcknbn}}
  \def\gcknbn@prefix{gckanbun}% given <prefix> for each commands
  \define@key{gcknbn}{prefix}{\gdef\gcknbn@prefix{#1}}

  \ExecuteOptions{prefix}
  \ProcessOptions\relax

  %% auto-detect engine
  \RequirePackage{ifuptex}
  \RequirePackage{ifluatex}
  \ifluatex
    \RequirePackage{luatexja-adjust}
  \else\ifuptex
    \RequirePackage{bxghost}
    \def\zw{zw}\def\zh{zh}
  \else\ifptex
    \RequirePackage{bxghost}
    \def\zw{zw}\def\zh{zh}
  \else
    \gcknbn@error{Package 'gckanbun' currently supports (u)pLaTeX and LuaLaTeX.}
  \fi\fi\fi

  \newif\ifgcknbn@tdir 
  \gcknbn@tdirfalse

  %% 判定処理をマクロにまとめる
  \def\gcknbn@check@direction{%
    \@ifundefined{iftdir}{\let\iftdir\iffalse}{}%
    \ifluatex
      \@ifundefined{ltjgetparameter}{}{%
        \ifnum\ltjgetparameter{direction}=3 \gcknbn@tdirtrue \fi
      }%
    \else
      \iftdir \gcknbn@tdirtrue \fi
    \fi
  }

  % 本文が始まる直前に判定を実行する
  \AtBeginDocument{\gcknbn@check@direction}

  %% kanjiskipの挿入
  \def\gck@ghost@char@pre{%%%
    \ifluatex%
      \ltjghostbeforejachar%
    \else%
      \bgroup%
        \noexpand\bxqgg@jafont%
        \bxqgg@fwsp\bxqgg@kern@m@ne@zw%
      \egroup%
    \fi%
  }
  \def\gck@ghost@char@post{%%%
    \ifluatex%
      \ltjghostafterjachar%
    \else%
      \bgroup%
        \noexpand\bxqgg@jafont%
        \bxqgg@kern@m@ne@zw\bxqgg@fwsp%
      \egroup%
    \fi%
  }

  %% 縦書き補正、横書き補正を切り替える
  \newcommand{\GCKTateOn}{\gcknbn@tdirtrue}
  \newcommand{\GCKTateOff}{\gcknbn@tdirfalse}

  % 補正パラメータ
  \newlength{\gcknbn@adjust@yokotate}
  \NewDocumentCommand{\gcknbn@adjust@yokotate@use}{}{%
    \ifgcknbn@tdir
      \setlength{\gcknbn@adjust@yokotate}{-.7525\zw}%
    \else%
      \setlength{\gcknbn@adjust@yokotate}{-.56\zw}%
    \fi%
  }
  \newlength{\gcknbn@adjust@kaeri}
  \NewDocumentCommand{\gcknbn@adjust@kaeri@use}{}{%
    \ifgcknbn@tdir
      \setlength{\gcknbn@adjust@kaeri}{.35\zw}%
    \else%
      \setlength{\gcknbn@adjust@kaeri}{.15\zw}%
    \fi%
  }

  % phantom（再読文字分の行間を補正する）
  \def\gckanbun@phantom{\vphantom{あ}}

  %% ルビ
  %%  * グループルビ
  %%  * 漢文訓点に対するふりがな（モノルビ）
  \let\gcknbn@rubybox@text\relax
  \let\gcknbn@rubybox@text@s\relax
  \newdimen\gcknbn@rubybox@width
  \newdimen\gcknbn@furigana@width \gcknbn@furigana@width\z@
  \newdimen\gcknbn@furigana@width@s \gcknbn@furigana@width@s\z@
  \newdimen\gcknbn@dima

  % 侵入制御。
  % pre,post,bothをとれる。
  \newdimen\gcknbn@intr@pre
  \newdimen\gcknbn@intr@post
  \define@key{gcknbn@ruby}{intrusion}{\edef\gcknbn@ruby@intr@mark{#1}}
  \NewDocumentCommand{\gckanbun@intrusioncal}{}{%
    \ifdim\wd\@ne>\wd\tw@% 侵入量計算
      \ifdim\wd\@ne>1\zw%
        \global\gcknbn@intr@pre=\dimexpr(\wd\@ne-1\zw)/2\relax% 再読なし前方
        \global\gcknbn@intr@post=\dimexpr(\wd\@ne-1\zw)/2\relax% 再読なし後方
      \else%
        \global\gcknbn@intr@pre=0em\relax%
        \global\gcknbn@intr@post=0em\relax%
      \fi%
    \else%
      \ifdim\wd\tw@>1\zw%
        \global\gcknbn@intr@pre=\dimexpr(\wd\tw@-1\zw)/2\relax% 再読あり前方
        \global\gcknbn@intr@post=\dimexpr(\wd\tw@-1\zw)/2\relax% 再読あり後方
      \else%
        \global\gcknbn@intr@pre=0em\relax%
        \global\gcknbn@intr@post=0em\relax%
      \fi%
    \fi%
  }

  % ルビ本体
  \DeclareDocumentCommand{\gcknbn@ruby}{ O{} m m O{\gckanbun@phantom}}{% normal
    \gcknbn@adjust@yokotate@use%
    \global\gcknbn@furigana@width\z@%
    \global\gcknbn@furigana@width@s\z@%
    \global\def\gcknbn@ruby@intr@mark{}%
    \leavevmode%
    \gck@ghost@char@pre%%%
    \begingroup%
      \setkeys{gcknbn@ruby}{#1}%
      \gcknbn@dima\f@size\p@\relax \divide\gcknbn@dima by \tw@%
      \def\tiny{\@setfontsize\tiny{\gcknbn@dima}{\z@}\gckanbun@gluechange{0pt}}%
      \setbox\z@=\hbox{#2}% 親文字
      \setbox\@ne=\hbox{\tiny#3}% 振り仮名
      \setbox\tw@=\hbox{\tiny#4}% 再読振り仮名（通常はvphantomを入れている）
      \gckanbun@intrusioncal% 侵入量を計算
      \ifdefstring{\gcknbn@ruby@intr@mark}{pre}{%
        \kern-\gcknbn@intr@pre%
      }{%
        \ifdefstring{\gcknbn@ruby@intr@mark}{both}{%
          \kern-\gcknbn@intr@pre%
        }{%
          % それ以外は何もなし
      }}%
    \gdef\gcknbn@rubybox@text{#3}%
    \gdef\gcknbn@rubybox@text@s{#4}%
    \global\gcknbn@rubybox@width=\wd\z@\relax%
    \gcknbn@furigana@okurigana%
  }

  % 次に来る文字を判定
  \def\gcknbn@furigana@okurigana{% normal
    \futurelet\gckanbun@let@token\gcknbn@@furigana@okurigana%
  }

  % 各種ボックスの長さを計算
  \NewDocumentCommand{\gckanbun@furigana@boxcal}{}{%
    \ifdim\wd\z@>\wd\@ne% \dimen\z@=max{\wd\z@,\wd\@ne,\wd\tw@}
      \dimen\z@=\wd\z@%
    \else%
      \dimen\z@=\wd\@ne%
    \fi%
    \ifdim\dimen\z@<\wd\tw@%
      \dimen\z@=\wd\tw@%
    \fi%
  }

  % ボックスの配置

  % 次が送り仮名の時
  \NewDocumentCommand{\gckanbun@furigana@boxing@nextokuri}{}{%
    \raisebox{\gcknbn@adjust@yokotate}{\hbox{%
      \vbox{\hbox to \dimen\z@{\box\@ne\hss}%
        \nointerlineskip\hbox to \dimen\z@{\hss\box\z@\hss}%
        \nointerlineskip\hbox to \dimen\z@{\box\tw@\hss}%
    }}}%
  }
  % 次が送り仮名以外の時
  \NewDocumentCommand{\gckanbun@furigana@boxing@nextsonota}{}{%
    \raisebox{\gcknbn@adjust@yokotate}{\hbox{%
      \vbox{\hbox to \dimen\z@{\tiny\hss\gcknbn@rubybox@text\hss}%
        \nointerlineskip\hbox to \dimen\z@{\hss\box\z@\hss}%
        \nointerlineskip\hbox to \dimen\z@{\hss\box\tw@\hss}%
    }}}%
  }

  % 通常・再読振り仮名の長さをコピー
  % そして計算。
  \def\gckanbun@furigana@lenset{%
    \global\gcknbn@furigana@width=\wd\@ne\relax%
    \global\gcknbn@furigana@width@s=\wd\tw@\relax%
  }
  \newdimen\gcknbn@furigana@kutouten@kern
  \def\gcknbn@furigana@kutoten@skip{%
    \gcknbn@furigana@kutouten@kern=0pt\relax % リセット
    % どちらか一方が1\zwより大きいか
    \ifnum 0%
      \ifdim\gcknbn@furigana@width > 1\zw 1\fi%
      \ifdim\gcknbn@furigana@width@s > 1\zw 1\fi%
      > 0%
      %片方が1\zwを超えている場合
      \ifdim\gcknbn@furigana@width > \gcknbn@furigana@width@s%
        \gcknbn@furigana@kutouten@kern=\gcknbn@furigana@width%
      \else%
        \gcknbn@furigana@kutouten@kern=\gcknbn@furigana@width@s%
      \fi%
      \advance\gcknbn@furigana@kutouten@kern by -1\zw%
      \divide\gcknbn@furigana@kutouten@kern by \tw@%
    \fi%
    \hspace*{-\gcknbn@furigana@kutouten@kern}%
  }

  % 次のトークン（\gckanbun@let@token）に応じて
  % 処理を切り替えている機構
  \def\gcknbn@@furigana@okurigana{% normal
    \ifx\gckanbun@let@token\gcknbn@okurigana% 次が送り仮名
      \gckanbun@furigana@lenset%
      \dimen\z@=\wd\z@%
      \gckanbun@furigana@boxing@nextokuri%
    \else\ifx\gckanbun@let@token\gcknbn@kaeriten% 次が返り点
      \gckanbun@furigana@lenset%
      \gckanbun@furigana@boxcal%
      \penalty\@lowpenalty%
      \gckanbun@furigana@boxing@nextsonota%
    \else\ifx\gckanbun@let@token、% 次が、
      \gckanbun@furigana@lenset%
      \gckanbun@furigana@boxcal%
      \penalty\@lowpenalty%
      \gckanbun@furigana@boxing@nextsonota%
      \gcknbn@furigana@kutoten@skip%
    \else\ifx\gckanbun@let@token。% 次が。
      \gckanbun@furigana@lenset%
      \gckanbun@furigana@boxcal%
      \penalty\@lowpenalty%
      \gckanbun@furigana@boxing@nextsonota%
      \gcknbn@furigana@kutoten@skip%
    \else% その他
      \gckanbun@furigana@lenset%
      \gckanbun@furigana@boxcal%
      \penalty\@lowpenalty%
      \gckanbun@furigana@boxing@nextsonota%
    \fi\fi\fi\fi%
    \ifdefstring{\gcknbn@ruby@intr@mark}{post}{%
      \kern-\gcknbn@intr@post%
    }{%
    \ifdefstring{\gcknbn@ruby@intr@mark}{both}{%
        \kern-\gcknbn@intr@post%
      }{%
        % それ以外は何もなし
    }}%
    \ifx\gckanbun@let@token、%
      \gck@ghost@char@post%%%
    \else\ifx\gckanbun@let@token。%
    \else%
      \gck@ghost@char@post%%%
    \fi\fi%
  \endgroup%
  }

  %% 訓点
  \newdimen\gcknbn@okurigana@width \gcknbn@okurigana@width\z@
  \newdimen\gcknbn@okurigana@width@s \gcknbn@okurigana@width@s\z@
  \newdimen\gcknbn@kaeriten@width \gcknbn@kaeriten@width\z@

  \define@key{gcknbn@okurigana}{intrusion}{\edef\gcknbn@okuri@intr@mark{#1}}
    % post,bothをとれるが挙動は一緒

  % 送り仮名のボックスを計算
  \NewDocumentCommand{\gckanbun@okurigana@boxcal}{}{%
    \ifdim\gcknbn@furigana@width>0.9999\zw\relax%
      \global\gcknbn@okurigana@width=\dimexpr\gcknbn@furigana@width + \wd\z@ - 1\zw\relax%
    \else%
      \global\gcknbn@okurigana@width=\dimexpr\wd\z@ - .5\zw\relax%
    \fi%
    \ifdim\gcknbn@furigana@width@s>0.9999\zw\relax%
      \global\gcknbn@okurigana@width@s=\dimexpr\gcknbn@furigana@width@s + \wd\@ne - 1\zw\relax%
    \else%
      \global\gcknbn@okurigana@width@s=\dimexpr\wd\@ne - .5\zw\relax%
    \fi%
  }

  % ボックスの配置
  \NewDocumentCommand{\gckanbun@okurigana@boxing}{}{%
    \hbox{%
      \raisebox{\gcknbn@adjust@yokotate}{%
        \vbox{\hbox to \gcknbn@okurigana@width{%
          \ifdim\gcknbn@furigana@width>0.9999\zw\relax%
            \hspace*{\dimexpr\gcknbn@furigana@width - 1\zw\relax}%
          \else%
            \hspace*{-.5\zw}%
          \fi%
          \box\z@}%
          \nointerlineskip%
          \hbox to \gcknbn@okurigana@width{%
            \hss%
            \vphantom{\char\euc"A1A1}%
            \hss%
          }%
          \nointerlineskip%
          \hbox to \gcknbn@okurigana@width@s{%
            \ifdim\gcknbn@furigana@width@s>0.9999\zw\relax%
              \hspace*{\dimexpr\gcknbn@furigana@width@s - 1\zw\relax}%
            \else%
              \hspace*{-.5\zw}%
            \fi%
            \box\@ne%
    }}}}%
  }

  % 送り仮名本体
  \DeclareDocumentCommand{\gcknbn@okurigana}{ O{} m O{\gckanbun@phantom} }{% normal
    \nobreak\leavevmode%
    \gcknbn@adjust@yokotate@use%
    \global\gcknbn@okurigana@width\z@%
    \global\gcknbn@okurigana@width@s\z@%
    \global\def\gcknbn@okuri@intr@mark{}%
    \begingroup%
      \setkeys{gcknbn@okurigana}{#1}%
      \gcknbn@dima\f@size\p@\relax \divide\gcknbn@dima by \tw@%
      \def\tiny{\@setfontsize\tiny{\gcknbn@dima}{\z@}\gckanbun@gluechange{0pt}}%
      \setbox\z@=\hbox{\tiny#2}% 通常送り仮名
      \setbox\@ne=\hbox{\tiny#3}% 再読送り仮名（通常はvphantomを入れている）
      \gckanbun@okurigana@boxcal%
      \gckanbun@okurigana@boxing%
    \global\gcknbn@furigana@width=\z@\relax%
    \gcknbn@okurigana@intr%
    \gcknbn@okurigana@kaeriten%
  }

  % 次に来る文字をセット
  \def\gcknbn@okurigana@kaeriten{\futurelet\gckanbun@let@token\gcknbn@@okurigana@kaeriten}

  % 次に来るトークン毎に処理を変更
  \def\gcknbn@@okurigana@kaeriten{%
    \ifx\gckanbun@let@token、
      \gcknbn@okurigana@kutoten@skip
      \global\gcknbn@okurigana@width=\z@
      \gck@ghost@char@post%%%
    \else\ifx\gckanbun@let@token。
      \gcknbn@okurigana@kutoten@skip
      \global\gcknbn@okurigana@width=\z@
      \gck@ghost@char@post%%%
    \else\ifx\gckanbun@let@token\gcknbn@kaeriten
      \gcknbn@okurigana@kaeriten@skip
      \gck@ghost@char@post%%%
    \else%
      \ifdefstring{\gcknbn@okuri@intr@mark}{post}{%
        \kern-\gcknbn@intr@post%
      }{%
      \ifdefstring{\gcknbn@okuri@intr@mark}{both}{%
          \kern-\gcknbn@intr@post%
        }{%
          % それ以外は何もなし
      }}%
      \gck@ghost@char@post%%%
    \fi\fi\fi
  \endgroup}

  % 各場合毎に入れるスペース
  \def\gcknbn@okurigana@kutoten@skip{%
    \ifdim\gcknbn@okurigana@width>\gcknbn@okurigana@width@s%
      \hspace*{-\gcknbn@okurigana@width}%
    \else%
      \hspace*{-\gcknbn@okurigana@width@s}%
    \fi%
  }
  \def\gcknbn@okurigana@kaeriten@skip{%
    \ifdim\gcknbn@okurigana@width>\gcknbn@okurigana@width@s%
      \hspace*{-\gcknbn@okurigana@width}%
    \else%
      \hspace*{-\gcknbn@okurigana@width@s}%
    \fi
  }
  \def\gcknbn@okurigana@intr{%
    \ifdim\gcknbn@okurigana@width>\gcknbn@okurigana@width@s%
      \global\gcknbn@intr@post=\gcknbn@okurigana@width%
    \else%
      \global\gcknbn@intr@post=\gcknbn@okurigana@width@s%
    \fi
  }

  %%訓点返り点
  \define@key{gcknbn@kaeriten}{intrusion}{\edef\gcknbn@kaeri@intr@mark{#1}}
    % post,bothをとれるが挙動は一緒

  % 返り点本体
  \DeclareDocumentCommand{\gcknbn@kaeriten}{ O{} m }{% normal
    \nobreak\leavevmode%
    \gcknbn@adjust@kaeri@use%
    \global\def\gcknbn@kaeri@intr@mark{}%
    \setkeys{gcknbn@kaeriten}{#1}%
    \begingroup%
      \gcknbn@dima\f@size\p@\relax \divide\gcknbn@dima by \tw@
      \def\tiny{\@setfontsize\tiny{\gcknbn@dima}{\z@}}%
      \setbox\z@=\hbox{\tiny #2}%
      \global\gcknbn@kaeriten@width=\wd\z@\relax
      \ifdim\wd\z@>\gcknbn@intr@post%
        \global\gcknbn@intr@post=\wd\z@%
      \fi%
      \lower\gcknbn@adjust@kaeri\hbox{\box\z@\hss}%
    \endgroup%
    \gcknbn@kaeriten@kutoten%
  }

  % 次に来る文字をセット
  \def\gcknbn@kaeriten@kutoten{\futurelet\gckanbun@let@token\gcknbn@@kaeriten@kutoten}

  % 次に来る文字毎に処理を変更
  \def\gcknbn@@kaeriten@kutoten{%
    \ifx\gckanbun@let@token、%
      \gcknbn@kaeriten@kutoten@skip%
      \global\gcknbn@kaeriten@width=\z@%
    \else\ifx\gckanbun@let@token。%
      \gcknbn@kaeriten@kutoten@skip%
      \global\gcknbn@kaeriten@width=\z@%
    \else%
      \ifdefstring{\gcknbn@kaeri@intr@mark}{post}{%
        \kern-\gcknbn@intr@post%
      }{%
      \ifdefstring{\gcknbn@kaeri@intr@mark}{both}{%
          \kern-\gcknbn@intr@post%
        }{%
          \gcknbn@kaeriten@okurigana@skip%
      }}%
      \gck@ghost@char@post%%%
    \fi\fi%
  }

  % 各場合分け毎に入れるスペース
  \def\gcknbn@kaeriten@kutoten@skip{%
    \ifgcknbn@tdir%
      \hspace*{-\gcknbn@kaeriten@width}%
    \fi%
  }
  \def\gcknbn@kaeriten@okurigana@skip{%
    \ifdim\gcknbn@okurigana@width>\gcknbn@kaeriten@width%
      \hspace*{\dimexpr\gcknbn@okurigana@width - \gcknbn@kaeriten@width\relax}%
    \fi%
    \ifdim\gcknbn@okurigana@width<\gcknbn@okurigana@width@s%
      \hspace*{\dimexpr\gcknbn@okurigana@width@s - \gcknbn@kaeriten@width\relax}%
    \else%
    \fi%
  }

  %% \<prefix>ruby, \<prefix>okurigana, \<prefix>kaeriten
  \expandafter\let\csname\gcknbn@prefix ruby\endcsname\gcknbn@ruby
  \expandafter\let\csname\gcknbn@prefix okurigana\endcsname\gcknbn@okurigana
  \expandafter\let\csname\gcknbn@prefix kaeriten\endcsname\gcknbn@kaeriten

  %% 短縮マクロ
  \expandafter\let\csname 振り\endcsname\gcknbn@ruby
  \expandafter\let\csname 送り\endcsname\gcknbn@okurigana
  \expandafter\let\csname 返り\endcsname\gcknbn@kaeriten

  %% 特殊返り点
  \NewDocumentCommand{\IchiRe}{}{%
    \ifgcknbn@tdir%
      \hspace{-0.21\zw}一\hspace{-0.72\zw}レ%
    \else%
      \raisebox{0.29\zw}{一}\llap{レ}%
    \fi%
  }
  \NewDocumentCommand{\JyouRe}{}{%
    \ifgcknbn@tdir%
      上\hspace{-0.3\zw}レ%
    \else%
      \raisebox{0.71\zw}{上}\llap{レ}%
    \fi%
  }
  \NewDocumentCommand{\KouRe}{}{%
    \ifgcknbn@tdir%
      甲\hspace{-0.17\zw}レ%
    \else%
      \raisebox{0.82\zw}{甲}\llap{レ}%
    \fi%
  }
  \NewDocumentCommand{\TenRe}{}{%
    \ifgcknbn@tdir%
      天\hspace{-0.17\zw}レ%
    \else%
      \raisebox{0.82\zw}{天}\llap{レ}%
    \fi%
  }
  \NewDocumentCommand{\KanHyphen}{}{\symbol{"2015}}


  %% GCKEnv
  \newcommand{\gckanbun@gluechange}[1]{%
    \ifluatex%
      \ltjsetparameter{kanjiskip=#1}%
    \else%
      \kanjiskip=#1%
    \fi%
  }
  \edef\gckanbn@skip@default{0.3\zw plus 0.15\zw minus 0.2\zw}
  \NewDocumentEnvironment{GCKEnv}{ m O{\gckanbn@skip@default} }{%
    \gckanbun@gluechange{#2}%
  }{\par}
  \NewDocumentCommand{\GCKanshiBox}{ m m }{%
    \makebox[#1][s]{\vphantom{\gcknbn@ruby{あ}{あ}[あ]}#2}%
  }
  \endinput
\end{lstlisting}

\end{document}