%#!lualatex
\documentclass[a4paper,titlepage]{article}
\usepackage{amsmath,amssymb,xcolor,pict2e}
\usepackage{booktabs,listings,lltjlisting,showexpl}
\usepackage{luatexja}
%\usepackage{luatexja-fontspec}
\usepackage[margin=20mm]{geometry}
\usepackage[unicode=true]{hyperref}

\title{The Lua\TeX-ja package}
\author{The Lua\TeX-ja project team}


\lstset{
  basicstyle=\ttfamily\small, pos=o, breaklines=true,
  numbers=none, rframe={}
}

\catcode`\<=13
\def<#1>{{\normalfont\itshape$\langle$#1$\rangle$}}
\begin{document}
\maketitle

\tableofcontents
\bigskip
{\Large\bf This documentation is far from complete. It may have many
grammatical (and contextual) errors.}

\newpage
\part{User's manual}
\makeatletter\the\ltj@@stack,\the\ltj@@group@level,\the\currentgrouplevel.


\section{Introduction}

The Lua\TeX-ja package is a macro package for typesetting high-quality
Japanese documents in Lua\TeX.

\subsection{Backgrounds}
Traditionally, ASCII p\TeX, an extension of \TeX, and its derivatives
are used to typeset Japanese documents in \TeX. p\TeX is an engine
extension of \TeX: so it can produce high-quality Japanese documents
without using very complicated macros. But this point is a mixed
blessing: p\TeX\ is left behind from other extensions of \TeX,
especially $\varepsilon$-\TeX\ and pdf\TeX, and from changes about
Japanese processing in computers (\textit{e.g.}, the UTF-8 encoding).

Recently the extensions of p\TeX, namely up\TeX\ (Unicode-implementation
of p\TeX) and $\varepsilon$-p\TeX\ (Merging of p\TeX and
$\varepsilon$-\TeX\ extension), have developed to fill those gap to some
extent, but gaps are still exist.

However, the appearance of Lua\TeX\ changed the whole situation. With
using Lua `callbacks', users can customize the internal processing of
Lua\TeX. So there is no need to modify sources of the \TeX\ engine to
support Japanese typesetting: to do this, we only have to write Lua
script for appropriate callbacks.


\subsection{Major Changes from p\TeX}
The Lua\TeX-ja package is much influenced by p\TeX\ engine. The initial
target of development was to implement features of p\TeX. However,
\emph{Lua\TeX-ja is not a just porting of p\TeX: Unnatural
specifications/behaviors of p\TeX\ were not adopted}.

The followings are major changes from p\TeX:
\begin{itemize}
\item Japanese fonts are a tuple of a `real' font, a Japanese font
      metric (\textbf{JFM}, for short), and an optional string called
      `variation'.

\item In p\TeX, a linebreak after Japanese character is ignored (and
      doesn't yield a space), since Japanese texts can linebreak almost
      everywhere. However, Lua\TeX-ja doesn't have this function
      completely, because of a specification of Lua\TeX.
\item The insertion process of glues/kerns between two Japanese
      characters and between a Japanese character and other characters
      (we refer these glues/kerns as \textbf{JAglue}) is rewritten from
      scratch.

\begin{itemize}
\item As Lua\TeX's internal character handling is `node-based'
      (\textit{e.g.}, \verb+of{}fice+ doesn't prevent ligatures), the
      insertion process of \textbf{JAglue} is now `node-based'.
\item Furthermore, nodes between two characters which have no effects in
      linebreak (\textit{e.g.}, \verb+\special+ node) are ignored in the
      insertion process.
\item In the process, two Japanese fonts which differ in their `real'
      fonts only are identified.
\end{itemize}
\item At the present, vertical typesetting (\textit{tategaki}), is not
      supported in Lua\TeX-ja.

\end{itemize} 
For detailed information, see Part~\ref{part-imp}.

\subsection{Notations}
In this document, the following terms and notations are used:
\begin{itemize}
\item Characters are divided into two types: 
\begin{itemize}
\item \textbf{JAchar}: standing for Japanese characters such as
      Hiragana, Katakana, Kanji and other punctuation marks for
      Japanese.'
\item \textbf{ALchar}: standing for all other characters like alphabets. 
\end{itemize}
\item A word in sans-serif font (like \textsf{prebreakpenalty})
      represents an internal parameter for Japanese typesetting, and it
      is used as a key in \verb+\ltjsetparameter+ command.
\item The word ``primitive'' is used not only for primitives in Lua\TeX,
      but also for control sequences that defined in the core module of
      Lua\TeX-ja.
\end{itemize}

\subsection{About the project}
\paragraph{Project Wiki} \url{http://sourceforge.jp/projects/luatex-ja/wiki/FrontPage%28en%29}

This project is hosted by SourceForge.JP.
\paragraph{Members}

%h7k
%kmaeda
%abenori
%kuroky
%munepi
%thonda
%zrbabbler

\newpage
\section{Getting Started}
\subsection{Installation}
To install the Lua\TeX-ja\ package, you will need:
\begin{itemize}
\item Lua\TeX, version 0.65.0-beta or later.\\
If you are using \TeX~Live\ 2011 or W32\TeX, you don't have to worry.
\item The source archive of Lua\TeX-ja, of course{\tt:)}
\end{itemize}

The installation methods are as follows:
\begin{enumerate}
\item Download the source archive.

At the present, Lua\TeX-ja has no official release, so you have to retrieve
the archive from the repository.
You can retrieve the Git repository via
\begin{verbatim}
$ git clone git://git.sourceforge.jp/gitroot/luatex-ja/luatexja.git
\end{verbatim} 
or download the archive of HEAD in the master branch from
\begin{flushleft}
\url{http://git.sourceforge.jp/view?p=luatex-ja/luatexja.git;a=snapshot;h=HEAD;sf=tgz}.
\end{flushleft}
\item Extract the archive. You will see {\tt src/} and several other sub-directories.
\item Copy all the contents of {\tt src/} into one of your \texttt{TEXMF} tree.
\item If {\tt mktexlsr} is needed to update the filename database, make it so.
\end{enumerate}

\subsection{Cautions}
\begin{itemize}
\item The encoding of your source file must be UTF-8. 
\item conflicts with unicode-math
\end{itemize}

\subsection{Using in plain \TeX}
To use Lua\TeX-ja in plain \TeX, simply put the following  at the beginning of the document:
\begin{verbatim}
\input luatexja.sty
\end{verbatim}

This does the minimal setting (like {\tt ptex.tex}) for typesetting Japanese documents:
\begin{itemize}
\item The following 6 Japanese fonts are preloaded.
\begin{center}
\begin{tabular}{ccccc}
\toprule
\textbf{classification}&\textbf{font name}&\textbf{13.5\,Q}&\textbf{9.5\,Q}&\textbf{7\,Q}\\\midrule
\textit{mincho}&Ryumin-Light    &\verb+\tenmin+&\verb+\sevenmin+&\verb+\fivemin+\\
\textit{gothic}&GothicBBB-Medium&\verb+\tengt+ &\verb+\sevengt+ &\verb+\fivegt+\\
\bottomrule
\end{tabular}
\end{center}
\begin{itemize}
\item The `Q' is an unit used in Japanese phototypesetting, and
      $1\,\textrm{Q}=0.25\,\textrm{mm}$. This length is stored in a
      dimension \verb+\jQ+.

\item It is widely accepted that the font `Ryumin-Light' and
      `GothicBBB-Medium' aren't embedded into PDF files, and the PDF
      reader substitutes them by some external Japanese font. We adopt
      this custom to the default setting.
\item size
\end{itemize}
\item A character in Unicode is treated as \textbf{JAchar} if and only
      if its code-point has more than or equal to U+0100.
\item The amount of glue that are inserted between \textbf{JAchar} and
      \textbf{ALchar} (the parameter \textsf{xkanjiskip}) is set to
\[
 0.25\,\hbox{\verb+\zw+}^{+1\,\text{pt}}_{-1\,\text{pt}} = \frac{27}{32}\,\mathrm{mm}^{+1\,\text{pt}}_{-1\,\text{pt}}.
\]
Here \verb+\zw+ is a counterpart of \texttt{em} for Japanese fonts, that is, the length of `full-width' in the current Japanese font.
\end{itemize}

\subsection{Using in \LaTeX}
\paragraph{\LaTeXe}
Using in \LaTeXe\ is basically same. To set up the minimal environment
for Japanese, you only have to load {\tt luatexja.sty}:
\begin{verbatim}
\usepackage{luatexja}
\end{verbatim}
It also does the minimal setting (the counterpart in p\LaTeX\ is  {\tt
plfonts.dtx} and {\tt pldefs.ltx}):

\begin{itemize}
\item {\tt JY3} is used as the font encoding for Japanese fonts (in horizontal direction).\\
If vertical typesetting is supported by Lua\TeX-ja, {\tt JT3} will be used for vertical fonts.
\item Two font families {\tt mc} and {\tt gt} are defined: 
\begin{center}
\begin{tabular}{ccccc}
\toprule
\textbf{classification}&\textbf{family}&\verb+\mdseries+&\verb+\bfseries+&\textbf{scale}\\\midrule
\textit{mincho}&\tt mc&Ryumin-Light    &GothicBBB-Medium&0.960444\\
\textit{gothic}&\tt gt&GothicBBB-Medium&GothicBBB-Medium&0.960444\\
\bottomrule
\end{tabular}
\end{center}
\item Japanese characters in math mode are typeset by the font family {\tt mc}.
\end{itemize}

However, the above setting is not sufficient for Japanese-based documents. To do this, 
You are better to use class files other than {\tt article.cls}, {\tt book.cls}, ...
The better alternatives are:
\begin{itemize}
\item BXjscls
\item ltjarticle, ltjbook?
\item ltjsarticle, ltjsbook?
\end{itemize}

\subsection{Changing Fonts}
\paragraph{Remark: Japanese Characters in Math Mode}
Since p\TeX\ supports Japanese characters in math mode, there are
sources like the following:

\begin{LTXexample}
$f_{高温}$~($f_{\text{high temperature}}$).
\[ y=(x-1)^2+2\quad{}よって\quad y>0 \]
$5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
\end{LTXexample}

We (the project members of Lua\TeX-ja) think that using
Japanese characters in math mode are allowed if these are used as identifiers.
In this point of view, 
\begin{itemize}
\item The lines 1~and~2 above are not correct, since `高温' in above is used as a textual label, and
`よって' is used as a conjunction. 
\item However, the line~3 is correct, since `素' is used as an identifier.
\end{itemize}

Hence, in our opinion, the above input should be corrected as:
\begin{LTXexample}
$f_{\text{高温}}$~%
($f_{\text{high temperature}}$).
\[ y=(x-1)^2+2\quad 
  \mathrel{\text{よって}}\quad y>0 \]
$5\in{}素:=\{\,p\in\mathbb N:\text{$p$ is a prime}\,\}$.
\end{LTXexample}
%BUG?: \{\}がなければ「素」がでない．上の段落の「よって」もでてない．


どう繋ごうか？

In this chapter, we don't describe how to change Japanese fonts in
math mode. For the method, please see Part~\ref{part-ref}.


\paragraph{plain \TeX}
To change Japanese fonts in plain \TeX, you must use the primitive
\verb+\jfont+. So please see Part~\ref{part-ref}.


\paragraph{NFSS2}
For \LaTeXe, Lua\TeX-ja simply adopted font selection system from that
of p\LaTeXe\ (in: {\tt plfont.dtx}).
\begin{itemize}
\item Two control sequences \verb+\mcdefault+ and \verb+\gtdefault+ are
      used to specify the default font family for \textit{mincho} and
      \textit{gothic}, respectively.
\item Commands \verb+\fontfamily+, \verb+\fontseries+,
      \verb+\fontshape+ and \verb+\selectfont+ can be used to change
      attributes of Japanese fonts. 
\begin{center}
\begin{tabular}{ccccc}
\toprule
&\textbf{encoding}&\textbf{family}&\textbf{series}&\textbf{shape}\\\midrule
alphabetic fonts
&\verb+\romanencoding+&\verb+\romanfamily+&\verb+\romanseries+&\verb+\romanshape+\\
Japanese fonts
&\verb+\kanjiencoding+&\verb+\kanjifamily+&\verb+\kanjiseries+&\verb+\kanjishape+\\
both&---&--&\verb+\fontseries+&\verb+\fontshape+\\
auto select&\verb+\fontencoding+&\verb+\fontfamily+&---&---\\
\bottomrule
\end{tabular}
\end{center}
\item For defining a Japanese font family, use \verb+\DeclareKanjiFamily+
      instead of \verb+\DeclareFontFamily+.
\end{itemize}

\paragraph{fontspec}
To use with \texttt{fontspec} package, it is needed to load
\texttt{luatexja-fontspec} package in the preamble. This additional
package automatically loads \texttt{luatexja} and \texttt{fontspec}
package, if needed.

In \texttt{luatexja-fontspec} package, the following 4 commands are defined as
counterparts of original commands in \texttt{fontspec}:
\begin{center}
\begin{tabular}{ccccc}
\toprule
Japanese fonts
&\verb+\jfontspec+&\verb+\setmainjfont+&\verb+\setsansjfont+&\verb+\newjfontfamily+\\
alphabetic fonts
&\verb+\fontspec+&\verb+\setmainfont+&\verb+\setsansfont+&\verb+\newfontfamily+\\
\bottomrule
\end{tabular}
\end{center}

Note that there is no command named \verb+\setmonojfont+, since it is
popular for Japanese fonts that (nearly) all Japanese glyphs have the same width.


\section{Changing Parameters}
There are many parameters in Lua\TeX-ja. And due to the implementation,
most of them were not stored as internal register of \TeX, but as an
original storage system in Lua\TeX-ja. Hence, to change or recall those
parameters, you have to use commands \verb+\ltjsetparameter+ and
\verb+\ltjgetparameter+.

\subsection{Editing the range of \textbf{JAchar}}
As noted before, the default setting is:
\begin{center}
A character in Unicode is treated as \textbf{JAchar} if and only if its
 code-point has more than or equal to U+0100.
\end{center}
$\uparrow$ TODO: CHANGE THIS!





\subsection{\textsf{kanjiskip} and \textsf{xkanjiskip}}\label{subs-kskip}
\textbf{JAglue} is divided into the following three categories:
\begin{itemize}
\item Glues/kerns specified in JFM. If \verb+\inhibitglue+ is issued,
      this glue will be not inserted.
\item The default glue which inserted between two \textbf{JAchar}s ({\sf
      kanjiskip}).
\item The default glue which inserted between a \textbf{JAchar} and an
      \textbf{ALchar} (\textsf{xkanjiskip}).
\end{itemize}
The value (a skip) of \textsf{kanjiskip} or \textsf{xkanjiskip} can be
changed as the following.
\begin{verbatim}
\ltjsetparameter{kanjiskip={0pt plus 0.4pt minus 0.4pt}, 
                 xkanjiskip={0.25\zw plus 1pt minus 1pt}}
\end{verbatim}


It may occur that JFM contains the data of `ideal width of {\sf
kanjiskip}' and/or `ideal width of \textsf{xkanjiskip}'.
To use these data from JFM, set the value of \textsf{kanjiskip} or 
\textsf{xkanjiskip} to \verb+\maxdimen+.

\subsection{Insertion Setting of \textsf{xkanjiskip}}
It is not desirable that \textsf{xkanjiskip} is inserted between every
boundary between \textbf{JAchar} and \textbf{ALchar}. For example,
\textsf{xkanjiskip} should not be inserted after opening parenthesis
(\textit{e.g.}, compare `(あ' and `(\hskip\ltjgetparameter{xkanjiskip}あ').

Lua\TeX-ja can control whether \textsf{xkanjiskip} can be inserted
before/after a character, by using \textsf{jaxspmode} and
\textsf{alxspmode} parameters. 
\begin{LTXexample}
\ltjsetparameter{jaxspmode={`あ,preonly}, alxspmode={`\!,postonly}} 
pあq い!う
\end{LTXexample}

The second argument {\tt preonly} means `the insertion of
\textsf{xkanjiskip} is allowed before this character, but not after'.
the other possible values are {\tt postonly}, {\tt allow} and {\tt
inhibit}.

If you want to enable/disable all insertion of \textsf{kanjiskip} and
\textsf{xkanjiskip}, set \textsf{autospacing} and \textsf{autoxspacing}
parameters to {\tt false}, respectively.


\subsection{Shifting Baseline}
To make a match between a Japanese font and an alphabetic font, sometimes
the shifting of baseline of one of the pair. In p\TeX, this is achieved
by setting \verb+\ybaselineshift+ to a non-zero length (the
baseline of alphabetic fonts is shifted below). However, for documents
whose main language is not Japanese,it is good to shift the baseline of
Japanese fonts, but not that of alphabetic fonts.
Because of this, Lua\TeX-ja can be independently set the shifting amount
of the baseline of alphabetic fonts (\textsf{yalbaselineshift}
parameter) and that of Japanese fonts (\textsf{yjabaselineshift}
parameter). 

\begin{LTXexample}
\vrule width 150pt height 0.4pt depth 0pt\hskip-120pt
\ltjsetparameter{yjabaselineshift=0pt, yalbaselineshift=0pt}abcあいう
\ltjsetparameter{yjabaselineshift=5pt, yalbaselineshift=2pt}abcあいう
\end{LTXexample}

Here the horizontal line in above is the baseline of a line.

There is an interesting side-effect from that the baseline of
Japanese fonts can be shifted: characters in different size can be
vertically aligned center in a line, by setting two parameters appropriately.

\begin{LTXexample}
xyz漢字 
{\scriptsize
  \ltjsetparameter{yjabaselineshift=-1pt, 
    yalbaselineshift=-1pt}
  XYZひらがな
}abcかな
\end{LTXexample}


\subsection{`tombow'}
`tombow' is a mark for indicating 4~corners and horizontal/vertical
center of the paper. p\LaTeX and this Lua\TeX-ja support `tombow' by
their kernel. The following steps are needed to typeset tombow:

\begin{enumerate}
\item First, define the banner which will be printed at the upper left
      of the paper. This is done by assigning a token list to
      \verb+\@bannertoken+.

For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}':
\begin{verbatim}
\makeatletter

\hour\time \divide\hour by 60 \@tempcnta\hour \multiply\@tempcnta 60\relax
\minute\time \advance\minute-\@tempcnta
\@bannertoken{%
   \jobname\space(\number\year-\two@digits\month-\two@digits\day
   \space\two@digits\hour:\two@digits\minute)}%
\end{verbatim}

\item ...
\end{enumerate}


\part{Reference}\label{part-ref}
\section{Font Metric and Japanese Font}
\subsection{\texttt{\char92jfont} primitive}
To load a font as a Japanese font, you must use the
\verb+\jfont+ primitive instead of~\verb+\font+, while
\verb+\jfont+ admits the same syntax used in~\verb+\font+. 
Lua\TeX-ja automatically loads \texttt{luaotfload} package,
so TrueType/OpenType fonts with features can be used for Japanese fonts:
\begin{LTXexample}
\jfont\tradgt={file:ipaexg.ttf:script=latn;%
  +trad;jfm=ujis} at 14pt
\tradgt{}当／体／医／区
\end{LTXexample}

Note that the defined control sequence (\verb+\tradgt+ in the example above) using \verb+\jfont+ is not a \textit{font\_def} token.

\paragraph{Prefix}
Besides \texttt{file:} and \texttt{name:} prefixes, \texttt{psft:} can
be used a prefix in \verb+\jfont+ (and~\verb+\font+) primitive..  Using
this prefix, you can specify a font that has its name only and is not
related to any real font.

The typical use of this \texttt{psft:} prefix is ...

\paragraph{Features}




\subsection{Structure of JFM file}
A JFM file is a Lua script which has only one function call:
\begin{verbatim}
luatexja.jfont.define_jfm { ... }
\end{verbatim}
Real data are stored in the table which indicated above by
\verb+{ ... }+.  So, the rest of subsection are devoted to describe the
structure of this table.  Note that all lengths in a JFM file are
floating-point numbers in design-size unit.

\begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
\item[dir=<direction>] (required)

The direction of JFM. At the present, only \texttt{'yoko'} is supported.

\item[zw=<length>] (required)

The amount of the length of the `full-width.

\item[zh=<length>] (required)

\item[kanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)

This field specifies the `ideal' amount of \textsf{kanjiskip}. As noted
	     in Subsection~\ref{subs-kskip}, if \textsf{kanjiskip} is
	     \verb+\maxdimen+, the value specified in this field is used
	     (if this field is not specified in JFM, 0\,pt is
	     used). Note that <stretch> and <shrink> fields are in
	     design-size unit too.


\item[xkanjiskip=\{<natural>, <stretch>, <shrink>\}] (optional)

Like the \texttt{kanjiskip} field, this field specifies the `ideal'
	     amount of \textsf{xkanjiskip}.

\end{list}

Besides from above fields, a JFM file have several sub-tables those
indices are natural numbers.  The table indexed by~$i\in\omega$ stores
informations of `character class'~$i$. At least, the character class~0 is
always present, so each JFM file must have a sub-table whose index is
\texttt{[0]}.  Each sub-table (its numerical index is denoted by $i$) has
the following fields:

\begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
\item[chars=\{<character>, ...\}] (required except character class~0)

This field is a list of \textbf{JAchar}s which are in this character
	     type~$i$. This field is not required if $i=0$, since all
	     \textbf{JAchar} which are not in any character class other
	     than 0 (hence, the character class~0 contains most of
	     \textbf{JAchar}s). In the list, a \textbf{JAchar} can be
	     specified by its code number, or by the character itself
	     (as a string of length~1).

In addition to those `real' characters, the following `imaginary
	     characters' can be specified in the list:

\item[width=<length>, height=<length>, depth=<length>, italic=<length>]\ 

Specify width of characters in character class~$i$, height, depth and
the amount of italic correction.  These fields are required.


\item[left=<length>, down=<length>, align=<align>]\ 

These are for adjusting the position of the `real' glyph. Legal
	     values of \texttt{align} field are \texttt{'left'},
	     \texttt{'middle'} and \texttt{'right'}. If one of these
	     3~fields are omitted, \texttt{left} and \texttt{down} are
	     treated as~0, and \texttt{align} field is treated as
	     \texttt{'left'}.
The effects of these 3~fields are indicated in Figure~\ref{fig-pos}.

In most cases, \texttt{left} and \texttt{down} fields are~0, while
it is not uncommon that the \texttt{align} field is \texttt{'middle'} or \texttt{'right'}.
For example, setting the \texttt{align} field to \texttt{'right'} is practically needed 
when the current character class is the class for opening delimiters'. 
\begin{figure}[tb]
\begin{minipage}{0.4\textwidth}%
\begin{center}\unitlength=10pt\small
\begin{picture}(15,12)(-1,-4)
\color{black!10!white}% real glyph :step1
\put(0,0){\vrule width 12\unitlength height 8\unitlength depth 3\unitlength}

\color{red!20!white}% real glyph :step1
\put(-1,-1.5){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}

\color{red}% real glyph
\thicklines
\put(-1,-1.5){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
\put(5,-1.5){\line(0,1){7}\line(0,-1){2.5}}
\put(-1,5.5){\line(1,0){6}}
\put(-1,-4){\line(1,0){6}}

\color{green!20!white}% real glyph :step1
\put(3,0){\vrule width 6\unitlength height 7\unitlength depth 2.5\unitlength}

\color{black}% real glyph :step1
\thicklines
\put(0,0){\vector(0,1){8}\line(0,-1){3}\vector(1,0){12}}
\put(12,0){\line(0,1){8}\vector(0,-1){3}}
\put(0,8){\line(1,0){12}}
\put(0,-3){\line(1,0){12}}
\put(0.2,4){\makebox(0,0)[l]{\texttt{height}}}
\put(12.2,-1.5){\makebox(0,0)[l]{\texttt{depth}}}
\put(6,0.2){\makebox(0,0)[b]{\texttt{width}}}

\color{green!50!black}% real glyph :step1
\thicklines
\put(3,0){\vector(0,1){7}\vector(0,-1){2.5}\vector(1,0){6}}
\put(9,0){\line(0,1){7}\line(0,-1){2.5}}
\put(3,7){\line(1,0){6}}
\put(3,-2.5){\line(1,0){6}}
\newsavebox{\eqdist}
\savebox{\eqdist}(0,0)[b]{%
  \thinlines
  \put(-0.08,0.2){\line(0,-1){0.4}}%
  \put(0.08,0.2){\line(0,-1){0.4}}}
\put(1.5,0){\usebox{\eqdist}}
\put(10.5,0){\usebox{\eqdist}}

\color{blue}% shifted
\thicklines
\put(3,-1.5){\vector(-1,0){4}}
\put(1,-1.7){\makebox(0,0)[t]{\texttt{left}}}
\put(3,0){\vector(0,-1){1.5}}
\put(3.2,-0.75){\makebox(0,0)[l]{\texttt{down}}}
\end{picture} 
\end{center}
\end{minipage}%
\begin{minipage}{0.6\textwidth}%
Consider a node containing Japanese character whose value of the \texttt{align} 
field is \texttt{'middle'}.
\begin{itemize}
\item The black rectangle is a frame of the node.
Its width, height and depth are specified by JFM.
\item Since the \texttt{align} field is \texttt{'middle'}, 
the `real' glyph is centered horizontally (the green rectangle).
\item Furthermore, the glyph is shifted according to values of fields
      \texttt{left} and \texttt{down}. The ultimate position of the real
      glyph is indicated by the red rectangle.
\end{itemize}
\end{minipage}
\caption{The position of the `real' glyph}
\label{fig-pos}
\end{figure}


\item[kern=\{\}]
\item[glue=\{\}]
\end{list}

\subsection{Math Font Family}

\section{Parameters}
\subsection{{\tt\char92 ltjsetparameter} primitive}

\subsection{List of Parameters}
In the following list of parameters, 
\begin{itemize}
\item `\ast' : local
\item `\dagger' always global
\item No mark: the last of paragraph
\end{itemize}

\begin{list}{}{\def\makelabel{\ttfamily}\def\{{\char`\{}\def\}{\char`\}}}
\item[\textsf{kcatcode}\,=\{<chr\_code>,<value>\}]
\item[\textsf{prebreakpenalty}\,=\{<chr\_code>,<penalty>\}]
\item[\textsf{postbreakpenalty}\,=\{<chr\_code>,<penalty>\}]
\item[\textsf{jatextfont}\,=\{<jfam>,<jfont\_cs>\}]
\item[\textsf{jascriptfont}\,=\{<jfam>,<jfont\_cs>\}]
\item[\textsf{jascriptscriptfont}\,=\{<jfam>,<jfont\_cs>\}]
\item[\textsf{yjabaselineshift}\,=<dimen>$^\ast$]
\item[\textsf{yalbaselineshift}\,=<dimen>$^\ast$]
\item[\textsf{jaxspmode}\,=\{<chr\_code>,<mode>\}]
\item[\textsf{alxspmode}\,=\{<chr\_code>,<mode>\}]
\item[\textsf{autospacing}\,=<bool>$^\ast$]
\item[\textsf{autoxspacing}\,=<bool>$^\ast$]
\item[\textsf{kanjiskip}\,=<skip>]
\item[\textsf{xkanjiskip}\,=<skip>]
\item[\textsf{jcharwidowpenalty}\,=<penalty>]
\item[\textsf{differentjfm}\,=<mode>$^\dagger$]
\item[\textsf{jacharrange}\,=<ranges>$^\ast$]
\end{list}
\section{Other Primitives}
\section{Control Sequences for \LaTeXe}
\part{Implementations}\label{part-imp}
\section{Storing Parameters}
\subsection{Used Dimensions and Attributes}
Here the following is the list of dimension and attributes which are used in Lua\TeX-ja.
\begin{list}{}{%
\def\makelabel{\ttfamily}
\def\dim#1{\item[\char92 #1\ \textrm{(dimension)}]}
\def\attr#1{\item[\char92 #1\ \textrm{(attribute)}]}
}

\dim{jQ}
\dim{jH}
\dim{ltj@zw}
\dim{ltj@zh}
\attr{jfam} 
\attr{ltj@curjfnt} The font index of current Japanese font.
\attr{ltj@charclass} The character class of Japanese \textit{glyph\_node}.
\attr{ltj@yablshift} The amount of shifting the baseline of alphabetic
			fonts in scaled point ($2^{-16}\,\textrm{pt}$).
\attr{ltj@ykblshift} The amount of shifting the baseline of Japanese
			fonts in scaled point ($2^{-16}\,\textrm{pt}$).
\attr{ltj@autospc} Whether the auto insertion of \textsf{kanjiskip} is allowed at the node.
\attr{ltj@autoxspc} Whether the auto insertion of \textsf{xkanjiskip} is allowed at the node.
\attr{ltj@icflag} For distinguishing `kinds' of the node. To this
			attribute, one of the following value is
			assigned:
\begin{description}
\item[ITALIC (1)]
\item[PACKED (2)]
\item[KINSOKU (3)]
\item[FROM\_JFM (4)]
\item[LINE\_END (5)]
\item[KANJI\_SKIP (6)]
\item[XKANJI\_SKIP (7)]
\item[PROCESSED (8)]
\item[IC\_PROCESSED (9)]
\item[BOXBDD (15)]
\end{description}
\attr{ltj@kcat$i$} Where $i$~is a natural number which is less than~8.
These 8~attributes store bit~vectors indicating ...
\end{list}

\subsection{Stack System of Lua\TeX-ja}
\paragraph{Overview}
Lua\TeX-ja has its own stack system, and most parameters of Lua\TeX-ja
are stored in it.  To clarify the reason, imagine the parameter
\textsf{kanjiskip} is stored by a skip, and consider the following
source:
\begin{LTXexample}
\ltjsetparameter{kanjiskip=0pt}ふがふが.%
\setbox0=\hbox{\ltjsetparameter{kanjiskip=5pt}ほげほげ}
\box0.ぴよぴよ\par
\end{LTXexample}

As described in Part~\ref{part-ref}, the only effective value of
\textsf{kanjiskip} in an hbox is the latest value, so the value of
\textsf{kanjiskip} which applied in the entire hbox should be 5\,pt.
However, by the implementation method of Lua\TeX, this `5\,pt' cannot be
known from any callbacks.  In the \texttt{tex/packaging.w} (which is a
file in the source of Lua\TeX), there are the following codes:
\begin{lstlisting}
void package(int c)
{
    scaled h;                   /* height of box */
    halfword p;                 /* first node in a box */
    scaled d;                   /* max depth */
    int grp;
    grp = cur_group;
    d = box_max_depth;
    unsave();
    save_ptr -= 4;
    if (cur_list.mode_field == -hmode) {
        cur_box = filtered_hpack(cur_list.head_field,
                                 cur_list.tail_field, saved_value(1),
                                 saved_level(1), grp, saved_level(2));
        subtype(cur_box) = HLIST_SUBTYPE_HBOX;
\end{lstlisting}
Notice that \verb+unsave+ is executed \emph{before}
\verb+filtered_hpack+ (this is where \verb+hpack_filter+ callback is
executed): so `5\,pt' in the above source is orphaned at
\texttt+unsave+, and hence it can't be accessed from \verb+hpack_filter+
callback.

\end{document}