From: Hironori Kitagawa Date: Wed, 7 Sep 2011 06:51:09 +0000 (+0900) Subject: Updated the manual, and ad hoc fix of the stack system around \globaldefs X-Git-Tag: 20120419.0~91 X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=82465c582e5844dab501a4bb4a2fa28baca3d8da;p=luatex-ja%2Fluatexja.git Updated the manual, and ad hoc fix of the stack system around \globaldefs --- diff --git a/doc/man-en.pdf b/doc/man-en.pdf index 5892492..3799c87 100644 Binary files a/doc/man-en.pdf and b/doc/man-en.pdf differ diff --git a/doc/man-en.tex b/doc/man-en.tex index f02ba0c..ca90c91 100644 --- a/doc/man-en.tex +++ b/doc/man-en.tex @@ -22,11 +22,13 @@ \maketitle \tableofcontents +\bigskip +{\Large\bf This documentation is far from complete. It may have many +grammatical (and contextual) errors.} \newpage \part{User's manual} -{\Large\bf This documentation is far from complete. It may have many -grammatical errors.} +\makeatletter\the\ltj@@stack,\the\ltj@@group@level,\the\currentgrouplevel. \section{Introduction} @@ -198,7 +200,6 @@ This does the minimal setting (like {\tt ptex.tex}) for typesetting Japanese doc 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 @@ -244,6 +245,7 @@ $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, @@ -453,7 +455,31 @@ For example, the following sets banner as `{\tt filename (2012-01-01 17:01)}': \part{Reference}\label{part-ref} \section{Font Metric and Japanese Font} \subsection{\texttt{\char92jfont} primitive} -Caution: 10pt +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: @@ -534,7 +560,7 @@ 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}[htb] +\begin{figure}[tb] \begin{minipage}{0.4\textwidth}% \begin{center}\unitlength=10pt\small \begin{picture}(15,12)(-1,-4) @@ -595,7 +621,9 @@ field is \texttt{'middle'}. 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 the red 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} @@ -613,6 +641,13 @@ the `real' glyph is centered horizontally (the green rectangle). \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}\,=\{,\}] \item[\textsf{prebreakpenalty}\,=\{,\}] @@ -620,19 +655,101 @@ the `real' glyph is centered horizontally (the green rectangle). \item[\textsf{jatextfont}\,=\{,\}] \item[\textsf{jascriptfont}\,=\{,\}] \item[\textsf{jascriptscriptfont}\,=\{,\}] -\item[\textsf{yjabaselineshift}\,=] -\item[\textsf{yalbaselineshift}\,=] +\item[\textsf{yjabaselineshift}\,=$^\ast$] +\item[\textsf{yalbaselineshift}\,=$^\ast$] \item[\textsf{jaxspmode}\,=\{,\}] \item[\textsf{alxspmode}\,=\{,\}] -\item[\textsf{autospacing}\,=] -\item[\textsf{autoxspacing}\,=] +\item[\textsf{autospacing}\,=$^\ast$] +\item[\textsf{autoxspacing}\,=$^\ast$] \item[\textsf{kanjiskip}\,=] \item[\textsf{xkanjiskip}\,=] \item[\textsf{jcharwidowpenalty}\,=] -\item[\textsf{differentjfm}\,=] -\item[\textsf{jacharrange}\,=] +\item[\textsf{differentjfm}\,=$^\dagger$] +\item[\textsf{jacharrange}\,=$^\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} \ No newline at end of file diff --git a/src/luatexja-core.sty b/src/luatexja-core.sty index bfd28c2..f7bd7b5 100644 --- a/src/luatexja-core.sty +++ b/src/luatexja-core.sty @@ -253,8 +253,8 @@ \define@key[ltj]{japaram}{jascriptscriptfont}{% \expandafter\ltj@@set@stackfont#1:{mjss}} \def\ltj@@set@stackfont#1,#2:#3{% - \ltj@tempcntb=\globaldefs{\globaldefs0 \ltj@curjfnt=-1 #2% - \global\ltj@tempcnta=\ltj@curjfnt}\globaldefs\ltj@tempcntb% + {\directlua{tex.globaldefs=0}\ltj@curjfnt=-1 #2% + \global\ltj@tempcnta=\ltj@curjfnt}% \ifnum\ltj@tempcnta=-1 \@PackageError{luatexja-core}% {\string#2 is not a control sequence that represents \MessageBreak @@ -357,9 +357,10 @@ } \protected\def\ltjsetparameter#1{% - \ifnum\globaldefs=0\directlua{ltj.isglobal=''}\else\directlua{ltj.isglobal='global'}\fi + \ifnum\globaldefs>0\directlua{ltj.isglobal='global'}\else\directlua{ltj.isglobal=''}\fi \setkeys[ltj]{japaram}{#1}\ignorespaces} -\protected\def\ltjglobalsetparameter#1{\directlua{ltj.isglobal='global'}% +\protected\def\ltjglobalsetparameter#1{% + \ifnum\globaldefs<0\directlua{ltj.isglobal=''}\else\directlua{ltj.isglobal='global'}\fi \setkeys[ltj]{japaram}{#1}\ignorespaces} %%%%%%%% diff --git a/src/luatexja/stack.lua b/src/luatexja/stack.lua index 7bb2614..ea23801 100644 --- a/src/luatexja/stack.lua +++ b/src/luatexja/stack.lua @@ -23,12 +23,16 @@ function get_stack_level() local j = tex.currentgrouplevel if j > tex.getcount('ltj@@group@level') then i = i+1 -- new stack level + local gd = tex.globaldefs + if gd>0 then tex.globaldefs = 0 end + -- 'tex.globaldefs = 0' is local even if \globaldefs > 0. tex.setcount('ltj@@group@level', j) for k,v in pairs(charprop_stack_table) do -- clear the stack above i if k>=i then charprop_stack_table[k]=nil end end charprop_stack_table[i] = table.fastcopy(charprop_stack_table[i-1]) tex.setcount('ltj@@stack', i) + if gd>0 then tex.globaldefs = gd end local g = node_new(id_whatsit, sid_user) g.user_id=30112; g.type=100; g.value=j; node.write(g) end