OSDN Git Service

Fix #37828
[luatex-ja/luatexja.git] / src / ltjsbook.cls
index e144c06..454cc66 100644 (file)
 %%   Right brace   \}     Tilde         \~}
 \NeedsTeXFormat{LaTeX2e}
 \ProvidesClass{ltjsbook}
-  [2016/08/03 ltjsclasses ]
+  [2018/01/14 ltjsclasses ]
 \def\jsc@clsname{ltjsbook}
 \RequirePackage{luatexja}
 \newif\if@restonecol
 \newif\if@titlepage
 \newif\if@openright
+\newif\if@openleft
 \newif\if@mainmatter \@mainmattertrue
 \newif\if@enablejfam \@enablejfamtrue
 \DeclareOption{a3paper}{%
 \newif\if@slide
 \@slidefalse
 \def\jsc@magscale{1}
-\DeclareOption{slide}{\@slidetrue\def\jsc@magscale{3.583}\@landscapetrue\@titlepagetrue}
 \DeclareOption{8pt} {\def\jsc@magscale{0.833}}% 1.2^(-1)
 \DeclareOption{9pt} {\def\jsc@magscale{0.913}}% 1.2^(-0.5}
 \DeclareOption{10pt}{\def\jsc@magscale{1}}
 \DeclareOption{10.5ptj}{\def\jsc@magscale{1.139}}
 \DeclareOption{11ptj}{\def\jsc@magscale{1.194}}
 \DeclareOption{12ptj}{\def\jsc@magscale{1.302}}
-\newif\if@ltjs@mag@xreal
-\@ltjs@mag@xrealtrue
-\DeclareOption{nomag*}{\@ltjs@mag@xrealtrue}
-\DeclareOption{nomag}{\@ltjs@mag@xrealfalse}
-\DeclareOption{noxreal}{%
-  \ClassWarningNoLine{\jsc@clsname}{%
-    The class option `noxreal' is obsolete. \MessageBreak
-    Please use the `nomag' option instead}%
-  \@ltjs@mag@xrealfalse}
-\DeclareOption{real}{%
-  \ClassWarningNoLine{\jsc@clsname}{%
-    The class option `real' is obsolete. \MessageBreak
-    Please use the `nomag' option instead}%
-  \@ltjs@mag@xrealfalse}
+\newif\ifjsc@mag@xreal
+\jsc@mag@xrealtrue
+\DeclareOption{nomag*}{\jsc@mag@xrealtrue}
+\DeclareOption{nomag}{\jsc@mag@xrealfalse}
 \DeclareOption{usemag}{%
   \ClassWarningNoLine{\jsc@clsname}{%
     This \jsc@clsname\space cls does not support `usemag'\MessageBreak
 option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
-  \@ltjs@mag@xrealtrue}
+  \jsc@mag@xrealtrue}
 
 \hour\time \divide\hour by 60\relax
 \@tempcnta\hour \multiply\@tempcnta 60\relax
@@ -165,8 +155,9 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \DeclareOption{twocolumn}{\@twocolumntrue}
 \DeclareOption{titlepage}{\@titlepagetrue}
 \DeclareOption{notitlepage}{\@titlepagefalse}
-\DeclareOption{openright}{\@openrighttrue}
-\DeclareOption{openany}{\@openrightfalse}
+\DeclareOption{openright}{\@openrighttrue\@openleftfalse}
+\DeclareOption{openleft}{\@openlefttrue\@openrightfalse}
+\DeclareOption{openany}{\@openrightfalse\@openleftfalse}
 \def\eqnarray{%
    \stepcounter{equation}%
    \def\@currentlabel{\p@equation\theequation}%
@@ -221,7 +212,9 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \DeclareOption{winjis}{%
   \ClassWarningNoLine{\jsc@clsname}{The \jsc@clsname\space class does not support `winjis' option}}
 \DeclareOption{uplatex}{%
-  \ClassWarningNoLine{\jsc@clsname}{The \jsc@clsname\space class does not support `uplatex' option}}
+  \ClassErrorNoLine{\jsc@clsname}{The \jsc@clsname\space class does not support `uplatex' option}}
+\DeclareOption{autodetect-engine}{%
+  \ClassWarningNoLine{\jsc@clsname}{The \jsc@clsname\space class does not support `autodetect-engine' option}}
 \DeclareOption{mingoth}{\mingothtrue}
 \DeclareOption{ptexjis}{\ptexjistrue}
 \DeclareOption{jis}{\jisfonttrue}
@@ -256,9 +249,10 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \ifdim\jsc@mpt=1.0954\p@ \renewcommand{\@ptsize}{1}\else
 \ifdim\jsc@mpt=1.2\p@    \renewcommand{\@ptsize}{2}\else
 \renewcommand{\@ptsize}{-20}\fi\fi
-\if@ltjs@mag@xreal\RequirePackage{type1cm}
+\ifjsc@mag@xreal
 \ifdim\jsc@mpt=\p@\else
   \expandafter\let\csname OT1/cmr/m/n/10\endcsname\relax
+  \expandafter\let\csname TU/lmr/m/n/10\endcsname\relax
   \expandafter\let\csname OMX/cmex/m/n/10\endcsname\relax
   \newluafunction\ltjs@@magnify@font@calc
   \begingroup\catcode`\%=12\relax
@@ -266,11 +260,11 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
     local getdimen, mpt=tex.getdimen, tex.getdimen('jsc@mpt')/65536
     local t = lua.get_functions_table()
     t[\the\ltjs@@magnify@font@calc] = function()
-      tex.sprint(math.floor(0.5+mpt*getdimen('dimen@')))
+      tex.sprint(-2,math.floor(0.5+mpt*getdimen('dimen@')))
     end
     function luatexja.ltjs_unmagnify_fsize(a)
       local s = luatexja.print_scaled(math.floor(0.5+a/mpt*65536))
-      tex.sprint( (s:match('%.0$')) and s:sub(1,-3) or s )
+      tex.sprint(-2, (s:match('%.0$')) and s:sub(1,-3) or s )
     end
   }
   \endgroup
@@ -278,7 +272,7 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
      \def\@tempa{#1}\def\@tempb{#2}%
      \ifx\@tempb\@empty
         \edef\@tempb{ scaled\directlua{%
-          tex.sprint(math.floor(0.5+\jsc@magscale*1000))
+          tex.sprint(-2,math.floor(0.5+\jsc@magscale*1000))
         }}%
      \else
         \dimen@\@tempb\relax
@@ -296,36 +290,48 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
     \expandafter\endgroup\@tempa
   }
 \fi\fi
-\newlength{\stockwidth}
-\newlength{\stockheight}
-\setlength{\stockwidth}{\paperwidth}
-\setlength{\stockheight}{\paperheight}
+\def\jsc@smallskip{\vspace\jsc@smallskipamount}
+\newskip\jsc@smallskipamount
+\jsc@smallskipamount=3\jsc@mpt plus 1\jsc@mpt minus 1\jsc@mpt
 \iftombow
+  \newlength{\stockwidth}
+  \newlength{\stockheight}
+  \setlength{\stockwidth}{\paperwidth}
+  \setlength{\stockheight}{\paperheight}
   \advance \stockwidth 2in
   \advance \stockheight 2in
-\fi
-\ifdefined\pdfpagewidth
-  \setlength{\pdfpagewidth}{\stockwidth}
-  \setlength{\pdfpageheight}{\stockheight}
+  \ifdefined\pdfpagewidth
+    \setlength{\pdfpagewidth}{\stockwidth}
+    \setlength{\pdfpageheight}{\stockheight}
+  \else
+    \setlength{\pagewidth}{\stockwidth}
+    \setlength{\pageheight}{\stockheight}
+  \fi
 \else
-  \setlength{\pagewidth}{\stockwidth}
-  \setlength{\pageheight}{\stockheight}
+  \ifdefined\pdfpagewidth
+    \setlength{\pdfpagewidth}{\paperwidth}
+    \setlength{\pdfpageheight}{\paperheight}
+  \else
+    \setlength{\pagewidth}{\paperwidth}
+    \setlength{\pageheight}{\paperheight}
+  \fi
 \fi
+ \def\Cjascale{0.924715}
 \expandafter\let\csname JY3/mc/m/n/10\endcsname\relax
 \ifmingoth
-  \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [0.924715] \ltj@stdmcfont:jfm=min}{}
-  \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [0.924715] \ltj@stdgtfont:jfm=min}{}
+  \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [\Cjascale] \ltj@stdmcfont:jfm=min}{}
+  \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [\Cjascale] \ltj@stdgtfont:jfm=min}{}
 \else
   \ifptexjis
-    \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [0.924715] \ltj@stdmcfont:jfm=jis}{}
-    \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [0.924715] \ltj@stdgtfont:jfm=jis}{}
+    \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [\Cjascale] \ltj@stdmcfont:jfm=jis}{}
+    \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [\Cjascale] \ltj@stdgtfont:jfm=jis}{}
   \else
-    \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [0.924715] \ltj@stdmcfont:jfm=ujis}{}
-    \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [0.924715] \ltj@stdgtfont:jfm=ujis}{}
+    \DeclareFontShape{JY3}{mc}{m}{n}{<-> s * [\Cjascale] \ltj@stdmcfont:jfm=ujis}{}
+    \DeclareFontShape{JY3}{gt}{m}{n}{<-> s * [\Cjascale] \ltj@stdgtfont:jfm=ujis}{}
   \fi
 \fi
-\DeclareFontShape{JT3}{mc}{m}{n}{<-> s * [0.924715] \ltj@stdmcfont:jfm=ujisv}{}
-\DeclareFontShape{JT3}{gt}{m}{n}{<-> s * [0.924715] \ltj@stdgtfont:jfm=ujisv}{}
+\DeclareFontShape{JT3}{mc}{m}{n}{<-> s * [\Cjascale] \ltj@stdmcfont:jfm=ujisv}{}
+\DeclareFontShape{JT3}{gt}{m}{n}{<-> s * [\Cjascale] \ltj@stdgtfont:jfm=ujisv}{}
 \DeclareFontShape{JY3}{mc}{bx}{n}{<->ssub*gt/m/n}{}
 \DeclareFontShape{JY3}{gt}{bx}{n}{<->ssub*gt/m/n}{}
 \DeclareFontShape{JY3}{mc}{m}{it}{<->ssub*mc/m/n}{}
@@ -408,12 +414,13 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
   \belowdisplayshortskip \belowdisplayskip
   \let\@listi\@listI}
 \mcfamily\selectfont\normalsize
-\setbox0\hbox{\char"3000}% 全角スペース
+\setbox0\hbox{漢}
 \setlength\Cht{\ht0}
 \setlength\Cdp{\dp0}
 \setlength\Cwd{\wd0}
 \setlength\Cvs{\baselineskip}
 \setlength\Chs{\wd0}
+\setbox0=\box\voidb@x
 \newcommand{\small}{%
   \ltj@@ifnarrowbaselines
     {\jsc@setfontsize\small\@ixpt{11}}%
@@ -468,11 +475,11 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \@lowpenalty   51
 \@medpenalty  151
 \@highpenalty 301
-\setlength\topskip{1.38\zh}%% 2016-08-17
+\setlength\topskip{1.38\zh}%% from 10\jsc@mpt (2016-08-17)
 \if@slide
   \setlength\headheight{0\jsc@mpt}
 \else
-  \setlength\headheight{20\jsc@mpt}%% 2016-08-17
+  \setlength\headheight{20\jsc@mpt}%% from 2\topskip (2016-08-17); from \topskip (2003-06-26)
 \fi
 \if@report
   \setlength\footskip{0.03367\paperheight}
@@ -487,6 +494,8 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
   \addtolength\headsep{-\topskip}
 \else
   \setlength\headsep{6\jsc@mmm}
+  \addtolength\headsep{-\topskip}%% added (2016-10-08)
+  \addtolength\headsep{10\jsc@mpt}%% added (2016-10-08)
 \fi
 \setlength\maxdepth{.5\topskip}
 \newdimen\fullwidth
@@ -511,7 +520,7 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \else
   \setlength{\textheight}{0.83\paperheight}
 \fi
-\addtolength{\textheight}{-\topskip}
+\addtolength{\textheight}{-10\jsc@mpt}%% from -\topskip (2016-10-08); from -\headheight (2003-06-26)
 \addtolength{\textheight}{-\headsep}
 \addtolength{\textheight}{-\footskip}
 \addtolength{\textheight}{-\topskip}
@@ -547,7 +556,7 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \if@slide
   \addtolength\topmargin{-\headheight}
 \else
-  \addtolength\topmargin{-0.5\headheight}%% 2016-08-17
+  \addtolength\topmargin{-10\jsc@mpt}%% from -\topskip (2016-10-08); from -\headheight (2003-06-26)
 \fi
 \addtolength\topmargin{-\headsep}
 \addtolength\topmargin{-\footskip}
@@ -577,6 +586,31 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \setlength\@dblfptop{0\jsc@mpt \@plus 1fil}
 \setlength\@dblfpsep{8\jsc@mpt \@plus 2fil}
 \setlength\@dblfpbot{0\jsc@mpt \@plus 1fil}
+\def\pltx@cleartorightpage{\clearpage\if@twoside
+  \unless\ifodd\numexpr\c@page+\ltjgetparameter{direction}\relax
+    \hbox{}\thispagestyle{empty}\newpage
+    \if@twocolumn\hbox{}\newpage\fi
+  \fi\fi}
+\def\pltx@cleartoleftpage{\clearpage\if@twoside
+  \ifodd\numexpr\c@page+\ltjgetparameter{direction}\relax
+    \hbox{}\thispagestyle{empty}\newpage
+    \if@twocolumn\hbox{}\newpage\fi
+  \fi\fi}
+\def\pltx@cleartooddpage{\clearpage\if@twoside
+  \ifodd\c@page\else
+    \hbox{}\thispagestyle{empty}\newpage
+    \if@twocolumn\hbox{}\newpage\fi
+  \fi\fi}
+\def\pltx@cleartoevenpage{\clearpage\if@twoside
+  \ifodd\c@page
+    \hbox{}\thispagestyle{empty}\newpage
+    \if@twocolumn\hbox{}\newpage\fi
+  \fi\fi}
+\if@openleft
+  \let\cleardoublepage\pltx@cleartoleftpage
+\else\if@openright
+  \let\cleardoublepage\pltx@cleartorightpage
+\fi\fi
 \def\ps@plainfoot{%
   \let\@mkboth\@gobbletwo
   \let\@oddhead\@empty
@@ -652,9 +686,9 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
           \mbox{} \\[1\zw]
           \large
           {\maybeblue\hrule height0\jsc@mpt depth2\jsc@mpt\relax}\par
-          \smallskip
+          \jsc@smallskip
           \@title
-          \smallskip
+          \jsc@smallskip
           {\maybeblue\hrule height0\jsc@mpt depth2\jsc@mpt\relax}\par
           \vfill
           {\small \@author}%
@@ -810,7 +844,7 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
         \begingroup \@svsechd \endgroup
         \unskip
         \@tempskipa #1\relax
-        \hskip -\@tempskipa\@inhibitglue
+        \hskip -\@tempskipa\ltjfakeparbegin
       \else
         \clubpenalty \@clubpenalty
         \everypar{}%
@@ -861,30 +895,30 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \newcommand{\@chapapp}{\prechaptername}
 \newcommand{\@chappos}{\postchaptername}
 \newcommand\frontmatter{%
-  \if@openright
-    \cleardoublepage
-  \else
-    \clearpage
-  \fi
+  \pltx@cleartooddpage
   \@mainmatterfalse
   \pagenumbering{roman}}
 \newcommand\mainmatter{%
-    \cleardoublepage
+  \pltx@cleartooddpage
   \@mainmattertrue
   \pagenumbering{arabic}}
 \newcommand\backmatter{%
-  \if@openright
+  \if@openleft
+\cleardoublepage
+  \else\if@openright
     \cleardoublepage
   \else
     \clearpage
-  \fi
+  \fi\fi
   \@mainmatterfalse}
 \newcommand\part{%
-  \if@openright
+  \if@openleft
+\cleardoublepage
+  \else\if@openright
     \cleardoublepage
   \else
     \clearpage
-  \fi
+  \fi\fi
   \thispagestyle{empty}% 欧文用標準スタイルでは plain
   \if@twocolumn
     \onecolumn
@@ -920,15 +954,18 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
   \@endpart}
 \def\@endpart{\vfil\newpage
   \if@twoside
-    \null
-    \thispagestyle{empty}%
-    \newpage
+   \if@openleft %% added (2017/02/24)
+    \null\thispagestyle{empty}\newpage
+   \else\if@openright %% added (2016/12/13)
+    \null\thispagestyle{empty}\newpage
+   \fi\fi %% added (2016/12/13, 2017/02/24)
   \fi
   \if@restonecol
     \twocolumn
   \fi}
 \newcommand{\chapter}{%
-  \if@openright\cleardoublepage\else\clearpage\fi
+  \if@openleft\cleardoublepage\else
+  \if@openright\cleardoublepage\else\clearpage\fi\fi
   \plainifnotempty % 元: \thispagestyle{plain}
   \global\@topnum\z@
   \if@english \@afterindentfalse \else \@afterindenttrue \fi
@@ -1018,15 +1055,16 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
     {\if@slide .5\Cvs \@plus.3\Cdp \else \z@ \fi}%
     {\normalfont\normalsize\headfont}}
 \fi
+\newcommand{\jsParagraphMark}{■}
 \if@twocolumn
   \newcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
     {\z@}{\if@slide .4\Cvs \else -1\zw\fi}% 改行せず 1\zw のアキ
-    {\normalfont\normalsize\headfont ■}}
+    {\normalfont\normalsize\headfont\jsParagraphMark}}
 \else
   \newcommand{\paragraph}{\@startsection{paragraph}{4}{\z@}%
     {0.5\Cvs \@plus.5\Cdp \@minus.2\Cdp}%
     {\if@slide .5\Cvs \@plus.3\Cdp \else -1\zw\fi}% 改行せず 1\zw のアキ
-    {\normalfont\normalsize\headfont ■}}
+    {\normalfont\normalsize\headfont\jsParagraphMark}}
 \fi
 \if@twocolumn
   \newcommand{\subparagraph}{\@startsection{subparagraph}{5}{\z@}%
@@ -1141,14 +1179,14 @@ option, since LuaTeX does not support \string\mag\MessageBreak in pdf output}%
 \def\@opargbegintheorem#1#2#3{\trivlist\labelsep=1\zw
       \item[\hskip \labelsep{\headfont #1\ #2(#3)}]}
 \newenvironment{titlepage}{%
-    \cleardoublepage
+    \pltx@cleartooddpage %% 2017-02-24
     \if@twocolumn
       \@restonecoltrue\onecolumn
     \else
       \@restonecolfalse\newpage
     \fi
     \thispagestyle{empty}%
-    \setcounter{page}\@ne
+    \ifodd\c@page\setcounter{page}\@ne\else\setcounter{page}\z@\fi
   }%
   {\if@restonecol\twocolumn \else \newpage \fi
     \if@twoside\else
@@ -1419,10 +1457,6 @@ class has defined the old font commands like\MessageBreak
 \def\footnote{\inhibitglue\footnotes@ve}
 \let\footnotemarks@ve=\footnotemark
 \def\footnotemark{\inhibitglue\footnotemarks@ve}
-\renewcommand\@makefnmark{%
-  \unless\ifnum\ltjgetparameter{direction}=3
-    \hbox{}\hbox{\@textsuperscript{\normalfont\@thefnmark}}\hbox{}%
-  \else\hbox{\yoko \@textsuperscript{\normalfont\@thefnmark}}\fi}
 \def\thefootnote{\ifnum\c@footnote>\z@\leavevmode\lower.5ex\hbox{*}\@arabic\c@footnote\fi}
 \renewcommand{\footnoterule}{%
   \kern-3\jsc@mpt
@@ -1453,7 +1487,7 @@ class has defined the old font commands like\MessageBreak
   \parindent 1\zw
   \noindent
   \llap{\@makefnmark\hskip0.3\zw}#1}
-\protected\def\@inhibitglue{\directlua{luatexja.jfmglue.create_beginpar_node()}}
+\let\@inhibitglue=\ltjfakeparbegin
 \def\@item[#1]{%
   \if@noparitem
     \@donoparitem
@@ -1496,7 +1530,7 @@ class has defined the old font commands like\MessageBreak
     \else
       \clubpenalty \@clubpenalty
       \everypar{}%
-    \fi\@inhibitglue}%
+    \fi\ltjfakeparbegin}%
   \if@noitemarg
     \@noitemargfalse
     \if@nmbrlist
@@ -1521,7 +1555,7 @@ class has defined the old font commands like\MessageBreak
     \@nolnerr
   \else
     \unskip \reserved@e {\reserved@f#1}\nobreak \hfil \break \null
-    \inhibitglue \ignorespaces
+    \inhibitglue\ignorespaces
   \fi}
 \IfFileExists{jslogo.sty}{}{\@jslogofalse}%
 \if@jslogo
@@ -1699,6 +1733,8 @@ class has defined the old font commands like\MessageBreak
 \hyphenation{ado-be post-script ghost-script phe-nom-e-no-log-i-cal man-u-script}
 \if@report \pagestyle{plain} \else \pagestyle{headings} \fi
 \pagenumbering{arabic}
+\fnfixbottomtrue % 2017-02-19
+\IfFileExists{stfloats.sty}{\RequirePackage{stfloats}\fnbelowfloat}{}
 \if@twocolumn
   \twocolumn
   \sloppy
@@ -1712,7 +1748,7 @@ class has defined the old font commands like\MessageBreak
   \renewcommand\familydefault{\sfdefault}
   \raggedright
   \ltj@setpar@global
-  \ltjsetxkanjiskip{0.1em}\relax
+  \ltjsetxkanjiskip0.1em\relax
 \fi
 \endinput
 %%