summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bxghost/bxghost.sty
blob: 33b965ef3a5d12fc0c0a3a2182ccda805a366b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
%%
%% This is file 'bxghost.sty'.
%%
%% Copyright 2019-2022 Takuto ASAKURA (wtsnjp)
%%   GitHub:   https://github.com/wtsnjp
%%   Twitter:  @wtsnjp
%%
%% This package is distributed under the MIT License.
%%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxghost}[2022/02/12 v0.4.0]

%% preparations
\def\bxqgg@pkgname{bxghost}
\def\bxqgg@warn{\PackageWarningNoLine\bxqgg@pkgname}

%--------------------------------------- general

%% \bxqgg@engine : engine type
\def\bxqgg@next#1#2{%
  \edef\bxqgg@tmpa{\string#1}\edef\bxqgg@tmpb{\meaning#1}%
  \ifx\bxqgg@tmpa\bxqgg@tmpb #2\fi}
\chardef\bxqgg@engine=0 % other TeX
\bxqgg@next\kanjiskip     {\chardef\bxqgg@engine=1 }% pTeX
\bxqgg@next\enablecjktoken{\chardef\bxqgg@engine=2 }% upTeX
\bxqgg@next\luatexversion {\chardef\bxqgg@engine=3 }% LuaTeX
\bxqgg@next\XeTeXversion  {\chardef\bxqgg@engine=4 }% XeTeX

%--------------------------------------- not supported engine

\ifnum\bxqgg@engine=\z@
  \bxqgg@warn{This engine is not supported, sorry}
  \expandafter\endinput
\fi

%--------------------------------------- load LuaTeX-ja

\ifnum\bxqgg@engine=\thr@@
  \RequirePackage{luatexja}
  \@ifpackageloaded{luatexja-adjust}{}{%
    \RequirePackage{luatexja-adjust}\ltjdisableadjust}
\fi

%--------------------------------------- the verb option

\newif\ifbxqgg@verb \bxqgg@verbfalse
\DeclareOption{verb}{\bxqgg@verbtrue}
\DeclareOption{noverb}{\bxqgg@verbfalse}
\ProcessOptions\relax

%--------------------------------------- eghostguarded

% use an arbitrary font available in T1 encoding
\font\bxqgg@TI=ec-lmr10 at 1.23456pt
\chardef\bxqgg@cwm=23 % compwordmark (in T1)

% allow xkanjiskip around
% Note: for XeTeX, xeCJK will handle nicely. We have nothing to do :)
\ifcase\bxqgg@engine
\or  % pTeX
  \xspcode\bxqgg@cwm=3\relax
\or  % upTeX
  \xspcode\bxqgg@cwm=3\relax
\or  % LuaTeX
  \ltjsetparameter{alxspmode={\bxqgg@cwm,3}}
\fi

%%<*> \eghostguarded{<text>}
\newcommand*\eghostguarded{%
  \ifmmode \expandafter\@firstofone
  \else \expandafter\bxqgg@eghostguarded@a
  \fi
}
\def\bxqgg@eghostguarded@a#1{%
  \bxqgg@eghost #1\bxqgg@eghost}
\def\bxqgg@eghost{\bgroup
  \bxqgg@TI\bxqgg@cwm\egroup}

% patch \verb
\ifbxqgg@verb
  \edef\verb{\noexpand\bxqgg@eghost\unexpanded\expandafter{\verb}}
  \edef\verb@egroup{%
    \unexpanded\expandafter{\verb@egroup}\noexpand\bxqgg@eghost}
\fi

%--------------------------------------- jghostguarded

%% \bxqgg@fwsp: a zenkaku space (U+3000)
\begingroup
  \ifnum\bxqgg@engine<\thr@@  % (u)pTeX
    \kansujichar\@ne=\jis"2121\relax
    \xdef\bxqgg@fwsp{\kansuji\@ne}
  \else  % others
    \lccode`\Z="3000\relax
    \lowercase{\xdef\bxqgg@fwsp{Z}}
  \fi
\endgroup

% make sure to use a font whose zenkaku space is class zero
\let\bxqgg@jafont\relax

\ifcase\bxqgg@engine
\or  % pTeX
  \DeclareFontFamily{JY1}{bxqgg}{}
  \DeclareFontFamily{JT1}{bxqgg}{}
  \DeclareFontShape{JY1}{bxqgg}{m}{n}{<->s*[0.961]jis}{}
  \DeclareFontShape{JT1}{bxqgg}{m}{n}{<->s*[0.961]tmin10}{}
  \def\bxqgg@jafont{\usekanji{\k@encoding}{bxqgg}{m}{n}}
\or  % upTeX
  \DeclareFontFamily{JY2}{bxqgg}{}
  \DeclareFontFamily{JT2}{bxqgg}{}
  \DeclareFontShape{JY2}{bxqgg}{m}{n}{<->s*[0.92469]upjisr-h}{}
  \DeclareFontShape{JT2}{bxqgg}{m}{n}{<->s*[0.92469]upjisr-v}{}
  \def\bxqgg@jafont{\usekanji{\k@encoding}{bxqgg}{m}{n}}
\fi

%% \bxqgg@kern@m@ne@zw: a negative zenkaku width kern
\ifnum\bxqgg@engine<\thr@@
  % (u)pTeX knows the unit `zw'
  \def\bxqgg@kern@m@ne@zw{\kern-1zw\relax}
\else
  % for other engines, we use \zw instead
  \def\bxqgg@kern@m@ne@zw{\kern-1\zw\relax}
\fi

%%<*> \jghostguarded{<text>}
\newcommand*\jghostguarded{%
  \ifmmode \expandafter\@firstofone
  \else \expandafter\bxqgg@jghostguarded@a
  \fi
}
\edef\bxqgg@jghostguarded@a#1{%
  \bgroup
    \noexpand\bxqgg@jafont
    \bxqgg@fwsp\bxqgg@kern@m@ne@zw
  \egroup
  #1%
  \bgroup
    \noexpand\bxqgg@jafont
    \bxqgg@kern@m@ne@zw\bxqgg@fwsp
  \egroup
}

% better definition for LuaTeX-ja (20220211.0 or later)
\ifnum\bxqgg@engine=\thr@@  % LuaTeX
  \ifx\ltjghostbeforejachar\@undefined\else
    \def\bxqgg@jghostguarded@a#1{%
      \ltjghostbeforejachar #1\ltjghostafterjachar
    }
  \fi
\fi

%--------------------------------------- all done
\endinput
%% EOF