<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% -*- coding: utf-8 -*-
% Package interchar: managing character class schemes of XeTeX
% Copyright (C) 2015 Zou Hu &lt;zohooo@yeah.net&gt;
%
% Please report bugs, problems, and suggestions via
%     https://github.com/zohooo/interchar
%
% This file may be distributed and/or modified under the conditions
% of the LaTeX Project Public License, either version 1.3 of this
% license or (at your option) any later version. The latest version
% of this license is in
%     http://www.latex-project.org/lppl.txt
\documentclass{article}
\usepackage[b5paper,margin=17mm]{geometry}
\usepackage{xcolor,hyperref,float,makedoc,niceverb,interchar}
\hypersetup{
   colorlinks,
   citecolor = teal,
   linkcolor = blue,
   urlcolor = purple,
   pdfstartview = {FitH},
   bookmarksnumbered
}
\begin{document}

\title{Documentation for package \texttt{interchar}
\footnote{Version 0.2. Please report bugs via \url{https://github.com/zohooo/interchar}.}}
\author{Zou Hu (zohooo@yeah.net)}
\maketitle
\tableofcontents

\section{Introduction}

With XeTeX\rq s character class mechanism, we could put characters into different classes,
and insert some tokens to the input stream between characters in one class and those in
another class. This mechanism is originally used for switching fonts and adjusting spaces.
But it has many other useful applications.

By default, all characters are of class 0, except CJK ideographs are of class 1, CJK left
punctuation of class 2, CJK right punctuation of class 3, text boundaries (glues, kerns,
maths, boxes, etc.) of class 255, and several characters of class 256 (this class is ignored).

\MakeNormal\`
\newintercharclass{\myclass}
\intercharclass{`\o}{\myclass}
\interchartoks{0}{\myclass}{\bgroup\color{red}}
\interchartoks{255}{\myclass}{\bgroup\color{red}}
\interchartoks{\myclass}{0}{\egroup}
\interchartoks{\myclass}{255}{\egroup}
\intercharstate{1}
\MakeActive\`
Package 'interchar' is written for making character class mechanism more easy to use. For example,
after loading the package with `\usepackage{interchar}', you may change the color of every
occurrences of character \texttt{o}:
\intercharstate[foo]{0}
\begin{verbatim}
\newintercharclass{\myclass}
\intercharclass{`\o}{\myclass}
\interchartoks{0}{\myclass}{\bgroup\color{red}}
\interchartoks{255}{\myclass}{\bgroup\color{red}}
\interchartoks{\myclass}{0}{\egroup}
\interchartoks{\myclass}{255}{\egroup}
\intercharstate{1}
\end{verbatim}

There are some existing packages using this mechanism, such as 'polyglossia', 'xeCJK' and
'xesearch'. But since one character could only be put into one single class, when loading two
or more of these packages simultaneously, it would be very likely that some conflicts occur.

Package 'interchar' also provides some migration commands for these packages. With minor changes
these packages should be compatible with 'interchar', and users could switch between different
character class schemes when loading these packages at the same time.

\section{Commands for normal users}

\begin{itemize}
  \item |\newintercharscheme{&lt;scheme&gt;}| creates a new char class scheme. For example,
        \begin{verbatim}\newintercharscheme{foo}\end{verbatim}
        There is a prebuilt `default' scheme which you need not to create it.
        The first argument of the other commands in this section is optional;
        its default value is `default'.
  \item |\intercharstate[&lt;scheme&gt;]{&lt;state-code&gt;}| changes current scheme.
        If '&lt;state-code&gt;' is positive, changes current scheme to `&lt;scheme&gt;';
        otherwise, changes current scheme to `default'. For example,
        \begin{verbatim}\intercharstate[foo]{1}\end{verbatim}
  \item |\getintercharstate[&lt;scheme&gt;]{\cs}| gets current state of the specified scheme
        and store the state code in `\cs'. For example,
        \begin{verbatim}\getintercharstate[foo]{\mystate}\end{verbatim}
  \item |\newintercharclass[&lt;scheme&gt;]{\cs}| creates a new char class in the specified scheme
        and stores the class number in `\cs'. For example,
        \begin{verbatim}\newintercharclass[foo]{\myclass}\end{verbatim}
  \item |\intercharclass[&lt;scheme&gt;]{&lt;char-range&gt;}{&lt;char-class&gt;}| moves all characters within
        `&lt;char-range&gt;' to the class `&lt;char-class&gt;' in the specified scheme. For example,
\begin{verbatim}
\intercharclass[foo]{`\@}{255}
\intercharclass[foo]{`\a-`\z}{\myclass}
\end{verbatim}
  \item |\getintercharclass[&lt;scheme&gt;]{&lt;char-code&gt;}{\cs}| gets the class number of the specified
        character in the specified scheme, and stores the result in `\cs'. For example,
        \begin{verbatim}\getintercharclass[foo]{`\@}{\result}\end{verbatim}
  \item |\interchartoks[&lt;scheme&gt;]{&lt;char-class-1&gt;}{&lt;char-class-2&gt;}{&lt;tokens&gt;}| defines tokens to be
        inserted between `&lt;char-class-1&gt;' and `&lt;char-class-2&gt;' (in that order) in the specified
        scheme. For example,
\begin{verbatim}
\interchartoks[foo]{0}{\myclass}{\bgroup\color{red}}
\interchartoks[foo]{\myclass}{0}{\egroup}
\end{verbatim}
  \item |\getinterchartoks[&lt;scheme&gt;]{&lt;char-class-1&gt;}{&lt;char-class-2&gt;}{\cs}| gets the tokens to be
        inserted between `&lt;char-class-1&gt;' and `&lt;char-class-2&gt;' in the specified scheme, and stores
        the result in `\cs'. For example,
        \begin{verbatim}\getinterchartoks[foo]{0}{\myclass}{\mytoks}\end{verbatim}
\end{itemize}

\section{Commands for macro writers}

For macro writers, we provide |\NewIntercharScheme| command which is an alias of user command `\newintercharscheme'. When you write `\NewIntercharScheme{foo}', 'interchar' package also 
creates the following migration commands for you:

\begin{table}[H]
\MakeNormal\&amp; \MakeNormal\` \MakeNormal\| \catcode`\?=13 \let?=| \MakeActive\` \MakeActive\|
\renewcommand{\arraystretch}{1.4}
\begin{tabular}{?l?l?}
  \hline
  \textbf{Migration Command} &amp; \textbf{Analogous to Commands} \\ \hline
  |\FooIntercharState = &lt;state-code&gt;| &amp; `\XeTeXinterchartokenstate' \\
  |\GetFooIntercharState| &amp; `\the\XeTeXinterchartokenstate' \\
  |\NewFooIntercharClass &lt;control-sequence&gt;| &amp; `\newXeTeXintercharclass' \\
  |\FooIntercharClass &lt;char-code&gt; = &lt;char-class&gt;| &amp; `\XeTeXcharclass' \\
  |\GetFooIntercharClass &lt;char-code&gt;| &amp; `\the\XeTeXcharclass'. \\
  |\FooIntercharToks &lt;class1&gt; &lt;class2&gt; = {&lt;toks&gt;}| &amp; `\XeTeXinterchartoks' \\
  |\GetFooIntercharToks &lt;class1&gt; &lt;class2&gt;| &amp; `\the\XeTeXinterchartoks' \\
  \hline
\end{tabular}
\end{table}

Within the command specifications in the above table, all of the equal signs `='
and most of the spaces are optional.

If you are the author of package 'foo' which use XeTeX\rq s char class mechanism,
with some minor changes you could make your package compatible with other packages.

\begin{enumerate}
  \item Add the following lines to the beginning of your package file:
\begin{verbatim}
\ifdefined\NewIntercharScheme
    \NewIntercharScheme{foo}%
\else
    \let \FooIntercharState = \XeTeXinterchartokenstate
    \def \GetFooIntercharState {\the\XeTeXinterchartokenstate}%
    \let \NewFooIntercharClass = \newXeTeXintercharclass
    \let \FooIntercharClass = \XeTeXcharclass
    \def \GetFooIntercharClass {\the\XeTeXcharclass}%
    \let \FooIntercharToks = \XeTeXinterchartoks
    \def \GetFooIntercharToks {\the\XeTeXinterchartoks}%
\fi
\end{verbatim}
  \item Rename every occurrence of XeTeX\rq s commands in your package file with the new name
        according to the above table.
\end{enumerate}

After these modifications, when users doesn\rq t load 'interchar', your package should
behave as before, but when users load 'interchar' package \textbf{before} your package,
'interchar' will takes over XeTeX\rq s char class mechanism, therefore users could switch
among different char class schemes at will.

Note that `\GetFooIntercharState' is \textbf{fully expandable}, which means you could write
the following conditional test:
\begin{verbatim}\ifnum \GetFooIntercharState &gt; 0 doA \else doB \fi\end{verbatim}
However `\GetFooIntercharClass' and `\GetFooIntercharToks' are
\textbf{not fully expandable} for the time being.

\section{Implementation}

%\AutoCmdSyntaxVerb
\NoEmptyCodeLines
\MakeInputJobDoc[sty][ltx]{0}{\ProcessInputWith{PScomment}}

\end{document}
</pre></body></html>