diff options
author | Karl Berry <karl@freefriends.org> | 2012-09-25 23:04:51 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-09-25 23:04:51 +0000 |
commit | eb411ed661c178e451eb3dd55d6ee8bc154c1265 (patch) | |
tree | 4658020be8d565c5639dd20164c5d9e83ac454da /Master/texmf-dist/doc/xelatex/ucharclasses | |
parent | bfe53688ab950cd41271c259a29df8dd5eff29cd (diff) |
new-to-TL xelatex package ucharclasses (25sep12)
git-svn-id: svn://tug.org/texlive/trunk@27811 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/xelatex/ucharclasses')
-rw-r--r-- | Master/texmf-dist/doc/xelatex/ucharclasses/README | 64 | ||||
-rw-r--r-- | Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.pdf | bin | 0 -> 161345 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.tex | 490 |
3 files changed, 554 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/xelatex/ucharclasses/README b/Master/texmf-dist/doc/xelatex/ucharclasses/README new file mode 100644 index 00000000000..3ff53493141 --- /dev/null +++ b/Master/texmf-dist/doc/xelatex/ucharclasses/README @@ -0,0 +1,64 @@ + ucharclasses package for XeLaTex + -------------------------------- + Michiel Kamermans, October 2011 + +The brief +--------- + + Sometimes you don't want to have to bother with font + switching just because you're using languages that are + distinct enough to use different unicode blocks, but + aren't covered by the polyglossia package. Where normal + word processing packages such as Microsoft Word or + OpenOffice Writer handle this for you, LATEX (because it + needs you to tell it what to do) has no default behaviour + for this, and so we arrive at a need for a package that + does this for us. You probably already discovered that + regular LATEX has no understanding of unicode, and ended + up going for Xe(La)TeX as your TeX compiler of choice, + which means you now have two excellent resources available: + fontspec, and ucharclasses. + + The first of these lets you pick fonts based on what your + system calls them, without needing to do anything special + such as turning them into metafonts. This is convenient, + user friendly, and the way of the future (at least, it + should be). + + The second lets you define what should happen when your + text changes from a character in one unicode block, to a + character in another. This is also convenient, and paired + with fontspec it offers automatic font switching in the + same way that normal Office applications perform, with + one big difference: you stay in control. If at some point + you need the switch rule to do something different, + you will be out of luck using an Office application. + In Xe(La)TeX, you stay on top of things and still get to + say exactly what happens, and when. + +So what is it? +-------------- + + This package sets up XeTeX character classes based on + which unicode block a character is found in. It then + allows transition rules to be defined when entering or + leaving particular unicode blocks, the code of which + gets inserted automatically when a transition from a + character from one unicode block to a character from + another unicode block is encountered by XeTeX + + Current compatibility should be Unicode 6.0, although + I may have missed one or more blocks that were added + between 5 and 6. + +license? +-------- + + Public Domain + http://www.tex.ac.uk/CTAN/help/Catalogue/licenses.pd.html + + +Repository? +----------- + + https://github.com/Pomax/ucharclasses
\ No newline at end of file diff --git a/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.pdf b/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.pdf Binary files differnew file mode 100644 index 00000000000..b58263c0c6e --- /dev/null +++ b/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.pdf diff --git a/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.tex b/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.tex new file mode 100644 index 00000000000..d6593e2cd73 --- /dev/null +++ b/Master/texmf-dist/doc/xelatex/ucharclasses/ucharclasses.tex @@ -0,0 +1,490 @@ +\documentclass{article} +\usepackage{tocloft} +\usepackage[pdfborder=0]{hyperref} +\usepackage{multicol} + +\renewcommand{\labelitemi}{・} + +% some custom environments, to force on-same-page-ness + +\newenvironment{itemlist}{% + \begin{itemize} + \setlength{\itemsep}{0pt} + \setlength{\parsep}{0pt} + \setlength{\topsep}{0pt} + \setlength{\partopsep}{0pt} + \setlength{\parskip}{0pt} + \setlength{\labelsep}{5pt}}% +{ + \end{itemize}} + +\newenvironment{numberlist}{% + \begin{enumerate} + \setlength{\itemsep}{0pt} + \setlength{\parsep}{0pt} + \setlength{\topsep}{0pt} + \setlength{\partopsep}{0pt} + \setlength{\parskip}{0pt} + \setlength{\labelsep}{5pt}}% +{ + \end{enumerate}} + +% and the font switching magic +\usepackage[CJK, Latin, Thai, Sinhala, Malayalam, DominoTiles, MahjongTiles]{ucharclasses} +\usepackage{fontspec} + +% default transition uses the widest coverage font I know of +\setDefaultTransitions{\fontspec{Code2000}}{} + +% overrides on the default rules for specific informal groups +\setTransitionsForLatin{\fontspec{Palatino Linotype}}{} +\setTransitionsForCJK{\fontspec{HAN NOM A}}{} +\setTransitionsForJapanese{\fontspec{Ume Mincho}}{} + +% overrides on the default rules for specific unicode blocks +\setTransitionTo{CJKUnifiedIdeographsExtensionB}{\fontspec{SimSun-ExtB}} +\setTransitionTo{Thai}{\fontspec{IrisUPC}} +\setTransitionTo{Sinhala}{\fontspec{Iskoola Pota}} +\setTransitionTo{Malayalam}{\fontspec{Arial Unicode MS}} +\setTransitionTo{DominoTiles}{\fontspec{FreeSerif}} +\setTransitionTo{MahjongTiles}{\fontspec{FreeSerif}} + +\begin{document} + + \title{ucharclasses} + \author{Mike “Pomax” Kamermans} + \date{\today} + \maketitle + + \tableofcontents + + \pagebreak + + \section{Introduction} + + Sometimes you don't want to have to bother with font switching just because you're languages that are distinct enough to use different Unicode blocks, but aren't covered by the polyglossia package. Where normal word processing packages such as MS, Star- or OpenOffice pretty much handle this for you, \LaTeX\ (because it needs you to tell it what to do) has no default behaviour for this, and so we arrive at a need for a package that does this for us. You already discovered that regular \LaTeX\ has no understanding of Unicode (in fact, it has no understanding of 8-bit characters at all, it likes them in seven bits instead), and ended up going for Xe(La)TeX as your TeX compiler of choice, which means you now have two excellent resources available: fontspec, and ucharclasses. + + The first of these lets you pick fonts based on what your system calls them, without needing to rewrite them as metafont files. This is convenient. This is good. The second lets you define what should happen when we change from a character in one Unicode block, to a character in another. This is also convenient, and paired with fontspec it offers automatic fontswitching in the same way that normal Office applications take care of this with you. With one big difference: you stay in control. If at some point you need the switch rule to use a completely different rule, in an Office application that's just too bad for you. In Xe(La)TeX, you stay on top of things and still get to say exactly what happens, and when. + + For instance, this document has no explicit font codes in the text itself, anywhere. Instead there are a few Unicode block transition rules defined, which all say “when entering block ..., use fontspec to change the font to ...”. As such, typesetting the following list in the appropriate fonts just works: + + \begin{itemlist} + \item English: This is an English phrase (using Palatino Linotype) + \item Japanese: 日本語が分かりますか (using Ume Mincho) + \item Thai: คุณพูดภาษาอังกฤษได้ไหม (using IrisUPC) + \item Sinhala: කරැණාකරල ඒක නැවත කියන්න පුළුවන්ද (using Iskoola Pota) + \item Malayalam: നിങ്ങളുടെ പേരെന്താണ്? (using Arial Unicode MS) + \item and even domino tiles, 🁇 🀼 🁐 🁋 🁚 🁝, and mahjong tiles: 🀑 🀑 🀑 🀒 🀒 🀒 🀕 🀕 🀕 🀗 🀗 🀗 🀅 🀅 (using FreeFont) + \end{itemlist} + + However, be aware that this only “just works” for Unicode blocks. If you are working with typographically overlapping languages, such as combining English and Vietnamese in one document, things get a lot more complex if you want one font for English and another for Vietnamese. Both of these languagese use Latin blocks, so it is inherently impossible to tell which language is intended based on which Unicode block a character in a word belongs to. + + As an example, this document uses one rule for applying a font for general CJK, and an override with a different font for all Japanese-specific CJK characters. This causes a problem for Chinese, because most Japanese fonts contain fewer characters than are necessary to typeset Chinese: + + \begin{itemlist} + \item Chinese, using the Japanese CJK font, which may have gaps: 我的母语是汉语 (uses Ume Mincho, which does not contain the three Chinese-specific characters used in that phrase) + \end{itemlist} + + We can get around this by turning off automatic font switching, and using an explicit command to temporarily set the font to one that has full Chinese support, using \{\textbackslash uccoff + a fontspec rule + the text we wanted to typeset + \textbackslash uccon\}. This gives us: {\uccoff \fontspec{HAN NOM A} 我的母语是汉语 \uccon} (This now explicitly uses Han Nom A) + + \section{Use} + + In order to get this all to work, the only thing that had to be incidated was a set of transition rules in the preamble: + + \disableTransitionRules + \begin{verbatim} + \usepackage[CJK, Latin, Thai, Sinhala, Malayalam, + DominoTiles, MahjongTiles]{ucharclasses} + \usepackage{fontspec} + \usepackage{bidi} + + \setDefaultTransitions{\fontspec{Code2000}}{} + \setTransitionsForLatin{\fontspec{Palatino Linotype}}{} + \setTransitionsForCJK{\fontspec{SimSun}{} + \setTransitionsForJapanese{\fontspec{Ume Mincho}}{} + + \setTransitionTo{Thai}{\fontspec{IrisUPC}} + \setTransitionTo{Sinhala}{\fontspec{Iskoola Pota}} + \setTransitionTo{Malayalam}{\fontspec{Arial Unicode MS}} + \setTransitionTo{DominoTiles}{\fontspec{FreeSerif}} + \setTransitionTo{MahjongTiles}{\fontspec{FreeSerif}} + \end{verbatim} + \enableTransitionRules + + By default, ucharclasses is agnostic with regards to what you want to at the start or end of Unicode blocks, so while using it for fontswitching is the most obvious application, you could also use it for far more creative purposes. + + \subsection{Overriding ucharclass transitions} + + If you need to “override” ucharclass transition rules (for instance, you want a custom font for a bit of cross-Unicode-block text), you will want to temporarily disable and reenabled XeTeX's interchartoks state. You can do this in three ways: + + \begin{numberlist} + \item call [\textbackslash XeTeXinterchartokstate = 0] before, and [\textbackslash XeTeXinterchartokstate = 1] after you're done, + \item call the macros \textbackslash disableTransitionRules before, and \textbackslash enableTransitionRules after you're done, or + \item call \textbackslash uccoff before, and \textbackslash uccon after you're done. + \end{numberlist} + + This last option is mainly there because it's nice and short, and is more convenient in a scoped environment \{\textbackslash uccoff such as this\textbackslash uccon\} where you only want to override the transition behaviour within a paragraph. If you need it disabled for a few blocks of text instead, the full name commands are probably a better choice, because it makes your .tex more readable. As the base XeTeX command uses the un\LaTeX y “... = ...” construction, it's best to avoid it outside of the preamble (and when using ucharclasses, should not be in the preamble at all). + + \section{Problems with RTL languages} + + The overlapping block problem is especially notable when using RTL/LTR rules for languages such as Arabic or Hebrew. While you would want to be able to specify something along the lines of: + + \begin{verbatim} + \setTransitionsForArabic{\fontspec{Tahoma}\setRTL}{\setLTR} + \end{verbatim} + + this will not work, because Arabic (and Hebrew, and other RTL languages) has things like spaces in it, and so rather than ending with a full sentence that starts with \textbackslash setRTL, then the Arabic text, and then finally \textbackslash setLTR, every word in the Arabic sentence will be wrapped by \textbackslash setRTL and \textbackslash setLTR, effectively getting the typesetting all wrong, because going from Arabic to a space character “leaves” the Arabic block, so the transition rule for leaving the Arabic block is applied. + + If you need script support, rather than Unicode blocks, you may want to have a look at the polyglossia package instead. You can try to combine the two packages by relying on \textbackslash uccoff and textbackslash uccon to turn off Unicode block transitions inside regions of text, but this may not always work, or may have interesting interaction side-effects. + + \section{Commands} + + \subsection{\textbackslash setTransitionTo[2]} + + This command has two arguments: + + \begin{numberlist} + \item The name of the Unicode class to which the transition should apply (see 'Unicode blocks' list) + \item The code you want used when entering this Unicode block + \end{numberlist} + + \subsection{\textbackslash setTransitionFrom[2]} + + This command has two arguments: + + \begin{numberlist} + \item The name of the Unicode class to which the transition should apply (see 'Unicode blocks' list) + \item The code you want used when exiting this Unicode block + \end{numberlist} + + \subsection{\textbackslash setTransitions[3]} + + This command has three arguments: + + \begin{numberlist} + \item The name of the Unicode class to which the transition should apply (see 'Unicode blocks' list) + \item The code you want used when entering this Unicode block + \item The code you want used when exiting this Unicode block + \end{numberlist} + + \subsection{\textbackslash setTransitionsForXXXX[2]} + + There are a number of these commands, pertaining to particular “informal groups”: collections of Unicode blocks which can be considered part of a single meta-block. Available informal groups (the names of which replace the XXXX in the section-stated command) are: + + \begin{itemlist} + \item FullArabic + \item Chinese + \item CJK + \item FullCyrillic + \item Diacritics + \item Greek + \item Korean + \item Japanese + \item Latin + \item Mathematics + \item Phonetics + \item Punctuation + \item Symbols + \item Yi + \end{itemlist} + + Furthermore, these commands have two arguments: + + \begin{numberlist} + \item The code you want used when entering blocks from the command's informal group + \item The code you want used when exiting blocks from the command's informal group + \end{numberlist} + + \subsection{\textbackslash setDefaultTransitions[2]} + + This is a blanket command that lets you set up the same to and from transition rules for all blocks in one go. It has (fairly obviously) two arguments: + + \begin{numberlist} + \item The code you want used when entering any Unicode block + \item The code you want used when exiting any Unicode block + \end{numberlist} + + \section{Code} + + The code relies on running through individual definition blcosk for each Unicode blocks, conditioned to whether ucharclasses is loaded with package options or not: + + \pagebreak + + \disableTransitionRules + \begin{verbatim} + ... + \ifboolexpr{ + togl {@loadAll} or togl {@loadBasicLatin} + }{\@defineUnicodeClass{\BasicLatinClass}{32}{127}} + ... + \end{verbatim} + \enableTransitionRules + + The classes are automatically numbered by using the \textbackslash newXeTeXintercharclass command, and every time a new class is defined, the class counter goes up. After all desired classes have been defined, the code iterates over the class numbers from lower bound to upper bound. + + The block loading code is defined as follows: + + \disableTransitionRules + \begin{verbatim} + \newcounter{glyphcounter} + \newcommand{\@defineUnicodeClass}[3]{ + \newXeTeXintercharclass#1 + \forloop{glyphcounter}{#2}{\value{glyphcounter}<#3}{ + \XeTeXcharclass\value{glyphcounter}=#1} + \XeTeXcharclass#3=#1} + + \newXeTeXintercharclass\@classstart + ... + \ifboolexpr{ + togl {@loadAll} or togl {@loadBasicLatin} + }{\@defineUnicodeClass{\BasicLatinClass}{32}{127}} + ... + \newXeTeXintercharclass\@classend + \end{verbatim} + \enableTransitionRules + + And the transition commands are defined as follows: + + \disableTransitionRules + \begin{verbatim} + \newcommand{\setTransitionsFor}[3]{ + \forloop{iclass}{he\@classstart}{\value{iclass} < \@nameuse{#1Class}}{ + \@transition{he\value{iclass}}{\@nameuse{#1Class}}{{#2}} + \@transition{\@nameuse{#1Class}}{he\value{iclass}}{{#3}}} + \addtocounter{iclass}{2} + \forloop{iclass}{\value{iclass}}{\value{iclass} < he\@classend}{ + \@transition{he\value{iclass}}{\@nameuse{#1Class}}{{#2}} + \@transition{\@nameuse{#1Class}}{he\value{iclass}}{{#3}}} + % and a binding for the transitions to and from boundary characters + \@transition{255}{\@nameuse{#1Class}}{{#2}} + \@transition{\@nameuse{#1Class}}{255}{{#3}}} + + \newcommand{\setTransitionTo}[2] { + \forloop{iclass}{\the\@classstart}{\value{iclass} < \@nameuse{#1Class}}{ + \@transition{\the\value{iclass}}{\@nameuse{#1Class}}{{#2}}} + \addtocounter{iclass}{2} + \forloop{iclass}{\value{iclass}}{\value{iclass} < \the\@classend}{ + \@transition{\the\value{iclass}}{\@nameuse{#1Class}}{{#2}}} + % and a binding for the transition from boundary characters + \@transition{255}{\@nameuse{#1Class}}{{#2}}} + + \newcommand{\setTransitionFrom}[2]{ + \forloop{iclass}{\the\@classstart}{\value{iclass} < \@nameuse{#1Class}}{ + \@transition{\@nameuse{#1Class}}{\the\value{iclass}}{{#2}}} + \addtocounter{iclass}{2} + \forloop{iclass}{\value{iclass}}{\value{iclass} < \the\@classend}{ + \@transition{\@nameuse{#1Class}}{\the\value{iclass}}{{#2}}} + % and a binding for the transition to boundary characters + \@transition{\@nameuse{#1Class}}{255}{{#2}}} + \end{verbatim} + \enableTransitionRules + + The broad level \textbackslash setTransitionsFor(InformalGroupName)[2] commands are essentially wrapper commands, calling \textbackslash setTransitionsFor for each blocks that is in the informal group. For Arabic, for instance, the code is: + + \disableTransitionRules + \begin{verbatim} + \newcommand{\setTransitionsForArabic}[2]{ + \setTransitionsFor{Arabic}{#1}{#2} + \setTransitionsFor{ArabicPresentationFormsA}{#1}{#2} + \setTransitionsFor{ArabicPresentationFormsB}{#1}{#2} + \setTransitionsFor{ArabicSupplement}{#1}{#2} + } + \end{verbatim} + \enableTransitionRules + + \section{Package options and Unicode blocks} + + The following Unicode blocks are available for use in transition rules, as well as for use as package options when you want ucharclasses to only load those classes that you know are used in your document: + + \begin{multicols}{2} + \begin{itemlist} + \item AegeanNumbers + \item AlphabeticPresentationForms + \item AncientGreekMusicalNotation + \item AncientGreekNumbers + \item AncientSymbols + \item Arabic + \item ArabicPresentationFormsA + \item ArabicPresentationFormsB + \item ArabicSupplement + \item Armenian + \item Arrows + \item Balinese + \item BasicLatin + \item Bengali + \item BlockElements + \item Bopomofo + \item BopomofoExtended + \item BoxDrawing + \item BraillePatterns + \item Buginese + \item Buhid + \item ByzantineMusicalSymbols + \item Carian + \item Cham + \item Cherokee + \item CJKCompatibility + \item CJKCompatibilityForms + \item CJKCompatibilityIdeographs + \item CJKCompatibilityIdeographsSupplement + \item CJKRadicalsSupplement + \item CJKStrokes + \item CJKSymbolsandPunctuation + \item CJKUnifiedIdeographs + \item CJKUnifiedIdeographsExtensionA + \item CJKUnifiedIdeographsExtensionB + \item CombiningDiacriticalMarks + \item CombiningDiacriticalMarksforSymbols + \item CombiningDiacriticalMarksSupplement + \item CombiningHalfMarks + \item ControlPictures + \item Coptic + \item CountingRodNumerals + \item Cuneiform + \item CuneiformNumbersandPunctuation + \item CurrencySymbols + \item CypriotSyllabary + \item Cyrillic + \item CyrillicExtendedA + \item CyrillicExtendedB + \item CyrillicSupplement + \item Deseret + \item Devanagari + \item Dingbats + \item DominoTiles + \item EnclosedAlphanumerics + \item EnclosedCJKLettersandMonths + \item Ethiopic + \item EthiopicExtended + \item EthiopicSupplement + \item GeneralPunctuation + \item GeometricShapes + \item Georgian + \item GeorgianSupplement + \item Glagolitic + \item Gothic + \item GreekandCoptic + \item GreekExtended + \item Gujarati + \item Gurmukhi + \item HalfwidthandFullwidthForms + \item HangulCompatibilityJamo + \item HangulJamo + \item HangulSyllables + \item Hanunoo + \item Hebrew + \item Hiragana + \item IdeographicDescriptionCharacters + \item IPAExtensions + \item Kanbun + \item KangxiRadicals + \item Kannada + \item Katakana + \item KatakanaPhoneticExtensions + \item KayahLi + \item Kharoshthi + \item Khmer + \item KhmerSymbols + \item Lao + \item LatinExtendedAdditional + \item LatinExtendedA + \item LatinExtendedB + \item LatinExtendedC + \item LatinExtendedD + \item LatinSupplement + \item Lepcha + \item LetterlikeSymbols + \item Limbu + \item LinearBIdeograms + \item LinearBSyllabary + \item Lycian + \item Lydian + \item MahjongTiles + \item Malayalam + \item MathematicalAlphanumericSymbols + \item MathematicalOperators + \item MiscellaneousMathematicalSymbolsA + \item MiscellaneousMathematicalSymbolsB + \item MiscellaneousSymbols + \item MiscellaneousSymbolsandArrows + \item MiscellaneousTechnical + \item ModifierToneLetters + \item Mongolian + \item MusicalSymbols + \item Myanmar + \item NewTaiLue + \item NKo + \item NumberForms + \item Ogham + \item OldChiki + \item OldItalic + \item OldPersian + \item OpticalCharacterRecognition + \item Oriya + \item Osmanya + \item PhagsPa + \item PhaistosDisc + \item Phoenician + \item PhoneticExtensions + \item PhoneticExtensionsSupplement + \item PrivateUseArea + \item Rejang + \item Runic + \item Saurashtra + \item Shavian + \item Sinhala + \item SmallFormVariants + \item SpacingModifierLetters + \item Specials + \item SuperscriptsandSubscripts + \item SupplementalArrowsA + \item SupplementalArrowsB + \item SupplementalMathematicalOperators + \item SupplementalPunctuation + \item SupplementaryPrivateUseAreaA + \item SupplementaryPrivateUseAreaB + \item SylotiNagri + \item Syriac + \item Tagalog + \item Tagbanwa + \item Tags + \item TaiLe + \item TaiXuanJingSymbols + \item Tamil + \item Telugu + \item Thaana + \item Thai + \item Tibetan + \item Tifinagh + \item Ugaritic + \item UnifiedCanadianAboriginalSyllabics + \item Vai + \item VariationSelectors + \item VariationSelectorsSupplement + \item VerticalForms + \item YiRadicals + \item YiSyllables + \item YijingHexagramSymbols + \end{itemlist} + \end{multicols} + + In addition, the informal blocks for use as package option are: + + \begin{itemlist} + \item FullArabic + \item Chinese + \item CJK + \item FullCyrillic + \item Diacritics + \item Greek + \item Korean + \item Japanese + \item Latin + \item Mathematics + \item Phonetics + \item Punctuation + \item Symbols + \item Yi + \end{itemlist} + +\end{document}
\ No newline at end of file |