%%
%% This is file `xeCJK-example-boundary-register.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% xeCJK.dtx  (with options: `ex-boundary-register')
%% 
\documentclass{article}
\usepackage{xeCJK}

\setCJKmainfont{FandolSong-Regular.otf}
\setCJKmonofont{FandolFang-Regular.otf}
\setlength{\fboxsep}{2pt}
\setlength{\fboxrule}{0.4pt}
\setlength{\parindent}{0pt}

\newcommand\MyBox[1]{\hbox{#1}}
\newcommand\MyWrapped[1]{\kern0pt #1\kern0pt}
\newcommand\MyStream[1]{\special{xeCJK-boundary-example}#1}
\newcommand\MyTransparent{\special{xeCJK-boundary-example}}
\newcommand\MyPostTransparent{\hbox{}}

\xeCJKsetup
  {
    CJKecglue = {\hskip 10pt},
    CJKglue   = {\hskip 2pt},
    experiment/boundary-register =
      { command = \MyBox, strategy = box },
    experiment/boundary-register =
      { command = \MyWrapped, strategy = wrapped-box },
    experiment/boundary-register =
      { command = \MyStream, strategy = stream },
    experiment/boundary-register =
      { command = \MyTransparent, strategy = transparent },
    experiment/boundary-register =
      { command = \MyPostTransparent, strategy = post-transparent }
  }

\newcommand\BoundaryCell[2]
  {
    \begin{tabular}[c]{@{}c@{}}
      \fbox{\hbox{#1}} \\
      \fbox{\hbox{#2}}
    \end{tabular}
  }

\newcommand\BoundaryRow[4]
  {
    \texttt{#1}
      & \BoundaryCell{#2#3#4}{#2\MyStream{#3}#4}
      & \BoundaryCell{#2 #3#4}{#2 \MyStream{#3}#4}
      & \BoundaryCell{#2#3 #4}{#2\MyStream{#3} #4}
      & \BoundaryCell{#2 #3 #4}{#2 \MyStream{#3} #4} \\[2pt]
  }

\newcommand\TestBoundaryMatrix[1]
  {
    \subsection*{\texttt{xCJKecglue=#1}}
    \xeCJKsetup{xCJKecglue=#1}
    \begin{tabular}{@{}lcccc@{}}
      & \texttt{00} & \texttt{10} & \texttt{01} & \texttt{11} \\
      \BoundaryRow{西文}{中}{A}{中}
      \BoundaryRow{中文}{A}{中文}{B}
      \BoundaryRow{中西}{A}{中A}{B}
      \BoundaryRow{西中}{A}{A中}{B}
      \BoundaryRow{公式}{中}{$x$}{中}
    \end{tabular}
  }

\begin{document}

\section*{\normalfont 用户命令的边界间距检查}
每格上方是直接输入，下方是采用 \texttt{stream} 策略注册的命令；
两只方框等宽表示这一格与直接输入一致。中西、西中两行分别只在左边界和
右边界产生中西文间距，用于排除两侧误差互相抵消的情况。公式行故意展示
通用注册不分析命令参数的限制：公式位于命令边界时，还需要专用参数适配，
不能把不等宽的结果当作正确行为。

\begingroup
  \small
  \setlength\tabcolsep{2pt}
  \TestBoundaryMatrix{false}
  \TestBoundaryMatrix{true}
\endgroup

\end{document}
%% 
%%
%% End of file `xeCJK-example-boundary-register.tex'.
