\documentclass[luatex,fontsize=8pt,paper=b5,twoside]{jlreq}%
\usepackage{amsmath,amssymb}
\usepackage{booktabs}
\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.6.0 (2026/06/21)}


\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}パッケージが提供する4つのコマンド\verb|\gckanbunruby|、\verb|\gckanbungroupruby|、\verb|\gckanbunokurigana|、\verb|\gckanbunkaeriten| をそれぞれ\verb|<prefix>ruby|、\verb|<prefix>groupruby|、\verb|<prefix>okurigana|、\verb|<prefix>kaeriten| として提供します。このオプションにより、他のパッケージで提供されるルビ振りコマンド \verb|\ruby| との衝突を避けられます。

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

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

\begin{itemize}
  \item 返り点
  \item 振り仮名（モノルビ）
  \item グループルビ
  \item 送り仮名
  \item 再読振り仮名
  \item 再読送り仮名
  \item 一レ点、上レ点、甲レ点、天レ点
  \item ハイフン
\end{itemize}

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

\begin{itemize}
  \item \verb|\<prefix>kaeriten|、\verb|\返り|
  \item \verb|\<prefix>ruby|、\verb|\振り|
  \item \verb|\<prefix>groupruby|、\verb|\グ振り|
  \item \verb|\<prefix>okurigana|、\verb|\送り|
  \item \verb|\<prefix>ruby|、\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>ruby|、\verb|\<prefix>groupruby|、\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{コマンド間の空白について}
\verb|\振り|・\verb|\グ振り|・\verb|\送り|・\verb|\返り|は、直後に続くコマンドや文字を\verb|\futurelet|で先読みし、送り仮名や返り点・句読点が続く場合に字送りを調整します。v2.6.0以降では、この先読みが\namiKK{協調するコマンドの間に挟まった空白・改行・コメントを無視}するようになりました。そのため、
\begin{quotation}
\verb|\グ振り{読}{よ}\返り{レ}書| と \verb|\グ振り{読}{よ} \返り{レ}書|
\end{quotation}
\noindent は同一の組版結果になります。ソースを読みやすく改行・字下げしても、余分な和文グルーが入ったり調整が外れたりしません。

\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|を指定します。v2.4.1以降では、通常の縦組と局所縦組のどちらでも、\verb|\KanHyphen|を親文字とするルビ外箱の前後に余分な和文グルーが入りません。

\subsubsection{\textbackslash <prefix>groupruby、\textbackslash グ振り}

\verb|\<prefix>groupruby|と\verb|\グ振り|は同一のコマンドで、複数の親文字を一つの親文字列として扱うグループルビを配置します。デフォルトのprefixでは\verb|\gckanbungroupruby|となります。書式は

\begin{verbatim}
\グ振り[intrusion=pre|post|both]{親文字列}{ルビ文字列}[再読ルビ文字列]
\end{verbatim}

\noindent です。親文字列とルビ文字列はそれぞれ不可分な一群となり、途中では改行されません。親文字列が長い場合は、LuaTeX-jaの標準グループルビと同じく、ルビ前・ルビ文字間・ルビ後の空きを1:2:1の比率で配分します。ルビ文字列が長い場合は自然幅で中央配置します。

第4引数（オプション）には、モノルビ（\verb|\振り|）の第4引数と同様に、再読文字用の再読ルビを指定できます。再読ルビは親文字列の下段（縦組では左側）に、上段ルビと同じ1:2:1の比率で伸縮配置されます。直後に\verb|\送り{送り仮名}[再読送り仮名]|を続けると、送り仮名は上段ルビの末尾に、再読送り仮名は再読ルビの末尾に、それぞれモノルビと同じ高さで並びます。箱幅は\verb|max(親文字列, 上段ルビ, 再読ルビ)|で決まり、いずれの段もはみ出しません。

\begin{SourceCode}{Input}{TeX}
  \グ振り{所以}{ゆえん}\送り{ノミ}

  \グ振り{所\返り[intrusion=post]{一}\KanHyphen 以}{ゆえん}\送り{ノミ}

  \グ振り[intrusion=both]{不可思議}{ふかしぎ}

  \グ振り{所以}{ゆえん}[かくか]\送り{ナリ}[シム]
\end{SourceCode}

\begin{OutPut}{Output}[横書き]
  \グ振り{所以}{ゆえん}\送り{ノミ}

  \グ振り{所\返り[intrusion=post]{一}\KanHyphen 以}{ゆえん}\送り{ノミ}

  \グ振り[intrusion=both]{不可思議}{ふかしぎ}

  \グ振り{所以}{ゆえん}[かくか]\送り{ナリ}[シム]
\end{OutPut}

親文字列には\verb|\返り|や\verb|\KanHyphen|などの訓点コマンドを含められます。親文字列内で更新された内部状態はグループルビの外へ持ち越されません。なお、親文字列に\verb|\KanHyphen|を含む場合は、ハイフンで連結した語を不可分な一群として扱うため、親文字列全体をベタ組（\verb|kanjiskip=0|）で組みます。\verb|\KanHyphen|を別名マクロやグループで包んだ場合も同じ処理になります。\verb|\KanHyphen|を含まない親文字列では、通常どおり\verb|kanjiskip|による字間が入ります。

親文字列内で\verb|\返り[intrusion=post]{...}\KanHyphen|と直接続けた場合、返り点の占有幅だけを完全に相殺します。ハイフン本体の一文字分の幅は維持されるため、返り点とハイフンの間に余計な空白を作らず、ハイフンが直前の親文字へ重なることもありません。

親文字列中の\verb|\KanHyphen|は、別名マクロや波括弧を何段か経由しても検出され、同じベタ組処理が適用されます。ただし、親文字列内へさらに\verb|\振り|や\verb|\グ振り|を入れ子にすると上下のルビが競合するため、この用法はサポートしません。

\verb|\グ振り{天地}{てんち}\返り{レ}文|のように直後へ返り点を置く場合、返り点は通常の\verb|\返り|と同じ幅を確保してグループ末尾の親文字の後へ配置されます。ルビや再読ルビが親文字列より長い場合も、ルビ外箱の右端ではなく末尾親文字の直後へ位置を戻します。そのため、前の親文字や続く本文文字とは重なりません。

\verb|\グ振り{天地}{てんち}[]|のように再読ルビへ空のオプション引数を明示した場合は、再読ルビを省略した場合と同じ行高・ベースラインになります。

\verb|intrusion|にはモノルビと同じく\verb|pre|、\verb|post|、\verb|both|を指定できます。ルビが親文字列より長い場合に限り、指定した側の突出量を前後の字送りから差し引きます。無指定の場合はルビ全体の自然幅を確保します。

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

v2.3.0以降では、各コマンドは呼び出し時に文書の組方向を動的に検出します。そのため、縦組み環境に切り替えたタイミングで自動的に縦書き補正が適用されます。

手動で制御する場合は以下のコマンドを使用します。

\begin{description}
  \item[\texttt{\textbackslash GCKTateOn}] 縦書き補正を強制的にオン（手動モード）。
  \item[\texttt{\textbackslash GCKTateOff}] 横書き補正を強制的にオン（手動モード）。
  \item[\texttt{\textbackslash GCKTateAuto}] 手動モードを解除し、自動検出に戻す（v2.3.0新規）。
\end{description}

局所縦書きを開始する際には、\verb|\GCKTateOn|を入れます。もし、通常が縦書き環境の中で局所横書きをする場合には\verb|\GCKTateOff|となります。\verb|\GCKTateAuto|を実行することで、その後の方向検出が再び自動になります。

\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 v2.6.0以降、上記以外の値を\verb|intrusion|に指定すると（例：\verb|intrusion=typo|）、黙って無視せずパッケージエラーを送出します。値の打ち間違いに気付きやすくなっています。

\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{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 (2026/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.
  \item \textbf{v2.3.0 (2026/06/12)} --- Each command now auto-detects writing direction at invocation time, enabling correct behavior in partial-vertical contexts without explicit \verb|\GCKTateOn|. Added \verb|\GCKTateAuto| to resume auto-detection after manual override. Internal code cleanup and bug fixes.
  \item \textbf{v2.3.2 (2026/06/13)} --- Suppress \verb|\KanHyphen| surrounding kanjiskip via \verb|\inhibitglue|. Replace \verb|\llap| with \verb|\makebox[0pt][r]| in special return-mark commands for clarity.
  \item \textbf{v2.4.0 (2026/06/13)} --- Migrated internal implementation to \textsf{expl3}: variable declarations (\verb|\dim_new:N|, \verb|\bool_new:N|), option processing (\verb|l3keys2e|), arithmetic (\verb|\dim_compare:nNnTF|), named scratch boxes, and load-time engine branching (\verb|\sys_if_engine_luatex:TF|). Fixed \verb|\AtBeginDocument| ignoring the manual tdir flag. The \verb|\futurelet| lookahead mechanism is retained.
  \item \textbf{v2.4.1 (2026/06/19)} --- Suppressed Japanese glue around a ruby whose parent is \verb|\KanHyphen| at the outer ruby-box level, preserving \verb|intrusion=post| in full and partial vertical writing.
  \item \textbf{v2.5.0 (2026/06/19)} --- Added group ruby command \verb|\gckanbungroupruby| (\verb|\グ振り|). Ruby shorter than its base uses LuaTeX-ja-compatible 1:2:1 spacing; longer ruby supports \verb|intrusion=pre|, \verb|post|, and \verb|both|. Parent text may contain Kanbun annotation commands.
  \item \textbf{v2.5.1 (2026/06/20)} --- Added re-read ruby support to group ruby and aligned its three-row structure with monoruby. Fixed spacing when a return mark with \verb|intrusion=post| is followed directly by \verb|\KanHyphen| inside the parent string: only the return-mark width is cancelled, keeping the hyphen width without an extra gap.
  \item \textbf{v2.5.2 (2026/06/20)} --- Made group-ruby hyphen detection robust through alias macros and nested braces by propagating the zero-\verb|kanjiskip| request to the parent box. A return mark following group ruby now preserves its natural width and is aligned after the final parent character, avoiding overlap on either side even when ruby is wider than its base. Explicitly empty reread ruby now preserves the same baseline as an omitted reread argument. Added horizontal, vertical, and upLaTeX edge-case regression matrices.
  \item \textbf{v2.5.3 (2026/06/21)} --- Prepared the corrected group-ruby and return-mark implementation for CTAN release. Added complete CTAN release metadata, included all horizontal, vertical, and upLaTeX regression files in the distribution archive, and made the documentation build depend explicitly on its embedded test PDF.
  \item \textbf{v2.6.0 (2026/06/21)} --- Made command chaining whitespace-insensitive: a space, line break, or comment between cooperating commands (e.g.\ \verb|\振り|/\verb|\グ振り| followed by \verb|\送り| or \verb|\返り|) no longer breaks the \verb|\futurelet| lookahead nor inserts spurious glue, so spaced and adjacent input now produce identical layout. Invalid \verb|intrusion| values are now rejected: \verb|\振り| accepts \verb|pre|/\verb|post|/\verb|both| and \verb|\送り|/\verb|\返り| accept \verb|post|/\verb|both|; any other value raises a package error instead of being silently ignored. Added a whitespace regression matrix (\texttt{gckanbun-edge-test-whitespace.tex}) and a LuaLaTeX-only \texttt{make check} release gate, and dropped the unused \textsf{caption} dependency from the documentation build.
\end{itemize}

% \section{Source Code}
% \lstinputlisting{gckanbun.sty}

\end{document}
