| 1 |
|
| 2 |
|
| 3 |
fontwrap package for XeLaTex |
| 4 |
---------------------------- |
| 5 |
Michiel Kamermans, june 2008 |
| 6 |
Available under GPL |
| 7 |
|
| 8 |
|
| 9 |
What is it? |
| 10 |
-------------- |
| 11 |
|
| 12 |
fontwrap is a package for XeLaTeX to automatically |
| 13 |
wrap multilingual utf8 encoded text in approriate |
| 14 |
font tags, issuing fontspec commands whenever text |
| 15 |
switches from one unicode block to another. As most |
| 16 |
of us use TeX in order to separate visual styling |
| 17 |
from the actual document as much as possible, this |
| 18 |
package removes the need to add fonttags all over |
| 19 |
the place when writing multilingual documents. |
| 20 |
|
| 21 |
|
| 22 |
... Example? |
| 23 |
-------------- |
| 24 |
|
| 25 |
Say you have a mixed text of English and Japanese, |
| 26 |
going something like this: |
| 27 |
|
| 28 |
"English and nihongo can both be written in utf8" |
| 29 |
|
| 30 |
with the word "nihongo" written in Japanes. |
| 31 |
the fontwrap package can automatically change |
| 32 |
this to the following: |
| 33 |
|
| 34 |
"\fontspec{SomeFont}English and \fontspec{OtherFont} |
| 35 |
nihongo\fontspec{SomeFont}\ can both be written in |
| 36 |
utf8" |
| 37 |
|
| 38 |
where 'SomeFont' is a font you picked for English |
| 39 |
- or rather, Latin - text, and 'OtherFont' is a |
| 40 |
font you picked for Japanese text. |
| 41 |
|
| 42 |
|
| 43 |
How do I use it? |
| 44 |
-------------- |
| 45 |
|
| 46 |
simply use the fontwrap package like any other, and |
| 47 |
wrap whichever text you want automatically font tagged |
| 48 |
with the following command: |
| 49 |
|
| 50 |
\fontwrap{...your text here...} |
| 51 |
|
| 52 |
Both the fontwrap.tex and fontwrap_example.tex files |
| 53 |
contain examples of this. |
| 54 |
|
| 55 |
Of course, fontwrap needs to know which fonts you want |
| 56 |
to use for which blocks, for which there are a few |
| 57 |
basic commands: |
| 58 |
|
| 59 |
\setfontwrapdefaultfont{Font Name} |
| 60 |
|
| 61 |
where 'Font Name' is the name of the font as you'd use |
| 62 |
it in a word processor (and capitalisation counts!). To |
| 63 |
then override the default, you can set fonts either for |
| 64 |
single unicode blocks, or for entire informal unicode |
| 65 |
groups: |
| 66 |
|
| 67 |
\setunicodeblockfont{BLock Name}{Font Name} |
| 68 |
|
| 69 |
\setunicodegroupfont{BLock Name}{Font Name} |
| 70 |
|
| 71 |
There are a small number of groups to pick from (namely |
| 72 |
Arabic, Chinese, CJK (which combines all Chinese, |
| 73 |
Japanese and Korean blocks), Cyrillic, Diacritics, |
| 74 |
Greek (including some Coptic), Korean, Japanese, Latin, |
| 75 |
Mathematics, Phonetics, Punctuation, Symbols, Yi and |
| 76 |
'Other'). There are few more blocks (158 of them), so |
| 77 |
I won't list all of there here - please see the more |
| 78 |
detailed pdf documentation for which specific blocks |
| 79 |
you can set fonts for. |
| 80 |
|
| 81 |
In addition to these fonts, you also need to instruct |
| 82 |
fontwrap which macros and environments it is allowed |
| 83 |
to process the content of, because by default it will |
| 84 |
skip over any macros or environments it is wrapping. |
| 85 |
|
| 86 |
\setfontwrapallowedmacros{macro list} |
| 87 |
|
| 88 |
\setfontwrapallowedenvironments{env. list} |
| 89 |
|
| 90 |
For both these commands, the lists are comma delimited, |
| 91 |
so that if you want fontwrap to process the content of |
| 92 |
emph, ruby and section macros, you would pass it the |
| 93 |
list "emph,ruby,section". |
| 94 |
|
| 95 |
|
| 96 |
Special notes |
| 97 |
-------------- |
| 98 |
|
| 99 |
This package requires you use perltex, which is just |
| 100 |
a wrapper for xelatex. if you use Tex Live or MikTeX |
| 101 |
then you should either already have it installed, |
| 102 |
or it should grab perltex automatically for you. |
| 103 |
The command is also rather simple: |
| 104 |
|
| 105 |
perltex --latex=xelatex inputfile.tex |
| 106 |
|
| 107 |
Running this when using fontwrap may result in a |
| 108 |
number of warnings/errors: |
| 109 |
|
| 110 |
1) free to wrong pool |
| 111 |
|
| 112 |
perltex can, in some cases, perform mem cleanup on |
| 113 |
the wrong thread. This will not affect your document |
| 114 |
in any way. it's just annoying. |
| 115 |
|
| 116 |
2) no unicode mapping available |
| 117 |
|
| 118 |
a font you picked for some block of text does not |
| 119 |
contain the characters of that text. this is common |
| 120 |
when using foreign language in a verbatim block. |