%% TeX macros to handle Japanese texinfo files for Egg
%% Modified by Satoru Tomura (tomura@etl.go.jp)
%% 92.7.8   modified for Mule Ver.0.9.5 by K.Handa <handa@etl.go.jp>
%%      To detect type of jTeX and its version, the method
%%      posted by Takafumi SAKURAI <sakurai@math.metro-u.ac.jp> is used.
%% 92.9.30  modified for Mule Ver.0.9.6 by K.Handa <handa@etl.go.jp>
%%      For unknown reason, \newif\ifNTTOLD should be before
%%      \ifNTT.
%% 93.4.29  modified for Mule Ver.0.9.7 by N.Hikichi <hikichi@sra.co.jp>
%% 95.10.6  modified for texinfo 2.145 by K.Handa <handa@etl.go.jp>
%% 95.10.13 modified by J.Sato <jun@svgw.rd.casio.co.jp>
%%      Support many Japanese oriented phrases (reference, etc)
%% 95.10.14 modified by K.Handa <handa@etl.go.jp>
%%      Bug for handling index fixed.
%% 96.1.16 modified by J.Sato <jun@svgw.rd.casio.co.jp>
%%      index with [] of @deffn.

%% 92.7.8 by K.Handa
\newif\ifNTT
\ifx\gtfam\undefined
\NTTtrue
\else
\NTTfalse
\fi

\newif\ifNTTOLD
\ifNTT
\ifx\jendlinetype\undefined
\NTTOLDtrue
\else
\NTTOLDfalse
\fi
\fi
%% end of patch

%% TeX macros to handle Japanese texinfo files
%% 92/05/24 merged jtexinfo.tex (by H. Isozaki and N. Hikichi) into this
%% Created by Satoru Tomura (tomura@etl.go.jp)

\def\texinfoJPversion{2.145J.2}

\ifNTT
\message{texi-jp (NTT JTeX) package [Version \texinfoJPversion]:}
\else
\message{texi-jp (ASCII JTeX) package [Version \texinfoJPversion]:}
\fi
\message{}

%% 日本語フォントに関する互換性
\ifNTT
\kanjifiletype=20 
\let\min=\dm\let\dg=\goth
\else
\let\dm=\min\let\goth=\dg
\fi

\setfont\textrm{r10}
\setfont\texttt{tt10}
\setfont\textbf{b10}
\setfont\textit{ti10}
\setfont\textsl{sl10}
\setfont\textsf{ss10}
\setfont\textsc{csc10}
\font\texti=cmmi10

%% 日本語フォントの定義
%% Fonts for text
\ifNTT
\ifNTTOLD                       % 92.7.8 by K.Handa
\jfont\textdm=dm10 scaled {\magstephalf}
\jfont\textdg=dg10 scaled {\magstephalf}
\jfont\shortcontdm=dm10 scaled {\magstep1}
\jfont\shortcontdg=dg10 scaled {\magsteph1}
\else
%\jfont\textdm=dm10 scaled \magstephalf
%\jfont\textdg=dg10 scaled \magstephalf
%\jfont\shortcontdm=dm10 scaled \magstephalf
\jfont\textdm=dm10
\jfont\textdg=dg10
\jfont\shortcontdm=dm12
\jfont\shortcontdg=dg12
\fi
\else
%\font\textdm=min10 scaled \magstephalf
%\font\textdg=goth10 scaled \magstephalf
%\jfont\shortcontdm=min10 scaled \magstephalf
\font\textdm=min10
\font\textdg=goth10
\jfont\shortcontdm=min10 scaled \magstep1
\jfont\shortcontdg=goth10 scaled \magstep1
\fi

%% Fonts for title
\ifNTT
\jfont\titledm=dg12 scaled \magstep3
\else
%\font\titledm=goth12 scaled \magstep3
\font\titledm=goth10 scaled \magstep4
\fi

%% Fonts for indics and small examples
\ifNTT
\jfont\inddm=dm9
\jfont\inddg=dm9
\else
\font\inddm=min9
\font\inddg=min9
\fi

%% Fonts for headings
\ifNTT
\jfont\chapdm=dg12 scaled \magstep2
\else
%\font\chapdm=min12 scaled \magstep2
\font\chapdm=goth10 scaled \magstep3
\fi
\let\chapdg=\chapdm

\ifNTT
\jfont\secdm=dg12 scaled \magstep1
\jfont\secdg=dg12 scaled \magstep1
\else
%\font\secdm=min12 scaled \magstep1
\font\secdm=goth10 scaled \magstep2
%\font\secdg=goth12 scaled \magstep1
\font\secdg=goth10 scaled \magstep2
\fi

\ifNTT
\ifNTTOLD                       % 92.7.8 by K.Handa
\jfont\ssecdm=dg12 scaled {\magstephalf}
\jfont\ssecdg=dg12 scaled {\magstephalf}
\else
\jfont\ssecdm=dg12 scaled \magstephalf
\jfont\ssecdg=dg12 scaled \magstephalf
\fi
\else
%\font\ssecdm=goth12 scaled \magstephalf
\font\ssecdm=goth10 at 13pt
%\font\ssecdg=goth12 scaled \magstephalf
\font\ssecdg=goth10 at 13pt
\fi

% 95.11.2 by K.Handa
% Reduce Overfull/Underfull \hbox by relaxing these glues.
\ifNTT
\jintercharskip=0pt plus 0.5pt minus -0.2pt
\jasciikanjiskip=2.28854pt plus 0.5pt minus -0.2pt
\fi

%% Re-definitions
\let\origrm=\rm
\def\rm{\origrm\tendm}
\let\origbf=\bf
\def\bf{\origbf\tendg}
\let\origsl=\sl
\def\sl{\origsl\tendg}

\let\origtextfonts=\textfonts
\def\textfonts{\let\tendm=\textdm\let\tendg=\textdg\origtextfonts\textrm\textdm
}
\let\origchapfonts=\chapfonts
\def\chapfonts{\let\tendm=\chapdm\let\tendg=\chapdg\origchapfonts}
\let\origsecfonts=\secfonts
\def\secfonts{\let\tendm=\secdm\let\tendg=\secdg\origsecfonts}
\let\origsubsecfonts=\subsecfonts
\def\subsecfonts{\let\tendm=\ssecdm\let\tendg=\ssecdg\origsubsecfonts}
\let\origindexfonts=\indexfonts
\def\indexfonts{\let\tendm=\inddm\let\tendg=\inddg\origindexfonts}

\def\titlefont#1{{%
\titlerm\titledm\spaceskip=.9\fontdimen2\titlerm%
\ifNTT\jintercharskip=-2pt\fi%
#1}}

% 95.11.2 by K.Handa
% Not to cause Underfull \hbox while skipping the block:
%       @ifset jp-draft ... @end ifset
\let\origignoremorecommands=\ignoremorecommands
\def\ignoremorecommands{
\origignoremorecommands
\let\result=\relax\let\expansion=\relax\let\print=\relax\let\equiv=\relax
}

% 95.11.2 by K.Handa
% The orignal codes have tailing \null, but JTeX doesn't
% insert \jasciikanjiskip in that case.  So the tailing
% \null is delted.
\def\t#1{{\tt \nohyphenation \rawbackslash \frenchspacing #1}}
\let\ttfont = \t
\def\samp #1{`\tclose{#1}'}
\let\file=\samp
\def\key #1{{\tt \nohyphenation \uppercase{#1}}}
\def\tclose#1{%
  {%
    % Change normal interword space to be same as for the current font.
    \spaceskip = \fontdimen2\font
    %
    % Switch to typewriter.
    \tt
    %
    % But `\ ' produces the large typewriter interword space.
    \def\ {{\spaceskip = 0pt{} }}%
    %
    % Turn off hyphenation.
    \nohyphenation
    %
    \rawbackslash
    \frenchspacing
    #1%
  }%
}
% The same can be said for the trailing \/.
\def\smartitalic#1{{\sl #1}}
\let\i=\smartitalic
\let\var=\smartitalic
\let\dfn=\smartitalic
\let\emph=\smartitalic
\let\cite=\smartitalic

% インデックスにソートキーを[]で指定する．
\def\Jempty{}
\def\singleindexer #1{\singleindexerB#1[]\singleindexerA}
% 93.4.29 by N.Hikichi
% \def\singleindexerB#1[#2]{\edef\Jone{#1}\edef\Jtwo{#2}%
\def\singleindexerB#1[#2]{\def\Jone{#1}\def\Jtwo{#2}%
\ifx\Jempty\Jtwo\let\Jnext=\relax\let\singleindexerA=\singleindexerD%
\else\let\Jnext=\singleindexerC\let\singleindexerA=\singleindexerE\fi%
\Jnext}
\def\singleindexerC#1[]{}
\def\singleindexerD{\doind{\indexname}{\Jone}}
\def\singleindexerE{\Jdoind{\indexname}{\Jone}{\Jtwo}}

\def\Jdoind #1#2#3{%
{\indexdummies % Must do this here, since \bf, etc expand at this stage
\count10=\lastpenalty %
\escapechar=`\\%
{\let\folio=0% Expand all macros now EXCEPT \folio
\def\rawbackslashxx{\indexbackslash}% \indexbackslash isn't defined now
% so it will be output as is; and it will print as backslash in the indx.
%
% Now process the index-string once, with all font commands turned off,
% to get the string to sort the index by.
{\indexnofonts
\xdef\temp1{#3}%
}%
% Now produce the complete index entry.  We process the index-string again,
% this time with font commands expanded, to get what to print in the index.
\edef\temp{%
\write \csname#1indfile\endcsname{%
\realbackslash entry {\temp1}{\folio}{#2}}}%
\temp }%
\penalty\count10}}

\def\initial #1{%
{\let\tentt=\sectt \let\tt=\sectt \let\sf=\sectt
\ifdim\lastskip<\initialskipamount
\removelastskip \penalty-200 \vskip \initialskipamount\fi
\line{\secbf\secdg#1\hfill}\kern 2pt\penalty10000}}

% 非互換な日本語化部分

% Set up fixed words for Japanese.
\gdef\putwordChapter{章}%
\gdef\putwordSee{を参照してください}%
\gdef\putwordsee{参照}%
\gdef\putwordfile{ファイル}%
\gdef\putwordpage{p.}%
\gdef\putwordsection{節}%
\gdef\putwordSection{節}%
\gdef\putwordTableofContents{目次}%
\gdef\putwordShortContents{簡略目次}%
\gdef\putwordAppendix{付録}%

\setbox0 = \hbox{\shortcontrm\shortcontdm \putwordAppendix }
\shortappendixwidth = \wd0

% And just the chapters.
\outer\def\summarycontents{%
   \startcontents{\putwordShortContents}%
      %
      \let\chapentry = \shortchapentry
      \let\unnumbchapentry = \shortunnumberedentry
      % We want a true roman here for the page numbers.
      \secfonts
      \def\rm{\shortcontrm\shortcontdm}
      \def\bf{\shortcontbf\shortcontdg}
      \def\sl{\shortcontsl\shortcontdg}
      \rm
      \advance\baselineskip by 1pt % Open it up a little.
      \def\secentry ##1##2##3##4{}
      \def\unnumbsecentry ##1##2{}
      \def\subsecentry ##1##2##3##4##5{}
      \def\unnumbsubsecentry ##1##2{}
      \def\subsubsecentry ##1##2##3##4##5##6{}
      \def\unnumbsubsubsecentry ##1##2{}
      \input \jobname.toc
   \endgroup
   \vfill \eject
}
\let\shortcontents = \summarycontents


\def\inforefzzz #1,#2,#3,#4**{\putwordInfo{}\putwordfile{} \file{\ignorespaces 
#3{}}, ノード\samp{\ignorespaces#1{}}\putwordSee{}}

%\def\numberedsec{\parsearg\secyyy}
\def\chapterzzz #1{\seccheck{chapter}%
\secno=0 \subsecno=0 \subsubsecno=0
\global\advance \chapno by 1 \message{第\the\chapno\putwordChapter}%
\chapmacro {#1}{\the\chapno}%
\gdef\thissection{#1}%
\gdef\thischaptername{#1}%
% We don't substitute the actual chapter name into \thischapter
% because we don't want its macros evaluated now.
\xdef\thischapter{第\the\chapno\putwordChapter{}: \noexpand\thischaptername}%
{\chapternofonts%
\edef\temp{{\realbackslash chapentry {#1}{\the\chapno}{\noexpand\folio}}}%
\escapechar=`\\%
\write \contentsfile \temp  %
\donoderef %
\global\let\section = \numberedsec
\global\let\subsection = \numberedsubsec
\global\let\subsubsection = \numberedsubsubsec
}}

\def\defthissection#1{%
{\def\code##1{'code {##1}}\def\file##1{'file {##1}}\xdef\thissection{#1}}}

\def\numberedsubseczzz #1{\seccheck{subsection}%
\defthissection{#1}\subsubsecno=0 \global\advance \subsecno by 1 %
\subsecheading {#1}{\the\chapno}{\the\secno}{\the\subsecno}%
{\chapternofonts%
\edef\temp{{\realbackslash subsecentry %
{#1}{\the\chapno}{\the\secno}{\the\subsecno}{\noexpand\folio}}}%
\escapechar=`\\%
\write \contentsfile \temp %
\donoderef %
\penalty 10000 %
}}

\def\numberedsubsubseczzz #1{\seccheck{subsubsection}%
\defthissection{#1}\global\advance \subsubsecno by 1 %
\subsubsecheading {#1}
  {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}%
{\chapternofonts%
\edef\temp{{\realbackslash subsubsecentry %
  {#1}
  {\the\chapno}{\the\secno}{\the\subsecno}{\the\subsubsecno}
  {\noexpand\folio}}}%
\escapechar=`\\%
\write \contentsfile \temp %
\donoderef %
\penalty 10000 %
}}

%%%\def\pxref#1{\putwordsee{} \xrefX[#1,,,,,,,]}
%%%\def\xref#1{\putwordSee{} \xrefX[#1,,,,,,,]}
\def\pxref #1{\xrefX [#1,,,,,,,]\putwordsee{}}
\def\xref #1{\xrefX [#1,,,,,,,]\putwordSee{}}

\def\xrefX[#1,#2,#3,#4,#5,#6]{\begingroup%
  \def\printedmanual{\ignorespaces #5}%
  \def\printednodename{\ignorespaces #3}%
  \setbox1=\hbox{\printedmanual}%
  \setbox0=\hbox{\printednodename}%
  \ifdim \wd0 = 0pt
    % No printed node name was explicitly given.
    \expandafter\ifx\csname SETxref-automatic-section-title\endcsname\relax %
      % Use the actual chapter/section title appear inside
      % the square brackets.  Use the real section title if we have it.
      \ifdim \wd1>0pt%
        % It is in another manual, so we don't have it.
        \def\printednodename{\ignorespaces #1}%
      \else
        \ifhavexrefs
          % We know the real title if we have the xref values.
          \def\printednodename{\refx{#1-title}{}}%
        \else
          % Otherwise just copy the Info node name.
          \def\printednodename{\ignorespaces #1}%
        \fi%
      \fi
%      \def\printednodename{#1-title}%
    \else
      % Use the node name inside the square brackets.
      \def\printednodename{\ignorespaces #1}%
    \fi
  \fi
  %
  % If we use \unhbox0 and \unhbox1 to print the node names, TeX does not
  % insert empty discretionaries after hyphens, which means that it will
  % not find a line break at a hyphen in a node names.  Since some manuals
  % are best written with fairly long node names, containing hyphens, this
  % is a loss.  Therefore, we give the text of the node name again, so it
  % is as if TeX is seeing it for the first time.
  \ifdim \wd1 > 0pt
    \cite{\printedmanual}の``\printednodename''\putwordsection{}%
  \else
    % _ (for example) has to be the character _ for the purposes of the
    % control sequence corresponding to the node, but it has to expand
    % into the usual \leavevmode...\vrule stuff for purposes of
    % printing. So we \turnoffactive for the \refx-snt, back on for the
    % printing, back off for the \refx-pg.
    {\turnoffactive\refx{#1-snt}{}}「\printednodename 」%
    \turnoffactive\putwordpage\refx{#1-pg}{}%
  \fi
\endgroup}

%%%\def\Ysectionnumberandtype{%
%%%\ifnum\secno=0 \putwordChapter\xreftie\the\chapno %
%%%\else \ifnum \subsecno=0 \putwordSection\xreftie\the\chapno.\the\secno %
%%%\else \ifnum \subsubsecno=0 %
%%%\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno %
%%%\else %
%%%\putwordSection\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno
 %
%%%\fi \fi \fi }

\def\Ysectionnumberandtype{%
\ifnum\secno=0 第\the\chapno\putwordChapter%
\else \ifnum \subsecno=0 \the\chapno.\the\secno\putwordSection%
\else \ifnum \subsubsecno=0 %
\xreftie\the\chapno.\the\secno.\the\subsecno\putwordSection%
\else %
\xreftie\the\chapno.\the\secno.\the\subsecno.\the\subsubsecno\putwordSection%
\fi \fi \fi }

\def\Yappendixletterandtype{%
\ifnum\secno=0 \putwordAppendix\xreftie'char\the\appendixno{}%
\else \ifnum \subsecno=0 \xreftie'char\the\appendixno.\the\secno\putwordSection
%
\else \ifnum \subsubsecno=0 %
\xreftie'char\the\appendixno.\the\secno.\the\subsecno\putwordSection %
\else %
\xreftie'char\the\appendixno.\the\secno.\the\subsecno.\the\subsubsecno\putwordS
ection %
\fi \fi \fi }

%
% A4 size(Japanese) define, top margin = 20, bottom margin = 21,
%  left margin = 30, right margin = 15
%
\def\a4book{
\global\lispnarrowing = 0.3in
\global\baselineskip 12pt
\global\parskip 3pt plus 1pt

% for @cropmarks
%\global\hsize = 6.5in
% without @cropmarks
\global\hsize = 6.7in

\global\doublecolumnhsize=2.4in \global\doublecolumnvsize=15.0in
\global\vsize=9.8in
\global\tolerance=700
\global\hfuzz=1pt

\global\pagewidth=\hsize
\global\pageheight=\vsize
\global\font\ninett=cmtt9

\global\let\smalllisp=\smalllispx
\global\let\smallexample=\smalllispx
\global\def\Esmallexample{\Esmalllisp}

% for @cropmarks
%\global\voffset = -1.0in
%\global\hoffset = -0.2in

% without @cropmarks
\global\voffset = 0.0in
%\global\hoffset = -1.0in
\global\hoffset = -0.2in
}

% @dfn
\def\doublebracket#1{『#1』}
\let\dfn=\doublebracket

% @smallbook for B5
\def\smallbook{
\outerhsize=182mm
\outervsize=257mm
\hoffset=-0.3in
\voffset=-0.3in

% These values for secheadingskip and subsecheadingskip are
% experiments.  RJC 7 Aug 1992
\global\secheadingskip = 17pt plus 6pt minus 3pt
\global\subsecheadingskip = 14pt plus 6pt minus 3pt

\global\lispnarrowing = 0.3in
\setleading{14pt}
\advance\topskip by -7mm
\global\parskip 3pt plus 1pt
\global\hsize = 5.5in
\global\vsize=8.25in
\global\tolerance=700
\global\hfuzz=1pt
\global\contentsrightmargin=0pt
\global\deftypemargin=0pt
\global\defbodyindent=.5cm

\global\pagewidth=\hsize
\global\pageheight=\vsize

\global\let\smalllisp=\smalllispx
\global\let\smallexample=\smalllispx
\global\def\Esmallexample{\Esmalllisp}
}

\def\croppageout#1{
{\escapechar=`\\\relax % makes sure backslash is used in output files.
                 \shipout
                 \vbox to \outervsize{\hsize=\outerhsize
                 \vbox{\line{\ewtop\hfill\ewtop}}
                 \nointerlineskip
                 \line{\vbox{\moveleft\cornerthick\nstop}
                       \hfill
                       \vbox{\moveright\cornerthick\nstop}}
                 \vskip \topandbottommargin
                 \centerline{\ifodd\pageno\hskip\bindingoffset\fi
                        \vbox{
                        {\let\hsize=\pagewidth \makeheadline}
                        \pagebody{#1}
                        {\let\hsize=\pagewidth \makefootline}}
                        \ifodd\pageno\else\hskip\bindingoffset\fi}
                 \vskip \topandbottommargin plus1fill minus1fill
                 \boxmaxdepth\cornerthick
                 \line{\vbox{\moveleft\cornerthick\nsbot}
                       \hfill
                       \vbox{\moveright\cornerthick\nsbot}}
                 \nointerlineskip
                 \vbox{\line{\ewbot\hfill\ewbot}}
        }}
  \advancepageno
  \ifnum\outputpenalty>-20000 \else\dosupereject\fi}

\newdimen\defaultparindent \defaultparindent = 1zw
\parindent = \defaultparindent

\def\includezzz #1{\begingroup
\openin 1 #1
\ifeof 1\message{File #1 does not exist.}\else \closein 1
\def\thisfile{#1}
\input\thisfile
\fi
\endgroup}

% added by J.Sato
% LaTeXのlinebreakの真似
% 半田さんより
\def\linebreak{\unskip\penalty -10000}

% added by J.Sato
% @deffnで読みを指定する
{\activeparens%
\gdef\deffnheader #1#2{\deffnheaderB{#1}#2[]\deffnheaderA}
\gdef\deffnheaderB#1#2[#3]{\def\Jone{#1}\def\Jtwo{#2}\def\Jthree{#3}%
\ifx\Jempty\Jthree%
\let\Jnext\relax%
\let\deffnheaderA\deffnheaderD%
\else%
\let\Jnext\deffnheaderC%
\let\deffnheaderA\deffnheaderE%
\fi\Jnext}
\gdef\deffnheaderC#1[]{}
\gdef\deffnheaderD#1{\doind {fn}{\code{\Jtwo}}%
\begingroup\defname {\Jtwo}{\Jone}\defunargs{#1}\endgroup %
\catcode 61=\other}
\gdef\deffnheaderE#1{\Jdoind {fn}{\code{\Jtwo}}{\Jthree}
\begingroup\defname {\Jtwo}{\Jone}\defunargs{#1}\endgroup %
\catcode 61=\other}}
