diff options
author | Karl Berry <karl@freefriends.org> | 2016-03-25 22:06:03 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2016-03-25 22:06:03 +0000 |
commit | f9e5222a931d1b2671fa84b5c93a4605c00c2373 (patch) | |
tree | 20ac69a38c367d4792d6e3aea532c5ba669fe10a /Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty | |
parent | 0cf37a0dcbc1de449eda38e14e357dd7b19dc5dd (diff) |
polyglossia (25mar16)
git-svn-id: svn://tug.org/texlive/trunk@40138 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty | 125 |
1 files changed, 76 insertions, 49 deletions
diff --git a/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty b/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty index 8d7f77e692b..ceece27c094 100644 --- a/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty +++ b/Master/texmf-dist/tex/latex/polyglossia/polyglossia.sty @@ -1,5 +1,5 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{polyglossia}[2015/08/06 v1.42.0 +\ProvidesPackage{polyglossia}[2015/03/25 v1.42.4 Alternative to Babel for XeLaTeX and LuaLaTeX] \RequirePackage{etoolbox} \RequirePackage{makecmds} @@ -26,6 +26,10 @@ \RequireLuaModule{polyglossia} \fi +% Useful for getting list of loaded languages and variants. Like babel's bbl@loaded +\let\xpg@loaded\@empty +\let\xpg@vloaded\@empty + %% custom message macros \providecommand*{\xpg@error}[1]{% \PackageError{polyglossia}{#1}{}% @@ -149,7 +153,7 @@ That is almost guaranteed to cause problems.} %% options currently available: %% language : the name of the language (as understood by fontspec) %% hyphennames : the different hyphenation patterns to try (comma separated list) -%%% TODO: if pattern is prefixed by !, then it should be loaded as a fallback, with \xpg@nopatterns@fallback - i.e. with a warning: e.g. sanskrit for hindi, or catalan for asturian. +%%% TODO: if pattern is prefixed by !, then it should be loaded as a fallback, with \xpg@nopatterns@fallback - i.e. with a warning: e.g. sanskrit for hindi, or catalan for asturian. – Also for languages with variants! (English and German, etc.) %% script : the name of the script (as understood by fontspec) – default is Latin %% direction : the direction of the script: LR or RL %% scripttag : the OpenType tag for the script @@ -163,6 +167,7 @@ That is almost guaranteed to cause problems.} %% TODO: localnumber = <csname> %% or even better localdigits = {0123456789} for fully automatic setup +\newif\if@xpg@language@really@defined@ \newcommand*\PolyglossiaSetup[2]{% %define booleans etoolbox style and set defaults %% TODO ? \providetoggle{#1@setup@done}% @@ -176,15 +181,16 @@ That is almost guaranteed to cause problems.} \csgdef{init@extras@#1}{}% \csgdef{init@noextras@#1}{}% we don't use this yet: remove? \csgdef{xpg@langname@#1}{\xpg@uppercasefirst{#1}}% - %needed for docvslist with hyphennames key: + %needed for docsvlist with hyphennames key: \def\do##1{% - \ifcsdef{l@#1}{}{% + \xpg@check@ifdefined{#1} + \if@xpg@language@really@defined@\else \ifstrequal{#1}{##1}{}% - {\ifcsdef{l@##1}% - {\csletcs{l@#1}{l@##1}\xpg@set@language@luatex@ii{##1}\listbreak}% - {}% + {\xpg@ifdefined{##1}% + {\expandafter\ifx\csname l@##1\endcsname\l@nohyphenation\else\csletcs{l@#1}{l@##1}\xpg@set@language@luatex@iv{##1}\fi}% + {\csdef{l@##1}{l@nohyphenation}}% }% - }% + \fi }% %define all keys: \xpg@define@keys{#1}% @@ -216,20 +222,18 @@ That is almost guaranteed to cause problems.} \csgdef{xpg@langtag@#1}{##1}}% \define@key[xpg@setup]{#1}{hyphennames}[{#1}]{% \docsvlist{##1}% - % \expandafter\show\csname l@##1\endcsname - % \expandafter\show\csname l@#1\endcsname % if l@#1 does not yet exist, % we assign it to nohyphenation % we do this here in case the hyphennames key was omitted - \ifcsundef{l@#1}% + \xpg@ifdefined{#1}{}% {\xpg@nopatterns{\csname xpg@langname@#1\endcsname}% - \expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax}{}% + \expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax}% \csdef{#1@language}{% \ifbool{xpg@hyphenation@disabled}{% \xdef\xpg@lastlanguage{\the\csname l@#1\endcsname}% }{% \ifluatex% - \xpg@set@language@luatex@ii{#1}% + \xpg@set@language@luatex@iv{#1}% \fi% \language=\csname l@#1\endcsname% }% @@ -240,7 +244,7 @@ That is almost guaranteed to cause problems.} \togglefalse{#1@RL}% \or \toggletrue{#1@RL}% - \ifcsundef{RTL}{\ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi}{}% + \ifcsundef{RTL}{\ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi}{}% FIXME Use \RequireBidi and remove calls in individual gloss files. \fi}% {\xpg@warning{#1: Invalid value \val\space for key "direction"}}% \define@key[xpg@setup]{#1}{hyphenmins}[{2,3}]% @@ -276,7 +280,7 @@ That is almost guaranteed to cause problems.} \ifbool{xpg@hyphenation@disabled}{}{% \booltrue{xpg@hyphenation@disabled}% \xdef\xpg@lastlanguage{\the\language}% - \xpg@set@language@luatex@ii{nohyphenation} + \xpg@set@language@luatex@iv{nohyphenation} \language=\l@nohyphenation% \ifluatex % \directlua{polyglossia.disable_hyphenation()}% @@ -516,6 +520,7 @@ That is almost guaranteed to cause problems.} \input{#1}\catcode`\@=\xpg@atcatcode} \newcommand{\setdefaultlanguage}[2][]{% + \edef\xpg@loaded{#2\ifx\xpg@loaded\@empty\else,\xpg@loaded\fi}% \IfFileExists{gloss-#2.ldf}% {\ifcsundef{#2@loaded}% {\xpg@input{gloss-#2.ldf}% @@ -630,6 +635,7 @@ That is almost guaranteed to cause problems.} } \newcommand{\setotherlanguage}[2][]{% + \edef\xpg@loaded{#2\ifx\xpg@loaded\@empty\else,\xpg@loaded\fi}% \IfFileExists{gloss-#2.ldf}% {\ifcsundef{#2@loaded}% {\xpg@input{gloss-#2.ldf}% @@ -724,11 +730,25 @@ That is almost guaranteed to cause problems.} \xpg@hook@setlanguage% \let\emp@langname\@undefined}% \aftergroup\xpg@pop@language% + % If the optional argument sets a value for the key “variant”, copy it to xpg@langvariant + \def\do##1{% + \def\xpg@parsekeyvalue####1=####2\relax{% + \def\@tmpa{####1} + \def\@tmpb{variant} + \ifx\@tmpa\@tmpb\setkeys{xpg@langvariant}{##1}\fi + }% + \xpg@parsekeyvalue##1=\relax + }% + \docsvlist{#1} \setkeys{#2}{#1}% \xpg@set@language{#2}% }% } +% Save any variant in csv list of variants +\define@key{xpg@langvariant}{variant}{% + \edef\xpg@vloaded{#1\ifx\xpg@vloaded\@empty\else,\xpg@vloaded\fi}} + \newcommand{\xpg@set@language}[1]{% \select@language{#1}% \if@filesw% @@ -739,22 +759,49 @@ That is almost guaranteed to cause problems.} \fi } +\def\xpg@set@language@luatex@iii#1#2{% + % here we use lu@texhyphen@loaded@\the\language, the same as in babel + \ifcsdef{bbl@hyphendata@#2}{}{% + \global\@namedef{bbl@hyphendata@\the\language}{}% + \directlua{polyglossia.select_language('\luatexluaescapestring{\string#1}', \the\csname l@#1\endcsname)}% + } +} + +\newcommand\xpg@check@ifdefined[1]{% + \expandafter\ifx\csname l@#1\endcsname\relax\@xpg@language@really@defined@false\else + \ifx\csname l@#1\endcsname\l@nohyphenation\@xpg@language@really@defined@false\else + \@xpg@language@really@defined@true + \fi + \fi +} + +\newcommand\xpg@ifdefined[3]{% + \ifluatex + \xpg@set@language@luatex@iv{#1}% + \fi + \xpg@check@ifdefined{#1} + \if@xpg@language@really@defined@#2\else#3\fi +}% + +\newcommand\xpg@set@language@luatex@iv[1]{% + \ifluatex + \xpg@check@ifdefined{#1}% + \if@xpg@language@really@defined@\else + \expandafter\chardef\csname l@#1\endcsname=\directlua{tex.sprint(polyglossia.newloader('#1'))}% + \fi + \language\directlua{tex.sprint(polyglossia.newloader('#1'))}% + \fi +} + \newcommand\xpg@set@language@luatex@ii[1]{% \ifluatex % - % here we use lu@texhyphen@loaded@\the\language, the same as in babel - \expandafter\ifcsname lu@texhyphen@loaded@\the\csname l@#1\endcsname\endcsname \else % - \global\@namedef{lu@texhyphen@loaded@\the\language}{}% - \directlua{polyglossia.select_language('\luatexluaescapestring{\string#1}', \the\csname l@#1\endcsname)}% - \fi % + \xpg@set@language@luatex@iii{#1}{\expandafter\the\csname l@#1\endcsname} \fi % } \def\select@language#1{% \ifluatex % - \ifcsname lu@texhyphen@loaded@\the\language\endcsname \else % - \global\@namedef{lu@texhyphen@loaded@\the\language}{}% - \directlua{polyglossia.select_language('\luatexluaescapestring{\string#1}', \the\csname l@#1\endcsname)}% - \fi % + \xpg@set@language@luatex@iii{#1}{\the\language} \fi % \xpg@initial@setup% \select@@language{#1}% @@ -786,15 +833,15 @@ That is almost guaranteed to cause problems.} {} \newcommand{\setlocalhyphenmins}[3]{% - \expandafter\ifx\csname l@#1\endcsname\relax% - \xpg@warning{\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}% - \else + \xpg@ifdefined{#1}{% \expandafter\ifx\csname l@#1\endcsname\l@nohyphenation% \xpg@warning{\string\setlocalhyphenmin\space~ useless~ for~ unhyphenated~ language~ #1}% \else \providehyphenmins{#1}{#2#3}% \fi - \fi} + }{% + \xpg@warning{\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}% + }}% \def\use@localhyphenmins#1{% \ifcsundef{#1hyphenmins}{}% @@ -802,7 +849,7 @@ That is almost guaranteed to cause problems.} \define@boolkey{polyglossia}[system@]{babelshorthands}[false]{} -\AtEndPreamble{\@ifpackageloaded{bidi}{\providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}}{}} +\AtEndPreamble{\@ifpackageloaded{bidi}{\providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}}{}}% TODO Make that work for luabidi too. %% Package Options %% \DeclareOption{nolocalmarks}{\setkeys{polyglossia}{localmarks=false}} @@ -819,26 +866,6 @@ That is almost guaranteed to cause problems.} \def\xpg@option#1#2{% \ifcsundef{xpg@main@language}{\setdefaultlanguage}{\setotherlanguage}% [#1]{#2}} -%\DeclareOption{USenglish}{\xpg@option{variant=american}{english}} -%\DeclareOption{american}{\xpg@option{variant=american}{english}} -%\DeclareOption{UKenglish}{\xpg@option{variant=british}{english}} -%\DeclareOption{british}{\xpg@option{variant=british}{english}} -%\DeclareOption{australian}{\xpg@option{variant=australian}{english}} -%\DeclareOption{newzealand}{\xpg@option{variant=newzealand}{english}} -%\DeclareOption{ngerman}{\xpg@option{spelling=new}{german}} -%\DeclareOption{polygreek}{\xpg@option{variant=poly}{greek}} -%\DeclareOption{monogreek}{\xpg@option{variant=mono}{greek}} -%\DeclareOption{ancientgreek}{\xpg@option{variant=ancient}{greek}} -%%% TODO add warning message that this approach is deprecated <<<<<<<<<<<<<< -%\DeclareOption*{% -% \edef\@temp{% -% \noexpand\ifcsundef{xpg@main@language}% -% \noexpand\setdefaultlanguage -% \noexpand\setotherlanguage -% {\CurrentOption}% -% }% -% \expandafter\AtEndOfPackage\expandafter{\@temp}% -%} \ExplSyntaxOff \ProcessOptions* \endinput |