[XeTeX] On cross-language font selection

Yin Dian yindian at gmail.com
Fri Feb 16 04:56:21 CET 2007


Hi jjgod,

   I came up with an inspiration yesterday night on the macro implementation
of font selection and space skipping. It is based on the thought of explicit
switch via the active tilde. After an hour's hack I've finished the
primitive part. Further development requires a judge for math mode and
parameterized commands, so the change of behavior of backslash and braces is
needed.

  Following is a test case encoded in UTF-8. Compiled successfully on my
XeTeX 2.2-0.996.

\catcode`@=11
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
\input xfwpunct.sty
\FWPsetcompactlig  % if you have xfwpunct.sty to judge the full-width
punctuation kerning
\font\zhfont="SimSun" at 12pt
\zhfont
\font\enfont="Times New Roman" at 12pt
\newskip\toggleskip % skip when toggling font
\newtoks\togglechinese
\toggleskip=0.3ex plus 0.6ex
\togglechinese={\enfont}
\long\def\xchin#1{\xchinese #1\endxchinese}
\def\xchinese{%
  \begingroup
  \xchinese at savespecials
  \let\xchinese at savespecials\relax % no further save needed
  \xchinese at makespecials
  \xchinese at iterate
}
\def\xchinese at savespecials{%
  \let\xchinese at oldtilde~
  \let\xchinese at oldtildecmd\~
}
{\catcode`\<=\active
\catcode`\>=\active
\catcode`\~=\active
\gdef\xchinese at makespecials{%
  \catcode`\<=\active
  \catcode`\>=\active
  \let<\xchinese at bgroup
  \let>\relax
  \let~\xchinese at tilde
  \let\~\xchinese at oldtilde
  \let\tild\xchinese at oldtildecmd
}%
}
\def\xchinese at restorespecials{%
  \catcode`\<=11
  \catcode`\>=11
  \let~\xchinese at oldtilde
  \let\~\xchinese at oldtildecmd
}
\long\def\xchinese at tilde#1~{%
  \begingroup
  \xchinese at restorespecials
  \the\togglechinese
  \hskip\toggleskip #1\hskip\toggleskip
  \endgroup
  \xchinese at iterate
}
{\catcode`\>=\active
\long\gdef\xchinese at bgroup#1>{%
  \xchinese
  #1\endxchinese
  \xchinese at iterate
}%
}
\long\def\xchinese at iterate#1{%
  \ifx #1\endxchinese
    \endxchinese
  \else
    \let\xchinese at iterate@next\xchinese at iterate
    \ifx #1\xchinese at tilde
      \let\xchinese at iterate@next\xchinese at tilde
    \else
      \ifx #1\xchinese at bgroup
        \let\xchinese at iterate@next\xchinese at bgroup
      \else
        \xchinese at restorespecials
        #1\xchinese at makespecials
      \fi
    \fi
    \expandafter\xchinese at iterate@next
  \fi
}
\def\endxchinese{%
  \endgroup
}

\line{\hrulefill}

\def\frac#1#2{\bgroup #1\over #2\egroup}
\xchinese

由图可见,~PID~控制器是通加对误差信号~$e(t)$~进行
比例、积分和微分运算,其结果的加权,得到控制器的输
出~$u(t)$~,该值就是控制对象的控制值。其输入
~$e(t)$~与输出~$u(t)$~的关系为:~

$$
u(t) = K_P e(t) + T_i \int_0^t e(\tau)d\tau + T_d \frac{de(t)}{dt}
$$~

\endxchinese

\xchinese\endxchinese

\bye


2007/2/14, Jjgod Jiang <gzjjgod at gmail.com>:
>
> Hi Peter and Bruno,
>
> 2007/2/14, Peter Dyballa <Peter_Dyballa at web.de>:
> > Font switching is not all, there should also happen a switch to a
> > different language with other typographic rules. Something like
> > Babel's \selectlanguage{} might be the right thing: switching the
> > text's language, switching the font and its script and language (like
> > fontspec offers), plus some internals like writing direction, glue ...
>
> I can understand your points now. Indeed, we guys using XeTeX
> to typeset Chinese are not very satified with glue between CJK
> characters and Latin characters. So the questions is, can we solve
> this problem at TeX macro level? If not, we still need low level
> mechanism provided by some XeTeX primitives.
>
> - jjgod.
> _______________________________________________
> XeTeX mailing list
> postmaster at tug.org
> http://tug.org/mailman/listinfo/xetex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/xetex/attachments/20070216/e774c484/attachment.html 


More information about the XeTeX mailing list