Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created January 5, 2013 11:12
Show Gist options
  • Save zr-tex8r/4461060 to your computer and use it in GitHub Desktop.
Save zr-tex8r/4461060 to your computer and use it in GitHub Desktop.
LaTeX: ghost insertion
% pxghost.sty
%% package declaration
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxghost}
%% preparations
\def\pxqgg@pkgname{pxghost}
%---------------------------------------
% use an arbitrary font available in T1 encoding
\font\pxqgg@TI=ec-lmr10 at 1.23456pt
\chardef\pxqgg@cwm=23 % compwordmark (in T1)
\xspcode\pxqgg@cwm=3 % allow xkanjiskip around
%%<*> \eghostguarded{<text>}
\newcommand*\eghostguarded{%
\ifmmode \expandafter\@firstofone
\else \expandafter\pxqgg@eghostguarded@a
\fi
}
\def\pxqgg@eghostguarded@a#1{%
{\pxqgg@TI\pxqgg@cwm}%
#1%
{\pxqgg@TI\pxqgg@cwm}%
}
%---------------------------------------
%% \pxqgg@fwsp: a zenkaku space (U+3000)
\begingroup
\kansujichar\@ne=\jis"2121\relax
\xdef\pxqgg@fwsp{\kansuji\@ne}
\endgroup
%%<*> \jghostguarded{<text>}
\newcommand*\jghostguarded{%
\ifmmode \expandafter\@firstofone
\else \expandafter\pxqgg@jghostguarded@a
\fi
}
\edef\pxqgg@jghostguarded@a#1{%
\pxqgg@fwsp
\kern-1zw\relax
#1%
\kern-1zw\relax
\pxqgg@fwsp
}
%---------------------------------------
%% all done
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment