summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bxghost/bxghost.sty
blob: 552d28ad9cf805e88ca7d8235c4a19ba7e80360a (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
%%
%% This is file 'bxghost.sty'.
%%
%% Copyright 2019 Takuto ASAKURA (wtsnjp)
%%   GitHub:   https://github.com/wtsnjp
%%   Twitter:  @wtsnjp
%%
%% This package is distributed under the MIT License.
%%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxghost}[2019/09/17 v0.2.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 }% (u)pTeX (or ApTeX)
\bxqgg@next\luatexversion{\chardef\bxqgg@engine=2 }% LuaTeX
\bxqgg@next\XeTeXversion {\chardef\bxqgg@engine=3 }% XeTeX

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

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

%--------------------------------------- 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  % 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@TI\bxqgg@cwm}%
  #1%
  {\bxqgg@TI\bxqgg@cwm}%
}

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

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

%% \bxqgg@kern@m@ne@zw: a negative zenkaku width kern
\ifnum\bxqgg@engine=\@ne
  % 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{%
  \bxqgg@fwsp\bxqgg@kern@m@ne@zw
  #1%
  \bxqgg@kern@m@ne@zw\bxqgg@fwsp
}

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