Indubitably, I need to remix Chinese and English in one document. But English characters in Chinese fonts aren’t look good in most time as others, so font fallback is needed here.
First, make a English font as a fallback of Chinese font:
\definefontsynonym[song][name:adobesongstd] \definefontfallback[hereos][name:texgyreherosregular][0x0000-0x0400] \definefontsynonym[fbsong][song][fallbacks=hereos] \definefont[newsong][fbsong] \setscript[hanzi] \starttext \newsong 夹杂 English 的中文文本 \stoptext |
This means we use texgyreherosregular as the fallback English font and name it as hereos, 0x0000-0x0400 is the interval of English characters in UTF-8 encoding. Then make “fbsong” the new font that is the remix of song (adobesongstd) and fallback hereos (texgyreherosregular).
But on the tutorial I am following, the author said such action will lose some feature when ConTeXt processing English, so change to using a Chinese font as a fallback of English font:
\definefontsynonym[hereos][name:texgyreherosregular] \definefontfallback[song][name:adobesongstd][0x00400-0x2FA1F] \definefontsynonym[fbsong][hereos][fallbacks=song] \definefont[newsong][fbsong] \setscript[hanzi] \starttext \newsong 夹杂~English~的中文文本 \stoptext |
Then I’ve rewritten my type-myfonts.tex with fallback font:
\starttypescript[serif][fbfont] \definefontsynonym[enserif][name:dejavuserif] \definefontsynonym[enserifbd][name:dejavuserifbold] \definefontsynonym[enserifit][name:dejavuserifitalic] \definefontsynonym[enserifbi][name:dejavuserifbolditalic] \definefontfallback[umingcn][name:arplumingcn][0x00400-0x2FA1F] \definefontsynonym[Serif][enserif][fallbacks=umingcn] \definefontsynonym[SerifBold][enserifbd][fallbacks=umingcn] \definefontsynonym[SerifItalic][enserifit][fallbacks=umingcn] \definefontsynonym[SerifBoldItalic][enserifbi][fallbacks=umingcn] \stoptypescript \starttypescript [sans][fbfont] \definefontsynonym[ensans][name:dejavusans] \definefontsynonym[ensansbd][name:dejavusansbold] \definefontsynonym[ensansob][name:dejavusansoblique] \definefontsynonym[ensansbo][name:dejavusansboldoblique] \definefontfallback[ukaicn][name:arplukaicn][0x00400-0x2FA1F] \definefontsynonym[Sans][ensans][fallbacks=ukaicn] \definefontsynonym[SansBold][ensansbd][fallbacks=ukaicn] \definefontsynonym[SansOblique][ensansob][fallbacks=ukaicn] \definefontsynonym[SansBoldOblique][ensansbo][fallbacks=ukaicn] \stoptypescript \starttypescript [mono][fbfont] \definefontsynonym[enmono][name:dejavusansmono] \definefontsynonym[enmonobd][name:dejavusansmonobold] \definefontsynonym[enmonoob][name:dejavusansmonooblique] \definefontsynonym[enmonobo][name:dejavusansmonoboldoblique] \definefontfallback[microhei][name:wenquanyimicroheimono][0x00400-0x2FA1F] \definefontsynonym[Mono][enmono][fallbacks=microhei] \definefontsynonym[MonoBold][enmonobd][fallbacks=microhei] \definefontsynonym[MonoOblique][enmonoob][fallbacks=microhei] \definefontsynonym[MonoBoldOblique][enmonobo][fallbacks=microhei] \stoptypescript \starttypescript[myfonts] \definetypeface[myfonts][rm][serif][fbfont] \definetypeface[myfonts][ss][sans][fbfont] \definetypeface[myfonts][tt][mono][fbfont] \stoptypescript |
And here is an example:
\usetypescriptfile[type-myfonts] \usetypescript[myfonts] \setupbodyfont[myfonts,rm,12pt] \setupbodyfontenvironment [default] [em=italic] % slanted is default emphasize in ConTeXt \setscript[hanzi] \pdfoptionpdfminorversion=6 \pdfcompresslevel=9 \starttext \startcomment this is a test comment, you shouldn't see me. \stopcomment 我们在运行 \CONTEXT{} \rm 这是 fbfont 里的 serif,dejavuserif+arplumingcn \\ \ss 这是 fbfont 里的 sans,dejavusans+arplukaicn \\ \tt 这是 fbfont 里的 mono,dejavusansmono+wenquanyimicroheimono \\ \stoptext |
“setupbodyfontenvironment” is a command that tell ConTeXt our body’s font environment, here we change nothing but emphasis to italic instead of default slanted face.
“%” is used to take comments and the TeX engine won’t do anything with items after it to the line’s ending. Multi-lines comments can be achieved by using “\startcomment … \stopcomment”.
“\pdfoptionpdfminorversion” is the setting for pdf option in minor version, and we can have a table to list it:
* (1993) – PDF 1.0 / Acrobat 1.0
* (1994) – PDF 1.1 / Acrobat 2.0
* (1996) – PDF 1.2 / Acrobat 3.0
* (1999) – PDF 1.3 / Acrobat 4.0
* (2001) – PDF 1.4 / Acrobat 5.0
* (2003) – PDF 1.5 / Acrobat 6.0
* (2005) – PDF 1.6 / Acrobat 7.0
* (2006) – PDF 1.7 / Acrobat 8.0
* (2008) – PDF 1.7, Adobe Extension Level 3 / Acrobat 9.0
The value of “pdfoptionpdfminorversion” is that x in “1.x”, in this example, “\pdfoptionpdfminorversion=6”, we set the version to PDF 1.6, correspond to Acrobat 7.0. The default setting is version 5 – PDF 1.5 for Acrobat 6.0.
“pdfcompresslevel” is the compress level of output pdf file, 0 is the least and 9 highest. Default setting is 0.
“\CONTEXT” is a sequence to produce the effect of sinking e in TEX. Other interesting are “\LATEX” “\TEX”, also “\LaTeX” and “\TeX” is acceptable, but I didn’t find how to produce a LaTeX2e, not “\LaTeXe” in LaTeX.
The {} after “\CONTEXT{}” tell the TeX engine don’t eat all extra whitespace and empty lines.
“\\” means force line breaking, we cannot use “\newline” as LaTeX does.