Created
September 19, 2017 00:14
-
-
Save zr-tex8r/94ff625578362e80f7bebc34d74e6980 to your computer and use it in GitHub Desktop.
TeX: fixjfm的なアレ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% fixjfm.sty | |
% Copyright 2017 Yue ZHANG | |
% License: Knuth License (https://ctan.org/license/knuth) | |
\csname ENDINPUTFIXJFMDOTSTY\endcsname | |
\let\ENDINPUTFIXJFMDOTSTY=\endinput | |
\begingroup\expandafter\expandafter\expandafter\endgroup | |
\expandafter\ifx\csname ProvidesPackage\endcsname\relax | |
\else | |
\ProvidesPackage{fixjfm}[2017/09/12 v0.5 Fix JFM (for *pTeX)]% | |
\fi | |
\edef\FIXJFMDOTSTYRESTORECATCODE{\catcode`\noexpand\@=\the\catcode`\@\relax} | |
\catcode`\@=11\relax | |
\def\fixjfm@ifprimitive#1{% | |
\begingroup | |
\edef\fixjfm@temp@meaning{\meaning#1}% | |
\edef\fixjfm@temp@string{\string#1}% | |
\expandafter | |
\endgroup | |
\ifx\fixjfm@temp@meaning\fixjfm@temp@string} | |
\fixjfm@ifprimitive\tate | |
\else | |
\errmessage{pTeX / e-pTeX / upTeX / e-upTeX / ApTeX is required}% | |
\FIXJFMDOTSTYRESTORECATCODE | |
\expandafter\endinput | |
\fi | |
\def\fixjfm@empty{} | |
\fixjfm@ifprimitive\quitvmode | |
\let\leavevmode=\quitvmode | |
\fi | |
\def\fixjfmspacing{\FixJFMSpacing} | |
\newif\iffixjfm@lastnodechar@available@ | |
\fixjfm@ifprimitive\lastnodechar | |
\fixjfm@lastnodechar@available@true | |
\fi | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% REVISION BEGIN | |
% NB. here a 'letter' means a non-speical character. | |
\newcount\fixjfm@letter % 1=letter 2=CJK-letter 0=non-letter | |
%% \fixjfm@check@kanji<token> | |
\begingroup | |
% Here \meaning test is used, since \ifcat test for CJK is unreliable. | |
\def\fixjfm@next#1>#2\fixjfm@nil{% | |
\gdef\fixjfm@check@kanji##1{% | |
\expandafter\fixjfm@@check@kanji\meaning##1#2\fixjfm@nil}% | |
\gdef\fixjfm@@check@kanji##1#2##2\fixjfm@nil{% | |
\ifcat @##1@\fixjfm@letter=2 \fi}} | |
\def\fixjfm@temp@meaning{kanji character } | |
\expandafter\fixjfm@next\meaning\fixjfm@temp@meaning\fixjfm@nil | |
\endgroup | |
%% \fixjfm@check@letter<token> | |
% Sets \fixjfm@letter. | |
\def\fixjfm@check@letter#1{% | |
\fixjfm@letter=0 | |
% NB. #1 might be an if-token. | |
\def\fixjfm@next{\fixjfm@@check@letter#1}% | |
\ifcat\noexpand#1\relax \let\fixjfm@next\relax \fi | |
\fixjfm@next} | |
\def\fixjfm@@check@letter#1{% | |
\ifcat\noexpand#1A\fixjfm@letter=1 | |
\else\ifcat\noexpand#10\fixjfm@letter=1 | |
\else \fixjfm@check@kanji#1% | |
\fi\fi} | |
\iffixjfm@lastnodechar@available@ | |
\def\FixJFMSpacing{\futurelet\fixjfm@sp@temp@token\fixjfm@fixspacing}% | |
\def\fixjfm@fixspacing{% | |
\begingroup | |
% NB. Perhaps use of \count0 is not safe here.... | |
\count@=\lastnodechar | |
\fixjfm@check@letter\fixjfm@sp@temp@token | |
\ifnum\count@>-1 \ifnum\fixjfm@letter>0 | |
% NB. Watch for if-tokens. | |
\fixjfm@@fixspacing | |
\fi\fi | |
\endgroup} | |
\def\fixjfm@@fixspacing{% | |
\setbox0=\hbox{% no spacing | |
\inhibitglue\char\count@\inhibitglue\hbox{}\inhibitglue\fixjfm@sp@temp@token\inhibitglue}% | |
\setbox2=\hbox{% correct spacing | |
\inhibitglue\char\count@\fixjfm@sp@temp@token\inhibitglue}% | |
\setbox4=\hbox{% excessive spacing | |
\inhibitglue\char\count@\hskip\z@\fixjfm@sp@temp@token\inhibitglue}% | |
% NB. \lastnodechar requires e-pTeX, which also has \dimexpr. | |
\dimen0=\dimexpr\wd2-\wd4\relax % adjustment | |
\dimen2=\dimexpr\wd2-\wd0\relax % total space | |
\fixjfm@temp@hskip\relax}% | |
\def\SetFixJFMSpacingStretch#1{\def\fixjfm@temp@hskip@stretch{#1}}% | |
\def\SetFixJFMSpacingShrink#1{\def\fixjfm@temp@hskip@shrink{#1}}% | |
\def\fixjfm@temp@hskip{% | |
% So '\width' can be used in \SetFixJFMSpacingXxx. | |
\dimendef\width=2 | |
% The resulted spacing must not be negative. | |
\dimen4=\fixjfm@temp@hskip@shrink\relax | |
\ifdim\dimen4>\dimen2 \dimen4=\dimen2 \fi | |
\hskip\dimen0 plus \fixjfm@temp@hskip@stretch minus \dimen4\relax}% | |
\SetFixJFMSpacingStretch{0.05zw}% | |
\SetFixJFMSpacingShrink{0.05zw}% | |
% or maybe... | |
% \SetFixJFMSpacingStretch{0pt}% | |
% \SetFixJFMSpacingShrink{\width}% | |
\else | |
\let\FixJFMSpacing=\fixjfm@empty | |
\def\SetFixJFMSpacingStretch#1{}% | |
\def\SetFixJFMSpacingShrink#1{}% | |
\fi | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% REVISION END | |
\begingroup\expandafter\expandafter\expandafter\endgroup | |
\expandafter\ifx\csname DeclareTextFontCommand\endcsname\relax | |
\def\DeclareFixJFMCJKTextFontCommand#1#2{}% | |
\def\DeclareStandardCJKTextFontCommand#1#2{}% | |
\let\UseFixJFMCJKTextFontCommands=\fixjfm@empty | |
\let\UseStandardCJKTextFontCommands=\fixjfm@empty | |
\else | |
\def\DeclareFixJFMCJKTextFontCommand#1#2{% | |
\DeclareRobustCommand#1[1]{% | |
\relax\ifmmode\expandafter\nfss@text\fi | |
{#2\fixjfmspacing##1}\fixjfmspacing}}% | |
\def\DeclareStandardCJKTextFontCommand#1#2{% | |
\DeclareRobustCommand#1[1]{% | |
\relax\ifmmode\expandafter\nfss@text\fi{#2##1}}}% | |
\def\UseFixJFMCJKTextFontCommands{% | |
\DeclareFixJFMCJKTextFontCommand\textmc{\mcfamily}% | |
\DeclareFixJFMCJKTextFontCommand\textgt{\gtfamily}}% | |
\def\UseStandardCJKTextFontCommands{% | |
\DeclareStandardCJKTextFontCommand\textmc{\mcfamily}% | |
\DeclareStandardCJKTextFontCommand\textgt{\gtfamily}}% | |
\UseFixJFMCJKTextFontCommands | |
\fi | |
\fixjfm@ifprimitive\protected | |
\protected\def\<{\ifvmode\leavevmode\fi\inhibitglue}% | |
\else | |
\def\<{\inhibitglue}% | |
\fi | |
\def\fixjfmparindent{\FixJFMParindent} | |
\begingroup | |
\expandafter\ifx\csname useparheadparenindent\endcsname\relax % bxjaprnind.sty | |
\else | |
\global\let\FixJFMParindent=\fixjfm@empty | |
\global\let\EveryparPreHook=\fixjfm@empty | |
\global\let\EveryparPostHook=\fixjfm@empty | |
\aftergroup\FIXJFMDOTSTYRESTORECATCODE | |
\aftergroup\endinput | |
\fi | |
\endgroup | |
\begingroup | |
\let\CATCODE=\catcode | |
\let\RELAX=\relax | |
\let\GDEF=\gdef | |
\let\ENDGROUP=\endgroup | |
\CATCODE`\k=12\RELAX | |
\CATCODE`\a=12\RELAX | |
\CATCODE`\n=12\RELAX | |
\CATCODE`\j=12\RELAX | |
\CATCODE`\i=12\RELAX | |
\CATCODE`\c=12\RELAX | |
\CATCODE`\h=12\RELAX | |
\CATCODE`\r=12\RELAX | |
\CATCODE`\t=12\RELAX | |
\CATCODE`\e=12\RELAX | |
\GDEF\FIXJFM@KANJICHARACTER{kanji character }% | |
\ENDGROUP | |
\def\FixJFMParindent{\futurelet\fixjfm@pi@temp@token\fixjfm@fixparindent} | |
\def\fixjfm@fixparindent{% | |
\expandafter\expandafter\expandafter\fixjfm@@fixparindent | |
\expandafter\meaning\expandafter\fixjfm@pi@temp@token | |
\FIXJFM@KANJICHARACTER\relax\fixjfm@pi@nil} | |
\expandafter\def\expandafter\fixjfm@@fixparindent | |
\expandafter#\expandafter1\FIXJFM@KANJICHARACTER#2#3\fixjfm@pi@nil{% | |
\def\fixjfm@pi@temp@tokens{#1}% | |
\ifx\fixjfm@pi@temp@tokens\fixjfm@empty | |
\ifnum\the\inhibitxspcode`#2=2\relax | |
\inhibitglue | |
\fi | |
\fi} | |
\begingroup\expandafter\expandafter\expandafter\endgroup | |
\expandafter\ifx\csname PushPostHook\endcsname\relax % everyhook.sty | |
\def\EveryparPreHook{}% | |
\def\EveryparPostHook{\fixjfmparindent}% | |
\let\fixjfm@previous@everypar=\everypar | |
\csname newtoks\expandafter\endcsname\csname everypar\endcsname | |
\let\fixjfm@private@everypar=\everypar | |
\fixjfm@private@everypar=\fixjfm@previous@everypar | |
\fixjfm@previous@everypar={% | |
\EveryparPreHook | |
\the\expandafter\fixjfm@private@everypar | |
\EveryparPostHook}% | |
\else | |
\PushPostHook{par}{\fixjfmparindent}% | |
\let\EveryparPreHook=\fixjfm@empty | |
\let\EveryparPostHook=\fixjfm@empty | |
\fi | |
\FIXJFMDOTSTYRESTORECATCODE | |
\endinput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment