%:skip
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Part of the ptx2pdf macro package for formatting USFM text
% copyright (c) 2007 by SIL International
% written by Jonathan Kew
%
% Permission is hereby granted, free of charge, to any person obtaining  
% a copy of this software and associated documentation files (the  
% "Software"), to deal in the Software without restriction, including  
% without limitation the rights to use, copy, modify, merge, publish,  
% distribute, sublicense, and/or sell copies of the Software, and to  
% permit persons to whom the Software is furnished to do so, subject to  
% the following conditions:
%
% The above copyright notice and this permission notice shall be  
% included in all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF  
% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
% NONINFRINGEMENT. IN NO EVENT SHALL SIL INTERNATIONAL BE LIABLE FOR  
% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  
% CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
% WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
%
% Except as contained in this notice, the name of SIL International  
% shall not be used in advertising or otherwise to promote the sale,  
% use or other dealings in this Software without prior written  
% authorization from SIL International.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Local configurations for ptxprint

\sethook{start}{wh}{\beginR}
\sethook{end}{wh}{\endR}
\sethook{start}{wg}{\beginL}
\sethook{end}{wg}{\endL}
\catcode`\@=11
\begingroup\obeylines
\catcode`\^=7
\gdef\zpdf{\bgroup\obeylines\unc@tcodespecials\@zdpf}
\gdef\@zdpf#1#2^^M{\egroup\includepdf{#2}}
%\gdef\rem{\bgroup\obeylines\unc@tcodespecials\catcode`\\=12\@rem}
%\gdef\@rem#1^^M{\egroup}
\gdef\zBottomRag{\bgroup\obeylines\m@kedigitsother\@zbottomrag}
\gdef\@zbottomrag #1^^M{\egroup\xdef\BalanceThreshold{#1}}
\gdef\include{\bgroup\obeylines\unc@tcodespecials\catcode`\/=12 \@include}
\gdef\@include#1#2^^M{\egroup\mapinput "#2" \relax}
\gdef\nopagenums{\global\let\pagenumberL=\relax\global\let\pagenumberR=\relax\global\let\pagenumber=\relax}
\gdef\dopagenums{\global\let\pagenumberL=\folio\global\let\pagenumberR=\folio\global\let\pagenumber=\folio}
\gdef\resetpagenums{\bgroup\m@kedigitsother\obeylines\r@setpagenums}
\gdef\r@setpagenums #1^^M{\global\pageno=#1\egroup}
\endgroup
\sethook{start}{xts}{\proc@strong{xts}}
\def\needoddemptyp@ge{\need@oddpage{\emptyoutput}}
\def\intropages#1{\ifversion{2}{\ifcsname\g@tperiphid{}{#1}\endcsname
    \ifx\IntroPageAlign\val@dd \endpage\needoddemptyp@ge \else
      \ifx\IntroPageAlign\val@GROUP \ifin@ntro\else\endpage\needoddemptyp@ge \fi\else
        \ifx\IntroPageAlign\val@MULTI\else
          \endpage
    \fi\fi\fi
    %\def\p@gefirstmark{}%
    \prepusfm\zgetperiph|#1\*\unprepusfm\in@ntrotrue
    \ifx\IntroPageAlign\val@MULTI \else\endpage\fi
  \fi}{\pb\needoddemptyp@ge\prepusfm\zgetperiph|#1\*\unprepusfm\pb\needoddemptyp@ge}}
\in@ntrofalse
\def\slash{\sl@shprint}
\let\ptxp@m@kechapterbox=\m@kechapterbox
\def\cjkgridchapterbox{\gdef\m@kechapterbox{\ptxp@m@kechapterbox
  \dimen0=12 \FontSizeUnit \dimen1=\ch@pterwd
  \m@d \advance\ch@pterwd\dimen0}}

\catcode`\@=12
\def\onebody{\global\BodyColumns=1}
\def\twobody{\global\BodyColumns=2}
\def\threebody{\global\BodyColumns=3}
\def\IntroPageAlign{page}
\def\goone{\global\BodyColumns=1\global\notransitionskiptrue\singlecolumn\global\notransitionskipfalse}
\def\gotwo{\global\BodyColumns=2\global\notransitionskiptrue\doublecolumns\global\notransitionskipfalse}
\def\gothree{\global\BodyColumns=3\global\notransitionskiptrue\doublecolumns\global\notransitionskipfalse}
\gdef\pausecharspacing{\global\let\currcharspacing\XeTeXinterchartokenstate \XeTeXinterchartokenstate=0}
\gdef\unpausecharspacing{\XeTeXinterchartokenstate=\currcharspacing}

% Special active chars
% FDEF - used as }
% FDEE - use as {
\DefineActiveChar{^^^^fdec}{\pausecharspacing}
\DefineActiveChar{^^^^fded}{\unpausecharspacing}

