OSDN Git Service

Improve \ltj@pkgpatch in luatexja-latex.sty.
authorKazuki Maeda <kmaeda@users.sourceforge.jp>
Mon, 21 Nov 2011 18:21:41 +0000 (03:21 +0900)
committerKazuki Maeda <kmaeda@users.sourceforge.jp>
Mon, 21 Nov 2011 18:21:41 +0000 (03:21 +0900)
 * If you load the following packages, patches for LuaTeX-ja also will be loaded by the filehook package:
   * listings
   * unicode-math
   * xunicode

17 files changed:
.gitignore [new file with mode: 0644]
doc/man-en.pdf
doc/man-ja.pdf
doc/manual.dtx
src/addons/luatexja-fontspec.sty
src/luatexja-latex.sty
src/luatexja/setwidth.lua
src/patches/lltjcore.sty [moved from src/lltjcore.sty with 95% similarity]
src/patches/lltjdefs.sty [moved from src/lltjdefs.sty with 98% similarity]
src/patches/lltjfont.sty [moved from src/lltjfont.sty with 99% similarity]
src/patches/lltjp-listings.sty [moved from src/lltjlisting.sty with 96% similarity]
src/patches/lltjp-unicode-math.sty [new file with mode: 0644]
src/patches/lltjp-xunicode.sty [new file with mode: 0644]
test/test07-math-unicode.pdf
test/test07-math-unicode.tex
test/test07-math.pdf
test/test07-math.tex

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e01d227
--- /dev/null
@@ -0,0 +1,6 @@
+*.log
+*.aux
+*.toc
+*.out
+*.tmp
+*~
index e7409a8..6d3b14d 100644 (file)
Binary files a/doc/man-en.pdf and b/doc/man-en.pdf differ
index ac6465d..ea0b004 100644 (file)
Binary files a/doc/man-ja.pdf and b/doc/man-ja.pdf differ
index c0b294b..654c33e 100644 (file)
@@ -5,7 +5,7 @@
 \usepackage[margin=20mm,footskip=5mm]{geometry}
 
 \usepackage{amsmath,amssymb,xcolor,pict2e,multienum,amsthm,float}
-\usepackage{booktabs,listings,lltjlisting,showexpl,multicol}
+\usepackage{booktabs,listings,showexpl,multicol}
 \usepackage{luatexja-otf}
 \usepackage{luatexja-fontspec}
 \usepackage[unicode]{hyperref}
@@ -763,7 +763,7 @@ If you want to use these functions, load \Pkg{luatexja-otf} package.
 \CID{7652}飾区の\CID{13706}野家,
 葛飾区の吉野家
 \end{LTXexample}
-%lltjlisting.sty要修正?:↑「森」の直後で改行.
+%lltjp-listings.sty要修正?:↑「森」の直後で改行.
 
 
 %<en>\subsection{Changing Fonts}
index 7e5bfd8..3a81907 100644 (file)
@@ -3,82 +3,9 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{luatexja-fontspec}[2011/11/16 v0.3]
-
-\def\UTFencname{EU2}\def\XeTeXpicfile{}
-\RequirePackage{xunicode}
-%% Patch for xunicode.sty
-{\catcode`\"=12
-\gdef\check@hexcom@digits@#1#2#3#4#5@!@#6#7#8{%
- \ifx @#4\relax
-  \UTFacc@warning@{insufficient hex digits #7 for #6-\string#8}%
- \else
-  \ifcat \active\noexpand#8%
-   \ifx\add@flag\@ne %
-    \expandafter\def\csname\UTFencname\string#8\endcsname{\ltjalchar"#1#2#3#4\relax}%
-    \ifx\unDeFiNed@#8%
-     \ifx\cf@encoding\UTFencname
-      \DeclareTextCommand{#8}{OT1}{\undefined}%
-     \else
-      \DeclareTextCommand{#8}{\cf@encoding}{\undefined}%
-     \fi
-    \else {% macro #8 exists already ...
-      \let\protect\noexpand
-      \edef\UTF@testi{#8}\def\UTF@testii{#8}%
-      \ifx\UTF@testi\UTF@testii\aftergroup\UTF@ignore
-      \else\aftergroup\UTF@doit\fi
-     }%
-     \iffalse
-      % ... but when it isn't robust, make it so
-      \expandafter\let\csname?-\string#8\endcsname#8\relax
-      \edef\next@UTF@{{\cf@encoding}%
-        {\expandafter\noexpand\csname?-\string#8\endcsname}}%
-      \expandafter\DeclareTextCommand\expandafter
-         {\expandafter#8\expandafter}\next@UTF@
-     \fi
-    \fi %
-   \else % \add@flag \z@
-    \expandafter\global\expandafter
-      \let\csname\UTFencname\string#8\endcsname\relax
-   \fi % end of \add@flag switch
-  \else % not active catcode --- shouldn't happen
-  % \typeout{*** did you really mean #8 ? ***}%
-   \ifx\add@flag\@ne %
-    \edef\tmp@name{\expandafter\string\csname\UTFencname\endcsname
-      \expandafter\string\csname#8\endcsname}%
-    \expandafter\def\csname\tmp@name\endcsname{\ltjalchar"#1#2#3#4\relax}%
-    \ifx\cf@encoding\UTFencname
-     \expandafter\DeclareTextCommand\expandafter
-       {\csname#8\endcsname}{OT1}{\undefined}%
-    \else
-     \expandafter\DeclareTextCommand\expandafter
-       {\csname#8\endcsname}{\cf@encoding}{\undefined}%
-    \fi
-   \else % \add@flag \z@
-    \expandafter\global\expandafter\let\csname#8\endcsname\relax
-   \fi % end of \add@flag switch
-  \fi % end of \ifcat
- \fi}
-\gdef\check@hex@digits@#1#2#3#4#5@!@#6#7#8#9{%
- \ifx @#4\relax
-  \UTFacc@warning@{insufficient hex digits #7 for #6-\string#8#9}%
- \else
-  \def\UTFchar{\ltjalchar"#1#2#3#4\relax}%
-  \expandafter\expandafter\expandafter\declare@utf@composite
-  \expandafter\expandafter\expandafter
-   {\expandafter\csname#6\endcsname}{\UTFchar}{#8}{#9}\relax
- \fi}
-%\gdef\add@UTF@accent#1#2#3{#2\ltjalchar"#1\relax}
-\gdef\add@UTF@accent#1#2#3{\ifx\relax#2\relax\ltjalchar"#3\else
- \ifx\ #2\relax\ltjalchar"#3\else
- \expandafter\ifx\UTF@space#2\relax\ltjalchar"#3\else
- \ifx~#2\ltjalchar"#3\else#2\ltjalchar"#1\fi\fi\fi\fi\relax}
-\gdef\add@UTF@accents#1#2#3{#2\ltjalchar"#1\ltjalchar"#3\relax}
-}
-%% End of patch for xunicode.sty "
+\ProvidesPackage{luatexja-fontspec}[2011/09/23 v0.2]
 
-\RequirePackage{fontspec}
-\RequirePackage{luatexja}
+\RequirePackage{fontspec,luatexja}
 
 \ExplSyntaxOn
 
 
 \cs_set_eq:NN \addjfontfeature \addjfontfeatures
 
-% We reload xunicode package here.
-\ExplSyntaxOff\ReloadXunicode{EU2}
 \endinput
-
-%% the following patch is needed to xunicode.sty:
-%% 
---- /opt/texlive/2011/texmf-dist/tex/xelatex/xunicode/xunicode.sty     2011-09-12 08:31:47.000000000 +0900
-+++ xunicode.sty       2011-11-16 22:06:17.061413113 +0900
-@@ -1475,7 +1475,11 @@
- \newtoks\tipasavetokens
- \newtoks\tipachecktokens
-+
-+\fi
- \newif\iftipaonetoken
-+\expandafter\ifx\csname ReloadXunicode\endcsname\relax
-+
- \def\tipalasttoken{!@! do nothing with this !@!}
- \def\tipacatchonechar#1{\begingroup
-  \def\textipa##1{##1}% prevent recursion
index 3091eeb..ee41e4b 100644 (file)
 \def\luatexjalatexLoaded{\endinput}
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{luatexja-latex}[2011/11/20 v0.2]
+\ProvidesPackage{luatexja-latex}[2011/11/22 LuaLaTeX-ja]
 
-\endlinechar=13
+\def\ltj@pkgpatchlist{}
+\def\ltj@pkgpatch#1{
+  \@ifpackageloaded{#1}{\usepackage{lltjp-#1}}{
+    \@ifpackageloaded{filehook}{\AtEndOfPackageFile*{#1}{\usepackage{lltjp-#1}}}{}
+  }
+  \ifx\ltj@pkgpatchlist\@empty
+    \gdef\ltj@pkgpatchlist{#1}
+  \else
+    \xdef\ltj@pkgpatchlist{\ltj@pkgpatchlist, #1}
+  \fi
+}
 
+\endlinechar=13
 
 %%% patch for LaTeX
-\input{lltjfont.sty}
-\input{lltjdefs.sty}
-\input{lltjcore.sty}
+\usepackage{lltjfont}
+\usepackage{lltjdefs}
+\usepackage{lltjcore}
 
 %%% default parameters
 \ltjsetparameter{kanjiskip=0pt plus 0.4pt minus 0.4pt, 
 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
 
 %%% patch for packages
-\RequirePackage{expl3}
-\ExplSyntaxOn
-\def\ltj@pkgpatch#1#2#3#4{\@ifpackageloaded{#1}{\typeout{#1: TRUE}#3#2}{\typeout{#1: FALSE}%
-  \@ifpackageloaded{filehook}{\bool_set_true:N \l_tmpa_bool} {\bool_set_false:N \l_tmpa_bool} %
-  \file_if_exist:nTF {filehook.sty} 
-    { \usepackage{filehook} \bool_set_true:N \l_tmpa_bool } 
-    {}%
-  \bool_if:NTF \l_tmpa_bool 
-    {\AtEndOfPackageFile*{#1}{#4#2}} 
-    {}
-  }%
+\IfFileExists{filehook.sty}{\usepackage{filehook}}{}
+\ltj@pkgpatch{listings}
+\ltj@pkgpatch{unicode-math}
+\ltj@pkgpatch{xunicode}
+\@ifpackageloaded{filehook}{}{%
+  \@PackageWarningNoLine{luatexja-latex}{
+    LuaTeX-ja uses filehook package to apply patches to the following packages:\MessageBreak
+    \ltj@pkgpatchlist.\MessageBreak
+    But your TeX system does not have the filehook package.\MessageBreak
+    Therefore problems may occur if you load the above packages after this message}%
 }
 
-\ltj@pkgpatch{fontspec}{\usepackage{luatexja-fontspec}}{}{}
-\ltj@pkgpatch{unicode-math}{%
-  \cs_set:Npn \um_set_mathcode:nnnn #1#2#3#4 {
-    \Umathcode \int_eval:n {#1} =
-      \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
-    \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
-  }
-  \cs_set:Npn \um_set_mathcode:nnn #1#2#3 {
-    \Umathcode \int_eval:n {#1} =
-      \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#1} \scan_stop:
-    \directlua{luatexja.math.is_math_letters[\int_eval:n {#1}]=true}
-  }
-  \cs_set:Npn \um_set_mathchar:NNnn #1#2#3#4 {
-    \Umathchardef #1 =
-      \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
-    \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
-  }
-}{}{}
-\ExplSyntaxOff
-
 %%------------------ all done
 \ltj@latex@AtEnd
 \endinput
index a74b37b..be779d0 100644 (file)
@@ -110,7 +110,11 @@ function set_ja_width(ahead, dir)
            local met = ltjf.font_metric_table[p.font]
            local class = has_attr(p, attr_jchar_class)
            char_data = ltjf.metrics[met.jfm].size_cache[met.size].char_type[class]
-           p = capsule_glyph(p, dir, false, met, class)
+            if char_data then
+               p = capsule_glyph(p, dir, false, met, class)
+            else
+               p = node_next(p)
+            end
         else 
            p.yoffset = p.yoffset - (has_attr(p,attr_yablshift) or 0); p = node_next(p)
         end
similarity index 95%
rename from src/lltjcore.sty
rename to src/patches/lltjcore.sty
index 98fa932..3dbcc41 100644 (file)
@@ -1,7 +1,11 @@
-%%
-%% lltjcore.sty: derived from plcore.dtx in pLaTeX.
-%% This file does not include the code relating to "tategaki".
-%% 
+%
+% lltjcore.sty: derived from plcore.dtx in pLaTeX.
+% This file does not include the code relating to "tategaki".
+% 
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{lltjcore}[2011/11/22 Patch to LaTeX2e Kernel for LuaLaTeX-ja]
+
 \makeatletter
 \newif\iftombow \tombowfalse
 \newif\iftombowdate \tombowdatetrue
similarity index 98%
rename from src/lltjdefs.sty
rename to src/patches/lltjdefs.sty
index 67a83a6..a76a24c 100644 (file)
@@ -1,3 +1,10 @@
+%
+% lltjdefs.sty
+% 
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{lltjdefs}[2011/11/22 Default font settings for LuaLaTeX-ja]
+
 \DeclareKanjiEncodingDefaults{}{}
 \DeclareErrorKanjiFont{JY3}{mc}{m}{n}{10}
 \DeclareYokoKanjiEncoding{JY3}{}{}
similarity index 99%
rename from src/lltjfont.sty
rename to src/patches/lltjfont.sty
index 70cace2..a3fec95 100644 (file)
@@ -1,7 +1,10 @@
-%%
-%% lltjfont.sty: derived from plfonts.dtx in pLaTeX.
-%% 
-\makeatletter
+%
+% lltjfont.sty: derived from plfonts.dtx in pLaTeX.
+% 
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{lltjfont}[2011/11/22 Patch to NFSS2 for LuaLaTeX-ja]
+
 \let\k@encoding\@empty
 \let\ck@encoding\@empty
 % LuaTeX-ja uses JY3 and JT3 encodings.
similarity index 96%
rename from src/lltjlisting.sty
rename to src/patches/lltjp-listings.sty
index 2563773..62e2385 100644 (file)
@@ -1,11 +1,14 @@
-% lltjlisting.sty: modified from jlisting.sty (by Thor) for
-% LuaTeX-ja. 
+%
+% lltjp-listings.sty
+%
+% Modified from jlisting.sty (by Thor) for LuaTeX-ja. 
+%
 
 \NeedsTeXFormat{LaTeX2e}
 \def\filedate{2006/02/20}
 \def\fileversion{0.2}
-\ProvidesPackage{lltjlisting}[\filedate\space\fileversion\space(Thor)]
-%
+\ProvidesPackage{lltjp-listings}[\filedate\space\fileversion\space(Thor)]
+\RequirePackage{listings}
 \newcount\lst@nextchar
 \let\lst@@ProcessSpace\lst@ProcessSpace
 \def\lst@ProcessSpace#1{%
diff --git a/src/patches/lltjp-unicode-math.sty b/src/patches/lltjp-unicode-math.sty
new file mode 100644 (file)
index 0000000..fb77d13
--- /dev/null
@@ -0,0 +1,26 @@
+%
+% lltjp-unicode-math.sty
+%
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{lltjp-unicode-math}[2011/11/22 Patch to unicode-math for LuaLaTeX-ja]
+
+\RequirePackage{unicode-math,luatexja}
+
+\ExplSyntaxOn
+\cs_set:Npn \um_set_mathcode:nnnn #1#2#3#4 {
+  \Umathcode \int_eval:n {#1} =
+  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
+  \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
+}
+\cs_set:Npn \um_set_mathcode:nnn #1#2#3 {
+  \Umathcode \int_eval:n {#1} =
+  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#1} \scan_stop:
+  \directlua{luatexja.math.is_math_letters[\int_eval:n {#1}]=true}
+}
+\cs_set:Npn \um_set_mathchar:NNnn #1#2#3#4 {
+  \Umathchardef #1 =
+  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
+  \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
+}
+\endinput
diff --git a/src/patches/lltjp-xunicode.sty b/src/patches/lltjp-xunicode.sty
new file mode 100644 (file)
index 0000000..702137b
--- /dev/null
@@ -0,0 +1,103 @@
+%
+% lltjp-xunicode.sty
+%
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{lltjp-xunicode}[2011/11/22 Patch to xunicode for LuaLaTeX-ja]
+
+\def\UTFencname{EU2}\def\XeTeXpicfile{}
+\RequirePackage{xunicode,luatexja}
+{\catcode`\"=12
+\gdef\check@hexcom@digits@#1#2#3#4#5@!@#6#7#8{%
+ \ifx @#4\relax
+  \UTFacc@warning@{insufficient hex digits #7 for #6-\string#8}%
+ \else
+  \ifcat \active\noexpand#8%
+   \ifx\add@flag\@ne %
+    \expandafter\def\csname\UTFencname\string#8\endcsname{\ltjalchar"#1#2#3#4\relax}%
+    \ifx\unDeFiNed@#8%
+     \ifx\cf@encoding\UTFencname
+      \DeclareTextCommand{#8}{OT1}{\undefined}%
+     \else
+      \DeclareTextCommand{#8}{\cf@encoding}{\undefined}%
+     \fi
+    \else {% macro #8 exists already ...
+      \let\protect\noexpand
+      \edef\UTF@testi{#8}\def\UTF@testii{#8}%
+      \ifx\UTF@testi\UTF@testii\aftergroup\UTF@ignore
+      \else\aftergroup\UTF@doit\fi
+     }%
+     \iffalse
+      % ... but when it isn't robust, make it so
+      \expandafter\let\csname?-\string#8\endcsname#8\relax
+      \edef\next@UTF@{{\cf@encoding}%
+        {\expandafter\noexpand\csname?-\string#8\endcsname}}%
+      \expandafter\DeclareTextCommand\expandafter
+         {\expandafter#8\expandafter}\next@UTF@
+     \fi
+    \fi %
+   \else % \add@flag \z@
+    \expandafter\global\expandafter
+      \let\csname\UTFencname\string#8\endcsname\relax
+   \fi % end of \add@flag switch
+  \else % not active catcode --- shouldn't happen
+  % \typeout{*** did you really mean #8 ? ***}%
+   \ifx\add@flag\@ne %
+    \edef\tmp@name{\expandafter\string\csname\UTFencname\endcsname
+      \expandafter\string\csname#8\endcsname}%
+    \expandafter\def\csname\tmp@name\endcsname{\ltjalchar"#1#2#3#4\relax}%
+    \ifx\cf@encoding\UTFencname
+     \expandafter\DeclareTextCommand\expandafter
+       {\csname#8\endcsname}{OT1}{\undefined}%
+    \else
+     \expandafter\DeclareTextCommand\expandafter
+       {\csname#8\endcsname}{\cf@encoding}{\undefined}%
+    \fi
+   \else % \add@flag \z@
+    \expandafter\global\expandafter\let\csname#8\endcsname\relax
+   \fi % end of \add@flag switch
+  \fi % end of \ifcat
+ \fi}
+\gdef\check@hex@digits@#1#2#3#4#5@!@#6#7#8#9{%
+ \ifx @#4\relax
+  \UTFacc@warning@{insufficient hex digits #7 for #6-\string#8#9}%
+ \else
+  \def\UTFchar{\ltjalchar"#1#2#3#4\relax}%
+  \expandafter\expandafter\expandafter\declare@utf@composite
+  \expandafter\expandafter\expandafter
+   {\expandafter\csname#6\endcsname}{\UTFchar}{#8}{#9}\relax
+ \fi}
+%\gdef\add@UTF@accent#1#2#3{#2\ltjalchar"#1\relax}
+\gdef\add@UTF@accent#1#2#3{\ifx\relax#2\relax\ltjalchar"#3\else
+ \ifx\ #2\relax\ltjalchar"#3\else
+ \expandafter\ifx\UTF@space#2\relax\ltjalchar"#3\else
+ \ifx~#2\ltjalchar"#3\else#2\ltjalchar"#1\fi\fi\fi\fi\relax}
+\gdef\add@UTF@accents#1#2#3{#2\ltjalchar"#1\ltjalchar"#3\relax}
+}
+% If unicode-math is already loaded, the following error occurs:
+%    ! Undefined control sequence.
+%    \hbar ->\hslash 
+% Therefore temporarily set \hbar=\relax.
+\let\ltj@tmpa\hbar
+\let\hbar\relax
+\ReloadXunicode{EU2}
+\makeatletter
+\let\hbar\ltj@tmpa
+\endinput
+
+%% the following patch is needed to xunicode.sty:
+%% 
+--- /opt/texlive/2011/texmf-dist/tex/xelatex/xunicode/xunicode.sty     2011-09-12 08:31:47.000000000 +0900
++++ xunicode.sty       2011-11-16 22:06:17.061413113 +0900
+@@ -1475,7 +1475,11 @@
+ \newtoks\tipasavetokens
+ \newtoks\tipachecktokens
++
++\fi
+ \newif\iftipaonetoken
++\expandafter\ifx\csname ReloadXunicode\endcsname\relax
++
+ \def\tipalasttoken{!@! do nothing with this !@!}
+ \def\tipacatchonechar#1{\begingroup
+  \def\textipa##1{##1}% prevent recursion
index 2182018..b85df38 100644 (file)
Binary files a/test/test07-math-unicode.pdf and b/test/test07-math-unicode.pdf differ
index 5b0f0eb..f456b38 100644 (file)
@@ -2,7 +2,7 @@
 \documentclass{article}
 \usepackage[a4paper]{geometry}
 
-\usepackage{fontspec}
+\usepackage{luatexja-fontspec}
 
 \usepackage{luatexja}
 \makeatletter\ltj@alljachar %←全部の(>=U+0080な)文字を和文文字扱いに!
index 591588a..dee24fc 100644 (file)
Binary files a/test/test07-math.pdf and b/test/test07-math.pdf differ
index 9d176e0..e2431db 100644 (file)
@@ -48,4 +48,3 @@ mathgt: $\mathrm{\mathmc{あa}}\mathmc{あb}\mathgt{あa}$
 \]
 
 \end{document}
-