%\iffalse
% polyglossia.dtx generated using mkpolyglossiadtx.pl
% (derived from makedtx.pl version 1.49 (c) Nicola Talbot)
% 
% To extract the files, use xetex polyglossia.dtx or luatex polyglossia.dtx
% 
%<*internal>
\iffalse
%</internal>
%<*README>
# THE POLYGLOSSIA PACKAGE v1.51
## Multilingual typesetting with XeLaTeX and LuaLaTeX

This package provides an alternative to Babel for users of XeLaTeX and LuaLaTeX.
This version includes support for over 70 different languages, some of which in
different regional or national varieties, or using a different writing system.

Polyglossia makes it possible to automate the following tasks:

* Loading the appropriate hyphenation patterns.
* Setting the script and language tags of the current font (if possible and
  available), using the package fontspec.
* Switching to a font assigned by the user to a particular script or language.
* Adjusting some typographical conventions in function of the current language
  (such as afterindent, frenchindent, spaces before or after punctuation marks,
  etc.).
* Redefining the document strings (like “chapter”, “figure”, “bibliography”).
* Adapting the formatting of dates (for non-gregorian calendars via external
  packages bundled with polyglossia: currently the Hebrew, Islamic and Farsi
  calendars are supported).
* For languages that have their own numeration system, modifying the formatting
  of numbers appropriately.
* Ensuring the proper directionality if the document contains languages
  written from right to left (via the packages bidi and luabidi, available
  separately).

# LICENCE

Copyright (c) 2008-2010 François Charette, 2013 Élie Roux, 2011-2021 Arthur Reutenauer,
Copyright (c) 2019-2021 Bastien Roucariès, 2019-2021 Jürgen Spitzmüller

Except where otherwise noted, Polyglossia is placed under the terms of the MIT licence
(https://opensource.org/licenses/MIT).

# BUGS

If you run into a bug, or suspect you do, or you have a request or comment, please
use the GitHub issue tracker: http://github.com/reutenauer/polyglossia/issues

This is more efficient than contacting the maintainer by email as it allows me
to track the issues and follow progress.
%</README>
%<*internal>
\fi
%</internal>
%
%<*internal>
\begingroup
%</internal>
%<*batchfile>
\input docstrip.tex
\keepsilent
\let\MetaPrefix\relax
\preamble
  ____________________________

  The polyglossia package         
  (C) 2008–2010 François Charette    
  (C) 2011–2021 Arthur Reutenauer
  (C) 2013 Elie Roux
  (C) 2019 Bastien Roucariès
  (C) 2019–2021 Jürgen Spitzmüller
  License information appended


\endpreamble
\postamble

 Copyright (C) 2021 by Arthur Reutenauer <arthur 'dot' reutenauer 'at' normalesup 'dot' org> 

 This work may be distributed and/or modified under the
 conditions of the LaTeX Project Public License, either version 1.3
 of this license of (at your option) any later version.
 The latest version of this license is in
   http://www.latex-project.org/lppl.txt
 and version 1.3 or later is part of all distributions of LaTeX
 version 2005/12/01 or later.

 This work has the LPPL maintenance status `maintained'.

 The Current Maintainer of this work is Arthur Reutenauer.


\endpostamble
\let\MetaPrefix\DoubleperCent
\askforoverwritefalse
\generate{\file{polyglossia.sty}{\from{polyglossia.dtx}{polyglossia.sty}}}
\generate{\file{farsical.sty}{\from{polyglossia.dtx}{farsical.sty}}}
\generate{\file{hebrewcal.sty}{\from{polyglossia.dtx}{hebrewcal.sty}}}
\generate{\file{hijrical.sty}{\from{polyglossia.dtx}{hijrical.sty}}}
\generate{\file{polyglossia-french.lua}{\from{polyglossia.dtx}{polyglossia-french.lua}}}
\generate{\file{polyglossia-korean.lua}{\from{polyglossia.dtx}{polyglossia-korean.lua}}}
\generate{\file{polyglossia-latin.lua}{\from{polyglossia.dtx}{polyglossia-latin.lua}}}
\generate{\file{polyglossia-punct.lua}{\from{polyglossia.dtx}{polyglossia-punct.lua}}}
\generate{\file{polyglossia-sanskrit.lua}{\from{polyglossia.dtx}{polyglossia-sanskrit.lua}}}
\generate{\file{polyglossia-tibt.lua}{\from{polyglossia.dtx}{polyglossia-tibt.lua}}}
\generate{\file{polyglossia.lua}{\from{polyglossia.dtx}{polyglossia.lua}}}
\generate{\file{babel-hebrewalph.def}{\from{polyglossia.dtx}{babel-hebrewalph.def}}}
\generate{\file{babelsh.def}{\from{polyglossia.dtx}{babelsh.def}}}
\generate{\file{cal-util.def}{\from{polyglossia.dtx}{cal-util.def}}}
\generate{\file{xgreek-fixes.def}{\from{polyglossia.dtx}{xgreek-fixes.def}}}
\generate{\file{gloss-acadien.ldf}{\from{polyglossia.dtx}{gloss-acadien.ldf}}}
\generate{\file{gloss-aeb.ldf}{\from{polyglossia.dtx}{gloss-aeb.ldf}}}
\generate{\file{gloss-af.ldf}{\from{polyglossia.dtx}{gloss-af.ldf}}}
\generate{\file{gloss-afb.ldf}{\from{polyglossia.dtx}{gloss-afb.ldf}}}
\generate{\file{gloss-afrikaans.ldf}{\from{polyglossia.dtx}{gloss-afrikaans.ldf}}}
\generate{\file{gloss-albanian.ldf}{\from{polyglossia.dtx}{gloss-albanian.ldf}}}
\generate{\file{gloss-am.ldf}{\from{polyglossia.dtx}{gloss-am.ldf}}}
\generate{\file{gloss-american.ldf}{\from{polyglossia.dtx}{gloss-american.ldf}}}
\generate{\file{gloss-amharic.ldf}{\from{polyglossia.dtx}{gloss-amharic.ldf}}}
\generate{\file{gloss-apd.ldf}{\from{polyglossia.dtx}{gloss-apd.ldf}}}
\generate{\file{gloss-ar-IQ.ldf}{\from{polyglossia.dtx}{gloss-ar-IQ.ldf}}}
\generate{\file{gloss-ar-JO.ldf}{\from{polyglossia.dtx}{gloss-ar-JO.ldf}}}
\generate{\file{gloss-ar-LB.ldf}{\from{polyglossia.dtx}{gloss-ar-LB.ldf}}}
\generate{\file{gloss-ar-MR.ldf}{\from{polyglossia.dtx}{gloss-ar-MR.ldf}}}
\generate{\file{gloss-ar-PS.ldf}{\from{polyglossia.dtx}{gloss-ar-PS.ldf}}}
\generate{\file{gloss-ar-SY.ldf}{\from{polyglossia.dtx}{gloss-ar-SY.ldf}}}
\generate{\file{gloss-ar-YE.ldf}{\from{polyglossia.dtx}{gloss-ar-YE.ldf}}}
\generate{\file{gloss-ar.ldf}{\from{polyglossia.dtx}{gloss-ar.ldf}}}
\generate{\file{gloss-arabic.ldf}{\from{polyglossia.dtx}{gloss-arabic.ldf}}}
\generate{\file{gloss-armenian.ldf}{\from{polyglossia.dtx}{gloss-armenian.ldf}}}
\generate{\file{gloss-arq.ldf}{\from{polyglossia.dtx}{gloss-arq.ldf}}}
\generate{\file{gloss-ary.ldf}{\from{polyglossia.dtx}{gloss-ary.ldf}}}
\generate{\file{gloss-arz.ldf}{\from{polyglossia.dtx}{gloss-arz.ldf}}}
\generate{\file{gloss-ast.ldf}{\from{polyglossia.dtx}{gloss-ast.ldf}}}
\generate{\file{gloss-asturian.ldf}{\from{polyglossia.dtx}{gloss-asturian.ldf}}}
\generate{\file{gloss-australian.ldf}{\from{polyglossia.dtx}{gloss-australian.ldf}}}
\generate{\file{gloss-austrian.ldf}{\from{polyglossia.dtx}{gloss-austrian.ldf}}}
\generate{\file{gloss-ayl.ldf}{\from{polyglossia.dtx}{gloss-ayl.ldf}}}
\generate{\file{gloss-bahasa.ldf}{\from{polyglossia.dtx}{gloss-bahasa.ldf}}}
\generate{\file{gloss-bahasai.ldf}{\from{polyglossia.dtx}{gloss-bahasai.ldf}}}
\generate{\file{gloss-bahasam.ldf}{\from{polyglossia.dtx}{gloss-bahasam.ldf}}}
\generate{\file{gloss-basque.ldf}{\from{polyglossia.dtx}{gloss-basque.ldf}}}
\generate{\file{gloss-be-tarask.ldf}{\from{polyglossia.dtx}{gloss-be-tarask.ldf}}}
\generate{\file{gloss-be.ldf}{\from{polyglossia.dtx}{gloss-be.ldf}}}
\generate{\file{gloss-belarusian.ldf}{\from{polyglossia.dtx}{gloss-belarusian.ldf}}}
\generate{\file{gloss-bengali.ldf}{\from{polyglossia.dtx}{gloss-bengali.ldf}}}
\generate{\file{gloss-bg.ldf}{\from{polyglossia.dtx}{gloss-bg.ldf}}}
\generate{\file{gloss-bn.ldf}{\from{polyglossia.dtx}{gloss-bn.ldf}}}
\generate{\file{gloss-bo.ldf}{\from{polyglossia.dtx}{gloss-bo.ldf}}}
\generate{\file{gloss-bosnian.ldf}{\from{polyglossia.dtx}{gloss-bosnian.ldf}}}
\generate{\file{gloss-br.ldf}{\from{polyglossia.dtx}{gloss-br.ldf}}}
\generate{\file{gloss-brazil.ldf}{\from{polyglossia.dtx}{gloss-brazil.ldf}}}
\generate{\file{gloss-breton.ldf}{\from{polyglossia.dtx}{gloss-breton.ldf}}}
\generate{\file{gloss-british.ldf}{\from{polyglossia.dtx}{gloss-british.ldf}}}
\generate{\file{gloss-bs.ldf}{\from{polyglossia.dtx}{gloss-bs.ldf}}}
\generate{\file{gloss-bulgarian.ldf}{\from{polyglossia.dtx}{gloss-bulgarian.ldf}}}
\generate{\file{gloss-ca.ldf}{\from{polyglossia.dtx}{gloss-ca.ldf}}}
\generate{\file{gloss-canadian.ldf}{\from{polyglossia.dtx}{gloss-canadian.ldf}}}
\generate{\file{gloss-canadien.ldf}{\from{polyglossia.dtx}{gloss-canadien.ldf}}}
\generate{\file{gloss-catalan.ldf}{\from{polyglossia.dtx}{gloss-catalan.ldf}}}
\generate{\file{gloss-ckb-Arab.ldf}{\from{polyglossia.dtx}{gloss-ckb-Arab.ldf}}}
\generate{\file{gloss-ckb-Latn.ldf}{\from{polyglossia.dtx}{gloss-ckb-Latn.ldf}}}
\generate{\file{gloss-ckb.ldf}{\from{polyglossia.dtx}{gloss-ckb.ldf}}}
\generate{\file{gloss-cop.ldf}{\from{polyglossia.dtx}{gloss-cop.ldf}}}
\generate{\file{gloss-coptic.ldf}{\from{polyglossia.dtx}{gloss-coptic.ldf}}}
\generate{\file{gloss-croatian.ldf}{\from{polyglossia.dtx}{gloss-croatian.ldf}}}
\generate{\file{gloss-cy.ldf}{\from{polyglossia.dtx}{gloss-cy.ldf}}}
\generate{\file{gloss-cz.ldf}{\from{polyglossia.dtx}{gloss-cz.ldf}}}
\generate{\file{gloss-czech.ldf}{\from{polyglossia.dtx}{gloss-czech.ldf}}}
\generate{\file{gloss-da.ldf}{\from{polyglossia.dtx}{gloss-da.ldf}}}
\generate{\file{gloss-danish.ldf}{\from{polyglossia.dtx}{gloss-danish.ldf}}}
\generate{\file{gloss-de-AT-1901.ldf}{\from{polyglossia.dtx}{gloss-de-AT-1901.ldf}}}
\generate{\file{gloss-de-AT-1996.ldf}{\from{polyglossia.dtx}{gloss-de-AT-1996.ldf}}}
\generate{\file{gloss-de-AT.ldf}{\from{polyglossia.dtx}{gloss-de-AT.ldf}}}
\generate{\file{gloss-de-CH-1901.ldf}{\from{polyglossia.dtx}{gloss-de-CH-1901.ldf}}}
\generate{\file{gloss-de-CH-1996.ldf}{\from{polyglossia.dtx}{gloss-de-CH-1996.ldf}}}
\generate{\file{gloss-de-CH.ldf}{\from{polyglossia.dtx}{gloss-de-CH.ldf}}}
\generate{\file{gloss-de-DE-1901.ldf}{\from{polyglossia.dtx}{gloss-de-DE-1901.ldf}}}
\generate{\file{gloss-de-DE-1996.ldf}{\from{polyglossia.dtx}{gloss-de-DE-1996.ldf}}}
\generate{\file{gloss-de-DE.ldf}{\from{polyglossia.dtx}{gloss-de-DE.ldf}}}
\generate{\file{gloss-de-Latf-AT-1901.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-AT-1901.ldf}}}
\generate{\file{gloss-de-Latf-AT-1996.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-AT-1996.ldf}}}
\generate{\file{gloss-de-Latf-AT.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-AT.ldf}}}
\generate{\file{gloss-de-Latf-CH-1901.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-CH-1901.ldf}}}
\generate{\file{gloss-de-Latf-CH-1996.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-CH-1996.ldf}}}
\generate{\file{gloss-de-Latf-CH.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-CH.ldf}}}
\generate{\file{gloss-de-Latf-DE-1901.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-DE-1901.ldf}}}
\generate{\file{gloss-de-Latf-DE-1996.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-DE-1996.ldf}}}
\generate{\file{gloss-de-Latf-DE.ldf}{\from{polyglossia.dtx}{gloss-de-Latf-DE.ldf}}}
\generate{\file{gloss-de-Latf.ldf}{\from{polyglossia.dtx}{gloss-de-Latf.ldf}}}
\generate{\file{gloss-de.ldf}{\from{polyglossia.dtx}{gloss-de.ldf}}}
\generate{\file{gloss-divehi.ldf}{\from{polyglossia.dtx}{gloss-divehi.ldf}}}
\generate{\file{gloss-dsb.ldf}{\from{polyglossia.dtx}{gloss-dsb.ldf}}}
\generate{\file{gloss-dutch.ldf}{\from{polyglossia.dtx}{gloss-dutch.ldf}}}
\generate{\file{gloss-dv.ldf}{\from{polyglossia.dtx}{gloss-dv.ldf}}}
\generate{\file{gloss-el-monoton.ldf}{\from{polyglossia.dtx}{gloss-el-monoton.ldf}}}
\generate{\file{gloss-el-polyton.ldf}{\from{polyglossia.dtx}{gloss-el-polyton.ldf}}}
\generate{\file{gloss-el.ldf}{\from{polyglossia.dtx}{gloss-el.ldf}}}
\generate{\file{gloss-en-AU.ldf}{\from{polyglossia.dtx}{gloss-en-AU.ldf}}}
\generate{\file{gloss-en-CA.ldf}{\from{polyglossia.dtx}{gloss-en-CA.ldf}}}
\generate{\file{gloss-en-GB.ldf}{\from{polyglossia.dtx}{gloss-en-GB.ldf}}}
\generate{\file{gloss-en-NZ.ldf}{\from{polyglossia.dtx}{gloss-en-NZ.ldf}}}
\generate{\file{gloss-en-US.ldf}{\from{polyglossia.dtx}{gloss-en-US.ldf}}}
\generate{\file{gloss-en.ldf}{\from{polyglossia.dtx}{gloss-en.ldf}}}
\generate{\file{gloss-english.ldf}{\from{polyglossia.dtx}{gloss-english.ldf}}}
\generate{\file{gloss-eo.ldf}{\from{polyglossia.dtx}{gloss-eo.ldf}}}
\generate{\file{gloss-es-ES.ldf}{\from{polyglossia.dtx}{gloss-es-ES.ldf}}}
\generate{\file{gloss-es-MX.ldf}{\from{polyglossia.dtx}{gloss-es-MX.ldf}}}
\generate{\file{gloss-es.ldf}{\from{polyglossia.dtx}{gloss-es.ldf}}}
\generate{\file{gloss-esperanto.ldf}{\from{polyglossia.dtx}{gloss-esperanto.ldf}}}
\generate{\file{gloss-estonian.ldf}{\from{polyglossia.dtx}{gloss-estonian.ldf}}}
\generate{\file{gloss-et.ldf}{\from{polyglossia.dtx}{gloss-et.ldf}}}
\generate{\file{gloss-eu.ldf}{\from{polyglossia.dtx}{gloss-eu.ldf}}}
\generate{\file{gloss-fa.ldf}{\from{polyglossia.dtx}{gloss-fa.ldf}}}
\generate{\file{gloss-farsi.ldf}{\from{polyglossia.dtx}{gloss-farsi.ldf}}}
\generate{\file{gloss-fi.ldf}{\from{polyglossia.dtx}{gloss-fi.ldf}}}
\generate{\file{gloss-finnish.ldf}{\from{polyglossia.dtx}{gloss-finnish.ldf}}}
\generate{\file{gloss-fr-CA.ldf}{\from{polyglossia.dtx}{gloss-fr-CA.ldf}}}
\generate{\file{gloss-fr-CH.ldf}{\from{polyglossia.dtx}{gloss-fr-CH.ldf}}}
\generate{\file{gloss-fr-FR.ldf}{\from{polyglossia.dtx}{gloss-fr-FR.ldf}}}
\generate{\file{gloss-fr.ldf}{\from{polyglossia.dtx}{gloss-fr.ldf}}}
\generate{\file{gloss-french.ldf}{\from{polyglossia.dtx}{gloss-french.ldf}}}
\generate{\file{gloss-friulan.ldf}{\from{polyglossia.dtx}{gloss-friulan.ldf}}}
\generate{\file{gloss-friulian.ldf}{\from{polyglossia.dtx}{gloss-friulian.ldf}}}
\generate{\file{gloss-fur.ldf}{\from{polyglossia.dtx}{gloss-fur.ldf}}}
\generate{\file{gloss-ga.ldf}{\from{polyglossia.dtx}{gloss-ga.ldf}}}
\generate{\file{gloss-gaelic.ldf}{\from{polyglossia.dtx}{gloss-gaelic.ldf}}}
\generate{\file{gloss-galician.ldf}{\from{polyglossia.dtx}{gloss-galician.ldf}}}
\generate{\file{gloss-gd.ldf}{\from{polyglossia.dtx}{gloss-gd.ldf}}}
\generate{\file{gloss-georgian.ldf}{\from{polyglossia.dtx}{gloss-georgian.ldf}}}
\generate{\file{gloss-german.ldf}{\from{polyglossia.dtx}{gloss-german.ldf}}}
\generate{\file{gloss-germanb.ldf}{\from{polyglossia.dtx}{gloss-germanb.ldf}}}
\generate{\file{gloss-gl.ldf}{\from{polyglossia.dtx}{gloss-gl.ldf}}}
\generate{\file{gloss-grc.ldf}{\from{polyglossia.dtx}{gloss-grc.ldf}}}
\generate{\file{gloss-greek.ldf}{\from{polyglossia.dtx}{gloss-greek.ldf}}}
\generate{\file{gloss-he.ldf}{\from{polyglossia.dtx}{gloss-he.ldf}}}
\generate{\file{gloss-hebrew.ldf}{\from{polyglossia.dtx}{gloss-hebrew.ldf}}}
\generate{\file{gloss-hi.ldf}{\from{polyglossia.dtx}{gloss-hi.ldf}}}
\generate{\file{gloss-hindi.ldf}{\from{polyglossia.dtx}{gloss-hindi.ldf}}}
\generate{\file{gloss-hr.ldf}{\from{polyglossia.dtx}{gloss-hr.ldf}}}
\generate{\file{gloss-hsb.ldf}{\from{polyglossia.dtx}{gloss-hsb.ldf}}}
\generate{\file{gloss-hu.ldf}{\from{polyglossia.dtx}{gloss-hu.ldf}}}
\generate{\file{gloss-hungarian.ldf}{\from{polyglossia.dtx}{gloss-hungarian.ldf}}}
\generate{\file{gloss-hy.ldf}{\from{polyglossia.dtx}{gloss-hy.ldf}}}
\generate{\file{gloss-ia.ldf}{\from{polyglossia.dtx}{gloss-ia.ldf}}}
\generate{\file{gloss-icelandic.ldf}{\from{polyglossia.dtx}{gloss-icelandic.ldf}}}
\generate{\file{gloss-id.ldf}{\from{polyglossia.dtx}{gloss-id.ldf}}}
\generate{\file{gloss-interlingua.ldf}{\from{polyglossia.dtx}{gloss-interlingua.ldf}}}
\generate{\file{gloss-irish.ldf}{\from{polyglossia.dtx}{gloss-irish.ldf}}}
\generate{\file{gloss-is.ldf}{\from{polyglossia.dtx}{gloss-is.ldf}}}
\generate{\file{gloss-it.ldf}{\from{polyglossia.dtx}{gloss-it.ldf}}}
\generate{\file{gloss-italian.ldf}{\from{polyglossia.dtx}{gloss-italian.ldf}}}
\generate{\file{gloss-ja.ldf}{\from{polyglossia.dtx}{gloss-ja.ldf}}}
\generate{\file{gloss-japanese.ldf}{\from{polyglossia.dtx}{gloss-japanese.ldf}}}
\generate{\file{gloss-ka.ldf}{\from{polyglossia.dtx}{gloss-ka.ldf}}}
\generate{\file{gloss-kannada.ldf}{\from{polyglossia.dtx}{gloss-kannada.ldf}}}
\generate{\file{gloss-khmer.ldf}{\from{polyglossia.dtx}{gloss-khmer.ldf}}}
\generate{\file{gloss-km.ldf}{\from{polyglossia.dtx}{gloss-km.ldf}}}
\generate{\file{gloss-kmr-Arab.ldf}{\from{polyglossia.dtx}{gloss-kmr-Arab.ldf}}}
\generate{\file{gloss-kmr-Latn.ldf}{\from{polyglossia.dtx}{gloss-kmr-Latn.ldf}}}
\generate{\file{gloss-kmr.ldf}{\from{polyglossia.dtx}{gloss-kmr.ldf}}}
\generate{\file{gloss-kn.ldf}{\from{polyglossia.dtx}{gloss-kn.ldf}}}
\generate{\file{gloss-ko.ldf}{\from{polyglossia.dtx}{gloss-ko.ldf}}}
\generate{\file{gloss-korean.ldf}{\from{polyglossia.dtx}{gloss-korean.ldf}}}
\generate{\file{gloss-ku-Arab.ldf}{\from{polyglossia.dtx}{gloss-ku-Arab.ldf}}}
\generate{\file{gloss-ku-Latn.ldf}{\from{polyglossia.dtx}{gloss-ku-Latn.ldf}}}
\generate{\file{gloss-ku.ldf}{\from{polyglossia.dtx}{gloss-ku.ldf}}}
\generate{\file{gloss-kurdish.ldf}{\from{polyglossia.dtx}{gloss-kurdish.ldf}}}
\generate{\file{gloss-kurmanji.ldf}{\from{polyglossia.dtx}{gloss-kurmanji.ldf}}}
\generate{\file{gloss-la-x-classic.ldf}{\from{polyglossia.dtx}{gloss-la-x-classic.ldf}}}
\generate{\file{gloss-la-x-ecclesia.ldf}{\from{polyglossia.dtx}{gloss-la-x-ecclesia.ldf}}}
\generate{\file{gloss-la-x-medieval.ldf}{\from{polyglossia.dtx}{gloss-la-x-medieval.ldf}}}
\generate{\file{gloss-la.ldf}{\from{polyglossia.dtx}{gloss-la.ldf}}}
\generate{\file{gloss-lao.ldf}{\from{polyglossia.dtx}{gloss-lao.ldf}}}
\generate{\file{gloss-latex.ldf}{\from{polyglossia.dtx}{gloss-latex.ldf}}}
\generate{\file{gloss-latin.ldf}{\from{polyglossia.dtx}{gloss-latin.ldf}}}
\generate{\file{gloss-latinclassic.ldf}{\from{polyglossia.dtx}{gloss-latinclassic.ldf}}}
\generate{\file{gloss-latinecclesiastic.ldf}{\from{polyglossia.dtx}{gloss-latinecclesiastic.ldf}}}
\generate{\file{gloss-latinmedieval.ldf}{\from{polyglossia.dtx}{gloss-latinmedieval.ldf}}}
\generate{\file{gloss-latvian.ldf}{\from{polyglossia.dtx}{gloss-latvian.ldf}}}
\generate{\file{gloss-lithuanian.ldf}{\from{polyglossia.dtx}{gloss-lithuanian.ldf}}}
\generate{\file{gloss-lo.ldf}{\from{polyglossia.dtx}{gloss-lo.ldf}}}
\generate{\file{gloss-lowersorbian.ldf}{\from{polyglossia.dtx}{gloss-lowersorbian.ldf}}}
\generate{\file{gloss-lsorbian.ldf}{\from{polyglossia.dtx}{gloss-lsorbian.ldf}}}
\generate{\file{gloss-lt.ldf}{\from{polyglossia.dtx}{gloss-lt.ldf}}}
\generate{\file{gloss-lv.ldf}{\from{polyglossia.dtx}{gloss-lv.ldf}}}
\generate{\file{gloss-macedonian.ldf}{\from{polyglossia.dtx}{gloss-macedonian.ldf}}}
\generate{\file{gloss-magyar.ldf}{\from{polyglossia.dtx}{gloss-magyar.ldf}}}
\generate{\file{gloss-malay.ldf}{\from{polyglossia.dtx}{gloss-malay.ldf}}}
\generate{\file{gloss-malayalam.ldf}{\from{polyglossia.dtx}{gloss-malayalam.ldf}}}
\generate{\file{gloss-marathi.ldf}{\from{polyglossia.dtx}{gloss-marathi.ldf}}}
\generate{\file{gloss-mk.ldf}{\from{polyglossia.dtx}{gloss-mk.ldf}}}
\generate{\file{gloss-ml.ldf}{\from{polyglossia.dtx}{gloss-ml.ldf}}}
\generate{\file{gloss-mn.ldf}{\from{polyglossia.dtx}{gloss-mn.ldf}}}
\generate{\file{gloss-mongolian.ldf}{\from{polyglossia.dtx}{gloss-mongolian.ldf}}}
\generate{\file{gloss-mr.ldf}{\from{polyglossia.dtx}{gloss-mr.ldf}}}
\generate{\file{gloss-naustrian.ldf}{\from{polyglossia.dtx}{gloss-naustrian.ldf}}}
\generate{\file{gloss-nb.ldf}{\from{polyglossia.dtx}{gloss-nb.ldf}}}
\generate{\file{gloss-newzealand.ldf}{\from{polyglossia.dtx}{gloss-newzealand.ldf}}}
\generate{\file{gloss-ngerman.ldf}{\from{polyglossia.dtx}{gloss-ngerman.ldf}}}
\generate{\file{gloss-nko.ldf}{\from{polyglossia.dtx}{gloss-nko.ldf}}}
\generate{\file{gloss-norsk.ldf}{\from{polyglossia.dtx}{gloss-norsk.ldf}}}
\generate{\file{gloss-norwegian.ldf}{\from{polyglossia.dtx}{gloss-norwegian.ldf}}}
\generate{\file{gloss-nswissgerman.ldf}{\from{polyglossia.dtx}{gloss-nswissgerman.ldf}}}
\generate{\file{gloss-nynorsk.ldf}{\from{polyglossia.dtx}{gloss-nynorsk.ldf}}}
\generate{\file{gloss-occitan.ldf}{\from{polyglossia.dtx}{gloss-occitan.ldf}}}
\generate{\file{gloss-persian.ldf}{\from{polyglossia.dtx}{gloss-persian.ldf}}}
\generate{\file{gloss-piedmontese.ldf}{\from{polyglossia.dtx}{gloss-piedmontese.ldf}}}
\generate{\file{gloss-polish.ldf}{\from{polyglossia.dtx}{gloss-polish.ldf}}}
\generate{\file{gloss-polutonikogreek.ldf}{\from{polyglossia.dtx}{gloss-polutonikogreek.ldf}}}
\generate{\file{gloss-portuges.ldf}{\from{polyglossia.dtx}{gloss-portuges.ldf}}}
\generate{\file{gloss-portuguese.ldf}{\from{polyglossia.dtx}{gloss-portuguese.ldf}}}
\generate{\file{gloss-romanian.ldf}{\from{polyglossia.dtx}{gloss-romanian.ldf}}}
\generate{\file{gloss-romansh.ldf}{\from{polyglossia.dtx}{gloss-romansh.ldf}}}
\generate{\file{gloss-russian.ldf}{\from{polyglossia.dtx}{gloss-russian.ldf}}}
\generate{\file{gloss-sami.ldf}{\from{polyglossia.dtx}{gloss-sami.ldf}}}
\generate{\file{gloss-samin.ldf}{\from{polyglossia.dtx}{gloss-samin.ldf}}}
\generate{\file{gloss-sanskrit.ldf}{\from{polyglossia.dtx}{gloss-sanskrit.ldf}}}
\generate{\file{gloss-scottish.ldf}{\from{polyglossia.dtx}{gloss-scottish.ldf}}}
\generate{\file{gloss-serbian.ldf}{\from{polyglossia.dtx}{gloss-serbian.ldf}}}
\generate{\file{gloss-serbianc.ldf}{\from{polyglossia.dtx}{gloss-serbianc.ldf}}}
\generate{\file{gloss-slovak.ldf}{\from{polyglossia.dtx}{gloss-slovak.ldf}}}
\generate{\file{gloss-slovene.ldf}{\from{polyglossia.dtx}{gloss-slovene.ldf}}}
\generate{\file{gloss-slovenian.ldf}{\from{polyglossia.dtx}{gloss-slovenian.ldf}}}
\generate{\file{gloss-sorbian.ldf}{\from{polyglossia.dtx}{gloss-sorbian.ldf}}}
\generate{\file{gloss-spanish.ldf}{\from{polyglossia.dtx}{gloss-spanish.ldf}}}
\generate{\file{gloss-spanishmx.ldf}{\from{polyglossia.dtx}{gloss-spanishmx.ldf}}}
\generate{\file{gloss-swedish.ldf}{\from{polyglossia.dtx}{gloss-swedish.ldf}}}
\generate{\file{gloss-swissgerman.ldf}{\from{polyglossia.dtx}{gloss-swissgerman.ldf}}}
\generate{\file{gloss-syriac.ldf}{\from{polyglossia.dtx}{gloss-syriac.ldf}}}
\generate{\file{gloss-tamil.ldf}{\from{polyglossia.dtx}{gloss-tamil.ldf}}}
\generate{\file{gloss-telugu.ldf}{\from{polyglossia.dtx}{gloss-telugu.ldf}}}
\generate{\file{gloss-thai.ldf}{\from{polyglossia.dtx}{gloss-thai.ldf}}}
\generate{\file{gloss-tibetan.ldf}{\from{polyglossia.dtx}{gloss-tibetan.ldf}}}
\generate{\file{gloss-turkish.ldf}{\from{polyglossia.dtx}{gloss-turkish.ldf}}}
\generate{\file{gloss-turkmen.ldf}{\from{polyglossia.dtx}{gloss-turkmen.ldf}}}
\generate{\file{gloss-ug.ldf}{\from{polyglossia.dtx}{gloss-ug.ldf}}}
\generate{\file{gloss-ukrainian.ldf}{\from{polyglossia.dtx}{gloss-ukrainian.ldf}}}
\generate{\file{gloss-uppersorbian.ldf}{\from{polyglossia.dtx}{gloss-uppersorbian.ldf}}}
\generate{\file{gloss-urdu.ldf}{\from{polyglossia.dtx}{gloss-urdu.ldf}}}
\generate{\file{gloss-usorbian.ldf}{\from{polyglossia.dtx}{gloss-usorbian.ldf}}}
\generate{\file{gloss-uyghur.ldf}{\from{polyglossia.dtx}{gloss-uyghur.ldf}}}
\generate{\file{gloss-vietnamese.ldf}{\from{polyglossia.dtx}{gloss-vietnamese.ldf}}}
\generate{\file{gloss-welsh.ldf}{\from{polyglossia.dtx}{gloss-welsh.ldf}}}
\generate{\file{arabicdigits.map}{\from{polyglossia.dtx}{arabicdigits.map}}}
\generate{\file{bengalidigits.map}{\from{polyglossia.dtx}{bengalidigits.map}}}
\generate{\file{devanagaridigits.map}{\from{polyglossia.dtx}{devanagaridigits.map}}}
\generate{\file{farsidigits.map}{\from{polyglossia.dtx}{farsidigits.map}}}
\generate{\file{thaidigits.map}{\from{polyglossia.dtx}{thaidigits.map}}}
\def\MetaPrefix{-- }
\generate{\file{polyglossia-french.lua}{\from{polyglossia.dtx}{polyglossia-french.lua}}}
\generate{\file{polyglossia-korean.lua}{\from{polyglossia.dtx}{polyglossia-korean.lua}}}
\generate{\file{polyglossia-latin.lua}{\from{polyglossia.dtx}{polyglossia-latin.lua}}}
\generate{\file{polyglossia-punct.lua}{\from{polyglossia.dtx}{polyglossia-punct.lua}}}
\generate{\file{polyglossia-sanskrit.lua}{\from{polyglossia.dtx}{polyglossia-sanskrit.lua}}}
\generate{\file{polyglossia-tibt.lua}{\from{polyglossia.dtx}{polyglossia-tibt.lua}}}
\generate{\file{polyglossia.lua}{\from{polyglossia.dtx}{polyglossia.lua}}}
\let\MetaPrefix\DoubleperCent
%</batchfile>
%<batchfile>\endbatchfile
%<*internal>
\generate{\file{polyglossia.ins}{\from{polyglossia.dtx}{batchfile}}}
\nopreamble\nopostamble
\generate{\file{examples.tex}{\from{polyglossia.dtx}{examples.tex}}}
\generate{\file{example-arabic.tex}{\from{polyglossia.dtx}{example-arabic.tex}}}
\generate{\file{example-thai.tex}{\from{polyglossia.dtx}{example-thai.tex}}}
\generate{\file{README.md}{\from{polyglossia.dtx}{README}}}
\endgroup
%</internal>
%
%<*driver>
% !TeX spellcheck = en_US
% !TeX TS-program = xelatex
\documentclass[11pt]{ltxdoc}
\usepackage{color}
\usepackage{xspace,fancyvrb,longtable,booktabs}
\usepackage[neverdecrease]{paralist}
\usepackage[format=hang,labelfont=bf,labelsep=period]{caption}
\definecolor{xpgblue}{rgb}{0.02,0.04,0.48}
\definecolor{lightblue}{rgb}{0.61,.8,.8}
\definecolor{xpgred}{rgb}{0.65,0.04,0.07}
\usepackage[
    unicode=true,
    bookmarks=true,
    colorlinks=true,
    linkcolor=xpgblue,
    urlcolor=xpgblue,
    citecolor=xpgblue,
    hyperindex=false,
    hyperfootnotes=false,
    pdftitle={Polyglossia: Modern multilingual typesetting with XeLaTeX and LuaLaTeX},
    pdfauthor={F Charette, A Reutenauer, B Roucariès, J Spitzmüller},
    pdfkeywords={xetex, xelatex, luatex, lualatex, multilingual, babel, hyphenation}
    ]{hyperref}
\usepackage{metalogo}
\let\XeTeX\undefined
\let\XeLaTeX\undefined
\usepackage[babelshorthands]{polyglossia}
\usepackage{farsical}
\setmainlanguage[variant=british,ordinalmonthday=false]{english}
\setotherlanguages{arabic,armenian,hebrew,syriac,greek,russian,serbian,catalan,georgian}
\usepackage[protrusion]{microtype}
\newcommand*\Cmd[1]{\cmd{#1}\DescribeMacro{#1}\xspace}
\newcommand*\pkg[1]{\textsf{\color{xpgblue}#1}}
\newcommand*\file[1]{\texttt{\color{xpgblue}#1}}
\newcommand*\TR[1]{\textcolor{xpgred}{#1}}
\newcommand*\TX[1]{\hyperref[#1]{\textcolor{xpgred}{#1}}}
\newcommand*\TA[1]{\textsc{\color{xpgblue}#1}}
\newcommand*\link[1]{\href{#1}{#1}}
\renewcommand*\meta[1]{\texttt{⟨#1⟩}}
\newcommand*\TXI[1]{\href{https://github.com/reutenauer/polyglossia/issues/#1}{\textcolor{xpgred}{\##1}}}
\def\eg{\textit{e.g.,}\xspace}
\def\ie{\textit{i.e.,}\xspace}
\def\ca{\textit{ca.}\@\xspace}
\def\Eg{\textit{E.g.,}\xspace}
\def\Ie{\textit{I.e.,}\xspace}
\def\etc{\@ifnextchar.{\textit{etc}}{\textit{etc.}\@\xspace}}

%% Commands for documenting options
\newcommand*\xpgoption[1]{\textcolor{xpgblue}{\ttfamily\bfseries #1}}
\newcommand*\xpgvalue[1]{\texttt{#1}}
\newcommand*\xpgpresetvalue[1]{\texttt{\textit{#1}}}
\newcommand*\xpgdefaultvalue[1]{\texttt{*#1}}

% arguments: #1 version number, #2 key name, #3 footnote, #4 possible values
\NewDocumentCommand\xpgchoicekey{omom}{%
	\xpgoption{#2}\IfValueT{#3}{\footnote{#3}}%
    \IfValueT{#1}{\new{#1}} \xpgvalue{=} #4\par%
}

% arguments: #1 version number, #2 key name, #3 footnote
\NewDocumentCommand\xpgboolkey{omo}{\xpgchoicekey[#1]{#2}[#3]{\xpgdefaultvalue{true} or \xpgvalue{false}}}
\NewDocumentCommand\xpgboolkeytrue{omo}{\xpgchoicekey[#1]{#2}[#3]{\xpgdefaultvalue{\xpgpresetvalue{true}} or \xpgvalue{false}}}
\NewDocumentCommand\xpgboolkeyfalse{omo}{\xpgchoicekey[#1]{#2}[#3]{\xpgdefaultvalue{true} or \xpgpresetvalue{false}}}

% arguments: #1 version number, #2 key name, #3 default code
\NewDocumentCommand\xpgcodekey{omv}{%
	\xpgoption{#2}\IfValueT{#1}{\new{#1}}
     \xpgvalue{=} \meta{code} (default value: \texttt{#3})\par%
}

% arguments: #1 version number, #2 key name, #3 value type, #4 default value
\NewDocumentCommand\xpgoptkey{ommo}{%
	\xpgoption{#2}\IfValueT{#1}{\new{#1}}
	\xpgvalue{=} \meta{#3} (default value: \texttt{#4})\par%
}

%% Sidenotes  << copied from fontspec.dtx
\newcommand\new[1]{%
  \edef\thisversion{v#1}%
  \ifhmode\unskip~\fi{\ifx\thisversion\fileversion\color{blue}\else\color[gray]{0.5}\fi
  $\leftarrow$}%
  \marginpar{\centering
    \small\ifx\thisversion\fileversion\color{blue}\else\color[gray]{0.5}\fi
    \textsf{v#1}}}
\newcommand\displaycmd[2]{%
  \\\DescribeMacro{#2}\centerline{\cmd{#1}}}
\renewenvironment{itemize}{\begin{compactitem}[\char"2023]}%[{\fontspec{DejaVu Sans}\char"25BB}]}%
		{\end{compactitem}}
\renewenvironment{enumerate}{\begin{compactenum}}{\end{compactenum}}
\newenvironment{shorthands}{%
	 \begin{list}{}%
	 	{\settowidth{\labelwidth}{MM}%
	 	 \setlength{\leftmargin}{\labelwidth}%
	 	 \addtolength{\leftmargin}{\labelsep}%
	     \renewcommand{\makelabel}[1]{##1\hfil}}}%
	{\end{list}}

% This is to prevent page breaks too short after subsections
\def\condbreak#1{%
	\vskip 0pt plus #1\pagebreak[3]\vskip 0pt plus -#1\relax}
\pretocmd{\subsection}{\condbreak{2\baselineskip}}{}{}

%% fontspec declarations:
\setmainfont{Linux Libertine O}[Numbers=OldStyle]
\setsansfont{Linux Biolinum O}
\setmonofont[Scale=MatchLowercase]{DejaVu Sans Mono}
\newfontfamily\arabicfont[Script=Arabic]{Amiri}
\newfontfamily\armenianfont[Script=Armenian]{DejaVu Sans}
\newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
\newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
\newfontfamily\georgianfont{DejaVu Serif}

\linespread{1.05}
\frenchspacing
\EnableCrossrefs
\CodelineIndex
\RecordChanges
% COMMENT THE NEXT LINE TO INCLUDE THE CODE
\AtBeginDocument{\OnlyDescription}


\begin{document}
\ifxetex
  \DocInput{polyglossia.dtx}
\fi
\end{document}
%</driver>
% 
% \fi
% 
% \errorcontextlines=999
% \makeatletter
% 
% \hyphenation{Kha-li-ghi Reu-ten-auer new-zea-land}
% \GetFileInfo{polyglossia.sty}
% 
% \title{\textcolor{lightblue}{\Huge\fontspec[LetterSpace=40]{GFS Ambrosia} Πολυγλωσσια}
% \\[16pt]
% \color{xpgblue}Polyglossia: Modern multilingual typesetting with \XeLaTeX\ and \LuaLaTeX}
% \author{\TA{François Charette} \and \TA{Arthur Reutenauer}\thanks{Current maintainer}
% 	    \and \TA{Bastien Roucariès} \and \TA{Jürgen Spitzmüller}}
% \date{\filedate \qquad \fileversion\\
% \footnotesize (\textsc{pdf} file generated on \today)}
% 
% \maketitle
% \tableofcontents
% 
% \condbreak{4\baselineskip}
% 
% 
% \DeleteShortVerb{\|}
% \MakeShortVerb{\¦}
% 
% ^^A\begin{abstract}
% ^^ABlablabla
% ^^A\end{abstract}
% 
% 
% \section{Introduction}
% 
% \pkg{Polyglossia} is a package for facilitating multilingual typesetting with
% \XeLaTeX\ and \LuaLaTeX. Basically, it
% can be used as an alternative to \pkg{babel} for performing the following
% tasks automatically:
% 
% \begin{enumerate}
% \item Loading the appropriate hyphenation patterns.
% \item Setting the script and language tags of the current font (if possible and
%       available), via the package \pkg{fontspec}.
% \item Switching to a font assigned by the user to a particular script or language.
% \item Adjusting some typographical conventions according to the current language
%       (such as afterindent, frenchindent, spaces before or after punctuation marks,
%       etc.).
% \item Redefining all document strings (like “chapter”, “figure”, “bibliography”).
% \item Adapting the formatting of dates (for non-Gregorian calendars via external
%       packages bundled with polyglossia: currently the Hebrew, Islamic and Farsi
%       calendars are supported).
% \item For languages that have their own numbering system, modifying the formatting
%       of numbers appropriately (this also includes redefining the alphabetic sequence
%       for non-Latin alphabets).\footnote{%
%         This is done by bundled sub-packages such as \pkg{arabicnumbers}.}
% \item Ensuring proper directionality if the document contains languages
%       that are written from right to left (via the package \pkg{bidi},
%       available separately).
% \end{enumerate}
% ^^A
% Several features of \pkg{babel} that do not make sense in the \XeTeX\ world (like font
% encodings, shorthands, etc.) are not supported.
% Generally speaking, \pkg{polyglossia} aims to remain as compatible as possible
% with the fundamental features of \pkg{babel} while being cleaner, light-weight,
% and modern. The package \pkg{antomega} has been very beneficial in our attempt to
% reach this objective.
% 
% \paragraph{Requirements} The current version of \pkg{polyglossia} makes use of some convenient
% macros defined in the \pkg{etoolbox} package by \TA{Philipp Lehmann} and \TA{Joseph Wright}.
% Being designed for \XeLaTeX\ and \LuaLaTeX, it obviously also relies on \pkg{fontspec} by
% \TA{Will Robertson}. For languages written from right to left, it needs the package \pkg{bidi}
% (for \XeTeX) or \pkg{luabidi} (for \LuaTeX) by \TA{Vafa Khalighi} (\textarabic{وفا خليقي}) and
% the \pkg{bidi-tex GitHub Organisation}.
% Polyglossia also bundles three packages for calendaric computations (\pkg{hebrewcal},
% \pkg{hijrical}, and \pkg{farsical}).
% 
% 
% \section{Setting up multilingual documents}
% 
% \subsection{Activating languages}
% 
% The default language of a document is specified by means of the command
% 	\displaycmd{\setdefaultlanguage\oarg{options}\marg{lang}}{\setdefaultlanguage}
% (or, equivalently, \Cmd\setmainlanguage).
% Secondary languages are specified with
% 	\displaycmd{\setotherlanguage\oarg{options}\marg{lang}.}{\setotherlanguage}
% All these commands allow you to set language-specific options.\footnote{%
% 	Section~\ref{specific} documents these options for the respective languages.}
% It is also possible to load a series of secondary languages at once (but without options)
% using
% 	\displaycmd{\setotherlanguages\marg{lang1⟩,⟨lang2⟩,⟨lang3⟩,⟨…}.}{\setotherlanguages}
% ^^A
% All language-specific options can be modified locally by means of the
% language-switching commands described in section \ref{languageswitching}.
% 
% \paragraph{Note} In general, it is advisable to activate the languages \emph{after} all
% packages have been loaded. This is particularly important if you use right-to-left scripts
% or languages with babel shorthands.
% 
% 
% \subsection{Supported languages}
% 
% Table~\ref{tab:lang} lists all languages currently supported.
% Those in \TR{red} have specific options and/or commands
% that are explained in section \ref{specific} below.
% 
% \begin{table}[ht]\centering
% \caption{\label{tab:lang}Languages currently supported in \pkg{polyglossia}}
% ^^A Produced with tools/insert-language-list.rb -- JS, 2019-11-01
% ^^A Edited by hand -- JS, 2019-11-01
% \begin{tabular}{lllll}
% \toprule
% \TX{afrikaans}  & danish         & \TX{hungarian} & \TX{marathi}    & \TX{slovenian} \\
% albanian        & divehi         & icelandic      & \TX{mongolian}  & \TX{sorbian}   \\
% amharic         & \TX{dutch}     & interlingua    & nko             & \TX{spanish}   \\
% \TX{arabic}     & \TX{english}   & \TX{italian}   & \TX{norwegian}  & swedish        \\
% \TX{armenian}   & \TX{esperanto} & japanese       & occitan         & \TX{syriac}    \\
% asturian        & estonian       & kannada        & \TX{persian}    & tamil          \\
% basque          & \TX{finnish}   & khmer          & piedmontese     & telugu         \\
% \TX{belarusian} & \TX{french}    & \TX{korean}    & polish          & \TX{thai}      \\
% \TX{bengali}    & friulian       & \TX{kurdish}   & \TX{portuguese} & \TX{tibetan}   \\
% bosnian         & \TX{gaelic}    & \TX{lao}       & romanian        & turkish        \\
% breton          & galician       & \TX{latin}     & romansh         & turkmen        \\
% bulgarian       & \TX{georgian}  & latvian        & \TX{russian}    & \TX{ukrainian} \\
% \TX{catalan}    & \TX{german}    & lithuanian     & \TX{sami}       & urdu           \\
% coptic          & \TX{greek}     & macedonian     & \TX{sanskrit}   & uyghur         \\
% \TX{croatian}   & \TX{hebrew}    & \TX{malay}     & \TX{serbian}    & vietnamese     \\
% \TX{czech}      & \TX{hindi}     & malayalam      & \TX{slovak}     & \TX{welsh}     \\
% \bottomrule
% \end{tabular}
% 
% \end{table}
% 
% \paragraph{Version Notes} The support for Amharic\new{1.0.1} should be considered an experimental attempt to
% port the package \pkg{ethiop}; feedback is welcome.
% Version 1.1.1\new{1.1.1} added support for Asturian, %\footnote{ Provided by Kevin Godby and Xuacu Saturio.},
% Lithuanian, %\footnote{ Provided by Kevin Godby and Paulius Sladkevičius.},
% and Urdu. %\footnote{ Provided by Kamal Abdali.}
% ^^A
% Version 1.2\new{1.2.0} introduced Armenian, Occitan, Bengali,
% Lao, Malayalam, Marathi, Tamil, Telugu, and Turkmen.\footnote{%
%   See acknowledgements at the end for due credit to the various contributors.}
% Version 1.43\new{1.43} brought basic support for Japanese (this
% is considered experimental, feedback is appreciated).
% In version 1.45\new{1.45}, support for Kurdish and Mongolian as well as some new
% variants (Canadian French and English) have been added. Furthermore, for consistency reasons, some language have
% been renamed (\emph{farsi}\textrightarrow\emph{persian}, \emph{friulan}\textrightarrow\emph{friulian},
% \emph{magyar}\textrightarrow\emph{hungarian}, \emph{portuges}\textrightarrow\emph{portuguese},
% \emph{samin}\textrightarrow\emph{sami}) or merged (\emph{bahasai}\slash\emph{bahasam}\textrightarrow\emph{malay},
% \emph{brazil}\slash\emph{portuges}\textrightarrow\emph{portuguese},
% \emph{lsorbian}\slash\emph{usorbian}\textrightarrow\emph{sorbian},
% \emph{irish}\slash\emph{scottish}\textrightarrow\emph{gaelic},
% \emph{norsk}\slash\emph{nynorsk}\textrightarrow\emph{norwegian}). The old names are still supported for backwards
% compatibility reasons.
% Version 1.46\new{1.46} introduces support for Afrikaans, Belarusian, Bosnian and Georgian.
% Version 1.52\new{1.52} introduces support for Uyghur.
% 
% 
% \subsection{Relation to and use of Babel language names}\label{sec:babelnames}
% 
% If you are familiar with the \pkg{babel} package, you will note that \pkg{polyglossia}'s language naming
% slightly differs. Whereas \pkg{babel} has a unique name for each language variety (\eg\emph{american} and \emph{british}),
% \pkg{polyglossia} differentiates language varieties via language options (\eg \emph{english}, ¦variant=american¦).
% 
% Furthermore, \pkg{babel} sometimes uses abbreviated language names (\eg\emph{bahasam} for Bahasa Malayu) as well
% as endonyms, \ie language names coming from the designated languages (such as \emph{bahasa}, \emph{canadien} or \emph{magyar}).
% As opposed to this, \pkg{polyglossia} always uses spelled-out (lower-cased) English language names.
% Please refer to table~\ref{tab:bbllang} for the differing language names in both packages.
% 
% \begin{table}
% \caption{\label{tab:bbllang}Babel-polyglossia language name matching}
% 
% \begin{minipage}[t]{1\columnwidth}
% \small\centering
% \begin{tabular}{lll}
% \toprule
% \textbf{Babel name} & \textbf{Polyglossia name} & \textbf{Polyglossia options}\tabularnewline
% \midrule
% acadien            & french     & variant=acadian                     \\
% american           & english    & variant=american [\emph{default}]   \\
% australian         & english    & variant=australian                  \\
% austrian           & german     & variant=austrian, spelling=old      \\
% bahasa             & malay      & variant=indonesian [\emph{default}] \\
% bahasam            & malay      & variant=malaysian                   \\
% brazil             & portuguese & variant=brazilian                   \\
% british            & english    & variant=british                     \\
% canadian           & english    & variant=canadian                    \\
% canadien           & french     & variant=canadian                    \\
% classiclatin\footnote{In \pkg{babel} currently only selectable via dot modifier (\emph{latin.classic}).}
%                    & latin      & variant=classic                     \\
% farsi              & persian    &                                     \\
% ecclesiasticlatin\footnote{In \pkg{babel} currently only selectable via dot modifier (\emph{latin.ecclesiastic}).}
%                    & latin      & variant=ecclesiastic                \\
% friulan            & friulian   &                                     \\
% german\footnote{Due to the name conflict only available in \pkg{polyglossia} as \emph{germanb} (which is a \pkg{babel} synonym).}
%                    & german     & spelling=old                        \\
% irish              & gaelic     & variant=irish [\emph{default}]      \\
% kurmanji           & kurdish    & variant=kurmanji                    \\
% lowersorbian       & sorbian    & variant=lower                       \\
% magyar             & hungarian  &                                     \\
% medievallatin\footnote{In \pkg{babel} currently only selectable via dot modifier (\emph{latin.medieval}).}
%                    & latin      & variant=medieval                    \\
% naustrian          & german     & variant=austrian                    \\
% newzealand         & english    & variant=newzealand                  \\
% ngerman            & german     & variant=german [\emph{default}]     \\
% norsk              & norwegian  & variant=bokmal                      \\
% nswissgerman       & german     & variant=swiss                       \\
% nynorsk            & norwegian  & variant=nynorsk [\emph{default}]    \\
% polutonikogreek    & greek      & variant=polytonic                   \\
% portuges           & portuguese & variant=portuguese [\emph{default}] \\
% samin              & sami       &                                     \\
% scottish           & gaelic     & variant=scottish                    \\
% serbianc           & serbian    & script=Cyrillic                     \\
% slovene            & slovenian  &                                     \\
% spanishmx          & spanish    & variant=mexican                     \\
% swissgerman        & german     & variant=swiss, spelling=old         \\
% uppersorbian       & sorbian    & variant=upper [\emph{default}]      \\
% \bottomrule
% \end{tabular}
% \end{minipage}
% 	
% \end{table}
% 
% For convenience reasons, \pkg{polyglossia} also supports the use of babel names\new{1.46} (for the few justified
% exceptions, please refer to the notes in table~\ref{tab:bbllang}).
% The babel names listed in table~\ref{tab:bbllang} can be used instead of the corresponding polyglossia
% name\slash options in \cmd\setdefaultlanguage\ and \cmd\setotherlanguage\ as well as in the \pkg{polyglossia} and
% \pkg{babel} language switching commands\slash environments documented in section~\ref{sec:langcmds} and
% \ref{sec:babelcmds} (\eg \cmd\textaustrian\ is synonymous to ¦\textgerman[variant=austrian,spelling=old]¦).
% However, unless you have special reasons, we strongly encourage you to use the \pkg{polyglossia} names.
% 
% 
% \subsection{Using IETF language tags}\label{sec:langtags}
% 
% \pkg{Polyglossia}\new{1.47} also supports the use of language tags that conform to the IETF BCP-47
% \emph{Best Current Practice}.\footnote{Please refer to \url{https://tools.ietf.org/html/bcp47} and
% 	\url{https://en.wikipedia.org/wiki/IETF_language_tag} for details.}
% Thus, you can use tags such as ¦en-GB¦ (for British English) or ¦de-AT-1901¦ (for Austrian German, old spelling)
% in \cmd\setdefaultlanguage\ and \cmd\setotherlanguage\ as well as in the language switching command
% \cmd{\textlang\marg{tag}}, the environment \cmd{\begin\{lang\}\marg{tag}} \ldots\ \cmd{\end\{lang\}} and the \pkg{babel}
% language switching commands\slash environments documented in section~\ref{sec:babelcmds}.
% Table~\ref{tab:BCP47-polyglossia} lists the currently supported tags.
% 
% \bgroup\small\addfontfeatures{Numbers={Monospaced,Lining}}
% \begin{longtable}[c]{lll}
% 	\caption{\label{tab:BCP47-polyglossia}BCP47-polyglossia language name matching}\\
% 	\toprule
% 	\textbf{BCP-47 tag} & \textbf{Polyglossia name} & \textbf{Polyglossia options}\\
% 	\midrule
% 	\endfirsthead
% 	\caption[]{BCP47-polyglossia language name matching (\emph{continued})}\\
% 	\toprule
% 	\textbf{BCP-47 tag} & \textbf{Polyglossia name} & \textbf{Polyglossia options}\\
% 	\midrule
% 	\endhead
% 	aeb              & arabic      & locale=tunisia                                     \\
% 	af               & afrikaans   &                                                    \\
% 	afb              & arabic      & locale=default                                     \\
% 	am               & amharic     &                                                    \\
% 	apd              & arabic      & locale=default                                     \\
% 	ar               & arabic      &                                                    \\
% 	ar-IQ            & arabic      & locale=mashriq                                     \\
% 	ar-JO            & arabic      & locale=mashriq                                     \\
% 	ar-LB            & arabic      & locale=mashriq                                     \\
% 	ar-MR            & arabic      & locale=mauritania                                  \\
% 	ar-PS            & arabic      & locale=mashriq                                     \\
% 	ar-SY            & arabic      & locale=mashriq                                     \\
% 	ar-YE            & arabic      & locale=default                                     \\
% 	arq              & arabic      & locale=algeria                                     \\
% 	ary              & arabic      & locale=morocco                                     \\
% 	arz              & arabic      & locale=default                                     \\
% 	ast              & asturian    &                                                    \\
% 	ayl              & arabic      & locale=libya                                       \\
% 	be               & belarusian  &                                                    \\
% 	be-tarask        & belarusian  & spelling=classic                                   \\
% 	bg               & bulgarian   &                                                    \\
% 	bn               & bengali     &                                                    \\
% 	bo               & tibetan     &                                                    \\
% 	br               & breton      &                                                    \\
% 	bs               & bosnian     &                                                    \\
% 	ca               & catalan     &                                                    \\
% 	ckb              & kurdish     & variant=sorani [\emph{default}]                    \\
% 	ckb-Arab         & kurdish     & variant=sorani, script=Arabic [\emph{default}]     \\
% 	ckb-Latn         & kurdish     & variant=sorani, script=Latin                       \\
% 	cop              & coptic      &                                                    \\
% 	cy               & welsh       &                                                    \\
% 	cz               & czech       &                                                    \\
% 	da               & danish      &                                                    \\
% 	de               & german      &                                                    \\
% 	de-AT            & german      & variant=austrian, spelling=new                     \\
% 	de-AT-1901       & german      & variant=austrian, spelling=old                     \\
% 	de-AT-1996       & german      & variant=austrian, spelling=new                     \\
% 	de-CH            & german      & variant=swiss, spelling=new                        \\
% 	de-CH-1901       & german      & variant=swiss, spelling=old                        \\
% 	de-CH-1996       & german      & variant=swiss, spelling=new                        \\
% 	de-DE            & german      & variant=german, spelling=new                       \\
% 	de-DE-1901       & german      & variant=german, spelling=old                       \\
% 	de-DE-1996       & german      & variant=german, spelling=new  [\emph{default}]     \\
% 	de-Latf          & german      & script=blackletter                                 \\
% 	de-Latf-AT       & german      & variant=austrian, spelling=new, script=blackletter \\
% 	de-Latf-AT-1901  & german      & variant=austrian, spelling=old, script=blackletter \\
% 	de-Latf-AT-1996  & german      & variant=austrian, spelling=new, script=blackletter \\
% 	de-Latf-CH       & german      & variant=swiss, spelling=new, script=blackletter    \\
% 	de-Latf-CH-1901  & german      & variant=swiss, spelling=old, script=blackletter    \\
% 	de-Latf-CH-1996  & german      & variant=swiss, spelling=new, script=blackletter    \\
% 	de-Latf-DE       & german      & variant=german, spelling=new, script=blackletter   \\
% 	de-Latf-DE-1901  & german      & variant=german, spelling=old, script=blackletter   \\
% 	de-Latf-DE-1996  & german      & variant=german, spelling=new, script=blackletter   \\
% 	dsb              & sorbian     & variant=lower                                      \\
% 	dv               & divehi      &                                                    \\
% 	el               & greek       &                                                    \\
% 	el-monoton       & greek       & variant=monotonic  [\emph{default}]                \\
% 	el-polyton       & greek       & varant=polytonic                                   \\
% 	en               & english     &                                                    \\
% 	en-AU            & english     & variant=australian                                 \\
% 	en-CA            & english     & variant=canadian                                   \\
% 	en-GB            & english     & variant=british                                    \\
% 	en-NZ            & english     & variant=newzealand                                 \\
% 	en-US            & english     & variant=us [\emph{default}]                        \\
% 	eo               & esperanto   &                                                    \\
% 	es               & spanish     &                                                    \\
% 	es-ES            & spanish     & variant=spanish [\emph{default}]                   \\
% 	es-MX            & spanish     & variant=mexican                                    \\
% 	et               & estonian    &                                                    \\
% 	eu               & basque      &                                                    \\
% 	fa               & persian     &                                                    \\
% 	fi               & finnish     &                                                    \\
% 	fr               & french      &                                                    \\
% 	fr-CA            & french      & variant=canadian                                   \\
% 	fr-CH            & french      & variant=swiss                                      \\
% 	fr-FR            & french      & variant=french [\emph{default}]                    \\
% 	fur              & friulian    &                                                    \\
% 	ga               & gaelic      & variant=irish [\emph{default}]                     \\
% 	gd               & gaelic      & variant=scottish                                   \\
% 	gl               & galician    &                                                    \\
% 	grc              & greek       & variant=ancient                                    \\
% 	he               & hebrew      &                                                    \\
% 	hi               & hindi       &                                                    \\
% 	hr               & croatian    &                                                    \\
% 	hsb              & sorbian     & variant=upper [\emph{default}]                     \\
% 	hu               & hungarian   &                                                    \\
% 	hy               & armenian    &                                                    \\
% 	ia               & interlingua &                                                    \\
% 	id               & malay       & variant=indonesian                                 \\
% 	is               & icelandic   &                                                    \\
% 	it               & italian     &                                                    \\
% 	ja               & japanese    &                                                    \\
% 	ka               & georgian    &                                                    \\
% 	km               & khmer       &                                                    \\
% 	kmr              & kurdish     & variant=kurmanji                                   \\
% 	kmr-Arab         & kurdish     & variant=kurmanji, script=Arabic                    \\
% 	kmr-Latn         & kurdish     & variant=kurmanji, script=Latin                     \\
% 	kn               & kannada     &                                                    \\
% 	ko               & korean      &                                                    \\
% 	ku               & kurdish     &                                                    \\
% 	ku-Arab          & kurdish     & script=Arabic                                      \\
% 	ku-Latn          & kurdish     & script=Latin                                       \\
% 	la               & latin       &                                                    \\
% 	la-x-classic     & latin       & variant=classic                                    \\
% 	la-x-ecclesia    & latin       & variant=ecclesiastic                               \\
% 	la-x-medieval    & latin       & variant=medieval                                   \\
% 	lo               & lao         &                                                    \\
% 	lt               & lithuanian  &                                                    \\
% 	lv               & latvian     &                                                    \\
% 	mk               & macedonian  &                                                    \\
% 	ml               & malayalam   &                                                    \\
% 	mn               & mongolian   &                                                    \\
% 	mr               & marathi     &                                                    \\
% 	nb               & norwegian   & variant=bokmal                                     \\
% 	nko              & nko         &                                                    \\
% 	nl               & dutch       &                                                    \\
% 	nn               & norwegian   & variant=nynorsk [\emph{default}]                   \\
% 	oc               & occitan     &                                                    \\
% 	pl               & polish      &                                                    \\
% 	pms              & piedmontese &                                                    \\
% 	pt               & portuguese  &                                                    \\
% 	pt-BR            & portuguese  & variant=brazilian                                  \\
% 	pt-PT            & portuguese  & variant=portuguese [\emph{default}]                \\
% 	rm               & romansh     &                                                    \\
% 	ro               & romanian    &                                                    \\
% 	ru               & russian     &                                                    \\
% 	ru-luna1918      & russian     & spelling=modern [\emph{default}]                   \\
% 	ru-petr1708      & russian     & spelling=old                                       \\
% 	sa               & sanskrit    &                                                    \\
% 	sa-Beng          & sanskrit    & script=Bengali                                     \\
% 	sa-Deva          & sanskrit    & script=Devanagari [\emph{default}]                 \\
% 	sa-Gujr          & sanskrit    & script=Gujarati                                    \\
% 	sa-Knda          & sanskrit    & script=Kannada                                     \\
% 	sa-Mlym          & sanskrit    & script=Malayalam                                   \\
% 	sa-Telu          & sanskrit    & script=Telugu                                      \\
% 	se               & sami        &                                                    \\
% 	sk               & slovak      &                                                    \\
% 	sl               & slovenian   &                                                    \\
% 	sq               & albanian    &                                                    \\
% 	sr               & serbian     &                                                    \\
% 	sr-Cyrl          & serbian     & script=Cyrillic                                    \\
% 	sr-Latn          & serbian     & script=Latin [\emph{default}]                      \\
% 	sv               & swedish     &                                                    \\
% 	syr              & syriac      &                                                    \\
% 	ta               & tamil       &                                                    \\
% 	te               & telugu      &                                                    \\
% 	th               & thai        &                                                    \\
% 	tk               & turkmen     &                                                    \\
% 	tr               & turkish     &                                                    \\
% 	ug               & uyghur      &                                                    \\
% 	uk               & ukrainian   &                                                    \\
% 	ur               & urdu        &                                                    \\
% 	vi               & vietnamese  &                                                    \\
% 	zsm              & malay       & variant=malaysian [\emph{default}]                 \\
% 	\bottomrule
% \end{longtable}
% \egroup
% 
% \subsection{Global options}
% 
% \pkg{Polyglossia} can be loaded with the following global package options:
% 
% \begin{itemize}
% 	\item \xpgboolkeyfalse[1.1.1]{babelshorthands}
% 		Globally activates \pkg{babel} shorthands whenever available. Currently
% 		shorthands are implemented for Afrikaans, Belarusian, Catalan, Croatian,
% 		Czech, Dutch, Finnish, Georgian, German, Italian, Latin, Mongolian,
% 		Russian, Slovak, and Ukrainian. Please refer to the respective language descriptions
% 		(sec.~\ref{specific}) for details.
% 
% 	\item \xpgboolkeyfalse{localmarks} redefines the internal \LaTeX\ macros \cmd\markboth\ and
% 		\cmd\markright\ to the effect that the header text is explicitly set in the currently
% 		active language (\ie wrapped into \cmd\foreignlanguage\{\meta{lang}\}\{\meta{\ldots}\}).
% 		
% 		In earlier versions of \pkg{polyglossia},\new{1.2.0} this
% 		option was enabled by default, but we now realize that it causes more problems
% 		than it helps (since it breaks if a package or class redefines \cmd\markboth\ or
% 		\cmd\markright), so it is now disabled by default. For backwards compatibility, the
% 		option \xpgoption{nolocalmarks} which used to switch off the previous default, and
% 		now equals the default, is still available.
% 
%     \item \xpgoptkey[1.50]{luatexrenderer}{renderer}[Harfbuzz] determines which font renderer is used
%         with \LuaTeX\ output. The correct font renderer is essential particularly for non-Latin scripts.
%         By default, \pkg{polyglossia} uses the \xpgvalue{Harfbuzz} renderer that has been introduced to
%         \LuaTeX\ in 2019 (\TeX Live 2020), as this gives the best results generally. If you want to use
%         a different renderer, you can specify this here (or individually for specific fonts via the optional
%         argument of the font selection commands). Please refer to the \pkg{fontspec} manual for supported
%         values and for details on how to change the renderer for individual fonts.\\
%         \xpgoption{luatexrenderer=none} disables \pkg{polyglossia}'s automatic renderer setting.
% 
% 	\item \xpgboolkeytrue{verbose} determines whether info messages and (some of the) warnings issued
% 		by \LaTeX, \pkg{fontspec} and \pkg{polyglossia} are output.
% \end{itemize}
% 
% \section{Language-switching commands}\label{languageswitching}
% 
% \subsection{Recommended commands}\label{sec:langcmds}
% For each activated language the command
% \cmd{\text\meta{lang}\oarg{options}\marg{…}} \DescribeMacro{\text\meta{lang}}
% (as well as the synonymous \DescribeMacro{\textlang}%
% \cmd{\textlang\oarg{options}\marg{lang}\marg{…}}\new{1.46})
% becomes available for short insertions of text in that language.
% 
% For example ¦\textrussian{\today}¦ and ¦\textlang{russian}{\today}¦ yield \textrussian{\today}
% The commands switch to the correct hyphenation patterns, they activate
% some extra features for the selected language (such as extra spacing before
% punctuation in French), and they translate the date when using \cmd\today.
% They do not, however, translate so-called \textit{caption strings}, \ie
% ``chapter'', ``figure'' etc., to the local language (these remain in the currently active `outer'
% language).
% 
% The\DescribeEnv{\meta{lang}}\ environment \meta{lang}, which is also available for any activated language
% (as well as the equivalent \DescribeMacro{lang}%
% \cmd{\begin\{lang\}\oarg{options}\marg{lang}} \dots{} \cmd{\end\{lang\}}\new{1.47}),
% is meant for longer passages of text. It behaves slightly different than the \cmd{\text\meta{lang}} and
% \cmd\textlang\ commands: It does everything the latter do, but additionally, the caption strings
% are translated as well, and the language is also passed to auxiliary files, the table of contents
% and the lists of figures/tables.
% Like the commands, the environment provides the possibility of setting language options locally.
% For instance the following allows us to quote the beginning
% of Homer’s \textit{Iliad}:
% 
% \begin{Verbatim}[formatcom=\color{xpgblue}]
%   \begin{quote}
%    \begin{greek}[variant=ancient]
%      μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην, ἣ μυρί' Ἀχαιοῖς
%      ἄλγε' ἔθηκε, πολλὰς δ' ἰφθίμους ψυχὰς Ἄϊδι προί̈αψεν ἡρώων,
%      αὐτοὺς δὲ ἑλώρια τεῦχε κύνεσσιν οἰωνοῖσί τε πᾶσι, Διὸς δ'
%      ἐτελείετο βουλή, ἐξ οὗ δὴ τὰ πρῶτα διαστήτην ἐρίσαντε Ἀτρεί̈δης
%      τε ἄναξ ἀνδρῶν καὶ δῖος Ἀχιλλεύς.
%    \end{greek}
%   \end{quote}
% \end{Verbatim}
% 
% \vspace{-.5\baselineskip}
% 
% \begin{quote}
% \begin{greek}[variant=ancient]
% μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην, ἣ μυρί' Ἀχαιοῖς ἄλγε' ἔθηκε,
% πολλὰς δ' ἰφθίμους ψυχὰς Ἄϊδι προί̈αψεν ἡρώων, αὐτοὺς δὲ ἑλώρια τεῦχε κύνεσσιν
% οἰωνοῖσί τε πᾶσι, Διὸς δ' ἐτελείετο βουλή, ἐξ οὗ δὴ τὰ πρῶτα διαστήτην ἐρίσαντε
% Ἀτρεί̈δης τε ἄναξ ἀνδρῶν καὶ δῖος Ἀχιλλεύς.
% \end{greek}
% \end{quote}
% 
% \noindent\DescribeEnv{Arabic} Note that for Arabic one cannot use the environment ¦arabic¦,
% as \cmd\arabic\ is defined internally by \LaTeX. In this case
% we need to use the environment ¦Arabic¦ instead.
% 
% \subsection{Babel commands}\label{sec:babelcmds}
% Some macros defined in \pkg{babel}’s \file{hyphen.cfg} (and thus usually
% compiled into the \XeLaTeX\ and \LuaLaTeX\ format) are redefined, but keep a
% similar behaviour.
% \begin{itemize}
% \item \DescribeMacro{\selectlanguage}\cmd{\selectlanguage\oarg{options}\marg{lang}}
% \item \DescribeMacro{\foreignlanguage}\cmd{\foreignlanguage\oarg{options}\marg{lang}\marg{…}}
% \item \DescribeEnv{otherlanguage}\cmd{\begin\{otherlanguage\}\oarg{options}\marg{lang}} \dots{} \cmd{\end\{otherlanguage\}}
% \item \DescribeEnv{otherlanguage*}\cmd{\begin\{otherlanguage*\}\oarg{options}\marg{lang}} \dots{} \cmd{\end\{otherlanguage*\}}
% \item \DescribeEnv{hyphenrules}\cmd{\begin\{hyphenrules\}\oarg{options}\marg{lang}} \dots{} \cmd{\end\{hyphenrules\}}\new{1.50}
% \end{itemize}
% ^^A
% \cmd\selectlanguage\marg{lang} and the ¦otherlanguage¦ environment are identical to the
% \meta{lang} environment, except that \cmd\selectlanguage\marg{lang}
% does not need to be explicitly closed. The command \cmd\foreinlanguage\marg{lang}\marg{…} and the ¦otherlanguage*¦
% environment are identical with the use of the \cmd\text\meta{lang} or \cmd\textlang\ command, with the one
% notable exception that they do not translate the date with \cmd\today.
% 
% The \meta{hyphenrules} environment only switches the hyphenation patterns to the one associated with the language \meta{lang}
% (or the language variety as specified via \meta{options}). It does no further language-specific change.
% 
% Since the \XeLaTeX\ and \LuaLaTeX\ format incorporate \pkg{babel}’s \file{hyphen.cfg},
% the low-level commands for hyphenation and language switching defined there are in principal also accessible.
% Note, however, that the availability of such low-level commands is not guaranteed, as \file{hyphen.cfg}, which is
% out of \pkg{polyglossia}'s control, is (or at least has been) subject to regular change.
% 
% \subsection{Other commands}
% The following commands are probably of lesser interest to the end user, but
% ought to be mentioned here.
% \begin{itemize}
% \item \DescribeMacro{\selectbackgroundlanguage}\cmd{\selectbackgroundlanguage\marg{lang}}:
%     this selects the global font setup and the numbering definitions for the default language.
% 
% \item \DescribeMacro{\resetdefaultlanguage}\cmd{\resetdefaultlanguage\oarg{options}\marg{lang}} (experimental):
% 	completely switches the default language
% 	to another one in the middle of a document: \textit{this may have adverse effects}!
% 
% \item \Cmd\normalfontlatin: in an environment where \cmd\normalfont\ has been redefined
% 	to a non-latin script, this will reset to the font defined with \cmd\setmainfont\ etc.
% 	In a similar vein, it is possible to use \Cmd\rmfamilylatin, \Cmd\sffamilylatin,
% 	and \Cmd\ttfamilylatin.
% 
% \item \Cmd\latinalph: Representation of counter as a lower-case letter:  1 = a, 2 = b, etc.
% 
% \item \Cmd\latinAlph: Representation of counter as a upper-case letter:  1 = A, 2 = B, etc.
% \end{itemize}
% 
% 
% \subsection{Setting up alias commands}
% 
% By means of the macro
% \displaycmd{\setlanguagealias\oarg{options}\marg{language}\marg{alias}}{\setlanguagealias}\new{1.46}
% you can define alias commands for specific language (variants). \Eg
% 
% \begin{quote}
% \begin{verbatim}
% \setlanguagealias[variant=austrian]{german}{AT}
% \end{verbatim}
% \end{quote}
% ^^A
% will define a command \cmd{\textAT} as well as an environment ¦{AT}¦ which will link towards
% the command ¦\textgerman[variant=austrian]¦ and the environment ¦{german}[variant=austrian]¦,
% respectively. The aliases can also be used in the language switching commands described in
% section~\ref{sec:langcmds} and \ref{sec:babelcmds}.
% Note, though, that the usual restrictions for command names apply, so something such as
% ¦de-AT¦ or ¦de_AT¦ will not work since ¦-¦ and ¦_¦ are not allowed in command names (the same
% holds true for any non-ASCII character and for digits).
% 
% For the latter case, and for the case where an alias would clash with an existing command
% (\eg ¦\fi¦) or a \cmd{\text\meta{\ldots}} command (\eg \cmd\textit), a starred version \Cmd{\setlanguagealias*}
% is provided which does neither define a \cmd{\text\meta{alias}} command nor an \meta{alias} environment,
% but which will set up the alias for everything else, including \cmd{\textlang\marg{alias}}
% and \cmd{\begin\{lang\}\marg{alias}}.
% 
% \pkg{Polyglossia} comes with some aliases predefined, namely aliases for \pkg{babel} language names
% (see sec.~\ref{sec:babelnames}) and for IETF BCP-47 language tags (the latter via \cmd{\setlanguagealias*};
% see sec.~\ref{sec:langtags}).
% 
% \section{Font setup}
% 
% With polyglossia it is possible to associate a specific font with any script or language
% that occurs in the document. That font should always be defined as
% \cmd{\⟨script⟩font}\ or \cmd{\⟨language⟩font}.
% For instance, if the default font defined by \cmd\setmainfont\
% does not support Greek, then one can define the font used to display Greek with:\\
% \centerline{ \cmd\newfontfamily\cmd{\greekfont[Script=Greek,\meta{…}]\marg{font}}. }
% Note that polyglossia will use the font defined as is, so assure to do all necessary settings
% (please refer to the \pkg{fontspec} documentation for details).
% For instance, if \cmd\arabicfont\ is explicitly defined, then the option ¦Script=Arabic¦ should
% be included in that definition.
% 
% If a specific sans serif or monospace (`teletype') font is needed for a particular script or language,
% it can be defined by means of \new{1.2.0}
% \cmd{\⟨script⟩fontsf} or \cmd{\⟨language⟩fontsf} and \cmd{\⟨script⟩fonttt} or \cmd{\⟨language⟩fonttt}, respectively.
% 
% Whenever a new language is activated, \pkg{polyglossia} will first check whether
% a font has been defined for that language or – for languages in non-Latin scripts –
% for the script it uses. If it is not defined, it will use the currently active font
% and – in the case of OpenType fonts – will attempt to turn on the appropriate
% OpenType tags for the script and language used, in case these are available in
% the font, by means of \pkg{fontspec}’s \cmd\addfontfeature. If the current font
% does not appear to support the script of that language, an error message is
% displayed.
% 
% \section{Adapting hyphenation}
% 
% \subsection{Hyphenation exceptions}
% 
% \TeX\ provides the command \cmd\hyphenation\marg{exceptions} to globally define hyphenation exceptions
% which override the hyphenation patterns for specified words. The command takes as argument a space-separated
% list of words where hyphenation points are marked by a dash (if no dash is used, the respective word is not
% hyphenated at all):
% \begin{quote}
% \begin{minipage}{\textwidth}
% \begin{verbatim}
% \hyphenation{%
%   po-ly-glos-sia
%   LaTeX
% }
% \end{verbatim}
% \end{minipage}
% \end{quote}
% ^^A
% These exceptions, however, apply to all languages. In addition to this, \pkg{polyglossia} provides
% the command\new{1.45}
% \displaycmd{\pghyphenation\oarg{options}\marg{lang}\marg{exceptions}}{\pghyphenation}
% which can be used to define exceptions that only apply to a specific language or language variant,
% respectively.
% 
% \subsection{Hyphenation thresholds}
% 
% \pkg{Polyglossia} sets reasonable defaults for the hyphenation thresholds of each language,
% \ie the number of characters that must  at least be there at the beginning or end of a
% word before it is hyphenated (\cmd\lefthyphenmin\ and \cmd\righthyphenmin\ in \TeX).
% For instance, with English, this threshold is 2 at the beginning (`left') and 3 at the end (`right'),
% so a word will not be hyphenated within the first two characters at the beginning and the last three
% characters at the end.
% 
% To change this value, \pkg{polyglossia} provides the command\new{1.50}
% \displaycmd{\setlanghyphenmins\oarg{options}\marg{lang}\marg{l}\marg{r}}{\setlanghyphenmins}
% ^^A
% where \meta{lang} is to be replaced with the respective language name or alias, \meta{options}
% can be used to delimit the modification to a particular variety (\eg via \texttt{variant} or \texttt{spelling}),
% \meta{l} with the left threshold value (\eg \texttt{3}), and \meta{r} with the right
% threshold value (\eg \verb|\setlanghyphenmins[spelling=old]{german}{4}{4}|).
% This setting can be changed repeatedly in the preamble and the document body.
% It applies to all subsequent text in the respective language (variety), but only after the
% next language switch.
% 
% \subsection{Hyphenation disabling}
% 
% In some very specific contexts (such as music score creation), \TeX\ hyphenation
% is something to avoid completely as it may cause troubles.
% \pkg{Polyglossia} provides two functions: \Cmd\disablehyphenation\ and \Cmd\enablehyphenation.
% Note that if you select a new language while hyphenation is disabled, it will remain disabled.
% If you re-enable it, the hyphenation patterns of the currently selected language
% will be activated.
% 
% \section{Language-specific options and commands}\label{specific}
% 
% This section gives a list of all languages for which options and end-user
% commands are defined. Note the following conventions:
% \begin{itemize}
% 	\item The preset value of each option (\ie the setting that applies by default,
% 	if the option is not explicitly set) is given in \xpgpresetvalue{italics}.
% 	\item If an option key may be used without a value, the value that applies
% 	for value-less keys is marked by a preceding \xpgdefaultvalue{asterisk}.
% \end{itemize}
% For instance, \texttt{babelshorthands = *true} or \texttt{\textit{false}} means that
% \xpgvalue{babelshorthands} is \xpgvalue{false} by default in the respective language,
% and that passing \xpgvalue{babelshorthands} (without value) is equivalent to passing
% \xpgvalue{babelshorthands=true}.
% 
% \subsection{afrikaans}\label{afrikaans}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse[1.1.1]{babelshorthands}
% 	If this is turned on, the following shorthands defined for fine-tuning hyphenation and
% 	micro-typography of Afrikaans words are activated:
% 	\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		in the hyphenation patterns (as opposed to \cmd\- in default \TeX).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash,
% 		hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
% 	\end{shorthands}
% \end{itemize}
% 
% \subsection{arabic}\label{arabic}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{calendar}{\xpgpresetvalue{gregorian} or \xpgvalue{islamic} (= \xpgvalue{hijri})}
% 	\item \xpgchoicekey{locale}{\xpgpresetvalue{default}\footnote{ %
% 			For Egypt, Sudan, Yemen and the Gulf states.},
% 		\xpgvalue{mashriq}\footnote{ %
% 			For Iraq, Syria, Jordan, Lebanon and Palestine.},
% 		\xpgvalue{libya}, \xpgvalue{algeria}, \xpgvalue{tunisia}, \xpgvalue{morocco}, \xpgvalue{mauritania}}
% 		This setting influences the spelling of the month names for the Gregorian calendar,
% 		as well as the form of the numerals (unless overriden by the following option).
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{mashriq} or \xpgvalue{maghrib}}
% 		The latter is the default when \xpgvalue{locale=algeria}, \xpgvalue{tunisia}, or \xpgvalue{morocco}.
% 	\item \xpgboolkeyfalse[1.50]{abjadalph}
% 	     Set this to true if you want the alphabetic counters to be output using \cmd\abjadalph\ rather than \cmd\abjad.
% 	     Note that this limits the counter scope to 28 (see \cmd\abjadalph\ below).
% 	\item \xpgboolkeyfalse[1.0.3]{abjadjimnotail}
%     Set this to true if you want the \textit{abjad} form of the number three to be \textarabic{ج‍} – as in the manuscript tradition – instead of the modern usage \textarabic{ج}.
% 	\end{itemize}
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\abjad outputs Arabic \textit{abjad} numbers according to the Mashriq varieties.
% 	      Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.	
% 	\item \Cmd\abjadmaghribi outputs Arabic \textit{abjad} numbers according to the Maghrib varieties.
% 	       Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
% 	\item \Cmd\abjadalph\new{1.50} steps through the Arabic alphabet, thus it can only be used up to 28.
% 	       Example: ¦\textarabic{\abjadalph{18}}¦ yields \textarabic{\abjadalph{18}}.
%     \item \Cmd\aemph to emphasize text with \cmd\overline.\new{1.2.0}
%           ¦\textarabic{\aemph{اب}}¦ yields \textarabic{\aemph{اب}}.
%            This command is also available for Farsi, Urdu, etc.
% 	\end{itemize}
% 
% \subsection{armenian}\label{armenian}
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgchoicekey[1.45]{variant}{\xpgvalue{eastern} or \xpgpresetvalue{western}}
% 	\item \xpgchoicekey[1.45]{numerals}{\xpgvalue{armenian} or \xpgpresetvalue{arabic}}
% \end{itemize}
% 
% \subsection[belarusian]{belarusian\new{1.46}}\label{belarusian}
% 
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgboolkeyfalse{babelshorthands}
% 	If this is turned on, the following shorthands are activated:
% 	\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		    in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦"=¦] adds an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		    other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		    cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
% 		\item[¦"‘¦] for German left double quotes (looks like ,,).
% 		\item[¦"’¦] for German right double quotes (looks like “).
% 		\item[¦"<¦] for French left double quotes (looks like <<).
% 		\item[¦">¦] for French right double quotes (looks like >>).
% 	\end{shorthands}
% 
% 	There are also three shorthands for the Cyrillic dash (\textrussian{тире}), which is shorter than the
% 	emdash but longer than the endash (namely 0.8\,em).
% 	Note that, since it is not covered by unicode, this character is faked by telescoping two endashes:
% 	\begin{shorthands}
% 		\item[¦"---¦] Cyrillic dash for the use in normal text. This requires preceding space
% 		       in input (trailing space is optional) and prints with a non-breakable thin space before
% 	           and after the dash.
% 		\item[¦"--\textasciitilde¦] Cyrillic dash for the use in compound names (surnames).
% 		       As opposed to ¦"---¦ this removes any space before and after the dash. 
% 		\item[¦"--*¦] Cyrillic dash for denoting direct speech. This adds a larger space after
% 		       the dash. Space before the dash is output as is.
% 	\end{shorthands}
%     \item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic}, \xpgvalue{cyrillic-alph} or \xpgvalue{cyrillic-trad}}
%          Uses either Arabic numerals or Cyrillic alphanumerical numbering. The two Cyrillic variants differ as follows:
%          \begin{itemize}
% 	          \item \xpgvalue{cyrillic-alph} steps through the Cyrillic alphabet. Thus it can only be used up to 30.
% 	          \item \xpgvalue{cyrillic-trad} (= \xpgvalue{cyrillic}) uses a traditional Cyrillic alphanumeric system.%
% 	                \footnote{See \url{https://en.wikipedia.org/wiki/Cyrillic_numerals}.}
% 	                It supports numbers up to 999\,999.
%          \end{itemize}
% 	\item \xpgchoicekey{spelling}{\xpgpresetvalue{modern} or \xpgvalue{classic} (= \xpgvalue{tarask})}
% 	With ¦spelling=classic¦, captions and dates adhere to the Taraškievica (or
% 	Belarusian classical) orthography rather than the standard orthography.
% \end{itemize}
% 
% \condbreak{\baselineskip}
% \paragraph*{Commands:}
% \begin{itemize}
%      \item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for environments such as ¦enumerate¦.
%           It steps through the Cyrillic alphabet and thus it can only be used up to 30.
%           The command takes a counter as argument, \eg ¦\textbelarusian{\Asbuk{page}}¦ produces \textrussian{\Asbuk{page}}.
%      \item \Cmd\asbuk: same as \cmd\Asbuk\ but in lowercase.
%      \item \Cmd\AsbukTrad: same as \cmd\Asbuk\ but using the traditional Cyrillic alphanumeric numbering which supports
%           numbers up to 999\,999.\\
%           \Eg ¦\textbelarusian{\AsbukTrad{page}}¦ produces \textrussian{\AsbukTrad{page}}.
%      \item \Cmd\asbukTrad: same as \cmd\AsbukTrad\ but in lowercase.
% \end{itemize}
% 
% \subsection[bengali]{bengali\new{1.2.0}}\label{bengali}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	  \item \xpgchoicekey{numerals}{\xpgvalue{Western}, \xpgvalue{Bengali}, or \xpgpresetvalue{Devanagari}}
% 		\item \xpgboolkeyfalse{changecounternumbering}
% 		Use specified numerals for headings and page numbers.
% 	\end{itemize}
% 
% \subsection{catalan}\label{catalan}
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgboolkeyfalse[1.1.1]{babelshorthands}
%     Activates the shorthands \texttt{"l} and \texttt{"L} to type geminated l or L.
% \end{itemize}
% 
% \paragraph*{Commands:}
% \begin{itemize}
%   \item \Cmd{\l.l} and \Cmd{\L.L}\new{1.1.1} can be used to type a geminated l, as in \textit{co\l.laborar},
%         similar to \pkg{babel} (the glyph U+00B7 MIDDLE DOT is used as a geminating sign).
% \end{itemize}
% 
% \subsection{croatian}\label{croatian}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse[1.47]{babelshorthands}
% 	If this is turned on, the following shorthands for fine-tuning hyphenation and micro-typography
% 	of Croatian words are activated.
% 	\begin{shorthands}
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦"=¦] for an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		            other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		            cases where the hyphen should stick at the following syllable.
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		            in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash, hyphenation
% 		            at the breakpoints preset in the hyphenation patterns is still allowed.
% 	\end{shorthands}
% 	Furthermore, the following shorthands generate easy access to Croatian digraphs (ligatures):
% 	\begin{shorthands}
% 		\item[¦"dz¦] Generates the ligature \charifavailable{01C6}{dž}\ if the font provides it. If not, the
% 		             two characters are output separately. Also available for ¦"Dz¦ (\charifavailable{01C5}{Dž})
% 		             and ¦"DZ¦ (\charifavailable{01C4}{DŽ}).
% 		\item[¦"lj¦] Generates the ligature \charifavailable{01C9}{lj}\ if the font provides it. If not, the
% 		             two characters are output separately. Also available for ¦"Lj¦ (\charifavailable{01C8}{Lj})
% 		             and ¦"LJ¦ (\charifavailable{01C7}{LJ}).
% 		\item[¦"nj¦] Generates the ligature \charifavailable{01CC}{nj}\ if the font provides it. If not, the
% 		             two characters are output separately. Also available for ¦"Nj¦ (\charifavailable{01CB}{Nj})
% 		             and ¦"NJ¦ (\charifavailable{01CA}{NJ}).
% 	\end{shorthands}
% 	
% 	Finally, there are also four shorthands for quotation marks:
% 	\begin{shorthands}
% 		\item[¦"`¦] for Croatian left double quotes („).
% 		\item[¦"'¦] for Croatian right double quotes (”).
% 		\item[¦">¦] for Croatian left guillemets (»).
% 		\item[¦"<¦] for Croatian right guillemets («).
% 	\end{shorthands}
% 	\item \xpgboolkeyfalse[1.47]{disableligatures}
% 		If this is \xpgvalue{true}, all Croatian ligatures (for digraphs such as
% 		\charifavailable{01C6}{dž}) will be replaced by single characters. This can
% 		be useful if the ligatures on your font are broken (if the font does not
% 		have them, they are automatically replaced).
%     \item \xpgboolkeytrue[1.51]{splithyphens}
% 	    According to Croatian typesetting conventions, if a word with a hard hyphen (such as \emph{je-li})
% 	    is hyphenated at this hyphen, a second hyphenation character is to be inserted at the beginning
% 	    of the line that follows the hyphenation (\emph{je-/-li}).
% 	    By default, this is done automatically (if you are using \LuaTeX, the \pkg{luavlna} package is
% 	    loaded to achieve this).
% 	    Set this option to ¦false¦ to disable the feature.
% \end{itemize}
% 
% \subsection{czech}\label{czech}
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse[1.45]{babelshorthands}
% 	If this is turned on, the following shorthands for Czech are activated:
% 	\begin{shorthands}
% 		\item[¦"=¦] for an explicit hyphen sign which is repeated at the beginning
% 		            of the next line when hyphenated, as common in Czech typesetting
% 		            (only needed with ¦splithyphens=false¦).
% 		\item[¦"‘¦] for Czech left double quotes („).
% 		\item[¦"’¦] for Czech right double quotes (“).
% 		\item[¦">¦] for Czech left double guillemets (»).
% 		\item[¦"<¦] for Czech right double guillemets («).
% 	\end{shorthands}
% 	\item \xpgboolkeytrue[1.45]{splithyphens}
% 	      According to Czech typesetting conventions, if a word with a hard hyphen (such as \emph{je-li})
% 	      is hyphenated at this hyphen, a second hyphenation character is to be inserted at the beginning
% 	      of the line that follows the hyphenation (\emph{je-/-li}).
%           By default, this is done automatically\new{1.46} (if you are using \LuaTeX, the \pkg{luavlna} package is
%           loaded to achieve this).
%           Set this option to ¦false¦ to disable the feature.
% 	\item \xpgboolkeytrue[1.45]{vlna}
%          According to Czech typesetting conventions, single-letter words (non-syllable prepositions)
%          must not occur at line ends.
%          \pkg{Polyglossia} takes care of this automatically by default\new{1.46} (if you are using \LuaTeX, the
%          \pkg{luavlna} package is loaded to achieve this).
%          Set this option to ¦false¦ to disable the feature.
% \end{itemize}
% 
% \subsection{dutch}\label{dutch}
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgboolkeyfalse[1.1.1]{babelshorthands}
% 		If this is turned on, the following shorthands defined for fine-tuning hyphenation and
% 		micro-typography of Dutch words are activated:
% 		\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 			        in the hyphenation patterns (as opposed to \cmd\- in default \TeX).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 			        cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash,
% 		            hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
% 		\end{shorthands}
%         In addition, the macro \Cmd\- is redefined to allow hyphens in the rest of the word (equivalent to ¦"-¦).
% \end{itemize}
% 
% \subsection{english}\label{english}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgpresetvalue{american} (= \xpgvalue{us}), \xpgvalue{usmax} (same as \xpgvalue{american} but with additional hyphenation patterns),
% 	\xpgvalue{british} (= \xpgvalue{uk}), \xpgvalue{australian}, \xpgvalue{canadian}\new{1.45}, or \xpgvalue{newzealand}}
% 	\item \xpgboolkeyfalse{ordinalmonthday}
% 		The default value is true for \xpgvalue{variant=british}.
% 	\end{itemize}
% 
% \subsection{esperanto}\label{esperanto}
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\hodiau\ and \Cmd\hodiaun are special forms of \cmd\today. The former produces the date in Esperanto
% 	      preceded by the article (\emph{la}), which is the most common date format.
% 	      The latter produces the same date format in accusative case.
% 	\end{itemize}
% 
% \subsection{finnish}\label{finnish}
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgboolkeyfalse[1.45]{babelshorthands}
% 		If this is turned on, the following shorthands for fine-tuning hyphenation
% 		and micro-typography of Finnish words are activated:
% 		\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
%                     in the hyphenation patterns (as opposed to \cmd\-).
%         \item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
%                     cases where the hyphen should stick at the following syllable.
%         \item[¦"|¦] disables a ligature at this position.
%         \item[¦""¦] allows for a line break at this position (without hyphenation sign).
%         \item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash,
%                   hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
% 		\end{shorthands}
% \end{itemize}
% 
% \subsection{french}\label{french}
% \paragraph*{Options:}
% 	\begin{itemize}
% 		\item \xpgchoicekey{variant}{\xpgpresetvalue{french} or \xpgvalue{canadian} (=~\xpgvalue{acadian})\new{1.45}, \xpgvalue{swiss}\new{1.47}}
% 			Currently, the only difference between the four variants is that \xpgvalue{swiss}
% 			uses \xpgvalue{thincolonspace=true} by default since this conforms to the Swiss
% 			conventions.
% 		\item \xpgboolkeytrue{autospacing}
% 			One of the most distinct features of French typography is the addition of
% 			extra spacing around punctuation and quotation marks (guillemets). By
% 			default, polyglossia adds these spaces automatically, so you don't need
% 			to enter them. This options allows you to switch this feature off
% 			globally.
% 		\item \xpgboolkeyfalse[1.46]{thincolonspace}
% 			With \xpgvalue{variant=swiss}, the default value is \xpgvalue{true}. If \xpgvalue{false}, a full
% 			(non-breaking) interword space is inserted before a colon. If \xpgvalue{true}, a
% 			thinner space -- as before \texttt{;}, \texttt{!}, and \texttt{?} -- is
% 			used. Note that this option must be set after the ¦variant¦ option.
% 		\item \xpgboolkeytrue{autospaceguillemets}[Up to version 1.44, the option was
% 		called \xpgvalue{automaticspacesaroundguillemets}. For backwards compatibility
% 		reasons, the more verbose old option is still supported.]
% 			If you only want to disable the automatic addition of spacing after
% 			opening and before closing guillemets (and not at punctuation), set this
% 			to \textit{false}. Note that the more general option \textit{autospacing}
% 			overrides this.
% 		\item \xpgboolkeyfalse[1.45]{autospacetypewriter}[Babel's syntax \xpgvalue{OriginalTypewriter}
% 		is also supported.]
% 			By default, automatic spacing is disabled in typewriter font. If this is
% 			enabled, spacing in typewriter context is the same as with roman and sans
% 			serif font, depending on the \xpgvalue{autospacing} and
% 			\xpgvalue{autospaceguillemets} settings (note that this was the default up
% 			to v.~1.44).
% 		\item \xpgboolkeyfalse{frenchfootnote}
% 			If \xpgvalue{true}, footnotes start with a non-superscripted number
% 			followed by a dot, as common in French typography. Note that this might
% 			interfere with the specific footnote handling of classes or packages.
% 			Also note that this option is only functional (by design) if French is
% 			the main language.
% 		\item \xpgboolkeyfalse[1.46]{frenchitemlabels}
% 			If \textit{true}, itemize item labels use em-dashes throughout, as common
% 			in French typography.  Note that this option is only functional (by
% 			design) if French is the main language. Also, it might interfere with
% 			list packages such as \pkg{enumitem}.
% 		\item \xpgboolkeytrue[1.51]{frenchpart}
% 			By default, \pkg{polyglossia} modifies part headings to match French conventions
% 			(\emph{Première partie} rather than \emph{Partie I}). Next to the standard classes,
% 			specifics of \pkg{KOMA-script}, \pkg{memoir} and the \pkg{titlesec} package are
% 			taken into account. With other classes or packages, redefinition might fail if these
% 			have particular part settings.
% 			In such case, or if you don't want the redefinition, you can switch off the feature
% 			by passing \textit{false} to this option.
% 		\item \xpgcodekey[1.46]{itemlabels}¦\textemdash¦
% 			If \emph{frenchitemlabels} is true, you can customize here the used item
% 			label of all levels.
% 		\item \xpgcodekey[1.46]{itemlabeli}¦\textemdash¦
% 			If \emph{frenchitemlabels} is true, you can customize here the used item
% 			label of the first level.
% 		\item \xpgcodekey[1.46]{itemlabelii}¦\textemdash¦
% 			If \emph{frenchitemlabels} is true, you can customize here the used item
% 			label of the second level.
% 		\item \xpgcodekey[1.46]{itemlabeliii}¦\textemdash¦
% 			If \emph{frenchitemlabels} is true, you can customize here the used item
% 			label of the third level.
% 		\item \xpgcodekey[1.46]{itemlabeliv}¦\textemdash¦
% 			If \emph{frenchitemlabels} is true, you can customize here the used item
% 			label of the fourth level.
% 	\end{itemize}
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\NoAutoSpacing\new{1.45} disables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\NoAutoSpacing foo:bar}¦
% 	\item \Cmd\AutoSpacing\new{1.45} enables automatic spacing around punctuation and quotation marks in all following text. The command can also be used locally if braces are used for grouping: ¦{\AutoSpacing regarde!}¦
% \end{itemize}
% 
% \subsection[gaelic]{gaelic\new{1.45}}\label{gaelic}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgpresetvalue{irish} or \xpgvalue{scottish}}
% \end{itemize}
% 
% \subsection[georgian]{georgian\new{1.46}}\label{georgian}
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse{babelshorthands}
% 		If this is turned on, the following shorthands are activated:
% 		\begin{shorthands}
% 			\item[¦"-¦] adds a hyphenation point that does still allow for
% 			    hyphenation at the points preset in the hyphenation patterns (as opposed to \cmd\-).
% 		    \item[¦"=¦] adds an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 			    other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 			\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 			cases where the hyphen should stick at the following syllable.
% 			\item[¦"|¦] disables a ligature at this position.
% 			\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 			\item[¦",¦] thinspace for initials with a breakpoint in following surname.
% 			\item[¦"‘¦] for German-style left double quotes (looks like ,,).
% 			\item[¦"’¦] for German-style right double quotes (looks like “).
% 			\item[¦"<¦] for French-style left double quotes (looks like <<).
% 			\item[¦">¦] for French-style right double quotes (looks like >>).
% 	    \end{shorthands}
%     
% 		There are also three shorthands for the Cyrillic dash (\textrussian{тире}), which is shorter than the
% 		emdash but longer than the endash (namely 0.8\,em).
% 		Note that, since it is not covered by unicode, this character is faked by telescoping two endashes:
% 		\begin{shorthands}
% 			\item[¦"---¦] Cyrillic dash for the use in normal text. This requires preceding space
% 			in input (trailing space is optional) and prints with a non-breakable thin space before
% 			and after the dash.
% 			\item[¦"--\textasciitilde¦] Cyrillic dash for the use in compound names (surnames).
% 			As opposed to ¦"---¦ this removes any space before and after the dash. 
% 			\item[¦"--*¦] Cyrillic dash for denoting direct speech. This adds a larger space after
% 			the dash. Space before the dash is output as is.
% 		\end{shorthands}
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic} or \xpgvalue{georgian}}
% 		Uses either Arabic numerals or Georgian alphanumerical numbering.
% 	\item \xpgboolkeyfalse{oldmonthnames}
% 		Uses traditional Georgian month names.
% \end{itemize}
% 
% \subsection{german}\label{german}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgpresetvalue{german}, austrian, or swiss\new{1.33.4}}
% 		Setting \xpgvalue{variant=austrian} or \xpgvalue{variant=swiss} uses some lexical variants.
% 		With \xpgvalue{spelling=old}, \xpgvalue{variant=swiss} furthermore loads specific hyphenation
% 		patterns.
% 	\item \xpgchoicekey{spelling}{\xpgpresetvalue{new} (= \xpgvalue{1996}) or \xpgvalue{old} (= \xpgvalue{1901})}
% 		Indicates whether hyphenation patterns for traditional (1901) or reformed
% 		(1996) orthography should be used. The latter is the default.
% 	\item \xpgboolkeyfalse[1.0.3]{babelshorthands}
% 		If this is turned on, all shorthands defined in \pkg{babel}
% 		for fine-tuning hyphenation and micro-typography of German words are activated.
% 		\begin{shorthands}
% 		\item[¦"ck¦] for ¦ck¦ to be hyphenated as ¦k-k¦ (1901 spelling).
% 		\item[¦"ff¦] for ¦ff¦ to be hyphenated as ¦ff-f¦ (1901 spelling); this is also available
% 		           for the letters l, m, n, p, r and t.
% 		\item[¦"|¦] disables a ligature at this position (\eg ¦Auf"|lage¦).
% 		\item[¦"=¦] for an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		           other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		           cases where the hyphen should stick at the following syllable, \eg ¦bergauf und "~ab¦.
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		           in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign);
% 		           \eg ¦(pseudo"~)""wissenschaftlich¦.
% 		\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash, hyphenation at the breakpoints
% 		           preset in the hyphenation patterns is still allowed.
% 		\end{shorthands}
% 
% 		There are also four shorthands for quotation signs:
% 		\begin{shorthands}
% 		\item[¦"`¦] for German-style left double quotes („)
% 		\item[¦"'¦] for German-style right double quotes (“)
% 		\item[¦"<¦] for French-style left double quotes («)
% 		\item[¦">¦] for French-style right double quotes (»).
% 		\end{shorthands}
% 	\item \xpgchoicekey[1.2.0]{script}{\xpgpresetvalue{latin} or \xpgvalue{blackletter}\new{1.46} (= \xpgvalue{fraktur})}
% 		Setting ¦script=blackletter¦ adapts the captions for typesetting German in blackletter type (using the long s (ſ)
% 		where appropriate).
% 	\end{itemize}
% 
% \subsection{greek}\label{greek}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgpresetvalue{monotonic} (= \xpgvalue{mono}), \xpgvalue{polytonic} (= \xpgvalue{poly}), or \xpgvalue{ancient}}
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{greek} or \xpgvalue{arabic}}
% 	\item \xpgboolkeyfalse{attic}
% 	\end{itemize}
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\Greeknumber and \Cmd\greeknumber \ (see section \ref{abjad}).
% 	\item The command \Cmd\atticnumeral (= \Cmd\atticnum) (activated with
% 	  the option ¦attic=true¦), displays numbers using the acrophonic
%           numbering system (defined in the Unicode range
% 	  \textsf{U+10140–U+10174}).\footnote{ %
% 	  	See the documentation of the \pkg{xgreek} package for more details.}
% 	\end{itemize}
% 
% \subsection{hebrew}\label{hebrew}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgvalue{hebrew} or \xpgpresetvalue{arabic}}
% 	\item \xpgchoicekey{calendar}{\xpgvalue{hebrew} or \xpgpresetvalue{gregorian}}
% 	\item \xpgboolkeyfalse{marcheshvan}
% 		If \xpgvalue{true}, the second month of the civil year will be output as
% 		\texthebrew{מרחשון} (Marcheshvan) rather than \texthebrew{חשון} (Heshvan),
% 		which is the default.
% 	\end{itemize}
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\hebrewnumeral\ (= \Cmd\hebrewalph) (see section \ref{abjad}).
%   \item \Cmd\aemph (see section \ref{arabic}).
% 	\end{itemize}
% 
% \subsection[hindi]{hindi\new{1.2.0}}\label{hindi}
% \paragraph*{Options:}
% 	\begin{itemize}
% 		\item \xpgchoicekey{numerals}{\xpgvalue{Western} or \xpgpresetvalue{Devanagari}}
% 	\end{itemize}
% 
% \subsection{hungarian}\label{hungarian}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.46]{swapstrings}{\xpgdefaultvalue{\xpgpresetvalue{all}},
% 	\xpgvalue{captions}, \xpgvalue{headings}, \xpgvalue{headers}, \xpgvalue{hheaders}, or \xpgvalue{none}}
% 	       In Hungarian, some caption strings need to be in a different order than in other languages
% 	       (\eg \emph{1. fejezet} instead of \emph{Chapter 1}). By default, \pkg{polyglossia} tries hard to
% 	       provide the correct order for different classes and packages (standard classes, \pkg{KOMA-script},
% 	       \pkg{memoir}, and \pkg{titlesec} package should work, as well as \pkg{fancyhdr} and \pkg{caption}).
% 	       However, since the definition of these strings is not standardized, the redefinitions might not work
% 	       and even interfere badly if you use specific classes or packages that redefine the respective strings
% 	       themselves. In this case, you can disable some or all changes.
% 	       The possibilities are:
% 	       \begin{itemize}
% 	       	\item ¦all¦: Redefine figure and table captions, part and chapter headings, and running headers (=~default setting)
% 	       	\item ¦captions¦: Redefine figure and table captions only
% 	       	\item ¦headings¦: Redefine part and chapter headings only
% 	       	\item ¦headers¦: Redefine running headers only
% 	       	\item ¦hheaders¦: Redefine part and chapter headings as well as running headers
% 	       	\item ¦none¦: Do not redefine anything
% 	       \end{itemize}
% \end{itemize}
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\ontoday\ (= \Cmd\ondatehungarian): special form of \cmd\today\ which produces a slightly different
% 	date format as used in prepositional phrases (such as ‘on February 10th’) in Hungarian.
% \end{itemize}
% 
% \subsection{italian}\label{italian}
% \paragraph*{Options:}
% \begin{itemize}
%   \item \xpgboolkeyfalse[1.2.0cc]{babelshorthands}% TODO: check version
%   Activates the ¦"¦ character as a switch to perform etymological
%   hyphenation when followed by a letter. Furthermore, the following shorthands are activated:
%   \begin{shorthands}
%   	\item[¦""¦] double raised open quotes (the Italian keyboard misses the backtick).
%   	\item[¦"<¦] open guillemet (looks like <<).
%   	\item[¦">¦] closing guillemet (looks like >>).
%   	\item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash,
%                hyphenation at the breakpoints preset in the hyphenation patterns is still allowed.
%   	\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
%                in the hyphenation patterns (as opposed to \cmd\-).
%   \end{shorthands}
% \end{itemize}
% 
% \subsection[korean]{korean\new{1.40.0}}\label{korean}
% \paragraph*{Options:}
%   \begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgpresetvalue{plain}, \xpgvalue{classic}, or \xpgvalue{modern}}
%     These variants control spacing before/after CJK punctuations.
%       \begin{itemize}
%         \item ¦plain¦: Do nothing
%         \item ¦classic¦: Suitable for text with no interword spaces.
%           This option forces CJK punctuations to half-width, and
%           inserts half-width glue around them.
%         \item ¦modern¦: Suitable for text with interword spaces.
%           This option forces CJK punctuations to half-width, and
%           inserts small (half of interword space) glue around them.
%       \end{itemize}
% 	\item \xpgchoicekey{captions}{\xpgpresetvalue{hangul} or \xpgvalue{hanja}}
% 	\item \xpgchoicekey[1.47]{swapstrings}{\xpgdefaultvalue{\xpgpresetvalue{all}},
% 	\xpgvalue{headers}, \xpgvalue{headings}, or \xpgvalue{none}}
%     With this option, Korean-style part and chapter headings, and
%     running headers are available.
%     It is similar to Hungarian (see \ref{hungarian}) except that
%     figure and table captions are not touched.
%       \begin{itemize}
%         \item ¦all¦: Redefine part and chapter headings, and running headers
%           (=~default setting)
%         \item ¦headings¦: Redefine part and chapter headings only
%         \item ¦headers¦: Redefine running headers only
%         \item ¦none¦: Do not redefine anything
%       \end{itemize}
%   \end{itemize}
% 
% \subsection[kurdish]{kurdish\new{1.45}}\label{kurdish}
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgvalue{kurmanji} or \xpgpresetvalue{sorani}}
% 	\item \xpgchoicekey{script}{\xpgvalue{Arabic} or \xpgvalue{Latin}}
% 		Defaults are \xpgvalue{Arabic} for Sorani and \xpgvalue{Latin} for Kurmanji.
% 	\item \xpgchoicekey{numerals}{\xpgvalue{western} or \xpgvalue{eastern}}
% 		Defaults are \xpgvalue{western} for Latin and \xpgvalue{eastern} for Arabic script, depending
% 		on the selection above.
% 	\item \xpgboolkeyfalse{abjadjimnotail}
% 		Set this to true if you want the \textit{abjad} form of the number three to
% 		be \textarabic{ج‍} – as in the manuscript tradition – instead of the
% 		modern usage \textarabic{ج}.
% ^^A	\item \xpgchoicekey{locale}{} (not yet implemented)
% ^^A	\item \xpgchoicekey{calendar}{} (not yet implemented)
% \end{itemize}
% \condbreak{2\baselineskip}
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\ontoday: special form of \cmd\today\ which produces a slightly different
% 	date format as used in prepositional phrases (as in ‘on February 10th’). Only available for Latin script.
% 	\item \Cmd\abjad (see section \ref{abjad})
% 	\item \Cmd\aemph (see section \ref{arabic})
% \end{itemize}
% 
% \subsection[lao]{lao\new{1.2.0}}\label{lao}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgvalue{lao} or \xpgpresetvalue{arabic}}
% 	\end{itemize}
% 
% \subsection{latin}\label{latin}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{variant}{\xpgvalue{classic}, \xpgvalue{medieval}, \xpgpresetvalue{modern}, or \xpgvalue{ecclesiastic}\new{1.46}}
% 			These variants refer to different spelling conventions. The \xpgvalue{classic}
% 			and the \xpgvalue{medieval} variant do not use the letters \emph{U} and
% 			\emph{v}, but only \emph{V} and \emph{u}. This concerns predefined terms like
% 			month names as well as the behaviour of the \cmd\MakeUppercase\ and the
% 			\cmd\MakeLowercase\ command. The ¦medieval¦ and the
% 			¦ecclesiastic¦ variant use the ligatures \emph{\ae} and \emph{\oe}.
% 			See table \ref{tab:latin-spelling} for examples.
% 
% 			Furthermore, the \xpgvalue{ecclesiastic} variant takes care for a punctuation
% 			spacing similar to French, but with smaller spaces, as provided for
% 			PDF\TeX\ by the \pkg{ecclesiastic} package.
% 			\begin{table}
% 			\centering
% 			\caption{\label{tab:latin-spelling}Spelling differences between the Latin
% 				language variants.\newline The capitalization of month names and the use of
% 				\emph{i/j} may be affected by the \xpgvalue{capitalizemonth} and the
% 				\xpgvalue{usej} option.}
% 			\begin{tabular}{llll}
% 			\toprule
% 			\textbf{classic} & \textbf{medieval} & \textbf{modern} & \textbf{ecclesiastic} \\
% 			\midrule
% 			Ianuarii & Ianuarii & Ianuarii & ianuarii \\
% 			Nouembris & Nouembris & Novembris & novembris \\
% 			Praefatio & Præfatio & Praefatio & Præfatio \\
% 			\addlinespace\multicolumn{4}{@{}l}{\cmd{\MakeUppercase\{Iulius\}} yields:} \\
% 			IVLIVS & IVLIVS & IULIUS & IULIUS \\
% 			\bottomrule
% 			\end{tabular}
% 			\end{table}
% 	\item \xpgchoicekey[1.46]{hyphenation}{\xpgvalue{classic}, \xpgvalue{modern}, or \xpgvalue{liturgical}}
% 			There are three different sets of hyphenation patterns for Latin. Separate
% 			documention for them is available on the
% 			Internet.\footnote{\url{https://github.com/gregorio-project/hyphen-la/blob/master/doc/README.md\#hyphenation-styles}}
% 			Each of the four variants mentioned above has its default set of hyphenation
% 			patterns as indicated by table \ref{tab:latin-hyphenation}. Use the
% 			¦hyphenation¦ option if the default style does not fit your needs.
% 			Note that the liturgical hyphenation patterns are the default of none of the
% 			language variants. To use them, you have to say
% 			\xpgvalue{hyphenation=liturgical} in any case.
% 			\begin{table}
% 			\caption{\label{tab:latin-hyphenation}Latin default hyphenation styles}
% 			\centering
% 			\begin{tabular}{ll}
% 			\toprule
% 			\textbf{Language variant} & \textbf{Default hyphenation style} \\
% 			\midrule
% 			classic & classic \\
% 			medieval & modern \\
% 			modern & modern \\
% 			ecclesiastic & modern \\
% 			\bottomrule
% 			\end{tabular}
% 			\end{table}
% 	\item \xpgboolkeyfalse[1.46]{ecclesiasticfootnotes}
% 			Use footnotes as provided by the \pkg{ecclesiastic} package, which typesets
% 			footnotes with ordinary instead of superior numbers and without indentation.
% 			As many ecclesiastic documents and liturgical books use footnotes that are
% 			very similar to the ordinary \LaTeX\ ones, we do not use this footnote style
% 			as default even for the ¦ecclesiastic¦ variant.
% 		
% 			Note that this option is only possible if Latin is the main language of your
% 			document.
% 	\item \xpgboolkeyfalse[1.46]{usej}
% 			Use \emph{J/j} in predefined terms. The letter \emph{j} is not of ancient
% 			origin. In early modern times, it was used to distinguish the consonantic
% 			\emph{i} from the vocalic~\emph{i}. Nowadays, the use of \emph{j} has
% 			disappeared from most Latin publications. So ¦false¦ is the default
% 			value for all four language variants. Use this option if you prefer
% 			\emph{Januarii} and \emph{Maji} to \emph{Ianuarii} and \emph{Maii}.
% 	\item \xpgboolkey[1.46]{capitalizemonth}
% 			Capitalize the month name when printing dates (using the \cmd\today\
% 			command).  Traditionally, month names are capitalized. However, in recent
% 			liturgical books they are lowercase. So ¦true¦ is the default value for
% 			the variants ¦classic¦, ¦medieval¦, and ¦modern¦,
% 			whereas ¦false¦ is the default value for the ¦ecclesiastic¦
% 			variant.
% 	\item \xpgboolkeyfalse{babelshorthands}
% 			Enable the following shorthands inherited from \pkg{babel-latin} and the
% 			\pkg{ecclesiastic} package.
% 			\begin{shorthands}
% 				\item[¦"<¦] for « (left guillemet)
% 				\item[¦">¦] for » (right guillemet)
% 				\item[¦"¦] If no other shorthand applies, ¦"¦ before any letter
% 					character defines an optional break point allowing further break points
% 					within the same word (as opposed to the \cmd\- command).
% 				\item[¦"|¦] the same as ¦"¦, but also possible before non-letter
% 					characters
% 				\item[¦'a¦] for á (a with acute), also available for é, í, ó, ú, ý, ǽ, and
% 					\'œ
% 				\item[¦'A¦] for Á (A with acute), also available for É, Í, Ó, Ú, \'V, Ý, Ǽ,
% 					and \'Œ
% 			\end{shorthands}
% 			The following shorthands are only available for the ¦medieval¦ and the
% 			¦ecclesiastic¦ variant.
% 			\begin{shorthands}
% 				\item[¦"ae¦] for æ (ae ligature), also available for œ
% 				\item[¦"Ae¦] for Æ (AE ligature), also available for Œ
% 				\item[¦"AE¦] for Æ (AE ligature), also available for Œ
% 				\item[¦'ae¦] for ǽ (ae ligature with acute), also available for \'œ
% 				\item[¦'Ae¦] for Ǽ (AE ligature with acute), also available for \'Œ
% 				\item[¦'AE¦] for Ǽ (AE ligature with acute), also available for \'Œ
% 			\end{shorthands}
% 	\item \xpgboolkeyfalse[1.46]{prosodicshorthands}
% 			Enable shorthands for prosodic marks (macrons and breves) very similiar to
% 			those provided by \pkg{babel-latin} using the ¦withprosodicmarks¦
% 			modifier.
% 			Note that the active ¦=¦ character used for macrons will cause problems with
% 			commands using \texttt{key=value} interfaces, such as the command
% 			¦\includegraphics[scale=2]{...}¦. Use \cmd{\shorthandoff\{=\}} before
% 			such commands (and \cmd{\shorthandon\{=\}} thereafter) within every
% 			environment with prosodic shorthands enabled.
% 		
% 			The following shorthands are available.
% 			\begin{shorthands}
% 				\item[¦=a¦] for ā (a with macron), also available for ē, ī, ō, ū, and ȳ
% 				\item[¦=A¦] for Ā (A with macron), also available for Ē, Ī, Ō, Ū, V̄, and Ȳ.
% 					Note that a macron above the letter V is only displayed if your font
% 					supports the Unicode character ¦0304¦ (\emph{combining macron}).
% 				\item[¦=ae¦] for a͞e (ae diphthong with macron), also available for a͞u, e͞u,
% 					and o͞e. Note that macrons above diphthongs are only displayed if your font
% 					supports the Unicode character ¦035E¦ (\emph{combining double
% 					macron}).
% 				\item[¦=Ae¦] for A͞e (Ae diphthong with macron), also available for A͞u, E͞u,
% 					and O͞e.
% 				\item[¦=AE¦] for A͞E (AE diphthong with macron), also available for A͞U, E͞U,
% 					and O͞E.
% 				\item[¦\textasciicircum a¦] for ă (a with breve), also available for ĕ, ĭ,
% 					ŏ, ŭ, and y̆.  Note that a breve above the letter y is only displayed if
% 					your font supports the Unicode character ¦0306¦ (\emph{combining
% 					breve}).
% 				\item[¦\textasciicircum A¦] Ă (A with breve), also available for Ĕ, Ĭ, Ŏ,
% 					Ŭ, V̆, and Y̆. Note that breves above the letters V and Y are only displayed
% 					if your font supports the Unicode character ¦0306¦ (\emph{combining
% 					breve}).
% 			\end{shorthands}
% \end{itemize}
% 
% \subsection{malay}\label{malay}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.45]{variant}{\xpgpresetvalue{indonesian} or \xpgvalue{malaysian}}
% \end{itemize}
% 
% \subsection{marathi}\label{marathi}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{Devanagari} or \xpgvalue{Western}}
% \end{itemize}
% 
% \subsection[mongolian]{mongolian\new{1.45}}\label{mongolian}
% Currently, only the Khalkha variety in Cyrillic script is supported.
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse{babelshorthands}
% 	If this is turned on, the following shorthands are activated:
% 	\begin{shorthands}
%         \item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		           in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦"=¦] adds an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		           other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		           cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
% 		\item[¦"‘¦] for German-style left double quotes (looks like ,,).
% 		\item[¦"’¦] for German-style right double quotes (looks like “).
% 		\item[¦"<¦] for French-style left double quotes (looks like <<).
% 		\item[¦">¦] for French-style right double quotes (looks like >>).
%     \end{shorthands}
% 
% 	There are also three shorthands for the Cyrillic dash (\textrussian{тире}), which is shorter than the
% 	emdash but longer than the endash (namely 0.8\,em).
% 	Note that, since it is not covered by unicode, this character is faked by telescoping two endashes:
% 	\begin{shorthands}
% 		\item[¦"---¦] Cyrillic dash for the use in normal text. This requires preceding space
% 		in input (trailing space is optional) and prints with a non-breakable thin space before
% 		and after the dash.
% 		\item[¦"--\textasciitilde¦] Cyrillic dash for the use in compound names (surnames).
% 		As opposed to ¦"---¦ this removes any space before and after the dash. 
% 		\item[¦"--*¦] Cyrillic dash for denoting direct speech. This adds a larger space after
% 		the dash. Space before the dash is output as is.
% 	\end{shorthands}
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic}, \xpgvalue{cyrillic-alph} or \xpgvalue{cyrillic-trad}}
%           Uses either Arabic numerals or Cyrillic alphanumerical numbering. The two Cyrillic variants differ as follows:
%           \begin{itemize}
% 	           \item \xpgvalue{cyrillic-alph} steps through the Cyrillic alphabet. Thus it can only be used up to 30.
% 	           \item \xpgvalue{cyrillic-trad} (= \xpgvalue{cyrillic}) uses a traditional Cyrillic alphanumeric system.%
% 	                 \footnote{See \url{https://en.wikipedia.org/wiki/Cyrillic_numerals}.}
% 	                 It supports numbers up to 999\,999.
%           \end{itemize}
% \end{itemize}
% ^^A
% \paragraph*{Commands:}
% \begin{itemize}
%     \item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for environments such as ¦enumerate¦.
%           It steps through the Cyrillic alphabet and thus it can only be used up to 30.
%           The command takes a counter as argument, \eg ¦\textmongolian{\Asbuk{section}}¦ produces \textrussian{\Asbuk{section}}.
%     \item \Cmd\asbuk: same as \cmd\Asbuk\ but in lowercase.
%     \item \Cmd\AsbukTrad: same as \cmd\Asbuk\ but using the traditional Cyrillic alphanumeric numbering which supports
%           numbers up to 999\,999.\\
%           \Eg ¦\textmongolian{\AsbukTrad{section}}¦ produces \textrussian{\AsbukTrad{section}}.
%     \item \Cmd\asbukTrad: same as \cmd\AsbukTrad\ but in lowercase.
% \end{itemize}
% 
% \subsection{norwegian}\label{norwegian}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.45]{variant}{\xpgvalue{bokmal} or \xpgpresetvalue{nynorsk}}
% \end{itemize}
% 
% \subsection{persian}\label{persian}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgvalue{western} or \xpgpresetvalue{eastern}}
% 	\item \xpgboolkeyfalse[1.0.3]{abjadjimnotail}
% 		Set this to \xpgvalue{true} if you want the \textit{abjad} form of the number three to
% 		be \textarabic{ج‍} – as in the manuscript tradition – instead of the
% 		modern usage \textarabic{ج}.
% ^^A	\item \xpgchoicekey{locale}{} (not yet implemented)
% ^^A	\item \xpgchoicekey{calendar}{} (not yet implemented)
% \end{itemize}
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\abjad (see section \ref{abjad})
% 	\item \Cmd\aemph (see section \ref{arabic}).
% \end{itemize}
% 
% \subsection{portuguese}\label{portuguese}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.45]{variant}{\xpgvalue{brazilian} or \xpgpresetvalue{portuguese}}
% \end{itemize}
% 
% \subsection{russian}\label{russian}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgboolkeyfalse{babelshorthands}
% 	If this is turned on, the following shorthands are activated:
% 	\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		           in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦"=¦] adds an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		           other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] adds an explicit hyphen without a breakpoint. Useful for
% 		           cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% 	 \end{shorthands}
% 
% 	There are also three shorthands for the Cyrillic dash (\textrussian{тире}), which is shorter than the
% 	emdash but longer than the endash (namely 0.8\,em).
% 	Note that, since it is not covered by unicode, this character is faked by telescoping two endashes:
% 	\begin{shorthands}
% 		\item[¦"---¦] Cyrillic dash for the use in normal text. This requires preceding space
% 		in input (trailing space is optional) and prints with a non-breakable thin space before
% 		and after the dash.
% 		\item[¦"--\textasciitilde¦] Cyrillic dash for the use in compound names (surnames).
% 		As opposed to ¦"---¦ this removes any space before and after the dash. 
% 		\item[¦"--*¦] Cyrillic dash for denoting direct speech. This adds a larger space after
% 		the dash. Space before the dash is output as is.
% ^^A These are commented out in gloss-russian
% ^^A		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
% ^^A		\item[¦"‘¦] for German left double quotes (looks like ,,).
% ^^A		\item[¦"’¦] for German right double quotes (looks like “).
% ^^A		\item[¦"<¦] for French left double quotes (looks like <<).
% ^^A		\item[¦">¦] for French right double quotes (looks like >>).
% 	\end{shorthands}
%     \item \xpgboolkeytrue[1.50]{forceheadingpunctuation}
%         By default, chapter and section numbers always have a trailing punctuation in Russian
%         (as in \emph{1.1.} as opposed to \emph{1.1}). If this option is set to \xpgvalue{false}, \textsf{polyglossia}
%         will not touch heading punctuation, so this will be whatever the class or a package determines.
% 	\item \xpgboolkeytrue[1.46]{indentfirst}
% 		By default, all paragraphs are indented in Russian, also those after a
% 		chapter or section heading. If this option is \xpgvalue{false}, the latter paragraphs
% 		are not indented, as normal in \LaTeX.
%     \item \xpgboolkeytrue[1.52]{mathfunctions}
% 	    By default, some specific math macros are defined for Russian (see below). In order to prevent command
% 	    clashes (\eg with the \pkg{chemformula} package), you can switch these definitions off by passing \xpgvalue{false}
% 	    to this option.
% 	\item \xpgchoicekey{spelling}{\xpgpresetvalue{modern} or \xpgvalue{old}}
% 		This option is for captions and date only, not for hyphenation.
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic}, \xpgvalue{cyrillic-alph} or \xpgvalue{cyrillic-trad}}
% 		Uses either Arabic numerals or Cyrillic alphanumerical numbering. The two Cyrillic variants differ as follows:
% 		\begin{itemize}
% 			\item \xpgvalue{cyrillic-alph} steps through the Cyrillic alphabet. Thus it can only be used up to 30.
% 			\item \xpgvalue{cyrillic-trad} (= \xpgvalue{cyrillic}) uses a traditional Cyrillic alphanumeric system.%
% 			      \footnote{See \url{https://en.wikipedia.org/wiki/Cyrillic_numerals}.}
% 			      It supports numbers up to 999\,999.
% 		\end{itemize}
% 	\end{itemize}
% ^^A
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for environments such as ¦enumerate¦.
% 	      It steps through the Cyrillic alphabet and thus it can only be used up to 30.
% 	      The command takes a counter as argument, \eg ¦\textrussian{\Asbuk{section}}¦ produces \textrussian{\Asbuk{section}}.
% 	\item \Cmd\asbuk: same as \cmd\Asbuk\ but in lowercase.
% 	\item \Cmd\AsbukTrad: same as \cmd\Asbuk\ but using the traditional Cyrillic alphanumeric numbering which supports
% 	      numbers up to 999\,999.\\
% 	      \Eg ¦\textrussian{\AsbukTrad{page}}¦ produces \textrussian{\AsbukTrad{page}}.
% 	\item \Cmd\asbukTrad: same as \cmd\AsbukTrad\ but in lowercase.
% 	\end{itemize}
%     If the \xpgoption{mathfunctions} option is \xpgvalue{true}, loading Russian defines a few macros than can be used
%     independently of the current language. These are nine macros to be used in math mode to type the names of
%     trigonometric functions common for Russian documents: \cmd\sh , \cmd\ch , \cmd\tg , \cmd\ctg , \cmd\arctg ,
%     \cmd\arcctg , \cmd\th , \cmd\cth , and \cmd\cosec . Cyrillic letters in math mode can be typed with
%     the aid of text commands such as \cmd\textbf , \cmd\textsf , \cmd\textit , \cmd\texttt , etc.
%     The macros \cmd\Prob , \cmd\Variance , \cmd\NOD , \cmd\nod , \cmd\NOK , \cmd\nok , \cmd\Proj\ print some rare
%     Russian mathematical symbols.
% 
% \subsection[sami]{sami\new{1.45}}\label{sami}
% Currently support for Sami is limited to Northern Sami.
% 
% \subsection{sanskrit}\label{sanskrit}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey[1.0.2]{script}{\xpgpresetvalue{Devanagari}, \xpgvalue{Gujarati},
% 	\xpgvalue{Malayalam}, \xpgvalue{Bengali}, \xpgvalue{Kannada}, \xpgvalue{Telugu}, or \xpgvalue{Latin}}
% 		The value is passed to \pkg{fontspec} in cases where the respective
% 		\cmd{\⟨script⟩font} is not defined.  This can be useful if you typeset Sanskrit
% 		texts in scripts other than Devanagari.
% 	\item \xpgchoicekey[1.45]{numerals}{\xpgpresetvalue{Devanagari} or \xpgvalue{Western}}
% 	\end{itemize}
% 
% \subsection{serbian}\label{serbian}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{script}{\xpgpresetvalue{Cyrillic} or \xpgvalue{Latin}}
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic}, \xpgvalue{cyrillic-alph} or \xpgvalue{cyrillic-trad}}
%           Uses either Arabic numerals or Cyrillic alphanumerical numbering. The two Cyrillic variants differ as follows:
%           \begin{itemize}
%                \item \xpgvalue{cyrillic-alph} steps through the Cyrillic alphabet. Thus it can only be used up to 30.
% 	           \item \xpgvalue{cyrillic-trad} (= \xpgvalue{cyrillic}) uses a traditional Cyrillic alphanumeric system.%
% 	                  \footnote{See \url{https://en.wikipedia.org/wiki/Cyrillic_numerals}.}
% 	                  It supports numbers up to 999\,999.
%           \end{itemize}
% \end{itemize}
% ^^A
% \paragraph*{Commands:}
% \begin{itemize}
%     \item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for environments such as ¦enumerate¦.
%           It steps through the Cyrillic alphabet and thus it can only be used up to 30.
%           The command takes a counter as argument, \eg ¦\textserbian{\Asbuk{section}}¦ produces \textrussian{\Asbuk{section}}.
%     \item \Cmd\asbuk: same as \cmd\Asbuk\ but in lowercase.
%     \item \Cmd\AsbukTrad: same as \cmd\Asbuk\ but using the traditional Cyrillic alphanumeric numbering which supports
%           numbers up to 999\,999.\\
%           \Eg ¦\textserbian{\AsbukTrad{page}}¦ produces \textrussian{\AsbukTrad{page}}.
%     \item \Cmd\asbukTrad: same as \cmd\AsbukTrad\ but in lowercase.
% \end{itemize}
% 
% 
% \subsection{slovak}\label{slovak}
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse[1.46]{babelshorthands}
% 		If this is turned on, the following shorthands for Slovak are activated:
% 		\begin{shorthands}
%         \item[¦"=¦] for an explicit hyphen sign which is repeated at the beginning
%                     of the next line when hyphenated, as common in Slovak typesetting
% 		            (only needed with ¦splithyphens=false¦).
%         \item[¦"|¦] disables a ligature at this position.
%         \item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
%                     cases where the hyphen should stick at the following syllable.
%         \item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
%                     in the hyphenation patterns (as opposed to \cmd\-).
%         \item[¦""¦] allows for a line break at this position (without hyphenation sign).
%         \item[¦"/¦] a slash that allows for a subsequent line break. As opposed to \cmd\slash, hyphenation at the breakpoints
%                     preset in the hyphenation patterns is still allowed.
%         \item[¦"‘¦] for Slovak left double quotes (looks like ,,).
%         \item[¦"’¦] for Slovak right double quotes (looks like “).
%         \item[¦">¦] for Slovak left double guillemets (looks like >>).
%         \item[¦"<¦] for Slovak right double guillemets (looks like <<).
% 		\end{shorthands}
% 	\item \xpgboolkeytrue[1.46]{splithyphens}
% 	      According to Slovak typesetting conventions, if a word with a hard hyphen (such as \emph{je-li})
% 	      is hyphenated at this hyphen, a second hyphenation character is to be inserted at the beginning
%           of the line that follows the hyphenation (\emph{je-/-li}).
% 	      By default, this is done automatically (if you are using \LuaTeX, the \pkg{luavlna} package is
% 	      loaded to achieve this).
% 	      Set this option to ¦false¦ to disable the feature.
% 	\item \xpgboolkeytrue[1.46]{vlna}
% 	      According to Slovak typesetting conventions, single-letter words (non-syllable prepositions)
% 	      must not occur at line ends.
% 	      \pkg{Polyglossia} takes care of this automatically by default (if you are using \LuaTeX, the
% 	      \pkg{luavlna} package is loaded to achieve this).
% 	      Set this option to ¦false¦ to disable the feature.
% \end{itemize}
% 
% \subsection{slovenian}\label{slovenian}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgboolkeyfalse{localalph}
% 	      If \xpgvalue{true}, alpha-numeric counters will use a localized version including characters with caron
% 	      (a, b, c, č, d, \ldots).
% 	\end{itemize}
% 
% \subsection{sorbian}\label{sorbian}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.45]{variant}{\xpgvalue{lower} or \xpgpresetvalue{upper}}
% 	\item \xpgboolkeyfalse[1.45]{olddate}
% 		If \xpgvalue{true}, \cmd\today\ will use traditional Sorbian month names (\ie it will be
% 		synonymous to \cmd\oldtoday\ below).
% \end{itemize}
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\oldtoday: outputs the current date using traditional Sorbian month names, even if
% 	       \xpgvalue{olddate} is \xpgvalue{false}.
% \end{itemize}
% 
% \subsection{spanish}\label{spanish}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey[1.46]{variant}{\xpgpresetvalue{spanish} or \xpgvalue{mexican}}
% 	\item \xpgchoicekey[1.46]{spanishoperators}{\xpgdefaultvalue{all}, \xpgvalue{accented},
% 	\xpgvalue{spaced}, \xpgvalue{none}, or \xpgpresetvalue{false}}
% 	      Determines of and how math operators are localized to Spanish.
% 	      \begin{itemize}
% 	      	\item ¦accented¦ causes some math operators to use accents where usual in Spanish (\emph{lím},
% 	      	      \emph{lím\,sup}, \emph{lím\,inf}, \emph{máx}, \emph{mín}, \emph{ínf}, \emph{mód}).
% 	      	\item ¦spaced¦ causes some math operators to use spaces where usual in Spanish (\emph{arc\,cos},
% 	      	      \emph{arc\,sen}, \emph{arc\,tg}).
% 	      	\item ¦all¦ activates ¦accented¦ and ¦spaced¦ and furthermore provides Spanish localizations of
% 	      	      \cmd\sin\ (\emph{sen}), \cmd\tan\ (\emph{tg}), \cmd\sinh\ (\emph{senh}), and \cmd\tanh\ (\emph{tgh}).
% 	      	\item ¦none¦ does no localization at all (default setting).
% 	      \end{itemize}
% \end{itemize}
% \paragraph*{\color{black}Commands:}\new{1.46}
% \begin{itemize}
% 	\item \Cmd\arcsen: alias to \cmd\arcsin\ (\pkg{babel} compatibility)
% 	\item \Cmd\arctg: alias to \cmd\arctan\ (\pkg{babel} compatibility)
% 	\item \Cmd\sen: alias to \cmd\sin\ (\pkg{babel} compatibility)
% 	\item \Cmd\senh: alias to \cmd\sinh\ (\pkg{babel} compatibility)
% 	\item \Cmd\tg: alias to \cmd\tan\ (\pkg{babel} compatibility)
% 	\item \Cmd\tgh: alias to \cmd\tanh\ (\pkg{babel} compatibility)
% 	\item \Cmd\spanishoperator: allows you to define further localized operators. For instance, ¦\spanishoperator{cotg}¦
% 	      defines a command \cmd\cotg\ that outputs \emph{cotg} in math. The optional argument of the command lets you specify the
% 	      spelling, if needed, \eg ¦\spanishoperator[arc\,ctg]{arcctg}¦.
% \end{itemize}
% 
% \subsection{syriac}\label{syriac}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey[1.0.1]{numerals}{\xpgpresetvalue{western} (\ie 1234567890), \xpgvalue{eastern}
% 		(for which the Oriental Arabic numerals are used: \textarabic{١٢٣٤٥٦٧٨٩٠}), or
% 		\xpgvalue{abjad}}
% 	\end{itemize}
% \paragraph*{Commands:}
% 	\begin{itemize}
% 	\item \Cmd\abjadsyriac (see section \ref{abjad})
%   \item \Cmd\aemph (see section \ref{arabic}).
% 	\end{itemize}
% 
% \subsection{thai}\label{thai}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgvalue{thai} or \xpgpresetvalue{arabic}}
% 	\end{itemize}
% ^^A
% To insert word breaks, you need to use an external processor.
% See the documentation to \pkg{thai-latex} and the file \file{testthai.tex}
% that comes with this package.
% 
% \subsection{tibetan}\label{tibetan}
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgchoicekey{numerals}{\xpgvalue{tibetan} or \xpgpresetvalue{arabic}}
% \end{itemize}
% 
% \subsection{ukrainian}\label{ukrainian}
% 
% \paragraph*{Options:}
% \begin{itemize}
% 	\item \xpgboolkeyfalse{babelshorthands}
% 	If this is turned on, the following shorthands are activated:
% 	\begin{shorthands}
% 		\item[¦"-¦] adds a hyphenation point that does still allow for hyphenation at the points preset
% 		     in the hyphenation patterns (as opposed to \cmd\-).
% 		\item[¦"=¦] adds an explicit hyphen with a breakpoint, allowing for hyphenation at the
% 		     other points preset in the hyphenation patterns (as opposed to plain ¦-¦).
% 		\item[\texttt{"\textasciitilde}] for a hyphen sign without a breakpoint. Useful for
% 		     cases where the hyphen should stick at the following syllable.
% 		\item[¦"|¦] disables a ligature at this position.
% 		\item[¦""¦] allows for a line break at this position (without hyphenation sign).
% ^^A These are commented out in gloss-ukrainian
% ^^A		\item[¦",¦] thinspace for initials with a breakpoint in following surname.
% ^^A		\item[¦"‘¦] for German left double quotes (looks like ,,).
% ^^A		\item[¦"’¦] for German right double quotes (looks like “).
% ^^A		\item[¦"<¦] for French left double quotes (looks like <<).
% ^^A		\item[¦">¦] for French right double quotes (looks like >>).
% 	\end{shorthands}
% 
% 	There are also three shorthands for the Cyrillic dash (\textrussian{тире}), which is shorter than the
% 	emdash but longer than the endash (namely 0.8\,em).
% 	Note that, since it is not covered by unicode, this character is faked by telescoping two endashes:
% 	\begin{shorthands}
% 		\item[¦"---¦] Cyrillic dash for the use in normal text. This requires preceding space
% 		in input (trailing space is optional) and prints with a non-breakable thin space before
% 		and after the dash.
% 		\item[¦"--\textasciitilde¦] Cyrillic dash for the use in compound names (surnames).
% 		As opposed to ¦"---¦ this removes any space before and after the dash. 
% 		\item[¦"--*¦] Cyrillic dash for denoting direct speech. This adds a larger space after
% 		the dash. Space before the dash is output as is.
% 	\end{shorthands}
%     \item \xpgboolkeytrue[1.52]{mathfunctions}
% 		By default, some specific math macros are defined for Ukrainian (see below). In order to prevent command
% 		clashes (\eg with the \pkg{chemformula} package), you can switch these definitions off by passing \xpgvalue{false}
% 		to this option.
% 	\item \xpgchoicekey{numerals}{\xpgpresetvalue{arabic}, \xpgvalue{cyrillic-alph} or \xpgvalue{cyrillic-trad}}
% 	      Uses either Arabic numerals or Cyrillic alphanumerical numbering. The two Cyrillic variants differ as follows:
% 	\begin{itemize}
% 		\item \xpgvalue{cyrillic-alph} steps through the Cyrillic alphabet. Thus it can only be used up to 30.
% 		\item \xpgvalue{cyrillic-trad} (= \xpgvalue{cyrillic}) uses a traditional Cyrillic alphanumeric system.%
% 		\footnote{See \url{https://en.wikipedia.org/wiki/Cyrillic_numerals}.}
% 		It supports numbers up to 999\,999.
% 	\end{itemize}
% \end{itemize}
% ^^A
% \paragraph*{Commands:}
% \begin{itemize}
% 	\item \Cmd\Asbuk: produces uppercased Cyrillic alphanumerals, for environments such as ¦enumerate¦.
% 	It steps through the Cyrillic alphabet and thus it can only be used up to 30.
% 	The command takes a counter as argument, \eg ¦\textukrainian{\Asbuk{section}}¦ produces \textrussian{\Asbuk{section}}.
% 	\item \Cmd\asbuk: same as \cmd\Asbuk\ but in lowercase.
% 	\item \Cmd\AsbukTrad: same as \cmd\Asbuk\ but using the traditional Cyrillic alphanumeric numbering which supports
% 	numbers up to 999\,999.\\
% 	\Eg ¦\textukrainian{\AsbukTrad{page}}¦ produces \textrussian{\AsbukTrad{page}}.
% 	\item \Cmd\asbukTrad: same as \cmd\AsbukTrad\ but in lowercase.
% \end{itemize}
% ^^A
% If the \xpgoption{mathfunctions} option is \xpgvalue{true}, loading Ukrainian defines a few macros than can be used
% independently of the current language. These are nine macros to be used in math mode to type the names of
% trigonometric functions common for Ukrainian documents: \cmd\sh , \cmd\ch , \cmd\tg , \cmd\ctg , \cmd\arctg ,
% \cmd\arcctg , \cmd\th , \cmd\cth , and \cmd\cosec . Cyrillic letters in math mode can be typed with
% the aid of text commands such as \cmd\textbf , \cmd\textsf , \cmd\textit , \cmd\texttt , etc.
% The macros \cmd\Prob , \cmd\Variance , \cmd\NOD , \cmd\nod , \cmd\NOK , \cmd\nok , \cmd\NSD , \cmd\nsd , \cmd\NSK ,
% \cmd\nsk , \cmd\Proj\ print some rare
% Ukrainian mathematical symbols.
% 
% \subsection{welsh}\label{welsh}
% \paragraph*{Options:}
% 	\begin{itemize}
% 	\item \xpgchoicekey{date}{\xpgvalue{long} or \xpgpresetvalue{short}}
% 	\end{itemize}
% 
% 
% \section{Modifying or extending captions, date formats and language settings}
% 
% \pkg{Polyglossia} uses the following macros to define language-specific captions
% (\ie strings such as ``chapter''), date formats and additional language settings
% (\meta{lang} is to be replaces with the respective language name):
% 
% \begin{itemize}
% 	\item \Cmd{\captions\meta{lang}} stores definitions of caption strings
% 	           (such as, in the case of English, ¦\def\chaptername{Chapter}¦)
% 	\item \Cmd{\date\meta{lang}} stores definitions of date formats (usually redefinitions
% 	           of \cmd\today, in some cases also definitions of additional date commands)
% 	\item \Cmd{\blockextras\meta{lang}} stores macros that are to be executed when the language
%               \meta{lang} is activated via \cmd\selectlanguage command or the \meta{lang} environment
% 	\item \Cmd{\inlineextras\meta{lang}} stores macros that are to be executed when the language
% 	          \meta{lang} is activated locally via \cmd\text\meta{lang} command
% 	\item \Cmd{\noextras\meta{lang}} stores macros that are to be executed when the language
% 	          \meta{lang} is closed
% \end{itemize}
% ^^A
% In order to redefine internal macros, we recommend to use the command \cmd\gappto.
% For compatibility with \pkg{babel} the command \cmd\addto\ is also available
% to the same effect. For instance, to change the \cmd\chaptername\ for language ¦lingua¦,
% you can do this:
% \begin{verbatim}
% \gappto\captionslingua{\def\chaptername{Caput}}
% \end{verbatim}
% ^^A
% Note that this needs to be done after the respective language has been loaded with
% \cmd\setmainlanguage\ or \cmd\setotherlanguage.
% 
% Specifically for package authors, analogous commands are provided which are only executed
% if a specific language \emph{variety} is used. As opposed to the macros above, these refer
% to babel names. Other than that, the function is identical:
% 
% \begin{itemize}
% 	\item \Cmd{\captions@bbl@\meta{babelname}}
% 	\item \Cmd{\date@bbl@\meta{babelname}}
% 	\item \Cmd{\blockextras@bbl@\meta{babelname}}
% 	\item \Cmd{\inlineextras@bbl@\meta{babelname}}
% 	\item \Cmd{\noextras@bbl@\meta{babelname}}
% \end{itemize}
% ^^A
% By default, these macros are undefined. If they are defined (\eg by an external package),
% they will be executed after their respective \meta{lang} counterpart and thus can be used to
% overwrite definitions of the former. Again, use \cmd\gappto\ to define\slash modify these macros.
% For instance, to add a new caption \cmd\footnotename\ to the Swiss variety of German (babel name
% ¦nswissgerman¦), you can do this:
% \begin{verbatim}
% \gappto\captions@bbl@nswissgerman{\def\footnotename{Fussnote}}
% \end{verbatim}
% ^^A
% If you do this in a document preamble rather than in a package, you need to embrace the redefinition
% by \cmd\makeatletter\ and \cmd\makeatother\ due to the ¦@¦ in the macro names.
% 
% Finally, as soon as the language has been switched (either inline or as a block), \pkg{polyglossia}
% executes the (by default empty) hook
% \begin{itemize}
% 	\item \Cmd{\polyglossia@language@switched}
% \end{itemize}
% to which you can append arbitrary code (via \cmd\gappto) that should be executed if (a particular)
% language is being activated. This is done before any of the above
% macros are issued (so you can still alter them), but at a point where \cmd\languagename, \cmd\babelname\
% and \cmd\languageid\ are already set, so you can condition on specific languages in your code.
% This hook is particularly provided for package authors.
% 
% \section{Script-specific numbering}
% 
% Languages and scripts have specific numbering conventions. Some use decimal digits
% (\eg Arabic numerals), some use alphabetic or alphanumerical notation (\eg Roman numbering).
% In some cases, different conventions are available (\eg Mashriq or Maghrib numbering
% in Arabic script, Arabic or Hebrew [=~alphanumeric] numbering in Hebrew).
% 
% If the latter is the case, \pkg{polyglossia} provides language options which allow you to select
% or switch to the suitable convention. With the appropriate language option set, \pkg{polyglossia}
% will automatically convert the output of internal \LaTeX\ counters to their
% localized forms, for instance to display page, chapter and section numbers.
% 
% For manual input of numbers, macros are provided. These convert Arabic numeric input to the respective
% local decimal digit (see sec.~\ref{sec:decdigit}), alphanumeric representation (see sec.~\ref{abjad})
% or whatever is appropriate (see sec.~\ref{sec:localnumber}). The possibilities are described in turn.
% 
% \subsection{General localization of numbering}\label{sec:localnumber}
% 
% As of 1.45,\new{1.45} \pkg{polyglossia} provides a generic macro \Cmd\localnumeral\ which converts numbers
% to the current local form (which might be script-specific decimal digit, an alphabetic numbering or something else).
% For instance in an Arabic environment
% ¦\localnumeral{42}¦ yields \textarabic{\localnumeral{42}}, whereas in an Hebrew environment, it
% results in \texthebrew[numerals=hebrew]{\localnumeral{42}} with ¦numerals=hebrew¦, and \texthebrew{\localnumeral{42}}
% with ¦numerals=arabic¦. Note that, as opposed to the various ¦digits¦ macros (described in sec.~\ref{sec:decdigit}),
% the argument of \cmd\localnumeral\ must consist of numbers only.
% 
% For\new{1.45} the conversion of counters, the starred version \Cmd{\localnumeral*} is provided. This takes a counter as argument.
% For instance in an Arabic environment ¦\localnumeral*{page}¦ yields \textarabic{\localnumeral*{page}}.
% 
% For scripts with alphanumeric numbering, the variants \Cmd{\Localnumeral} and \Cmd{\Localnumeral*} provide the uppercased
% versions.\medskip
% 
% \noindent All these macros provide the following options:
% 
% \begin{itemize}
% 	\item \DescribeMacro{[lang=]}\xpgchoicekey{lang}{\xpgpresetvalue{local}, \xpgvalue{main},
% 	or \xpgvalue{\meta{language}}}
% 		Output number in the local form of the currently active language for
% 		¦local¦, the main language of the document for ¦main¦, and any (loaded)
% 		language for \meta{language} (\eg ¦\localnumeral[lang=arabic]{42}}¦).
% \end{itemize}
% 
% \subsection{Non-Western decimal digits}\label{sec:decdigit}
% 
% In addition\new{1.1.1} to the generic macros described above, \pkg{polyglossia} provides language-specific conversion macros
% which can be used if the generic ones do not suit the need.\footnote{%
% A third method are so-called TECKit fontmappings.
% Those can be activated with the \pkg{fontspec} ¦Mapping¦ option,
% using ¦arabicdigits¦, ¦farsidigits¦ or ¦thaidigits¦.
% For instance if \cmd\arabicfont\ is defined with the option ¦Mapping=arabicdigits¦,
% typing \cmd{\textarabic\{2010\}} results in \textarabic{٢٠١٠}. Note that this method has some drawbacks, though,
% for instance when the value of a counter has to be written and read from auxiliary files.
% So please use this with care.}
% The macros have the form \cmd{\⟨script⟩digits}. They convert Arabic numerical input and leave every other input untouched.
% In an Arabic context, for instance, ¦\arabicdigits{9182/738543-X}¦ yields \textarabic{\arabicdigits{9182/738543-X}}.
% 
% Currently, the following macros are provided:
% 
% \begin{itemize}
% 	\item \Cmd\arabicdigits
% 	\item \Cmd\bengalidigits
% 	\item \Cmd\devanagaridigits
% 	\item \Cmd\farsidigits
% 	\item \Cmd\kannadadigits
% 	\item \Cmd\khmerdigits
% 	\item \Cmd\laodigits
% 	\item \Cmd\nkodigits
% 	\item \Cmd\thaidigits
% 	\item \Cmd\tibetandigits
% \end{itemize}
% 
% 
% \subsection{Non-Latin alphabetic numbering}\label{abjad}
% 
% For languages which use special (non-Latin) alphanumerical notation\footnote{%
% 	For instance, see \url{http://en.wikipedia.org/wiki/Greek_numerals},
% 	\url{http://en.wikipedia.org/wiki/Abjad_numerals},
% 	\url{http://en.wikipedia.org/wiki/Hebrew_numerals},
% 	and \url{http://en.wikipedia.org/wiki/Syriac_alphabet}.}, dedicated macros are provided.
% 
% They work in a similar way than the \cmd{\⟨script⟩digits} macros described above: They take Arabic numerical input
% and output the respective value in the local alphabetic numbering scheme (most of these macros are equivalent
% to \cmd\localnumeral\ and \cmd\Localnumeral\ in the respective context).
% 
% The following macros are provided:
% 
% \begin{itemize}
%     \item \Cmd\abjad outputs Arabic \textit{abjad} numbers according to the Mashriq varieties.
% 			Example: ¦\abjad{1863}¦ yields \textarabic{\abjad{1863}}.
% 			
% 	\item \Cmd\abjadmaghribi outputs Arabic \textit{abjad} numbers according to the Maghrib varieties.
% 			Example: ¦\abjadmaghribi{1863}¦ yields \textarabic{\abjadmaghribi{1863}}.
% 			
% 	\item \Cmd\abjadsyriac outputs Syriac abjad numerals.\footnote{%
% 				A fine guide to numerals in Syriac can be found at \link{http://www.garzo.co.uk/documents/syriac-numerals.pdf}.}\\
% 			Example: ¦\abjadsyriac{463}¦ yields \textsyriac{\abjadsyriac{463}}.
% 	
% 	\item \Cmd\armeniannumeral produces Armenian alphabetic numbering.
% 	          Example: ¦\armeniannumeral{1863}¦ yields \textarmenian{\armeniannumeral{1863}}.
% 	          
% 	\item \Cmd\belarusiannumeral produces Belarusian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Belarusiannumeral.
% 	          Depending on the ¦numerals¦ option in the Belarusian language selection, this is either Arabic digit or Cyrillic
% 	          alphanumercial output.\\
% 	          Example: With ¦numerals=latin¦ ¦\belarusiannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
% 	          with ¦numerals=cyrillic-trad¦ ¦\belarusiannumeral{19}¦ results in \textrussian[numerals=cyrillic-trad]{\russiannumeral{19}},\\
% 	          with ¦numerals=cyrillic-alph¦ ¦\belarusiannumeral{19}¦ results in \textrussian[numerals=cyrillic-alph]{\russiannumeral{19}}.
% 
% 	\item \Cmd\georgiannumeral produces Georgian alphabetic numbering.\\
%               Example: ¦\georgiannumeral{1863}¦ yields \textgeorgian{\georgiannumeral{1863}}.
% 
% 	\item \Cmd\greeknumeral produces Greek alphabetic numbering, \Cmd\Greeknumeral outputs uppercased variants.
% 			Example: ¦\greeknumeral{1863}¦ yields \textgreek{\greeknumeral{1863}},
% 			¦\Greeknumeral{1863}¦ results in \textgreek{\Greeknumeral{1863}}.
% 
% 	\item \Cmd\hebrewnumeral, \Cmd\Hebrewnumeral and \Cmd\Hebrewnumeralfinal generate variants of Hebrew alphanumeric numerals.
% 			The commands behave exactly as they do in \pkg{babel}: \cmd\hebrewnumeral\ outputs the numbers without any decoration,
% 			\cmd\Hebrewnumeral\ adds \textit{gereshayim} before the last letter, \cmd\Hebrewnumeralfinal\ uses in addition the final forms of Hebrew letters.
% 			Examples:
% 			¦\hebrewnumeral{1750}¦ yields \texthebrew{\hebrewnumeral{1750}},
% 			¦\Hebrewnumeral{1750}¦ yields \texthebrew{\Hebrewnumeral{1750}},
% 			and ¦\Hebrewnumeralfinal{1750}¦ yields \texthebrew{\Hebrewnumeralfinal{1750}}.
% 			
% 	\item \Cmd\mongoliannumeral produces Mongolian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Mongoliannumeral.
%             Depending on the ¦numerals¦ option in the Mongolian language selection, this is either Arabic digit or Cyrillic
%             alphanumercial output.\\
%             Example: With ¦numerals=latin¦ ¦\mongoliannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
%             with ¦numerals=cyrillic-trad¦ ¦\mongoliannumeral{19}¦ results in \textrussian[numerals=cyrillic-trad]{\russiannumeral{19}},\\
%             with ¦numerals=cyrillic-alph¦ ¦\mongoliannumeral{19}¦ results in \textrussian[numerals=cyrillic-alph]{\russiannumeral{19}}.
% 	
% 	\item \Cmd\russiannumeral produces Russian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Russiannumeral.
% 	        Depending on the ¦numerals¦ option in the Russian language selection, this is either Arabic digit or Cyrillic
% 	        alphanumercial output.\\
% 	        Example: With ¦numerals=latin¦ ¦\russiannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
% 	        with ¦numerals=cyrillic-trad¦ ¦\russiannumeral{19}¦ results in \textrussian[numerals=cyrillic-trad]{\russiannumeral{19}},\\
% 	        with ¦numerals=cyrillic-alph¦ ¦\russiannumeral{19}¦ results in \textrussian[numerals=cyrillic-alph]{\russiannumeral{19}}.
% 			
% 	\item \Cmd\serbiannumeral produces Serbian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Serbiannumeral.
% 		    Depending on the ¦numerals¦ option in the Serbian language selection, this is either Arabic digit or Cyrillic
% 		    alphanumercial output.\\
% 		    Example: With ¦numerals=latin¦ ¦\serbiannumeral{19}¦ yields \textrussian{\serbiannumeral{19}},
% 			with ¦numerals=cyrillic-trad¦ ¦\serbiannumeral{19}¦ results in \textrussian[numerals=cyrillic-trad]{\serbiannumeral{19}},\\
% 			with ¦numerals=cyrillic-alph¦ ¦\serbiannumeral{19}¦ results in \textrussian[numerals=cyrillic-alph]{\serbiannumeral{19}}.
% 			
% 	\item \Cmd\ukrainiannumeral produces Ukrainian numbering, with uppercased variant (for alphanumerical variant) via \Cmd\Ukrainiannumeral.
% 			Depending on the ¦numerals¦ option in the Ukrainian language selection, this is either Arabic digit or Cyrillic
% 			alphanumercial output.\\
% 			Example: With ¦numerals=latin¦ ¦\ukrainiannumeral{19}¦ yields \textrussian{\russiannumeral{19}},
% 			with ¦numerals=cyrillic-trad¦ ¦\ukrainiannumeral{19}¦ results in \textrussian[numerals=cyrillic-trad]{\russiannumeral{19}},\\
% 			with ¦numerals=cyrillic-alph¦ ¦\ukrainiannumeral{19}¦ results in \textrussian[numerals=cyrillic-alph]{\russiannumeral{19}}.
% \end{itemize}
% 
% 
% \section{Footnotes in right-to-left context}
% 
% With languages that use right-to-left scripts, footnote apparatuses are usually placed at the right side of the page bottom.
% Consequently, the footnote rule also is to be placed right. Things get more tricky, though, if right-to-left and left-to-right
% scripts are mixed. Then you might want to put the footnotes on some pages left, on some right, or even mix positions on a page.
% Thus, footnote handling in right-to-left context sometimes needs manual intervention. This is described in what follows.
% 
% \subsection{Horizontal footnote position}
% 
% When right-to-left languages are used, the \cmd\footnote\ command becomes sensitive to the text directionality. The footnote is
% always placed on the side that is currently the origin of direction: on the left side of the page in LTR paragraphs and
% on the right in RTL paragraphs.
% 
% For cases where this is not desired, two additional footnote commands are provided: \Cmd\RTLfootnote and \Cmd\LTRfootnote.
% \cmd\LTRfootnote\ always places the footnote on the left side, notwithstanding the current
% directionality. Likewise, \cmd\RTLfootnote\ always places it on the right side. Like \cmd\footnote, \cmd\RTLfootnote\
% and \cmd\LTRfootnote\ provide an optional argument to customize the number.
% 
% 
% \subsection{Footnote rule length and position}
% 
% The default placement of the footnote rule differs in \XeTeX\ and \LuaTeX\ output (this is due to differences in the \textsf{bidi}
% and \textsf{luabidi} packages). With \XeTeX, footnote rules are always placed left, which is often wrong in RTL context.
% With \LuaTeX, by contrast, the rule is placed always right if the main language is a right-to-left language, and always left
% if the main language is a left-to-right language, which is the right thing in many cases.
% 
% In both cases, you can change the default behavior as follows:
% \begin{itemize}
% 	\item Put \Cmd\leftfootnoterule in the preamble to have all rules left-aligned.
% 	\item Put \Cmd\rightfootnoterule in the preamble to have all rules right-aligned.
% 	\item Put \Cmd\autofootnoterule in the preamble to have automatic placement depending on the context (see below for elaboration).
% 	\item Put \Cmd\textwidthfootnoterule in the preamble to have a rule that spans the whole text width.
% \end{itemize}
% With \cmd\autofootnoterule, the first footnote on the current page determines the placement. Note that this automatic can fail with
% footnotes at page boundaries that differ in directionality from the first footnote on the page. You can work around such cases by switching to \cmd\rightfootnoterule\ or \cmd\leftfootnoterule\ on these pages.
% 
% Note also that the rule switches might interfere in bad ways with packages or classes that redefine footnotes themselves. This is also the reason
% why \cmd\autofootnoterule\ is not used by default.
% 
% 
% \section{Calendars}
% 
% \subsection{Hebrew calendar (hebrewcal.sty)}
% The package \file{hebrewcal.sty} is almost a verbatim copy of \file{hebcal.sty}
% that comes with \pkg{babel}.
% The command \Cmd\Hebrewtoday\ formats the current date in the Hebrew calendar
% (depending of the current writing direction this will automatically set either
% in Hebrew script or in roman transliteration).
% 
% \subsection{Islamic calendar (hijrical.sty)}
% This package computes dates in the lunar Islamic (Hijra) calendar.\footnote{ %
% 	It makes use of the arithmetical algorithm in chapter 6 of
% 	Reingold \& Gershowitz, \textit{Calendrical calculation: the Millenium edition}
% 	(Cambridge University Press, 2001).\label{reingold}}
% It provides two macros for the end-user.
% The command
% 	\displaycmd{\HijriFromGregorian\marg{year}\marg{month}\marg{day}}{\HijriFromGregorian}
% sets the counters ¦Hijriday¦, ¦Hijrimonth¦ and ¦Hijriyear¦.
% \Cmd\Hijritoday\ formats the Hijri date for the current day.
% This command is now locale-aware\new{1.1.1}: its output will differ depending on the
% currently active language. Presently \pkg{polyglossia}’s language definition files
% for Arabic, Farsi, Urdu, Turkish and Malay provide a localized version of \cmd\Hijritoday.
% If the formatting macro for the current language is undefined, the Hijri date will be formatted
% in Arabic or in roman transliteration, depending of the current writing direction.
% You can define a new format or redefine one with the command
%   \displaycmd{\DefineHijriDateFormat\marg{lang}\marg{code}.}{\DefineHijriDateFormat}
% 
% The command \cmd\Hijritoday\ also accepts an optional argument to add or subtract a correction
% (in days) to the date computed by the arithmetical algorithm.\footnote{ %
% 	The Islamic calendar is indeed a purely lunar calendar based on the observation
% 	of the first visibility of the lunar crescent at the beginning of the lunar month,
% 	so there can be differences between different localities, as well as between
% 	civil and religious authorities.}
% For instance if \cmd\Hijritoday\ yields the date “7 Rajab 1429” (which is the date that was
% displayed on the front page of \href{http://www.aljazeera.net}{aljazeera.net} on
% 11th July 2008), ¦\Hijritoday[1]¦ would rather print “8 Rajab 1429” (the date
% indicated the same day on the site \href{http://www.gulfnews.com}{gulfnews.com}).
% 
% \subsection{Farsi (jalālī) calendar (farsical.sty)}
% This package is an almost verbatim copy of ¦Arabiftoday.sty¦ (in the \pkg{Arabi} package),
% itself a slight modification of ¦ftoday.sty¦ in Farsi\TeX.\footnote{ %
% 	One day we may rewrite \pkg{farsical} from scratch using the algorithm in
% 	Reingold \& Gershowitz (ref.~n.\,\ref{reingold}).}
% Here we have renamed the command \cmd\ftoday\ to
% \Cmd\Jalalitoday.
% Example: today is \Jalalitoday.
% 
% 
% \section{Auxiliary commands}
% 
% The macro \displaycmd{\charifavailable\marg{char code}\marg{substitution}}{\charifavailable}\new{1.47} checks whether
% the character with the specified \meta{char code} (\ie unicode utf-16 code without preceding ¦0x¦) exists in
% the current font. If so, the character is printed, if not, the \meta{substitution} is printed.
% 
% Example: ¦\charifavailable{1E9E}{SS}¦ prints the capital version of the German letter ⟨ß⟩ if available
% (\ie \charifavailable{1E9E}{SS}), else it prints the substitution digraph SS.
% 
% 
% \section{Accessing language information}
% 
% The following is specifically relevant to package authors who need information about the languages in use.
% In order to get such information, \pkg{polyglossia} provides the following macros:
% 
% \begin{itemize}
% 	\item \Cmd\languagename\ stores the currently active (polyglossia) language name.
% 	\item \Cmd\mainlanguagename\ stores the (polyglossia) language name of the main document language.
% 	\item \Cmd\languagevariant\ stores the language variant if set. The macro is empty if no variant has been set.
% 	\item \Cmd\mainlanguagevariant\ stores the language variant of the main document language if set.
% 	       The macro is empty if no variant has been set.
% 	\item \Cmd\babelname\ stores the corresponding name of the currently active language (variant) in \pkg{babel}.
% 	      This might not only be useful if you want to support both \pkg{babel} and \pkg{polyglossia}, but also
% 	      since this name is unique for a given language variety (\eg ngerman, german, swissgerman etc.).
% 	      Note that this macro is also defined for languages that are not supported in \pkg{babel}. In that
% 	      case, they are equal to the polyglossia language name.
% 	\item \Cmd\mainbabelname\ analogously stores the name of document's main language (variant) in \pkg{babel}.
% 	\item \Cmd{\languageid\marg{type}}\new{1.47} stores the identifier tag of the current language. Currently supported \meta{types}:
% 	      \begin{itemize}
% 	      	\item ¦bcp-47¦ (alias ¦bcp47¦): IETF BCP-47 language identifier
% 	      \end{itemize}
% 	 \item \Cmd{\mainlanguageid\marg{type}}\new{1.47} stores identifier tag of the main language. Currently supported \meta{types}:
% 	      see \cmd\languageid.
% \end{itemize}
% \bigskip
% 
% \noindent If you want to have a full list of loaded languages/variants, use the following macros:
% \begin{itemize}
% 	\item \Cmd{\xpg@loaded}\ stores a comma-separated list of all loaded languages (polyglossia name)
% 	\item \Cmd{\xpg@vloaded}\ stores a comma-separated list of all loaded variants
% 	\item \Cmd{\xpg@bloaded}\ stores a comma-separated list of \pkg{babel} names of all language variants
% 	\item \Cmd{\xpg@bcp@loaded}\new{1.47}\ stores a comma-separated list of the BCP-47 IDs of all language variants
% \end{itemize}
% \bigskip
% 
% \noindent Whether a language is loaded can be tested by
% \displaycmd{\iflanguageloaded\marg{lang}\marg{true}\marg{false}}{\iflanguageloaded}
% where \texttt{\meta{lang}} is a \pkg{polyglossia} language name, by
% \displaycmd{\ifbabellanguageloaded\marg{lang}\marg{true}\marg{false}}{\ifbabellanguageloaded}
% where \texttt{\meta{lang}} is a \pkg{babel} language name (see table~\ref{tab:bbllang} on p.~\pageref{tab:bbllang}), or by
% \displaycmd{\iflanguageidloaded\marg{type}\marg{id}\marg{true}\marg{false}}{\iflanguageidloaded}\new{1.47}
% where \meta{type} is a supported language id type (such as ¦bcp-47¦) and \meta{id} is a language id
% (such as ¦en-US¦; see table~\ref{tab:BCP47-polyglossia} on p.~\pageref{tab:BCP47-polyglossia}).
% \bigskip
% 
% \noindent Finally, if you want to know whether a specific language option has been set, you can use
% \displaycmd{\iflanguageoption\marg{lang}\marg{opt. key}\marg{opt. value}\marg{true}\marg{false}}{\iflanguageoption}\new{1.47}
% 
% \section{Revision history}
% 
% \bgroup\footnotesize
% \subsection*{1.52 (16-03-2021)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item Adaptations to \LaTeX\ 2021/05/01 pre-release 2 for Korean (\TXI{477}).
% \item Add support for Uyghur (\TXI{475}).
% \item New option \xpgoption{mathfunctions} for Russian and Ukrainian allows to disable the definitions
%       of math macros that might clash with other packages (\TXI{465}).
% \item Support LaTeX's new NFSS hooks (\TXI{471}).
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix French part modifications with \pkg{hyperref} (\TXI{469}).
% \item Fix markup of French ¦\see¦ and ¦\alsoname¦ (\TXI{468}).
% \end{itemize}
% 
% \subsection*{1.51 (08-12-2020)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item New option \xpgoption{frenchpart} for French (\TXI{458}).
% \item New option \xpgoption{splithyphens} for Croatian (\TXI{454}).
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Use new LaTeX core hooks rather than \pkg{filehook} package. This fixes
%       a recent breakage of \pkg{filehook} with other external packages (\TXI{453}).
% \item Remove very old code that pretends \pkg{polyglossia} is \pkg{babel} (\TXI{455}).
% \item Fix spelling of Albanian contentsname (\TXI{456}).
% \item Fix part heading modification in French (\TXI{458}).
% \item Fix extra space in Hebrew (\TXI{459}).
% \item Register main polyglossia language earlier (\TXI{461}).
% \item Allow for hyphenations in words following opening guillemet in French with XeTeX (\TXI{462}).
% \end{itemize}
% 
% 
% \subsection*{1.50a (15-10-2020)}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Assure ¦\autodot¦ is defined with ¦\KOMAScript¦ in Russian.
% \end{itemize}
% 
% \subsection*{1.50 (09-10-2020)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item Polyglossia now uses the Harfbuzz renderer by default with LuaTeX
%       output. This brings LuaTeX on par with XeTeX for all scripts (\TXI{337}).
%       The renderer can be changed via the new global \xpgoption{luatexrenderer} option.
% \item The (previously inadvertently working) ¦hyphenrules¦ environment that ceased
%       to work after a recent \pkg{babel} update is back and now officially supported.
%       The environment now also supports language options and aliases (\TXI{427}).
% \item New command ¦\setlanghyphenmins¦ to adapt hyphenation thresholds of languages
%       and varieties.
% \item New command ¦\abjadalph¦ for Arabic with corresponding option (\TXI{431}).
% \item Replace consecutive glues around punctuation by the correct amount of space
%       with lualatex for French, ecclesiastic Latin, and Sanskrit (\TXI{437}).
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Remove warning about missing Brazil patterns (\TXI{404}).
% \item Fix incompatibility with recent \pkg{babel} release (\TXI{408}).
% \item Fixed some spellings in Marathi (\TXI{409}).
% \item Fix spacing of geminating dot in Catalan (\TXI{410}).
% \item Fix incompatibility of Marathi with \pkg{beamer}.
% \item Correct ¦\partname¦ in Hindi (\TXI{416}).
% \item Updates and improvements to Kurdish (\TXI{418}).
% \item Only activate shorthand character if \xpgoption{babelshorthands} is \xpgvalue{true} (\TXI{421}). 
% \item Fix whitespace issue in Czech and Slovak with \xpgvalue{vlna=true} (\TXI{423}).
% \item Fix whitespace issue in Danish (\TXI{424}).
% \item Fix catcode conflicts that might occur in language definition files
%       f.\,ex.\ when loaded from a LaTeX3 class (\TXI{67}, \TXI{425}).
% \item Robustify font family switches (\TXI{428}).
% \item Fix whitespace issue in Russian \xpgoption{indentfirst} option (\TXI{433}).
% \item In Russian, \xpgoption{indentfirst} is now again default (\TXI{434}).
% \item Fix LaTeX error with arabic numbering in Ukrainian (\TXI{440}).
% \item Fix directionality after Hebrew decimal numbers (\TXI{441}).
% \item Fix ¦babelname¦ of Latin Serbian (\TXI{442}).
% \item Fix recording of secondary languages in ¦\xpg@bloaded¦ and ¦\xpg@bcp@loaded¦
%       lists (\TXI{443}).
% \item Simplify and robustify section heading modification in Russian
%       and introduce option \xpgoption{forceheadingpunctuation} (\TXI{444}).
% \item Fix Cyrillic dash (via babelshorthand ¦"---¦) when TeX ligatures
%       are disabled (\TXI{445}).
% \item Fix problem with large character indices in Lua module for punctuation
%       spacing
% \end{itemize}
% 
% \subsubsection*{Interface and defaults changes}
% \begin{itemize}
% \item Polyglossia now uses the Harfbuzz renderer by default with LuaTeX
%       output. See new features section.
% \end{itemize}
% 
% \subsubsection*{Build fixes}
% \begin{itemize}
% \item Fix a bug in the dtx build script which was the reason for an utterly
%        incomplete ¦polyglossia.dtx¦ file (\TXI{420}).
% \end{itemize}
% 
% \subsubsection*{Documentation improvements}
% \begin{itemize}
% \item Document how to change ¦\lefthyphenmin¦ and ¦\righthyphenmin¦ for a language
%       (\TXI{435}).
% \end{itemize}
% 
% 
% \subsection*{1.49 (08-04-2020)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item Add hook ¦\polyglossia@language@switched¦ to the external package interface (\TXI{398}).
% \item Real fix for \TXI{400}, that wasn’t properly taken care of in 1.48.
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix compilation error with some \xpgoption{swapstring} options in Hungarian (\TXI{373}).
% \item Fix whitespace problem in Greek language.
% \end{itemize}
% 
% \subsubsection*{Interface and defaults changes}
% \begin{itemize}
% \item Changed Finnish caption for ``Table of Contents'' to ``Sisällys'' (\TXI{403}).
% \end{itemize}
% 
% 
% \subsection*{1.48 (25-03-2020)}
% 
% \begin{itemize}
% \item No new features
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix use of Hebrew with LuaLaTeX (\TXI{389}).
% \item Do not overwrite footnote redefinitions of other packages
%       with Latin and French (\TXI{391}).
% \item Fix Serbian cyrillic numerals code (\TXI{392}).
% \item Fix \xpgoption{[no]localmarks} option, whose logic was swapped (part of \TXI{395}).
% \item Protect \xpgoption{localmarks} function against uppercased language names (part of \TXI{395}).
% \item Fix buggy redefinition of ¦\@markright¦ with option localmarks (\TXI{396}).
% \item Fix incompatibility between Latin and unicode-math (\TXI{394}).
% \item Make (undocumented) ¦\defineshorthand¦ command (imported from babel) work.
% \item Fix usage of \xpgoption{localmarks} option without value.
% \item Emergency fixes for bugs caused by updates in \pkg{babel}’s ¦switch.def¦ (\TXI{399} and \TXI{400}).
% \end{itemize}
% 
% \subsubsection*{Interface and defaults changes}
% \begin{itemize}
% \item Use private macros in keyval choice keys (\TXI{390}).
% \end{itemize}
% 
% \subsection*{1.47 (29-01-2020)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item IETF BCP-47 compliant language tags can now be used for loading and switching
%       languages alternatively to language names (\TXI{226}).
% \item New commands ¦\languageid{<type>}¦ and ¦\mainlanguageid{<type>}¦.
% \item New test ¦\iflanguageidloaded¦.
% \item New list ¦\xpg@bcp@loaded¦.
% \item New environment ¦{lang}{<lang>}¦ (this is equivalent to ¦{<lang>}¦,  but also available with
%       ¦\setlanguagealias*¦ which does not define dedicated alias environments).
% \item New gloss option ¦totalhyphenmin¦ (corresponds to LuaTeX's ¦\hyphenationmin¦) (\TXI{111}).
% \item New test ¦\iflanguageoption{<lang>}{<key>}{<val>}¦ (\TXI{364}).
% \item Restore simple alphabetic numbering for ¦\asbuk¦ and ¦\Asbuk¦ in Belarusian, Mongolian,
%       Russian, Serbian, and Ukrainian (\TXI{377}).
% \item New command ¦\AsbukTrad¦ and ¦\asbukTrad¦ for Belarusian, Mongolian, Russian, Serbian,
%       and Ukrainian which uses traditional alphanumerical numbering.
% \item New numerals option ¦cyrillic-trad¦ and ¦cyrillic-alph¦ to differentiate simple
%       alphabetic and traditional alphanumerical Cyrillic numbering.
% \item ¦\selectbackgroundlanguage¦ and ¦\resetdefaultlanguage¦ now also support language
%       aliases.
% \item New macro ¦\charifavailable{<char code>}{<substitution>}¦.
% \item Add French language variant ¦swiss¦.
% \item Implement \xpgoption{babelshorthands} for Croatian.
% \item Implement ¦\localnumeral¦ for Japanese.
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix font family issue in headers (\TXI{355}).
% \item Fix whitespace issues in ¦\text<lang>¦ (\TXI{356}).
% \item Fix option-less ¦\babelname¦ in multi-variant languages (\TXI{357}).
% \item Fix some spacing inconsistencies with French, Latin, and Sanskrit (\TXI{358}).
% \item Fix issues with \xpgoption{babelshorthands} and \pkg{graphics} package (\TXI{368}).
% \item Fix some captions and improve numbering in Marathi (\TXI{370}).
% \item Fix Hungarian \xpgoption{swapstrings} feature (\TXI{373}).
% \item Fix lua punctuation code problem (\TXI{374}).
% \item Fix Bengali changecounternumbering option (\TXI{381}).
% \item Fix whitespace issue in Japanese (\TXI{387}).
% \item Fix ¦\text<lang>¦ command with multiple paragraphs.
% \item Actually implement documented german spelling variant ¦1996¦ (= ¦new¦).
% \item Fix Slovenian \xpgoption{localalph} option.
% \item Fix Czech and Slovak \xpgoption{splithyphens} with typewriter fonts.
% \item ¦farsical.sty¦: fix spacing issue with some month names.
% \item Fix directionalty of numbers in Hebrew with XeTeX.
% \item Improve interoperatability with \pkg{biblatex} (some language variants did not work yet).
% \end{itemize}
% 
% \subsubsection*{Interface and defaults changes}
% \begin{itemize}
% \item Some boolean options had ¦false¦ value by default, which meant if you passed
%       them without value, the logic was reversed. This has been changed, leading to
%       change of behavior should you have used one of these options without value (\TXI{363}).
%       Concerned are the following options:
%       \begin{itemize}
% 	   \item ¦babelshorthands¦ in language Belarusian, Mongolian, Ukrainian, and Russian
%              (now ¦babelshorthands¦ equals ¦babelshorthand=true¦, no longer ¦babelshorthands=false¦).
% 	   \item ¦localalph¦ in language Slovenian (¦localalph¦ now equals ¦localalph=true¦).
% 	   \item ¦latesthyphen¦ in language German (¦latesthyphen¦ now equals ¦latesthyphen=true¦).
% 	   \item ¦fullyear¦ in package \pkg{hebrewcal} (¦fullyear¦ now equals ¦fullyear=true¦).
%       \end{itemize}
% \item The command ¦\setlanguagealias*¦ (introduced in v1.46) does no longer define
%       dedicated alias environments.
% \item The babelnames for Latin variants have been corrected to ¦classiclatin¦, ¦ecclesiasticlatin¦
%       and ¦medievallatin¦. This is how the hyphenation patterns and \pkg{babel} ¦\extras¦ are named, even
%       though the variants can currently be selected in \pkg{babel} only via appended ``dot modifier''.
% \item In accordance with the respective \pkg{l3kernel} change, ¦\str_lower_case:n¦  has been renamed to
%       ¦\str_lowercase:n¦ where used in ¦polyglossia.sty¦. Thus \pkg{polyglossia} 1.47 requires \pkg{l3kernel}
%       2020-01-12 at least.
% \end{itemize}
% 
% \subsection*{1.46 (15-11-2019)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item Add option \xpgoption{indentfirst} to Russian (\TXI{78}).
% \item Add options to set and customize French-style itemize item labels to French (\TXI{89}).
% \item \pkg{Polyglossia} now decodes all supported \pkg{babel} language names in ¦\setdefaultlanguage¦,
%       ¦\setotherlanguage¦ and the language switching commands (\TXI{112}, \TXI{132}).
% \item Add optional localized math operators to Spanish (\TXI{123}).
% \item Swap section headings in Hungarian (\TXI{344}). New option \xpgoption{swapstrings} provides control
%       over this.
% \item Introduce macro ¦\setlanguagealias¦ and ¦\setlanguagealias*¦.
% \item Introduce language switching command ¦\textlang{lang}{...}¦ (equivalent to ¦\text<lang>¦,
%       but also available with ¦\setlanguagealias*¦ which does not define ¦\text<alias>¦).
% \item Add support for Afrikaans.
% \item Add support for Belarusian.
% \item Add support for Bosnian.
% \item Add support for Georgian.
% \item Add Spanish variant ¦mexican¦.
% \item Add babelshorthands as well as options \xpgoption{splithyphens} and \xpgoption{vlna} to Slovak.
% \item Add Latin language variant ¦ecclesiastic¦.
% \item Add Latin language options ¦capitalizemonth¦, ¦ecclesiasticfootnotes¦, ¦hyphenation¦,
%       ¦prosodicshorthands¦, and ¦usej¦.
% \item Add Latin shorthands for «, », æ, Æ, œ, and Œ.
% \item Add French language option \xpgoption{thincolonspace}.
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix problems with fragile font settings (\TXI{24}).
% \item Fix clash of French punctuation spacing with the \pkg{soul} package (\TXI{52}).
% \item Re-enable the possibility to pass a macro as main argument to ¦\setmainlanguage¦ and
%       ¦\setotherlanguage¦ (\TXI{331}).
% \item Fix detection of default ¦\languagevariant¦ (\TXI{332}).
% \item Fix LaTeX error with undefined hyphenation pattern (\TXI{346}).
% \item Fix some babel shorthand issues by updating the shorthand code from recent \pkg{babel}.
% \item Fix some problems with French and Latin auto-spacing (\TXI{345}, \TXI{352}).
% \item Fix an \pkg{expl3} declaration (\TXI{348}).
% \end{itemize}
% 
% \subsubsection*{Interface and defaults changes}
% \begin{itemize}
% \item The sub-package ¦cyrillicnumbers.sty¦ has been renamed to
%       ¦xpg-cyrillicnumbers.sty¦ (per TeXLive request).
% \item In Russian, all paragraphs are now indented by default, as common in Russian typography.
%       The behavior can be opted out by \xpgoption{indentfirst=false}.
% \item In Czech, \xpgoption{splithyphens} and \xpgoption{lvna} are enabled by default.
%       Also, the option does now work as well with LuaTeX.
% \item Changed option name ¦fraktur¦ to ¦blackletter¦ in German (the former is still available
%       as an alias).
% \item In French, high punctuation characters and guillemets are spaced by half an interword
%       space now instead of a ¦\thinspace¦ (cf. \TXI{345}).
% \end{itemize}
% 
% \subsection*{1.45 (27-10-2019)}
% 
% \subsubsection*{New features}
% \begin{itemize}
% \item Introduce a framework for external packages to access language variants. This fixes,
%       among other things, long-standing problems in the interaction of \pkg{biblatex} and \pkg{polyglossia}.
% \item Add new macros ¦\languagevariant¦, ¦\mainlanguagevariant¦, ¦\babelname¦ and ¦\mainbabelname¦
%       for package authors to access language information.
% \item Add new test ¦\iflanguageloaded{<language>}{<true>}{<false>}¦ where <language>
%       can be a \pkg{polyglossia} or \pkg{babel} language name.
% \item Add new macros ¦\localnumeral,¦ ¦\localnumeral*,¦ ¦\Localnumeral¦ and
%       ¦\Localnumeral*¦ that convert Arabic digitals to the local number scheme.
% \item Add new macro ¦\pghyphenation¦ to add language-specific hyphenation exceptions (\TXI{18}).
% \item Add support form (Khalkha \& Cyrillic) Mongolian in line with \pkg{babel-mongolian} (\TXI{23}).
% \item Add option \xpgoption{splithyphens} and \xpgoption{vlna} to Czech (XeTeX only; for LuaTeX, use the package
%       \pkg{luavlna} to get these features) (\TXI{32}).
% \item Add support for Kurdish, both Kurmanji and Sorani (\TXI{277}).
% \item Implement proper Cyrillic (alphanumeric) numbering (\TXI{285}).
% \item Add new language ¦friulian¦.
%       This deprecates ¦friulan¦ (which is still supported for backwards compatibility).
% \item Add new language ¦malay¦ with variants ¦indonesian¦ and ¦malaysian¦.
%       This deprecates ¦bahasai¦ and ¦bahasam¦ (which are still supported for
%       backwards compatibility).
% \item Add new language ¦gaelic¦ with variants ¦irish¦ and ¦scottish¦.
%       This deprecates ¦irish¦ and ¦scottish¦ as own \pkg{polyglossia} languages (which
%       are still supported for backwards compatibility).
% \item Add new language ¦hungarian¦.
%       This deprecates ¦magyar¦ (which is still supported for backwards compatibility).
% \item Add new language ¦sorbian¦ with variants ¦lower¦ and ¦upper¦.
%       This deprecates ¦lsorbian¦ and ¦usorbian¦ (which are still supported for
%       backwards compatibility).
% \item Add new language ¦portuguese¦ with variants ¦portuguese¦ and ¦brazilian¦.
%       This deprecates ¦brazil¦ and ¦portuges¦ (which are still supported for
%       backwards compatibility).
% \item Add new language ¦norwegian¦ with variants ¦nynorsk¦ and ¦bokmal¦.
%       This deprecates ¦nynorsk¦ and ¦norsk¦ (which are still supported for
%       backwards compatibility).
% \item Add new language ¦persian¦.
%       This deprecates ¦farsi¦ (which is still supported for backwards compatibility).
% \item Add new language ¦sami¦. Currently only Northern Sami is supported.
%       This deprecates ¦samin¦ (which is still supported for backwards compatibility).
% \item ¦gloss-serbian¦: add \xpgoption{numerals=cyrillic} option. Add ¦\asbuk¦ and ¦\Asbuk¦ (\TXI{285}).
% \item Implement basic support for (French) ¦canadien¦ and (English) ¦canadian¦ (\TXI{22}).
% \item Improve support for Armenian (\TXI{79}): Add captions, Eastern month names
%       (accessible via variant=eastern) and Armenian alphabetic numbering
%       (via \xpgoption{numerals=armenian} and ¦\armenicnumeral¦).
% \item Add french option \xpgoption{autospacing} and commands ¦\AutoSpacing,¦ ¦\NoAutoSpacing¦
%       This allows to switch off autospacing globally or locally (\TXI{113}).
% \item Fixup ¦\normalfont¦ (\TXI{203}).
% \item Fix directionality issues in mixed RTL/LTR paragraphs (\TXI{204}).
% \item Implement \xpgoption{babelshorthands} for Finnish (\TXI{212}) and Czech.
% \item Implement access to current language via Lua (\TXI{243}).
% \item Introduce french option option \xpgoption{autospacetypewriter}
%       alias \xpgoption{OriginalTypewriter}.
% \item Support ¦\aemph¦ with lualatex
% \item Rename \xpgoption{automaticspacesaroundguillemets} to \xpgoption{autospaceguillemets} 
%       The old option is kept for backwards compatibility.
% \end{itemize}
% 
% \subsubsection*{Bug fixes}
% \begin{itemize}
% \item Fix equation number in Arabic and Farsi (\TXI{7}).
% \item Simplify and document Hebrew \xpgoption{marcheshvan} option (\TXI{16}).
% \item Fix hyphenation of Greek with LuaTeX (\TXI{55}).
% \item Fix N'ko date format (\TXI{63}).
% \item Disable the extras of a language when a nested language starts (\TXI{66}, \TXI{169}).
% \item Properly implement Bengali numbers (\TXI{69}, \TXI{184}).
% \item Fix conflicts with other packages caused by premature shorthand activation
%       in preamble (\TXI{81}, \TXI{200}).
% \item Fix kerning in math with French (\TXI{92}).
% \item Fix expansion issue in Hebrew (\TXI{93}).
% \item Fix numbering expansion issue in Greek (\TXI{110}).
% \item Postpone ¦\disablehyphenation¦ in preamble until after setting of
%       document language (\TXI{125}).
% \item Postpone the assignment of defaultfamily to ¦\AtBeginDocument¦,
%       thus do not overwrite ¦\familydefault¦ redefinitions in the preamble (\TXI{127}).
% \item Reset number settings when switching language (\TXI{133}).
% \item Hebrew: Properly store ¦\MakeUppercase¦ for later restoration (\TXI{152}).
% \item Fix whitespace issue in ¦\datewelsh¦ (\TXI{158}).
% \item When switching language, set the language/script specific font families (\TXI{164}).
% \item Correct some Bengali captions (\TXI{165}).
% \item Fix documentation of Serbian (\TXI{168}).
% \item Reset ucl codes in Latin only if the respective variant is used (\TXI{172}).
% \item Fix ¦\disablehyphenation¦ with LuaTeX (\TXI{187}).
% \item Fix typos in Hindi captions (\TXI{202}).
% \item Pass language options to the aux files (\TXI{205}).
% \item Rewrite and fix English variant handling (\TXI{208}).
% \item Define magyar caption formats in ¦\blockextras¦ and undef them in ¦\noextras¦ (\TXI{209}).
% \item Ensure proper direction with arabic digits in Arabic and Farsi (\TXI{213}).
% \item Fix ¦\linespread¦ with Korean (\TXI{218}).
% \item Define Russian caption before key allocation (\TXI{219}).
% \item Register current language in \pkg{polyglossia} lua module after selection (\TXI{234}).
% \item Fix \pkg{babel} language switching commands (\TXI{239}):
%       ¦\foreignlanguage¦ and the starred ¦otherlanguage*¦ environment are not
%       supposed to change dates.
% \item Fix French spacing leaking beyond French (\TXI{270}).
% \item Redefine font families for French only if language is loaded (\TXI{270}).
% \item ¦gloss-russian¦: 
%      \begin{itemize}
% 	 \item Check whether command exist before redefining (\TXI{280}).
% 	 \item Fix some whitespace issues.
%      \end{itemize}
% \item Fix and simplify ¦\frenchfootnote¦ definition (\TXI{294}).
% \item Fix footnote numbering in Farsi.
% \item Fix Latin footnotes in Arabic documents.
% \item Set the correct main direction with \pkg{luabidi}.
% \item Fix \xpgoption{autospaceguillemets} option in French.
% \item Fix grouping in ¦gloss-danish.ldf¦.
% \item Properly store ¦\MakeUppercase¦ and ¦\@arabic¦ for later restoration.
% \end{itemize}
% 
% \subsubsection*{Documentation}
% \begin{itemize}
% \item Add documentation about footnotes in RTL context
% \item Document Tibetan numerals option (\TXI{109}).
% \item Improve ¦\frenchfootnote¦ documentation.
% \item Mention Japanese support in the docs.
% \end{itemize}
% 
% \subsection*{1.44 (04-04-2019)}
% \begin{itemize}
% \item Correction to Russian language file, by \TA{Maksim Zholudev} (commit d2f383e).
% \item Added Macedonian language file, by \TA{Stefan Zlatinov} (commit cd379e1).
% \end{itemize}
% 
% \subsection*{1.43 (05-03-2019)}
% \begin{itemize}
% \item Correction to Hindi language file, by \TA{Zdenĕk Wagner}.
% \end{itemize}
% 
% \subsection*{1.42.5 (13-04-2017)}
% \begin{itemize}
% \item Many changes to the French language file, by \TA{Maïeul Rouquette}.
% \end{itemize}
% 
% \subsection*{1.42.4 (February, March 2016)}
% \begin{itemize}
% \item Remedial actions for the \pkg{babel} changes.
% \item Fixed side effect of pull request \TXI{122} (see commit d2a34ff).
% \item Added automatic Josa selection, variant, and captions options to Korean, by \TA{Dohyun Kim} (pull request \TXI{128}).
% \item Updated ¦gloss-occitan¦ from CTAN.
% \end{itemize}
% 
% \subsection*{18-01-2016}
% \begin{itemize}
% 	\item Fixed issue \TXI{124} (minor typo in ¦polyglossia-frpt.lua¦)
% 	\item Merged pull request \TXI{117} for more French guillemet spacing
% 	\item Merged pull request \TXI{121} to add ¦\bbl@loaded¦; fixes issue \TXI{120}
% 	\item Merged pull request \TXI{122} that build on \TXI{121}
% 	\item Merged pull request \TXI{116} for French (spacing around guillemets)
% 	\item Fixed issue \TXI{115} (spurious spaces in Arabic)
% \end{itemize}
% 	
% \subsection*{19-08-2015}
% \begin{itemize}
% 	\item Fixed issue \TXI{107} for Marathi (labels and month names)
% \end{itemize}
% 		
% \subsection*{1.42.0 (06-08-2015)}
% \begin{itemize}
% 	\item Add Bengali digits package, and option to reset all numbering functions.
% 	\item Add ¦long¦ option for Welsh date.
% 	\item Add local alphabet in Slovenian, for enumerations and such.
% 	\item Fix long-standing bug with Welsh: date should use ordinals.
% 	\item Fix for Latin with LuaTeX: all variants had same problems as Classic.
% 	\item Fixed error with British variant of English and LuaTeX (issue \TXI{86}).
% \end{itemize}
% 			
% \subsection*{1.41.0 (16-07-2015)}
% \begin{itemize}
% 	\item Added support for Khmer, by \TA{Say Ol} (private email)
% \end{itemize}
% 			
% \subsection*{1.40.1 (14-07-2015)}
% \begin{itemize}
% 	\item Bugfix for Korean, by \TA{Dohyun Kim} (pull request \TXI{103})
% \end{itemize}
% 			
% \subsection*{1.40.0 (07-07-2015)}
% \begin{itemize}
% 	\item ¦gloss-korean.ldf¦ contributed by \TA{Dohyun Kim} (pull request \TXI{102})
% \end{itemize}
% 			
% \subsection*{1.33.7 (04-07-2015)}
% \begin{itemize}
% 	\item Release to CTAN, no code change
% 	\item Fixed extraneous space in code for Swiss German (pull request \TXI{101})
% 	\item Fixed a typo in Ukrainian alphabet, for ¦\Asbuk¦ (pull request \TXI{99})
% 	\item Fix for Classic Latin: load patterns for LuaTeX
% 	\item Made ¦\rmfamily¦, ¦\sffamily¦ and ¦\ttfamily¦ robust again
% 	\item Merged fix for Hebrew date format, by \TA{Guy Rutenberg} (pull request \TXI{94})
% 	\item Merged fix for spurious space, by \TA{Caleb McKennan} (pull request \TXI{91})
% 	\item Merged pull request \TXI{84} by \TA{Élie Roux} for Tibetan
% 	\item Added support for Swiss German (pull request \TXI{75})
% 	\item Added commands ¦\Asbuk¦ and ¦\asbuk¦ for Ukrainian (pull request \TXI{76}), similar to Russian
% 	\item Documented changes to Latin from last year.
% 	\item Be friendlier to right-to-left languages with LuaTeX
% 	\item Enhanced Latin support by \TA{Claudio Beccari}
% \end{itemize}
% 
% \subsection*{1.33.6 (15-05-2015)}
% \begin{itemize}
% 	\item Introduce a ¦classical¦ and ¦medieval¦ variant of Latin
% 	\item Add ¦\asbuk¦ and ¦\Asbuk¦ for Ukrainian (after their Russian counterpart)
% 	\item Fix a number of bugs
% \end{itemize}
% 					
% \subsection*{1.33.5 (21-05-2014)}
% \begin{itemize}
% 	\item Option to disable hyphenation entirely, by \TA{Élie Roux}
% 	\item Fix spurious spaces in gloss-russian.ldf, by \TA{Oleg Domanov}
% 	\item Support for the Austrian variant of German, by \TA{Jürgen Spitzmüller}
% 	\item Changes to the Croatian translations, by \TA{Ivan Kokan}
% 	\item Correction to the Lithuanian translations, by \TA{Ignas Anikevičius}
% \end{itemize}
% 					
% \subsection*{1.33.4 (27-06-2013)}
% \begin{itemize}
% 	\item Emergency release for a bug introduced in ¦babelsh.def¦
% \end{itemize}
% 					
% \subsection*{1.33.3 (28-05-2013)}
% \begin{itemize}
% 	\item Changed formatting of some error messages (emergency fixes for TeX Live 2013)
% \end{itemize}
% 					
% \subsection*{1.33.2 (26-05-2013)}
% \begin{itemize}
% 	\item Added ¦\disablehyphenation¦ and ¦\enablehyphenation¦, contributed by
% 	      \TA{Élie Roux}.
% 	\item Fixed bug related to package inclusion. \pkg{Polyglossia} would break if
% 	      we loaded ¦breqn.sty¦, and then called ¦\setmainlanguage{english}¦, this
% 	      is no longer the case.
% 	\item Removed spurious space introduced by ¦\captionswedish¦.
% \end{itemize}
% 					
% \subsection*{1.33.1 (23-05-2013)}
% \begin{itemize}
% 	\item Editorial changes to the documentation
% 	\item Hunted and documented bugs
% \end{itemize}
% 					
% \subsection*{1.33.0 (20-05-2013)}
% \begin{itemize}
% 	\item Added support for N’Ko.
% 	\item Bugfixes for LuaTeX
% 	\item More work in progress on Bidi in LuaTeX.
% \end{itemize}
% 					
% \subsection*{1.32.0 (15-05-2013)}
% \begin{itemize}
% 	\item Transitional version to support right-to-left languages with LuaTeX.
% \end{itemize}
% 
% \subsection*{1.31 (10-05-2013) / 1.3 (11-05-2013)}
% \begin{itemize}
% 	\item Several bugfixes.
% 	\item Sync with \pkg{babel} 3.9.
% 	\item Consolidated support for LuaTeX for all languages but the ones using
% 	      South and South-East Asian scripts, and languages written from right
% 	      to left.  Many thanks to \TA{Élie Roux} for his help.
% 	\item Added support for Tibetan, contributed by \TA{Élie Roux} (end of lines are experimental).
% \end{itemize}
% 					
% \subsection*{1.30 (06-08-2012)}
% \begin{itemize}
% 	\item Added support for LuaTeX.  Many languages don’t work yet.  Please be patient.
% \end{itemize}
% 					
% \subsection*{1.2.0e (28-04-2012)}
% \begin{itemize}
% 	\item Fixed a number of outstanding and not very interesting bugs.
% 	\item Added gloss files for Romansh and Friulan, contributed by \TA{Claudio Beccari}.
% \end{itemize}
% 					
% \subsection*{1.2.0d (12-01-2012)}
% \begin{itemize}
% 	\item Removed ¦\makeatletter¦ and ¦\makeother¦ from gloss files entirely.
% \end{itemize}
% 					
% \subsection*{1.2.0c (12-10-2011) [First update by Arthur Reutenauer]}
% \begin{itemize}
% 	\item Update to ¦gloss-italian.ldf¦ by \TA{Claudio Beccari}, incorporating changes
% 	      by \TA{Enrico Gregorio}.
% 	\item Conclude every gloss file with ¦\makeatother¦ to match the initial
% 	      ¦\makeatletter¦.  (Not necessary from a technical point of vue, because of one 
% 	      of the changes by Enrico reported below, but I like it better that way :-)
% 	\item Conclude ¦polyglossia.sty¦ with ¦\ExplSyntaxOff¦ to match the initial
% 	      ¦\ExplSyntaxOn¦.
% 	\item Added gloss file for Kannada, contributed by \TA{Aravinda VK} and others.
% 	\item Corrections to the gloss-dutch.ldf thanks to \TA{Wouter Bolsterlee}.
% 	\item Several patches by \TA{Enrico Gregorio}, fixing long-standing bugs.
% 	      From the git log:
% 			\begin{itemize}
% 				\item Deleted setup for right-to-left writing direction, see \url{http://tug.org/pipermail/xetex/2011-April/020319.html}
% 				\item Changed three appearances of ¦\newcommand¦ to ¦\newrobustcmd,¦ as the commands needs to be protected.
% 				      Bug reported by \TA{kamensky}.
% 				\item Corrected ¦\datepolish¦ as suggested by \TA{Piotr Kempa}
% 				\item Changed ¦\lccode"¦ into ¦\lccode\string",¦ because it might come into action at wrong times when ¦"¦ is active
% 				\item Changed definition of key ¦\xpg@setup¦, as ¦\@tmpfirst¦ and ¦\@tmpsecond¦ were not expanded, causing dependence
% 				      of ¦\lefthyphenmin¦ and   ¦\righthyphenmin¦ to the last loaded language.
% 				      Raised by \TA{Vadim Rodionov} on the XeTeX mailing list.
% 				\item Deleted ¦\bgroup¦ and ¦\egroup¦ tokens from the definition of ¦otherlanguage*¦; they serve no purpose
% 				      (we are already inside an environment) and conflict with \pkg{csquotes}. Noticed by \TA{P. Lehman}.
% 				\item Changed the calls of ¦\input¦ to ¦\xpg@input,¦ which inputs the required file and resets the catcode
% 				      of ¦@¦ to the same value as it had before the input. Since each ¦.ldf¦ file starts with ¦\makeatletter¦,
% 				      the old behaviour would leave a category 11 @, which is wrong.
% 				\item Added ¦\csuse{date#2}¦ to the definition of ¦otherlanguage*¦.
% 			\end{itemize}
% \end{itemize}				
% 						
% \subsection*{1.2.0b (03-10-2011) [Update by Philipp Stephani]}
% \begin{itemize}
% 	\item Load \pkg{xkeyval} package explicitly since newer versions
% 	      of \pkg{fontspec} don't load it any more.
% \end{itemize}
% 							
% \subsection*{1.2.0a (27-07-2010) [Last update by François Charette]}
% \begin{itemize}
% 	\item Initialize ¦\fontfamily¦ acc to value of ¦\familydefault¦
% 	      (Fixes a bug when using \pkg{polyglossia} with beamer)
% 	\item Remove spurious space in def of ¦\dateenglish¦
% 	\item Add missing English variant ¦american¦
% 	\item Serbian: fix date format and captions (Latin+Cyrillic)
% 	\item Fix ¦\atticnumeral¦ in ¦gloss-greek¦
% 	\item Small improvements and fixes in documentation
% \end{itemize}
% 								
% 								
% \subsection*{1.2.0 (15-07-2010)}
% \begin{itemize}
% 	\item Adapted for \pkg{fontspec} 2.0 (will not work with earlier versions!)
% 	\item New implementation of a ¦\PolyglossiaSetup¦ interface
% 	      that simplifies writing ¦gloss-*.ldf¦ files
% 	\item Many internal enhancements and refactoring
% 	      (including a patch by \TA{Dirk Ulrich})
% 	\item Improved automatic font setup when ¦\<lang>font¦ is not defined
% 	\item New environment otherlanguage* (env. equivalent of ¦\foreignlanguage¦
% 	      (\TA{Enrico Gregorio})
% 	\item Bugfix to prevent bogus expansion of ¦\{rm,sf,tt}family¦ even in aux files (\TA{Enrico Gregorio})
% 	\item New gloss files for Armenian, Bengali, Occitan, Bengali, Lao,
% 	      Malayalam, Marathi, Tamil, Telugu, and Turkmen.
% 	\item New auxiliary packages ¦devanagaridigits¦ and ¦bengalidigits¦
% 	\item \pkg{hijrical} no longer loads \pkg{bidi} and checks for incompatible \pkg{l3calc}
% 	\item Add \pkg{babel} shorthands for Russian (based on a patch by \TA{Vladimir Lomov})
% 	\item Fix ¦\fnum@{table,figure}¦ for Lithuanian
% 	\item Various improvements in ¦gloss-russian¦ (provided by \TA{Vladimir Lomov} and
% 	      others)
% 	\item Corrected captions for Bahasai, Lithuanian, Russian, Croatian
% 	\item Add option \xpgoption{indentfirst=true} for Spanish, Croation and other languages
% 	      (NB: \xpgoption{indentfirst} was previously named \xpgoption{frenchindent})
% 	\item New option \xpgoption{script} for German: Setting \xpgoption{script=fraktur} modifies the
% 	      captions for typesetting in Fraktur.
% 	\item New command ¦\aemph¦ for Arabic, Farsi, Urdu, etc. to mark emphasis through
% 	      overlining.
% 	\item Package option \xpgoption{nolocalmarks} is now true by default: to activate it the
% 	      option \xpgoption{localmarks} must be passed instead.
% 	\item Loading languages à la \pkg{babel} as package options is no longer possible (this
% 	      feature was deprecated since v1.1.0).
% \end{itemize}
% 							
% \subsection*{1.1.1 (23-03-2010)}
% \begin{itemize}
% 	\item Bugfix for French: explicit spaces before/after double punctuation
% 	      signs (Par exemple : les grands « espaces » du Canada !) are
% 	      now replaced by the appropriate non-breaking spaces, as in \pkg{babel}.
% 	\item Bugfix for font switching mechanism within Latin script
% 	      (pending a complete re-implementation in v1.2):
% 	      the font shape and series are no longer reset when switching language.
% 	\item New macros for non-Western decimal digits
% 	      (instead of fontmappings)
% 	\item New gloss files for Asturian, Lithuanian and Urdu
% 	\item ¦hijrical.sty¦ is now locale-aware: ¦\hijritoday¦ is
% 	      formatted differently in Arabic, Farsi, Urdu, Turkish
% 	      and Bahasa Indonesia.
% 	\item Enable \xpgoption{babelshorthands} for Dutch
% 	\item Add missing macro ¦\allowhyphens¦
% 	\item Add global option \xpgoption{babelshorthands}
% 	\item Support Catalan geminated l
% 	\item Bugfix when declaring more than one pkg option
% 	\item Protect ¦\reset@font¦
% 	\item Add missing requirement \pkg{makecmds}
% 	\item Bugfix for smallcaps in captions
% 	\item Typo for ¦ccname¦ in Hebrew
% 	\item Add option \xpgoption{numerals} to ¦gloss-russian¦
% 	\item Provide ¦\newXeTeXintercharclass¦ when undefined
% 	\item Bugfix for Russian ¦\alph¦
% 	\item Remove superfluous level of ¦{}¦ in definition of ¦\markright¦
% 	\item Bugfix for ¦\datecatalan¦
% 	\item Change ¦hyphenmins¦ for Sanskrit
% \end{itemize}
% 							
% \subsection*{1.1.0b (22-11-2009)}
% \begin{itemize}
% 	\item Modify ¦\hyphenmins¦ for Sanskrit (\TA{Yves Codet})
% 	\item Bugfixes for Serbian and Bulgarian (\TA{Enrico Gregorio})
% \end{itemize}
% 
% \subsection*{1.1.0a (22-11-2009)}
% \begin{itemize}
% 	\item Bugfix for interchar tokens
% \end{itemize}
% 
% \subsection*{1.1.0 (20-11-2009)}
% \begin{itemize}
% 	\item Use ¦\newXeTeXintercharclass¦ (thanks to \TA{Enrico Gregorio})
% 	\item Fixed implementation of shorthands for German (\pkg{babel} code in file ¦babelsh.def¦)
% 	\item Arabic (\TA{Khaled Hosny}):
% 	\begin{itemize}
% 		\item Fix abjad form for 3 and 5 and add option ¦\abjadjimnotail¦
% 		\item bugfix for ¦\arabicnumber¦
% 		\item make Gregorian calendar the default
% 		\item fixed typos in the sample text
% 	\end{itemize}
% 	\item Turkish (\TA{S. Ö. Yıldız}):
% 	\begin{itemize}
% 		\item fix white-space before : and !
% 		\item also check if the font specified TRK for language
% 		\item added missing Turkish translation of ``Glossary''
% 	\end{itemize}
% 	\item Suppress ¦nopattern¦ warning for non-hyphenated scripts
% 	\item Changed U+0163 to U+021B for Romanian (\TA{Elie Roux})
% 	\item Stylistic fixes and use macro ¦\xpg@option¦ for package options (\TA{E. Gregorio})
% 	\item Fix month names in Dutch (\TA{A. Ledda})
% 	\item Add Brazilian translation for ``glossary''
% 	\item Remove spurious space generated by ¦gloss-spanish¦
% 	\item Fix ¦ldf¦ file for brazilian
% 	\item Various improvements in the code communicated by \TA{E. Gregorio}:
% 	\begin{itemize}
% 		\item remove superfluous ¦\protect\language¦
% 		\item change default language from ¦0¦ to ¦\l@nohyphenation=255¦
% 		\item localize ¦lccode¦ handling of apostrophe in French; add it to Italian
% 	\end{itemize}
% 	\item Fix ¦frenchspacing¦ for Vietnamese
% 	\item Other minor bugfixes
% \end{itemize}
% 							
% \subsection*{1.0.2 (27-01-2009)}
% \begin{itemize}
% 	\item Captions corrected in Hebrew, Russian and Spanish
% 	\item Removed all ¦\text<lang>¦ wrappers within caption definitions
% 	\item Improved compatibility with \pkg{babel}
% 	\item New option \xpgoption{babelshorthands} for German
% 	\item New option \xpgoption{Script} for Sanskrit
% \end{itemize}
% 							
% \subsection*{1.0.1 (31-07-2008)}
% \begin{itemize}
% 	\item Improved documentation (added sections on font setup and numeration mappings)
% 	\item Improvements and bug fixes for English and German
% 	\item Bugfix in ¦gloss-syriac.ldf¦ (spurious space after ¦\textsyriac{...}¦)
% 	\item Extended the scope of ¦\syriacabjad¦
% 	\item Added ¦gloss-amharic.ldf¦ (ported from ¦ethiop.ldf¦ in the package \pkg{ethiop})
% \end{itemize}
% 							
% \subsection*{1.0 (13-07-2008)}
% \begin{itemize}
% 	\item Initial release on CTAN.
% \end{itemize}
% \egroup
% 
% \section{Acknowledgements (by François Charette)}
% \pkg{Polyglossia} is notable for being a recycle box of previous contributions
% by other people. I take this opportunity to thank the following individuals,
% whose splendid work has made my task almost trivial in comparision: \TA{Johannes
% Braams} and the numerous contributors to the \pkg{babel} package (in particular
% \TA{Boris Lavva} and others for its Hebrew support), \TA{Alexej Kryukov} (\pkg{antomega}),
% \TA{Will Robertson} (\pkg{fontspec}), \TA{Apostolos Syropoulos} (\pkg{xgreek}), \TA{Youssef Jabri}
% (\pkg{arabi}), and \TA{Vafa Khalighi} (\pkg{xepersian} and \pkg{bidi}).
% The work of \TA{Mojca Miklavec} and \TA{Arthur Reutenauer} on hyphenation patterns with their package
% \pkg{hyph-utf8} is of course invaluable. I should also thank other
% individuals for their assistance in supporting specific languages: \TA{Yves Codet}
% (Sanskrit), \TA{Zdenĕk Wagner} (Hindi), \TA{Mikhal Oren} (Hebrew), \TA{Sergey Astanin} (Russian),
% \TA{Khaled Hosny} (Arabic), \TA{Sertaç Ö. Yıldız} (Turkish), \TA{Kamal Abdali} (Urdu),
% and several other members of the \XeTeX\ user community, notably \TA{Enrico Gregorio}, who
% has sent me many useful suggestions and corrections and contributed the \cmd\newXeTeXintercharclass\
% mechanism in xelatex.ini which is now used by polyglossia.
% More recently, \TA{Kevin Godby} of the \href{http://ubuntu-manual.org}{Ubuntu Manual} project has
% contributed very useful feedback, bug hunting and, with the help of translators,
% new language definition files for Asturian, Lithuanian, Occitan, Bengali, Malayalam, Marathi, Tamil, and Telugu.
% It is particularly heartening to realize that this package is used to typeset a widely-read
% document in dozens of different languages!
% Support for Lao was also added thanks to \TA{Brian Wilson}.
% I also thank \TA{Alan Munn} for kindly proof-reading the penultimate version of this documentation.
% And of course my gratitude also goes to \TA{Jonathan Kew}, the formidable author of \XeTeX!
% 
% \section{More acknowledgements (by the current development team)}
% Many thanks to all the people who have contributed bugfixes and new features to \pkg{polyglossia}
% since we took over.
% In alphabetical order: \TA{Ignas Anikevicius}, \TA{Sina Ahmadi}, \TA{Wouter Bolsterlee}, \TA{Christian Buhtz},
% \TA{Zgarbul Andrey}, \TA{Oleg Domanov}, \TA{Philipp Gesang}, \TA{Kevin Godby}, \TA{Enrico Gregorio},
% \TA{Khaled Hosny}, \TA{Najib Idrissi}, user \TA{julroy67}, \TA{Dohyun Kim}, \TA{Phil Kime}, \TA{Mike Kroutikov},
% \TA{Ivan Kokan}, \TA{Caleb Maclennan}, \TA{José Mancera}, \TA{Miquel Ortega}, \TA{Yevgen Pogribnyi}, \TA{Will Robertson},
% \TA{Maïeul Rouquette}, \TA{Elie Roux}, \TA{Hugo Roy},  \TA{Guy Rutenberg}, \TA{Philipp Stephani}, \TA{Niranjan Tambe},
% \TA{Osman Tursun}, \TA{Keno Wehr}, \TA{Dominik Wujastyk}, \TA{Sertaç Ö. Yıldız}, \TA{Maksim Zholudev}, \TA{Yan Zhou},
% and \TA{Stefan Zlatinov}.
% Their respective contributions can be identified from the contributor statistics on
% \href{https://github.com/reutenauer/polyglossia/graphs/contributors}{GitHub}.
% 
% Among the ones who sent contributions directly to us we would like to especially thank
% \TA{Claudio Beccari}, the indefatigable champion of Romance languages, and beyond! Furthermore,
% kudos go to \TA{Moritz Wemheuer} (of \pkg{biblatex}) who has helped a lot to improve \pkg{polyglossia} interaction
% with \pkg{biblatex} and \pkg{csquotes}.
% 
% Not at least, we are very grateful for all bug reports and feature enhancement requests we received from
% the numerous users we cannot list all here (but again, you can find all names on \href{https://github.com/reutenauer/polyglossia/issues?utf8=%E2%9C%93&q=is%3Aissue}{GitHub}).
% Please go on with that, you are keeping \pkg{polyglossia} running!
% 
% 
% 
% 
% \StopEventually{}
% \section{Implementation}
% \iffalse
%<*polyglossia.sty>
% \fi
% \clearpage
% 
% \subsection{polyglossia.sty}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{polyglossia}[2021/03/16 v1.52
  Modern multilingual typesetting with XeLaTeX and LuaLaTeX]
\RequirePackage{etoolbox}
\RequirePackage{makecmds}
\RequirePackage{xkeyval}[2008/08/13]
% Will raise error if used with anything else than XeTeX or LuaTeX
\RequirePackage{fontspec}[2010/06/08]% v2.0
\RequirePackage{iftex}
\RequirePackage{expl3}
\RequirePackage{l3keys2e}
\RequirePackage{xparse}

% fontspec now uses LaTeX3 packages such as expl3, so we need this:
\ExplSyntaxOn

% Execute code #3 if package #1 has been loaded already, else
% add to package hook #2
\newcommand\xpg@at@package[3]{%
    \@ifpackageloaded{#1}{#3}{\AddToHook{#2}{#3}}%
}

% correct a bug in tracklang
\xpg@at@package{tracklang}{file/after/tracklang.sty}{%
  \@ifpackagelater{tracklang}{2019/08/30}{}{\global\def\AddTrackedLangage{\AddTrackedLanguage}}
}


%% This is for compatibility with Babel-aware package:
\def\languageshorthands#1{\relax} %this is for scrlttr2 class
\def\bbl@cs#1{\csname bbl@#1\endcsname}%
\AtEndPreamble{\let\bbl@set@language\xpg@set@language@aux} %for biblatex
\AtEndPreamble{\let\bbl@main@language\xpg@main@language} %for biblatex
\providecommand\texorpdfstring[2]{#1}% dummy command if hyperref is not loaded

\ifluatex
  \RequirePackage{luatexbase} % already included by fontspec, but needed here
  \RequireLuaModule{polyglossia}
\fi

% Which version of XeTeX do we use? What is the boudary class? 4095 or 255
\@ifundefined{e@alloc@intercharclass@top}
  {\chardef\xpg@boundaryclass=\@cclv}
  {\let\xpg@boundaryclass=\e@alloc@intercharclass@top}

% Useful for getting list of loaded languages and variants. Like babel's bbl@loaded
\let\xpg@loaded\@empty% list of loaded languages (polyglossia name)
\let\xpg@vloaded\@empty% list of loaded variants
\let\xpg@bloaded\@empty% list of loaded languages (babel name)
\let\xpg@bcp@loaded\@empty% list of loaded languages (bcp-47 id)

% counter in latin
\def\latinalph#1{\expandafter\latin@alph\csname c@#1\endcsname}
\def\latinAlph#1{\expandafter\latin@Alph\csname c@#1\endcsname}

% select language hook
\cs_new_nopar:Nn \polyglossia@AtBeginDocument@selectlanguage: {}
% \disablehyphenation hook
\cs_new_nopar:Nn \polyglossia@AtBeginDocument@hyphenation: {}

% hook to be executed at begin of document
\cs_new_nopar:Nn \polyglossia@AtBeginDocument: {
  % save various command
  \let\latin@alph\@alph   % TODO rename when we have the C locale
  \let\latin@Alph\@Alph   % TODO rename when we have the C locale
  % push to C language gloss
  \let\polyglossia@Clang@@arabic\@arabic
  \let\polyglossia@Clang@arabic\arabic
  
  \xpg@initial@setup
  % apply \familydefault changes
  \xpg@set@familydefault
}

\AtBeginDocument{
  \polyglossia@AtBeginDocument:
}

% The following needs to go after any \AtBeginDocument (also of packages
% loaded after \set[main|other]language
\AfterEndPreamble{
  % now we have the C locale definition: select the language
  \polyglossia@AtBeginDocument@selectlanguage:
  % If hyphenation disabling has been requested in preamble, do it now
  \polyglossia@AtBeginDocument@hyphenation:
}

%% custom message macros
\providecommand*{\xpg@error}[1]{%
   \PackageError{polyglossia}{#1}{}%
}

\providecommand*{\xpg@warning}[1]{%
   \PackageWarning{polyglossia}{#1}%
}

\providecommand*{\xpg@info}[1]{%
   \PackageInfo{polyglossia}%
   {#1\@gobble}%
} %% the \@gobble is to prevent displaying the line nr

%TODO change all instances of \xpg@nopatterns in gloss-*.ldf files
\providecommand*{\xpg@nopatterns@fallback}[2][nohyphenation]{%
   \xpg@warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#2'\MessageBreak
         I~ will~ use~ \string\language=\string\l@ #1\space instead}%
   \expandafter\adddialect\csname l@#2\expandafter\endcsname\csname l@#1\endcsname\relax}

\providecommand*{\xpg@nopatterns}[1]{%
   \xpg@warning{No~ hyphenation~ patterns~ were~ loaded~ for~ `#1'\MessageBreak
         I~ will~ use~ \string\language=\string\l@nohyphenation\space instead}%
   %%TODO? \expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax
   }

\def\xpg@ill@value#1#2{%
  \xpg@warning{Illegal~ value~ (#1)~ for~ #2}}

% error out if lang is not loaded
\cs_new_nopar:Nn \polyglossia@error@iflangnotloaded:n
{
  \cs_if_exist:cF{#1@loaded}
  {
    \xpg@error{language~ #1~ is~ not~ loaded.~ Please~ load~ it~ before~ using~ it.}
  }
}


% error do not use directly the gloss file
\msg_new:nnn { polyglossia } { directloadgloss }
{
  You~ should~ not~ load~ directly~ the~ gloss~ file~ using~ `\string\usepackage'.
  You~ must~ use~ `\string\setotherlanguage\{#1\}' or  `\string\setmainlanguage\{#1\}'.
}
\msg_redirect_name:nnn { polyglossia } { directloadgloss } { critical }

%% use macro if defined, else warn that it is not
\def\csuse@warn#1{%
   \ifcsundef{#1}{\xpg@warning{ \expandafter\string\csname #1\endcsname\space is~ not~ defined}}%
   {\csname #1\endcsname}}

%% ensure directionality if bidi is loaded, else ignore
\def\@@ensure@dir#1{\ifcsundef{@ensure@dir}{#1}{\@ensure@dir{#1}}}
\def\@@ensure@maindir#1{\ifcsundef{@ensure@maindir}{#1}{\@ensure@maindir{#1}}}

%% Used by the language definitions files for right-to-left languages
\def\RequireBidi{%
  \str_case_e:nnF{\c_sys_engine_str}{
    {luatex}{\ifx\@onlypreamble\@notprerr\else\RequirePackage{luabidi}\fi}
    {xetex}{\ifx\@onlypreamble\@notprerr\else\RequirePackage{bidi}\fi}
  }
  {
    \xpg@warning{You’re running a TeX engine that is not LuaTeX or XeTeX.\MessageBreak
      That is almost guaranteed to cause problems.}
  }
}

% (lua)bidi commands to change directionality for paragraphs
% and inline text.
% overwritten with correct package
\cs_new_nopar:Nn{\polyglossia@setpardirection:n}{%
  \str_case_e:nnTF{#1}{%
       {LR}{\relax}%
       {RL}{\xpg@error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}}%
     }%
     {}%
     {\xpg@error{Unknown~ language~ direction~ #1 ~(base~ wrapper)}}%
}
\cs_new_nopar:Nn{\polyglossia@settextdirection:n}{%
  \str_case_e:nnTF{#1}{%
       {LR}{\relax}%
       {RL}{\xpg@error{right-to-left,~ but~ (lua)bidi~ package~ was~ not~ loaded!}}%
     }%
     {}%
     {\xpg@error{Unknown~ language~ direction~ #1 ~(base~ wrapper)}}%
}
\xpg@at@package{bidi}{package/after/bidi}{%
  \ExplSyntaxOn%
  \cs_gset_nopar:Nn{\polyglossia@setpardirection:n}{%
    \str_case_e:nnTF{#1}{%
        {LR}{\setLR}%
        {RL}{\setRL}%
      }%
      {}%
      {\xpg@error{Unknown~ language~ direction~ #1 ~(bidi~ wrapper)}}%
  }%
  \cs_gset_nopar:Nn{\polyglossia@settextdirection:n}{%
    \str_case_e:nnTF{#1}{%
        {LR}{\LRE}%
        {RL}{\RLE}%
      }%
      {}%
      {\xpg@error{Unknown~ language~ direction~ #1 ~(bidi~ wrapper)}}%
  }%
  \ExplSyntaxOff%
}
\xpg@at@package{luabidi}{package/after/luabidi}{%
  \ExplSyntaxOn%
  \cs_gset_nopar:Nn{\polyglossia@setpardirection:n}{%
    \str_case_e:nnTF{#1}{%
        {LR}{\setLR}%
        {RL}{\setRL}%
      }
      {}%
      {\xpg@error{Unknown~ language~ direction~ #1 ~(luabidi~ wrapper)}}%
  }%
  \cs_gset_nopar:Nn{\polyglossia@settextdirection:n}{%
    \str_case_e:nnTF{#1}{%
        {LR}{\LRE}%
        {RL}{\RLE}%
      }
      {}%
      {\xpg@error{Unknown~ language~ direction~ #1 ~(luabidi~ wrapper)}}%
  }%
  \ExplSyntaxOff%
}

%% compatibility with babel
\let\addto\gappto% gappto is defined in etoolbox

%% NEW EXPERIMENTAL SETUP INTERFACE FOR GLOSS FILES
%% 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. – Also for languages with variants!  (English and German, etc.)
%% script : the name of the script (as understood by fontspec) – default is Latin
%% scripttag : the OpenType tag for the script
%% langtag : the OpenType tag for the language
%% hyphenmins : the hyphenmins for this language (comma-sep list of two integers)
%% frenchspacing : boolean
%% indentfirst : boolean
%% fontsetup : boolean
%% TODO: nouppercase : boolean (for scripts like Arabic, Devanagari, etc which have no concept of uppercase/lowercase)
%% TODO: localalph = {<alph_csname>,<Alph_csname>}
%% TODO: localnumeral = <csname>
%%       or even better localdigits = {0123456789} for fully automatic setup
\newif\if@xpg@language@really@defined@
\newcommand*\PolyglossiaSetup[2]{%
  \polyglossia@keys_define_lang:n{#1}%
  \keys_set:nn { polyglossia / #1 } { #2 }%
  \prop_log:N{\polyglossia@langsetup}
  \polyglossia_setup_hyphen:n {#1}
  %define booleans etoolbox style and set defaults
  %% TODO ? \providetoggle{#1@setup@done}%
  % we initialize these so that we can use \gappto below
  \csgdef{init@extras@#1}{}%
  \csgdef{init@noextras@#1}{}% we don't use this yet: remove?
  % here we do the fontsetup:
  \polyglossia@lang@autosetupfont:n{#1}
  %% TODO? \toggletrue{#1@setup@done}%
  % reinit \do
  \def\do##1{\setotherlanguage{##1}}%
}

% Adjust language key setting after initial setup
% This is needed, e.g., for languages with varying script
\DeclareDocumentCommand \SetLanguageKeys { m m }
{
  \clist_map_inline:nn { #1 } { \keys_set:nn { polyglossia / ##1 } { #2 } }
}


% setup hyphennames from a str list of hyphen
\cs_new:Nn \polyglossia_setup_hyphen:n {
  \exp_args:Nne \clist_set:Nn{\l_tmpa_clist}{\prop_item:Nn \polyglossia@langsetup {#1 / hyphennames}}
  \providebool{havehyphen}
  \boolfalse{havehyphen}
  % for each hyphen in the set until we find one that works
  \clist_map_inline:Nn \l_tmpa_clist {
    \ifbool{havehyphen}{}{%
       % check if language hyphenname is defined
       \polyglossia@check@ifdefined:NF{#1}{%
          % if not, first consider nohyphenation
          \str_if_eq:nnTF{##1}{nohyphenation}
            {%
               \cs_gset_eq:cc{l@#1}{l@##1}
               \global\booltrue{havehyphen}
            }{%
               % then test if hyphenation is defined
               \xpg@ifdefined{##1}{
                  % test if language hyphenation is nohyphenation
                  \cs_if_eq:cNF{l@#1}{\l@nohyphenation}{\global\booltrue{havehyphen}}{%
                      % if false define language to hyphenation if it is not equal...
                      \str_if_eq:nnF{#1}{##1}{\cs_gset_eq:cc{l@#1}{l@##1}}
                      % ...and load
                      \xpg@set@hyphenation@patterns{##1}
                      \global\booltrue{havehyphen}
                  }%
               }{}%
           }%
       }%
    }%
  }%
  % if l@#1 does not yet exist,
  % we assign it to nohyphenation
  % we do this here in case and if the hyphennames key was omitted
  \ifbool{havehyphen}{}{%
    \xpg@ifdefined{#1}{}%
    {
      \xpg@nopatterns{#1}
      \expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax
    }%
  }%
  \csdef{#1@language}{%
    \polyglossia@setup@language@patterns{#1}%
  }%
  % setup hyphenmins
  \exp_args:NNe \clist_set:Nn \l_tmpa_clist
    { \prop_item:Nn \polyglossia@langsetup {#1 / hyphenmins} }
  \cs_if_eq:cNF {l@#1} \l@nohyphenation
    {
      \use:x
        {
          \exp_not:N \setlocalhyphenmins {#1}
            { \clist_item:Nn \l_tmpa_clist {1} }
            { \clist_item:Nn \l_tmpa_clist {2} }
        }
    }
}

\newcommand*\polyglossia@setup@language@patterns[1]{%
  \ifbool{xpg@hyphenation@disabled}{%
    \xdef\xpg@lastlanguage{\the\csname l@#1\endcsname}%
  }{%
    % first, test if \l@#1 exists
    % without that, \csname l@#1\endcsname will be defined as \relax
    \cs_if_exist:cTF {l@#1}
      {
        \cs_if_eq:cNTF {l@#1} \l@nohyphenation
          {
            \language=\l@nohyphenation
          }
          {
            \xpg@set@hyphenation@patterns{#1}
          }
      }
      {%
        % Since this function is sometimes called from the gloss files
        % directly, we need to check whether the requested hyphenname exists.
        \xpg@ifdefined{#1}{}%
        {%
          \xpg@nopatterns{#1}
          \expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax%
        }%
        \xpg@set@hyphenation@patterns{#1}
      }
  }
}

\prop_new:N \polyglossia@langsetup

\cs_new_protected:Npn \polyglossia@keys_define_lang:n #1 {
  \keys_define:nn {polyglossia}{
    % the script font
    #1 / script
       .code:n = {
          \prop_gput:Nnn{\polyglossia@langsetup}{#1/script}{##1}
          \prop_gput:Nnx{\polyglossia@langsetup}{#1/lcscript}
               {\tl_if_empty:nF{##1}{\str_lowercase:n##1}}
    },
    #1 / script
       .value_required:n = true,
    #1 / script
       .initial:n = latin,
    % the opentype script tag
    #1 / scripttag
       .code:n = {\prop_gput:Nnn{\polyglossia@langsetup}{#1/scripttag}{##1}},
    #1 / scripttag
       .default:n = {},
    #1 / scripttag
      .initial:n = {},
    % the language full name
    #1 / language
       .code:n = {\prop_gput:Nnn{\polyglossia@langsetup}{#1/language}{##1}},
    #1 / language
       .value_required:n = true,
    #1 / language
        .initial:x = {\str_upper_case:n#1},
    % the language tag
    #1 / langtag
       .code:n = {\prop_gput:Nnn{\polyglossia@langsetup}{#1/langtag}{##1}},
    #1 / langtag
       .value_required:n = true,
    #1 / langtag
       .initial:n = {},
    % the BCP-47 tag
    #1 / bcp47
       .code:n = {\prop_gput:Nnn{\polyglossia@langsetup}{#1/bcp47}{##1}},
    #1 / bcp47
       .value_required:n = true,
    #1 / bcp47
       .initial:n = {},
    % hyphennames
    #1 / hyphennames
    .code:n = {
      \clist_set:Nn{\l_tmpa_clist}{##1}
      \prop_gput:Nnx{\polyglossia@langsetup}{#1/hyphennames}{\clist_use:Nn \l_tmpa_clist {,}}
    },
    #1 / hyphennames
       .value_required:n = true,
    #1 / hyphennames
      .initial:x = {\c_empty_clist},
    % direction
    #1 / direction
    .  code:n = {
           \str_case_e:nnTF{##1}{
             {LR}{}
             {RL}{\RequireBidi}
           }
           {\prop_gput:Nnn{\polyglossia@langsetup}{#1/direction}{##1}}
           {\xpg@error{Unknown~ direction~ "##1"~ for~ language~ "#1"}}
       },
    #1 / direction
      .value_required:n = true,
    #1 / direction
      .initial:n = {LR},
    % minimal left and right hyphenation minima using
    #1 / hyphenmins
    .code:n = {
      % check syntax
      \int_compare:nNnF { \clist_count:n {##1} } = {2}
        {\xpg@error{hypenmins~should~be~a~list~of~two~entries,~got~"##1"}}
      % set prop
      \prop_gput:Nnn \polyglossia@langsetup {#1/hyphenmins} {##1}
    },
    #1 / hyphenmins
      .value_required:n = true,
    #1 / hyphenmins
     .initial:n = {2,3},
    % minimal length for hyphenation (LuaTeX only)
    #1 / totalhyphenmin
    .code:n = {
      % check syntax
      \int_compare:nNnF { \clist_count:n {##1} } = {1}
        {\xpg@error{totalhyphenhypenmin~should~be~a~single~entry,~got~"##1"}}
      % set prop
      \prop_gput:Nnn \polyglossia@langsetup {#1/totalhyphenmin} {##1}
    },
    #1 / totalhyphenmin
      .value_required:n = false,
    % frenchspacing
    #1 / frenchspacing
    .code:n = {
        \str_case_e:nnTF{##1}{
            {true}{}
            {false}{}
          }
          {}
          {\xpg@error{frenchspacing~should~be~true~or~false. Is~ "##1"~ for~ language~ "#1"}}
        \prop_gput:Nnn{\polyglossia@langsetup}{#1/frenchspacing}{##1}
    },
    #1 / frenchspacing
      .default:n = true,
    #1 / frenchspacing
      .initial:n = false,
    % indent first line
    #1 / indentfirst
    .code:n = {
      \str_case_e:nnTF{##1}{
            {true}{}
            {false}{}
          }
          {}
          {\xpg@error{indentfirst~should~be~true~or~false. Is~ "##1"~ for~ language "#1"}}
      \prop_gput:Nnn{\polyglossia@langsetup}{#1/indentfirst}{##1}
    },
    #1 / indentfirst
      .default:n = true,
    #1 / indentfirst
      .initial:n = false,
    % fontsetup
    #1 / fontsetup
      .code:n = {
         \str_case_e:nnTF{##1}{
            {true}{}
            {false}{}
          }
          {}
          {\xpg@error{fontsetup~should~be~true~or~false. Is "##1"~ for~ language~ "#1"}}
       \prop_gput:Nnn{\polyglossia@langsetup}{#1/fontsetup}{##1}
       },
    #1 / fontsetup
      .default:n = true,
    #1 / fontsetup
      .initial:n = false,
    % environment name
    #1 / envname
       .code:n = {
           \prop_gput:Nnn{\polyglossia@langsetup}{#1/envname}{##1}
       },
    #1/ envname.value_required:n = true,
    #1/ envname.initial:n = {#1},
    % babel name
    #1 / babelname
       .code:n = {
           \prop_gput:Nnn{\polyglossia@langsetup}{#1/babelname}{##1}
       },
    #1/ babelname.value_required:n = true,
    #1/ babelname.initial:n = {#1},
    % default numerals
    #1 / localnumeral
         . code:n =  {
            \prop_gput:Nnn{\polyglossia@langsetup}{#1/localnumeral}{##1}
            \prop_gput:Nnn{\polyglossia@langsetup}{#1/Localnumeral}{##1}
         },
    #1 / localnumeral.value_required:n = true,
    #1 / localnumeral.initial:n = {polyglossia@C@localnumeral},
    % uppercased
    #1 / Localnumeral
         . code:n =  {
            \prop_gput:Nnn{\polyglossia@langsetup}{#1/Localnumeral}{##1}
         },
    #1 / Localnumeral.value_required:n = true,
    #1 / Localnumeral.initial:n = {polyglossia@C@localnumeral}
  }
}

% TODO move to C module
\newcommand*{\polyglossia@C@localnumeral}[2]{
   \polyglossia@Clang@@arabic{#2}
}

% print using main language
% #2 is the numeral to print
% #3 is the mainlanguage (should be expanded)
% #4 is the current language (should be expanded)
% #1 is the option list (should be expanded)
% #5 is the name of the field to use
\cs_new:Nn \polyglossia_localnumeral_mainlang:nnnnn {
  \foreignlanguage{#3}{\use:c {\prop_item:Nn \polyglossia@langsetup  {#3/#5}} {#1} {#2}}
}


% print using local language
% #2 is the numeral to print
% #3 is the mainlanguage (should be expanded)
% #4 is the current language (should be expanded)
% #1 is the option list (should be expanded)
% #5 is the name of the field to use
\cs_new:Nn \polyglossia_localnumeral_locallang:nnnnn {
  \use:c {\prop_item:Nn \polyglossia@langsetup  {#4/#5}} {#1} {#2}
}

% this function try to resolve some simple parameter about lang
% call #2 then branching if found
% call parameter #3 if not found
% (use curing)
\cs_new:Npn \polyglossia_localnumeral_callshortcutorlong:nF #1#2 {
  \str_case:nnF{#1}{
    {lang=local}{\polyglossia_localnumeral_locallang:nnnnn}
  }
  {#2}
}

\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_iii_localnumeral:w  #1 = #2 \q_stop {
  \str_case:nnF{#2}{
    {local}  {\clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn }}
    {default}{\clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn }}
    {*}      {\clist_map_break:n{\use_i:nn\polyglossia_localnumeral_mainlang:nnnnn   }}
    {main}   {\clist_map_break:n{\use_i:nn\polyglossia_localnumeral_mainlang:nnnnn   }}
  }{
    \clist_map_break:n{ \use_i_ii:nnn \polyglossia_localnumeral_langlang:nnnnnn {{#2}} }
  }
}


% call the language
% #3 is the numeral to print
% #4 is the mainlanguage (should be expanded)
% #5 is the current language (should be expanded)
% #2 is the option list (should be expanded)
% #6 is the name of the field to use
% #1 is the language used
\cs_new:Nn \polyglossia_localnumeral_langlang:nnnnnn {
   \foreignlanguage{#1}{\use:c {\prop_item:Nn \polyglossia@langsetup  {#1/#6}} {#2} {#3}}
}


% check if empty value
\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_ii_localnumeral:w  #1 #2 = #3 \q_stop {
  \quark_if_no_value:NTF {#3}
  {
    \clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnnn}
  }
  {
    \polyglossia_iii_map_csv_field_split_kv_iii_localnumeral:w #1 \q_stop
  }
}

\cs_new:Npn \polyglossia_iii_map_csv_field_split_kv_i_localnumeral:nw #1 #2 = #3 \q_stop {
  % parse only lang tag
  \tl_trim_spaces_apply:nN {#2} \str_if_eq:nnT {lang}
  {
    % if empty value
    \quark_if_nil:nTF{#3}
    {
      \clist_map_break:n{\use_i:nn \polyglossia_localnumeral_locallang:nnnn}
    }
    {
      % here we know what we have an equal sign
      \polyglossia_iii_map_csv_field_split_kv_ii_localnumeral:w {#1} #1 \q_no_value \q_stop
    }
  }
}

% map function 
\cs_new:Nn \polyglossia_iii_map_csv_localnumeral:n {
  % fast case is do nothing is empty 
  \tl_if_empty:nF{#1}
  {
    \polyglossia_iii_map_csv_field_split_kv_i_localnumeral:nw {#1} #1 = \q_nil \q_stop
  }
}


% treat option is empty and option is lang=local
% #2 number
% #3 mainlanguage
% #4 locallanguage
% #5 field to call
% #1 option
% strip space to option
\cs_new:Nn \polyglossia_iii_localnumeral:nnnnn {
  \tl_if_blank:nTF{#1}
  {
    \polyglossia_localnumeral_mainlang:nnnnn
  }
  {
    \str_if_eq:nnTF{#1}{lang=local}
    {
      \polyglossia_localnumeral_locallang:nnnnn
    }
    {
      % use postscript like trick push to stack {#1} {#2} {#3} {#4}
      \polyglossia_localnumeral_callshortcutorlong:nF {#1}
      {
        % same trick here if found we emit  \use_i:nn
        % thus discarding the default choice that is not lang specified thus local
        \clist_map_function:nN {#1} {\polyglossia_iii_map_csv_localnumeral:n}
        \polyglossia_localnumeral_locallang:nnnnn
      }
    }
    {#1} {#2} {#3} {#4} {#5}
  }
}


% internal helper useful for oeee and onnn
% #1 number
% #2 mainlanguage
% #3 locallanguage
% #4 option
% #5 field to call
% strip space to option
\cs_new:Nn \polyglossia_ii_localnumeral:nnnnn {
  \tl_trim_spaces_apply:nN {#4} \polyglossia_iii_localnumeral:nnnnn {#1}{#2}{#3}{#5}
}
\cs_generate_variant:Nn \polyglossia_ii_localnumeral:nnnnn {
  eeenn, eeeon, eeeen
}

% convert the counter to value
% #1 counter
% #2 mainlanguage
% #3 locallanguage
% #4 option
\cs_new:Nn \polyglossia_i_localnumeral:nnnnn
{
  \polyglossia_ii_localnumeral:eeeen {\int_value:w #1} {#2} {#3} {#4} {#5}
}

% print number usage \localnumeral[option]{numeral}
% or \localnumeral*[option]{counter}
% \Localnumeral[]{numeral} use main language
% \localnumeral{numeral} use local language
\NewExpandableDocumentCommand{\localnumeral}{som}
{
  \IfBooleanTF{#1}%
    {% starred: take counter
      \exp_args:Nc \polyglossia_i_localnumeral:nnnnn {c@#3}
         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {localnumeral}
    }{% unstarred: take number
      \polyglossia_ii_localnumeral:eeeen {\int_eval:n{#3}}
         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {localnumeral}
    }
}

% print number usage \Localnumeral[option]{numeral}
% or \Localnumeral*[option]{counter}
% \Localnumeral[]{numeral} use main language
% \localnumeral{numeral} use local language
\NewExpandableDocumentCommand{\Localnumeral}{som}
{
  \IfBooleanTF{#1}%
    {% starred: take counter
      \exp_args:Nc \polyglossia_i_localnumeral:nnnnn {c@#3}
         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {Localnumeral}
    }{% unstarred: take number
      \polyglossia_ii_localnumeral:eeeon {\int_eval:n{#3}}
         {\mainlanguagename} {\languagename} {\IfNoValueTF {#2}{lang=local}{#2}} {Localnumeral}
    }
}

\cs_new_nopar:Nn{\polyglossia@lang@frenchspacing:n}{
  \prop_get:NxNTF \polyglossia@langsetup {#1/frenchspacing} \l_tmpa_tl
      {
        \str_case_e:nnF{\l_tmpa_tl}{
          {true}{\frenchspacing}
          {false}{\nonfrenchspacing}
        }
        {\xpg@error{frenchspacing~should~be~true~or~false. Is~"\l_tmpa_ttl"~ for~ language~ "#1"}}
      }
      {
        \xpg@error{Could~ not~ retrieve~ key~ frenchspacing~ for~ language~ "#1"}
        \prop_show:N{\polyglossia@langsetup}
      }
}

\cs_new_nopar:Nn{\polyglossia@lang@indentfirst:n}{
  \prop_get:NxNTF \polyglossia@langsetup {#1/indentfirst} \l_tmpa_tl
      {
        \str_case_e:nnF{\l_tmpa_tl}{
          {true}{\french@indent}
          {false}{\nofrench@indent}
        }
        {\xpg@error{indentfirst~should~be~true~or~false. Is~"\l_tmpa_ttl"~ for~ language~ "#1"}}
      }
      {
        \xpg@error{Could~ not~ retrieve~ key~ indentfirst~ for~ language~ "#1"}
        \prop_show:N{\polyglossia@langsetup}
      }
}


\cs_new:Nn{\polyglossia@lang@setpardirection:n}{
  \prop_get:NxNTF \polyglossia@langsetup {#1/direction} \l_tmpa_tl
      {
        \polyglossia@setpardirection:n{\l_tmpa_tl}
      }
      {
        \xpg@error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
        \prop_show:N{\polyglossia@langsetup}
      }
}


\cs_new:Nn{\polyglossia@lang@settextdirection:nn}{
  \prop_get:NxNTF \polyglossia@langsetup {#1/direction} \l_tmpa_tl
      {
        \polyglossia@settextdirection:n{\l_tmpa_tl}{#2}
      }
      {
        \xpg@error{Could~ not~ retrieve~ key~ direction~ for~ language~ "#1"}
        \prop_show:N{\polyglossia@langsetup}
      }
}

\AtEndDocument{\prop_log:N{\polyglossia@langsetup}}
\def\xpg@lastlanguage{0}%

\providebool{xpg@hyphenation@disabled}%
\boolfalse{xpg@hyphenation@disabled}

\def\xpg@disablehyphenation{%
  \ifx\@onlypreamble\@notprerr%
     \xpg@@disablehyphenation%
  \else%
     % if this is used in the preamble, we have to postpone
     % the execution until the main language has been set (#125).
     \cs_gset_nopar:Nn \polyglossia@AtBeginDocument@hyphenation: {
        \xpg@@disablehyphenation%
     }%
  \fi%
}

\def\xpg@@disablehyphenation{%
  \ifbool{xpg@hyphenation@disabled}{}{%
    \booltrue{xpg@hyphenation@disabled}%
    \xdef\xpg@lastlanguage{\the\language}%
    % We do not call \xpg@set@hyphenation@patterns here to avoid a warning message.
    % "nohyphenation" is not listed in language.dat.lua.
    \language=\l@nohyphenation%
  }%
}

\def\xpg@enablehyphenation{%
  \ifbool{xpg@hyphenation@disabled}{%
    \boolfalse{xpg@hyphenation@disabled}%
    \language=\csname xpg@lastlanguage\endcsname%
  }{}%
}

\let\disablehyphenation\xpg@disablehyphenation
\let\enablehyphenation\xpg@enablehyphenation

%\def\xpg@fontsetup#1{\xpg@csifdef@warn{xpg@fontsetup@#1}}
%\def\xpg@fontsetup@none#1{\csgdef{#1@font}{\ifcsdef{#1font}{\csname #1font\endcsname}{}}} %<-- simplistic
%\def\xpg@fontsetup@custom#1{\csuse{#1@font}}

\cs_new:Nn \polyglossia@lang@autosetupfont:n {
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#1/fontsetup}}{true}
  {
    \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#1/lcscript}}{latin}%
         {\xpg@fontsetup@latin{#1}}
         {\xpg@fontsetup@nonlatin{#1}}
  }
  {
    \xpg@info{Skipping~ automatic~ font~ setup~ for~ language~ #1}
  }
}


% add fontfeature Language=#2 to langtag #1
% do nothing if #1 or #2 is empty
\cs_new:Nn \polyglossia@addfontfeature@language:nn {
  \bool_if:nTF{\tl_if_empty_p:n{#1} || \tl_if_empty_p:n{#2}}
  {
    % maybe an error ?
    \xpg@warning{Asking~ to~ add~ empty~ feature~to~ latin~ font~
      (Language="#2"~ to~ langtag~ "#1")}
  }
  {
    \str_if_eq:nnTF{#2}{Turkish}{
      \fontspec_if_language:nTF {TRK}%
      {
        \addfontfeature{Language=Turkish}
      }
      {
        \fontspec_if_language:nTF {TUR}%
        {
          \addfontfeature{Language=Turkish}
        }{}
      }
    }{
      \fontspec_if_language:nTF{#1}
      {
        \addfontfeature{Language=#2}
      }
      {}
    }
  }
}
\cs_generate_variant:Nn  \polyglossia@addfontfeature@language:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}

% add fontfeature Script=#2 to scripttag #1
% do nothing if #1 or #2 is empty
\cs_new:Nn \polyglossia@addfontfeature@script:nn {
  \bool_if:nTF{\tl_if_empty_p:n{#1} || \tl_if_empty_p:n{#2}}
  {
    % maybe an error ?
    \xpg@warning{Asking~ to~ add~ empty~ feature~to~ latin~ font
                 (Script="#2"~ to~ scripttag~ "#1")}
  }
  {
    \fontspec_if_script:nTF{#1}
       {\addfontfeature{Script=#2}}
       {\xpg@error{
          The~ current~ latin ~ font~ \l_fontspec_family_tl\space does~ not~ contain~ the~"#2"~ script!\MessageBreak
          Please~ define~\csname\tl_if_empty:nF{#2}{\str_lowercase:n#2}font\endcsname~
          with~ \string\newfontfamily\space command
          }
        }
  }
}
\cs_generate_variant:Nn  \polyglossia@addfontfeature@script:nn { on , no, oo , Vn, nV, VV , xn, nx, xx}

\def\xpg@fontsetup@latin#1{%
  \begingroup
  \csgdef{#1@font@rm}{%
    \cs_if_exist_use:cF{#1font}{
      \rmfamilylatin
      \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
    }
  }
  \csgdef{#1@font@sf}{%
    \cs_if_exist_use:cF{#1fontsf}{
      \sffamilylatin
      \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
    }%
  }%
  \csgdef{#1@font@tt}{%
    \cs_if_exist_use:cF{#1fonttt}{
      \ttfamilylatin
      \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
    }%
  }%
  \endgroup
}

\def\xpg@fontsetup@nonlatin#1{%
  \begingroup
  \csgdef{#1@font@rm}{%
    \cs_if_exist_use:cF{#1font}
      {
       \providetoggle{#1@use@script@font}%
       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia@langsetup}{#1/script}}{\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
        {\rmfamilylatin}%
        {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia@langsetup}{#1/lcscript} font}
          {
             \toggletrue{#1@use@script@font}%
           }
           {
             \rmfamilylatin
           }
       }
       \iftoggle{#1@use@script@font}{}{%
           \polyglossia@addfontfeature@script:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/scripttag}}
                                                 {\prop_item:Nn{\polyglossia@langsetup}{#1/script}}
       }%
       \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
      }}%
  \csgdef{#1@font@sf}{%
    \cs_if_exist_use:cF{#1fontsf}%
      {
       \providetoggle{#1@use@script@fontsf}%
       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia@langsetup}{#1/script}}{\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
        {\sffamilylatin}%
        {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia@langsetup}{#1/lcscript} fontsf}
          {
             \toggletrue{#1@use@script@fontsf}%
           }
           {
             \sffamilylatin
           }
       }
       \iftoggle{#1@use@script@fontsf}{}{%
           \polyglossia@addfontfeature@script:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/scripttag}}
                                                 {\prop_item:Nn{\polyglossia@langsetup}{#1/script}}
       }%
       \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
      }}%
  \csgdef{#1@font@tt}{%
    \cs_if_exist_use:cF{#1fonttt}%
      {
       \providetoggle{#1@use@script@fonttt}%
       \str_if_eq:nnTF{\prop_item:Nn{\polyglossia@langsetup}{#1/script}}{\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
       {\ttfamilylatin}%
       {\cs_if_exist_use:cTF{\prop_item:Nn{\polyglossia@langsetup}{#1/lcscript} fonttt}
           {
             \toggletrue{#1@use@script@fonttt}%
           }
           {
             \ttfamilylatin
           }
       }
       \iftoggle{#1@use@script@fonttt}{}{%
           \polyglossia@addfontfeature@script:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/scripttag}}
                                                 {\prop_item:Nn{\polyglossia@langsetup}{#1/script}}
       }%
       \polyglossia@addfontfeature@language:xx{\prop_item:Nn{\polyglossia@langsetup}{#1/langtag}}
                                              {\prop_item:Nn{\polyglossia@langsetup}{#1/language}}
      }}%
  \endgroup
}

%%% END OF PolyglossiaSetup

%% ensure localization of \markright and \markboth commands
%%% THIS IS NOW DISABLED BY DEFAULT
\cs_new_nopar:Nn {\polyglossia@local@marks:n} {}
\cs_new_nopar:Nn {\polyglossia@enable@local@marks:}
{
      \xpg@info{Option:~ localmarks}%
      \cs_gset_nopar:Nn \polyglossia@local@marks:n
      {%
         \def\xpg@tmp@lang{##1}%
         \DeclareRobustCommand\markboth[2]{%
            \begingroup
               \let\label\relax \let\index\relax \let\glossary\relax
               \unrestored@protected@xdef\@themark
               {%
                {\lowercase{\foreignlanguage{\xpg@tmp@lang}}{\protect\@@ensure@maindir{####1}}}%
                {\lowercase{\foreignlanguage{\xpg@tmp@lang}}{\protect\@@ensure@maindir{####2}}}%
               }%
               \@temptokena \expandafter{\@themark}%
               \mark{\the\@temptokena}%
            \endgroup
            \if@nobreak\ifvmode\nobreak\fi\fi%
         }%
         \DeclareRobustCommand\markright[1]{%
            \begingroup
               \let\label\relax \let\index\relax \let\glossary\relax
               \expandafter\@markright\@themark
               {\lowercase{\foreignlanguage{\xpg@tmp@lang}}{\protect\@@ensure@maindir{####1}}}%
               \@temptokena \expandafter{\@themark}%
               \mark{\the\@temptokena}%
            \endgroup
            \if@nobreak\ifvmode\nobreak\fi\fi%
         }%
% This part seems wrong (see #396 for explanation). Remove after a while.
%         \def\@markright####1####2####3{%
%            \@temptokena{\protect\@@ensure@maindir{####1}}%
%            \unrestored@protected@xdef\@themark{%
%               {\the\@temptokena}%
%               {\protect\@@ensure@maindir{####3}}%
%            }%
%         }%
      }%
}


% Easy way out – Arthur, 2012-08-01
\ifcsdef{newXeTeXintercharclass}{%
% to reset the intercharclass of a character to "normal"
\newXeTeXintercharclass\xpg@normalclass %TODO
}{}

\ifxetex
%% when no patterns are available, we use \l@nohyphenation, assigned to 255
%%  (suggestion by Enrico Gregorio)
  \@ifundefined{l@nohyphenation}{\chardef\l@nohyphenation=255 }{}
\else\ifluatex
  \@ifundefined{l@nohyphenation}{\chardef\l@nohyphenation=\directlua{
    tex.sprint(polyglossia.newloader_loaded_languages.nohyphenation)}\relax
  }{}
\fi\fi

%we call this macro when a gloss file is not found for a given language
\def\xpg@nogloss#1{%
   \xpg@warning{File~ gloss-#1.ldf~ does~ not~ exist!\MessageBreak
   I~ will~ nevertheless~ try~ to~ use~ hyphenation~ patterns~ for~ #1.}%
  \PolyglossiaSetup{#1}{hyphenmins,hyphennames={#1},fontsetup=true}%
  % the above amounts to:
  %\ifcsundef{l@#1}%
  %  {\expandafter\adddialect\csname l@#1\endcsname\l@nohyphenation\relax}%
  %  {\setlocalhyphenmins{#1}{2}{3}}%
  %\csdef{#1@language}{\language=\csname l@#1\endcsname}%
}

\newcommand{\xpg@input}[1]{%
  % Store catcode of @ before making at letter
  \chardef\xpg@saved@at@catcode\catcode`\@
  \makeatletter
  \input{#1}%
  % restore former @ catcode
  \catcode`\@=\xpg@saved@at@catcode%
}

% try to load a language file
\cs_new:Nn \polyglossia_load_lang_definition:nn {
  \file_if_exist:nTF{gloss-#2.ldf}
  {
    % Temporarily force catcode of ~ to 13 since babelsh.def
    % requires it. This is needed particularly with LaTeX3
    % packages which force \ExplSyntaxOn (#425)
    \protected\edef\xpg@restore@tilde@catcode{\catcode 126 = \the\catcode 126\relax}
    \catcode 126 = 13
    \xpg@input{gloss-#2.ldf}
    \setkeys{#2}{#1}
    % restore former ~ catcode
    \xpg@restore@tilde@catcode
  }
  {
    \xpg@nogloss{#2}
  }
}

% load a master language from an alias file
\newcommand*\xpg@load@master@language[1] {
   \xpg@input{gloss-#1.ldf}
   \ifcsundef{#1@loaded}%
   {
     \exp_args:Nx\polyglossia@define@language@cmd:n{#1}%
   }{}
   \polyglossia@register@language:nn{}{#1}%
   \csgdef{#1@loaded}{}%
}


% define environment and command
\cs_new:Nn \polyglossia@define@language@cmd:n {
  \ifcsundef{#1@alias@lang}{%
    \exp_args:Ne
    \newenvironment {\prop_item:Nn{\polyglossia@langsetup}{#1/envname}} [1] []
    {
      \begin{otherlanguage}[##1]{#1}
    }%
    {
      \end{otherlanguage}
    }%
    \exp_args:Nc \newcommand {text#1} [2][]
    {%
      \xpg@textlanguage[##1]{#1}{##2}%
    }%
  }{}
}

% provide way to define alias environment and command
% \setlanguagealias[<options>]{<language>}{<alias>}
\DeclareDocumentCommand \setlanguagealias {s O{} m m}
{
  % The starred version does not define commands and environments
  \IfBooleanF {#1}
    {
     \ifcsundef{#4@alias@lang}{%
       \exp_args:Ne
       \newenvironment {#4}
       {
         \begin{otherlanguage}[#2]{#3}
       }%
       {
         \end{otherlanguage}
       }%
       \exp_args:Nc \newcommand {text#4} [2][]
       {%
         \xpg@textlanguage[#2,##1]{#3}{##2}%
       }%
     }{%
       \exp_args:Ne
       \renewenvironment {#4}
       {
         \begin{otherlanguage}[#2]{#3}
       }%
       {
         \end{otherlanguage}
       }%
       \exp_args:Nc \renewcommand {text#4} [2][]
       {%
         \xpg@textlanguage[#2,##1]{#3}{##2}%
       }%
     }%
  }%
  \csgdef{#4@alias@lang}{#3}%
  \tl_if_blank:nF {#2} {\csgdef{#4@alias@opts}{#2}}%
}

\cs_new:Nn \polyglossia@register@language:nn {
   % register polyglossia language name
   \ifcsundef{#2@registered}{%
       \global\edef\xpg@loaded{%
           \ifx\xpg@loaded\@empty\else\xpg@loaded,\fi #2%
        }%
   }{}
   \csgdef{#2@registered}{}%
   \tl_if_blank:nF {#1}{%
      % Register the language options
      \polyglossia@set@lang@options:nn {#2} {#1}%
   }%
   % register babelname
   \def\xpg@tmp@babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
   \ifcsundef{\csname xpg@tmp@babelname\endcsname @bbl@registered}{%
       \global\edef\xpg@bloaded{%
           \ifx\xpg@bloaded\@empty\else\xpg@bloaded,\fi\xpg@tmp@babelname}%
   }{}%
   \csgdef{\csname xpg@tmp@babelname\endcsname @bbl@registered}{}%
   % register BCP-47 ID
   \def\xpg@tmp@bcpname{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
   \ifcsundef{\csname xpg@tmp@bcpname\endcsname @bcp@registered}{%
       \global\edef\xpg@bcp@loaded{%
           \ifx\xpg@bcp@loaded\@empty\else\xpg@bcp@loaded,\fi\xpg@tmp@bcpname}%
   }{}%
   \csgdef{\csname xpg@tmp@bcpname\endcsname @bcp@registered}{}%
}


\newcommand{\setdefaultlanguage}[2][]{%
  % latex is an internal language, so do not record
  \ifstrequal{#2}{latex}{}{%
     % register polyglossia language name
     \ifcsundef{#2@registered}{%
       \global\edef\xpg@loaded{%
           \ifx\xpg@loaded\@empty\else\xpg@loaded,\fi #2%
        }%
     }{}%
     \csgdef{#2@registered}{}%
  }%
  \ifcsundef{#2@loaded}%
  {
    \polyglossia_load_lang_definition:nn{#1}{#2}
    % define environment and command (except for internal latex language)
    \ifstrequal{#2}{latex}{}{%
      \exp_args:Nx\polyglossia@define@language@cmd:n{#2}
    }%
    \csgdef{#2@loaded}{}%
  }
  {
    \relax
  }
  \ifcsdef{#2@alias@lang}{%
     \ifcsdef{#2@alias@opts}{%
       \exp_args:Nxx \polyglossia_load_lang_definition:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
       \exp_args:Nxx \polyglossia@set@default@language:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
     }{%
       \polyglossia@set@default@language:nn {#1} {\csuse{#2@alias@lang}}%
     }%
  }{%
    \polyglossia@set@default@language:nn {#1} {#2}%
  }%
}

\cs_new:Nn \polyglossia@set@default@language:nn
{
  \gdef\xpg@main@language{#2}%
  \tl_if_blank:nTF {#1}{\gdef\mainlanguagevariant{}}{%
     % Register the language options
     \polyglossia@set@lang@options:nn {#2} {#1}%
  }%
  \csgdef{#2@gvar}{\mainlanguagevariant}%
  %% The following settings are for the default language and script
  % this tells bidi.sty or luabidi.sty that the document is RTL
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/direction}}{RL}{%
    \str_case_e:nnF{\c_sys_engine_str}{%
      {luatex}{\setRTLmain}
      {xetex}{\@RTLmaintrue\setnonlatin}
    }{}%
  }{}%
  \cs_gset_nopar:Nn \polyglossia@AtBeginDocument@selectlanguage: {
    \selectbackgroundlanguage{#2}
    \selectlanguage[#1]{#2}%
  }
  \xpg@info{Default~ language~ is~ #2}%
  \polyglossia@set@language@name[#1]{#2}%
  \def\mainlanguagename{#2}
  % Store babelname of main language (for external packages such as biblatex)
  \prop_get:NxNT \polyglossia@langsetup {#2/babelname} \l_tmpa_tl
      { \edef\mainbabelname{\l_tmpa_tl} }
  % Store babelname of current language (for external packages such as biblatex)
  \prop_get:NxNT \polyglossia@langsetup {#2/babelname} \l_tmpa_tl
      { \edef\babelname{\l_tmpa_tl}% 
        \cs_gset_eq:cc{#2@gbabelname}{babelname}%
      }
  % Store BCP-47 id of main language
  \prop_get:NxNT \polyglossia@langsetup {#2/bcp47} \l_tmpa_tl
      { \csedef{mainbcp47id}{\l_tmpa_tl} }
  % Store BCP-47 id of current language
  \prop_get:NxNT \polyglossia@langsetup {#2/bcp47} \l_tmpa_tl
      { \csedef{bcp47id}{\l_tmpa_tl}% 
        \cs_gset_eq:cc{#2@gbcp47id}{bcp47id}%
      }
  \ifluatex %
  \directlua{polyglossia.set_default_language('\luatexluaescapestring{\string#2}')}%
  \fi %
}

\let\setmainlanguage=\setdefaultlanguage

% Returns the language ID of the current language
% Currently supported: bcp-47
\DeclareDocumentCommand \languageid {m}
{
    \str_case:nnTF {#1}
      {
        {bcp-47}    { \csuse{bcp47id} }
        {bcp47}     { \csuse{bcp47id} }
      }
      {}
      {
        \xpg@error{Invalid~ \string\languageid\space argument:~ #1}
      }
}

% Returns the language ID of the main language
% Currently supported: bcp-47
\DeclareDocumentCommand \mainlanguageid {m}
{
    \str_case:nnTF {#1}
      {
        {bcp-47}    { \csuse{mainbcp47id} }
        {bcp47}     { \csuse{mainbcp47id} }
      }
      {}
      {
        \xpg@error{Invalid~ \string\mainlanguageid\space argument:~ #1}
      }
}

\def\mainbabelname{}%
\def\mainlanguagevariant{}%
% Store main language variant for external packages
\define@key{xpg@main@langvariant}{variant}{%
  \gdef\mainlanguagevariant{#1}%
}

\def\babelname{}%
\def\languagevariant{}%
% Store current language variant for external packages
\define@key{xpg@set@langvariant}{variant}{%
  \def\languagevariant{#1}%
}

\newcommand*\polyglossia@set@language@name[2][]{
  \def\languagename{#2}%
  \tl_if_blank:nTF {#1}{%
     \ifcsundef{#2@gvar}{\def\languagevariant{}}{\def\languagevariant{\csuse{#2@gvar}}}
   }{%
     % Register the language options
     \polyglossia@set@lang@options:nn {#2} {#1}%
  }%
}


\newcommand*{\resetdefaultlanguage}[2][]{%
  \ifcsdef{#2@alias@lang}{%
     \ifcsdef{#2@alias@opts}{%
       \exp_args:Nxx \polyglossia@reset@default@language:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
     }{%
       polyglossia@reset@default@language:nn {#1} {\csuse{#2@alias@lang}}%
     }%
  }{%
    polyglossia@reset@default@language:nn {#1} {#2}%
  }%
}

\cs_new:Nn \polyglossia@reset@default@language:nn
{
  \polyglossia@error@iflangnotloaded:n{#2}
  % disable globalnumbers of previously defined default language
  \csuse{no\xpg@main@language @globalnumbers}
  \csuse{noextras@\xpg@main@language}%
  % This is a hook for external packages which want to access variants
  % via babelname (such as biblatex)
  \cs_if_exist_use:c{noextras@bbl@\mainbabelname}%
  \csuse{init@noextras@\xpg@main@language}%
  \polyglossia@set@language@name[#1]{#2}%
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/direction}}{RL}{\@rlmaintrue\@rl@footnotetrue}{}%
  \selectlanguage[#1]{#2}%
  \selectbackgroundlanguage{#2}%
  % Store babelname of current language (for external packages such as biblatex)
  \tl_if_blank:nTF {#1}{%
    \ifcsundef{#2@gbabelname}{%
       \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
    }{%
       \edef\babelname{\csuse{#2@gbabelname}}%
    }%
  }{%
    \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
  }%
  % Store BCP-47 id of current language
  \tl_if_blank:nTF {#1}{%
    \ifcsundef{#2@gbcp47id}{%
       \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
    }{%
       \csedef{bcp47id}{\csuse{#2@gbcp47id}}%
    }%
  }{%
    \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
  }%
}

% This saves the normalfont for the latin script since we may change normalfont in other scripts
\let\normalfontlatin=\normalfont%

% Provide default fonts (as set with \setmainfont, \setsansfont and \setmonofont)
% for Latin scripts and as a fallback for non-Latin scripts.
\DeclareRobustCommand\xpg@defaultfont@rm{%
   \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}%
   \fontfamily\rmdefault%
   \ifdefined\UseHook\UseHook{rmfamily}\fi%
   \selectfont%
}
\DeclareRobustCommand\xpg@defaultfont@sf{%
   \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}%
   \fontfamily\sfdefault%
   \ifdefined\UseHook\UseHook{sffamily}\fi%
   \selectfont%
}
\DeclareRobustCommand\xpg@defaultfont@tt{%
   \tl_if_empty:NF{\g__fontspec_nfss_enc_tl}{\fontencoding{\g__fontspec_nfss_enc_tl}}%
   \fontfamily\ttdefault%
   \ifdefined\UseHook\UseHook{ttfamily}\fi%
   \selectfont%
}

\def\xpg@patch@fontfamilies{%
  % This robustifies the redefinitions of \<xx>family (suggestion by Enrico Gregorio)
  % e.g. to prevent expansion of the \familytype redefinition in auxiliary files
  \csgappto{rmfamily~}{\def\familytype{rm}}
  \csgappto{sffamily~}{\def\familytype{sf}}
  \csgappto{ttfamily~}{\def\familytype{tt}}
}

% These switches activate the default fonts
% Note that a simple \let\rmfamilylatin=\rmfamily
% does not work reliably (see #24)
\cs_gset_eq:cc{rmfamilylatin}{xpg@defaultfont@rm}%
\cs_gset_eq:cc{sffamilylatin}{xpg@defaultfont@sf}%
\cs_gset_eq:cc{ttfamilylatin}{xpg@defaultfont@tt}%

\def\xpg@set@familydefault{%
  % We need the \edef route here in order
  % to detect both \renewcommand and \let
  % changes.
  \edef\tempa{\familydefault}%
  \edef\tempb{\sfdefault}%
  \ifcsequal{tempa}{tempb}%
     {\def\familytype{sf}}
     {\edef\tempb{\ttdefault}%
      \ifcsequal{tempa}{tempb}%
         {\def\familytype{tt}}
         {\def\familytype{rm}}}
  \xpg@patch@fontfamilies%
  % This (re-)saves the normalfont for the latin script since we may
  % change normalfont in other scripts
  \let\normalfontlatin=\normalfont%
  % And for all cases, we also reset \<xx>familylatin
  \cs_gset_eq:cc{rmfamilylatin}{xpg@defaultfont@rm}%
  \cs_gset_eq:cc{sffamilylatin}{xpg@defaultfont@sf}%
  \cs_gset_eq:cc{ttfamilylatin}{xpg@defaultfont@tt}%
}

\def\resetfontlatin{%
  \DeclareRobustCommand\rmfamily{\xpg@defaultfont@rm}%
  \DeclareRobustCommand\sffamily{\xpg@defaultfont@sf}%
  \DeclareRobustCommand\ttfamily{\xpg@defaultfont@tt}%
  \xpg@patch@fontfamilies%
  \global\let\normalfont=\normalfontlatin%
}

\def\selectfontfamilylatin{%
  \def\tmp@tt{tt}\def\tmp@sf{sf}%
  \ifx\familytype\tmp@tt%
    \ttfamilylatin%
    \else\ifx\familytype\tmp@sf%
      \sffamilylatin%
      \else\rmfamilylatin\fi\fi}

\def\xpg@select@fontfamily#1{%
  \def\tmp@tt{tt}\def\tmp@sf{sf}%
  \ifx\familytype\tmp@tt
    \csuse@warn{#1@font@tt}%
  \else\ifx\familytype\tmp@sf
    \csuse@warn{#1@font@sf}%
      \else\csuse@warn{#1@font@rm}\fi\fi}

\def\xpg@set@normalfont#1{%
  \DeclareRobustCommand\rmfamily{\csuse{#1@font@rm}}%
  \DeclareRobustCommand\sffamily{\csuse{#1@font@sf}}%
  \DeclareRobustCommand\ttfamily{\csuse{#1@font@tt}}%
  \gdef\normalfont{\protect\xpg@select@fontfamily{#1}%
                   \fontseries{\seriesdefault}\selectfont%
                   \fontshape{\shapedefault}
                   \ifdefined\UseHook\UseHook{normalfont}\fi%
                   \selectfont}%
  \gdef\reset@font{\protect\normalfont}%
}

\let\@@fterindentfalse\@afterindentfalse
\def\french@indent{%
    \let\@afterindentfalse\@afterindenttrue
    \@afterindenttrue%
}
\def\nofrench@indent{%
    \let\@afterindentfalse\@@fterindentfalse
    \@afterindentfalse%
}

\newcommand*{\selectbackgroundlanguage}[1]{%
  \ifcsdef{#1@alias@lang}{%
     \polyglossia@select@background@language:n {\csuse{#1@alias@lang}}%
  }{%
     \polyglossia@select@background@language:n {#1}%
  }%
}

\cs_new:Nn \polyglossia@select@background@language:n
{
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#1/lcscript}}{latin}
                   {}
                   {\xpg@set@normalfont{#1}}%
  \csuse{#1@globalnumbers}%
}

\newcommand{\setotherlanguage}[2][]{%
  \ifcsundef{#2@loaded}
  {
    \polyglossia_load_lang_definition:nn{#1}{#2}
    % define environment and command
    \exp_args:Nx\polyglossia@define@language@cmd:n{#2}
    \ifcsdef{#2@alias@lang}{%
       \ifcsdef{#2@alias@opts}{%
         \exp_args:Nxx \polyglossia_load_lang_definition:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
         \exp_args:Nxx \polyglossia@set@other@language:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
       }{%
         \polyglossia@set@other@language:nn {#1} {\csuse{#2@alias@lang}}%
       }%
    }{%
      \polyglossia@set@other@language:nn {#1} {#2}%
    }%
    \csgdef{#2@loaded}{}%
  }
  {}
}

\cs_new:Nn \polyglossia@set@other@language:nn
{
  \polyglossia@register@language:nn{#1}{#2}%
  % If a variant is set, store it.
  \gdef\otherlanguagevariant{}
  \tl_if_blank:nTF {#1}{}{%
    % Register the language options
    \polyglossia@set@lang@options:nn {#2} {#1}%
  }%
  \csgdef{#2@gvar}{\otherlanguagevariant}%
  \prop_get:NxNT \polyglossia@langsetup {#2/babelname} \l_tmpa_tl
    { \xdef\otherlanguagebabelname{\l_tmpa_tl} }
  \cs_gset_eq:cc{#2@gbabelname}{otherlanguagebabelname}%
}

% Store main language variant for external packages
\define@key{xpg@other@langvariant}{variant}{%
  \gdef\otherlanguagevariant{#1}%
}

\newcommand\setotherlanguages[1]{%
  \def\do##1{\setotherlanguage{##1}}%
   \exp_args:Nx\docsvlist{#1}}%

\def\common@language{% FIXME is this really needed???
  \ifbool{xpg@hyphenation@disabled}{%
    \xdef\xpg@lastlanguage{\z@}%
  }{%
    \language=\z@
  }%
  \lefthyphenmin=\tw@
  \righthyphenmin=\thr@@}

\def\xpg@initial@setup{%
  \common@language%
}


% Alias to \text<lang>, but more suitable
% for specific (esp. tag-based) aliases
% where \text<alias> would cause clashes
% (e.g., \textit)
\newcommand\textlang[3][]{%
  \ifcsdef{#2@alias@lang}{%
     \ifcsdef{#2@alias@opts}{%
       \exp_args:Nxx \xpg@textlanguage[\csuse{#2@alias@opts},#1]{\csuse{#2@alias@lang}}{#3}%
     }{%
       \xpg@textlanguage[#1]{\csuse{#2@alias@lang}}{#3}%
     }%
  }{%
    \xpg@textlanguage[#1]{#2}{#3}%
  }%
}%

% Alias to {<lang>}, but more suitable
% for specific (esp. tag-based) aliases
% where {<alias>} would cause clashes
% (e.g., \fi)
\newenvironment{lang}[2][]{%
  \begin{otherlanguage}[#1]{#2}%
}{%
  \end{otherlanguage}
}%

\providecommand{\foreignlanguage}{}

% wrapper for foreignlanguage and otherlanguage*
\newcommand*\polyglossia@setforeignlanguage[2][]{
  \select@@language[#1]{#2}
  \polyglossia@register@language:nn{#1}{#2}%
  % Store babelname of current language (for external packages such as biblatex)
  \tl_if_blank:nTF {#1}{%
    \ifcsundef{#2@gbabelname}{%
       \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
    }{%
       \edef\babelname{\csuse{#2@gbabelname}}%
    }%
  }{%
    \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
  }%
  % Store BCP-47 id of current language
  \tl_if_blank:nTF {#1}{%
    \ifcsundef{#2@gbcp47id}{%
       \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
    }{%
       \csedef{bcp47id}{\csuse{#2@gbcp47id}}%
    }%
  }{%
    \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
  }%
}

% joint code of \foreignlanguage, otherlanguage*
% and \text<lang>
\newcommand{\xpg@otherlanguage}[2][]
{%
  \polyglossia@error@iflangnotloaded:n{#2}
  \exp_args:Nne \setkeys{#2}{#1}%
  \polyglossia@setforeignlanguage[#1]{#2}
  % Hook for external packages such as biblatex
  \polyglossia@language@switched%
  % buggy restoration heure
  \csuse{inlineextras@#2}%
  % This is a hook for external packages which want to access variants
  % via babelname (such as biblatex)
  \cs_if_exist_use:c{inlineextras@bbl@\babelname}%
}

\renewcommand{\foreignlanguage}[3][]
{%
  \ifcsdef{#2@alias@lang}{%
     \ifcsdef{#2@alias@opts}{%
       \exp_args:Nxx \polyglossia@foreignlanguage:nnn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}} {#3}%
     }{%
       \polyglossia@foreignlanguage:nnn {#1} {\csuse{#2@alias@lang}} {#3}%
     }%
  }{%
    \polyglossia@foreignlanguage:nnn {#1} {#2} {#3}%
  }%
}

\cs_new:Nn \polyglossia@foreignlanguage:nnn
{
   \polyglossia@error@iflangnotloaded:n{#2}
   \bgroup
   \xpg@otherlanguage[#1]{#2}%
   \polyglossia@lang@settextdirection:nn{#2}{#3}%
   \egroup
}

% otherlanguage* is the environment equivalent of \foreignlanguage
\expandafter\providecommand\csname otherlanguage*\endcsname{}

\renewenvironment{otherlanguage*}[2][]
{%
  \ifcsdef{#2@alias@lang}{%
     \ifcsdef{#2@alias@opts}{%
       \exp_args:Nxx \polyglossia@otherlanguage:nn {\csuse{#2@alias@opts},#1} {\csuse{#2@alias@lang}}%
     }{%
       \polyglossia@otherlanguage:nn {#1} {\csuse{#2@alias@lang}}%
     }%
  }{%
    \polyglossia@otherlanguage:nn {#1} {#2}%
  }%
}
{\egroup}

\cs_new:Nn \polyglossia@otherlanguage:nn
{
  \xpg@otherlanguage[#1]{#2}%
  \polyglossia@lang@settextdirection:nn{#2}\bgroup%
}

% use by \text<lang> and \textlang. Equivalent to \foreignlanguage,
% except that dates are localized.
\newcommand\xpg@textlanguage[3][]{%
  \polyglossia@error@iflangnotloaded:n{#2}
   \bgroup
   \xpg@otherlanguage[#1]{#2}%
   \csuse{date#2}%
   % This is a hook for external packages which want to access variants
   % via babelname (such as biblatex)
   \cs_if_exist_use:c{date@bbl@\babelname}%
   \polyglossia@lang@settextdirection:nn{#2}{#3}%
   \egroup
  % Reset the language's/script's font families
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/lcscript}}{latin}{}{\resetfontlatin}%
}


% Define language-specific hyphenation exceptions
\newcommand\pghyphenation[3][]{
  \bgroup
  \polyglossia@error@iflangnotloaded:n{#2}
  \setkeys{#2}{#1}%
  \select@@language[#1]{#2}%
  \hyphenation{#3}%
  \egroup
}


% Hook that other package authors can use
% (for instance biblatex):
\newcommand*{\xpg@hook@setlanguage}{}

\def\xpg@pop@language@i#1#2{%
  \xpg@set@language@aux[#1]{#2}%
  \xpg@hook@setlanguage
  \let\emp@langname\@undefined}

\DeclareDocumentCommand \selectlanguage {s O{} m}
{%
  \ifcsdef{#3@alias@lang}{%
     \ifcsdef{#3@alias@opts}{%
       \exp_args:Nxx \polyglossia@select@language:nnn {#1} {\csuse{#3@alias@opts},#2} {\csuse{#3@alias@lang}}%
     }{%
       \polyglossia@select@language:nnn {#1} {#2} {\csuse{#3@alias@lang}}%
     }%
  }{%
     \polyglossia@error@iflangnotloaded:n{#3}%
     \polyglossia@select@language:nnn {#1} {#2} {#3}%
  }
}

\cs_new:Nn \polyglossia@select@language:nnn
{
  \IfBooleanF {#1}
    {
      \cs_set_nopar:Npx \xpg@pop@language { \exp_not:N \xpg@pop@language@i {#2} {#3} }
      \group_insert_after:N \xpg@pop@language
    }
  \tl_if_blank:nTF {#2}{}{%
    % Register the language options
    \polyglossia@set@lang@options:nn {#3} {#2}%
   }%
   % The starred variant does not write to the aux
   \IfBooleanTF#1{%
     \xpg@set@language@nonaux[#2]{#3}%
   }{%
     \xpg@set@language@aux[#2]{#3}%
   }%
   \ifluatex%
     \directlua{polyglossia.select_language('\luatexluaescapestring{\string#3}',
                     \the\csname l@#3\endcsname)}%
   \fi%
  \polyglossia@register@language:nn{#2}{#3}%
}


\cs_new:Nn \polyglossia@set@lang@options:nn
{  
    % If the optional argument sets a value for the key “variant”, copy it to xpg@langvariant
    \clist_map_inline:nn { #2 } {%
        \xpg@parsevariantkeyvalue##1=@xpg@langvariant:#1\relax
    }%
    \exp_args:Nne \setkeys{#1}{#2}%
}

% Initialize default language options, so that
% \iflanguageoption has the info it needs also
% for default settings
\newcommand*\xpg@initialize@gloss@options[2]{%
   \polyglossia@set@lang@options:nn {#1} {#2}%
}

% Record synonymous keyvals such as variant=us and variant=american
% Syntax: \xpg@set@alias@values{<lang>}{<key>}{<val>}{<alias vals, comma-separated>}
\newcommand*\xpg@set@alias@values[4]{%
   \prop_if_exist:cF { xpg@alias@keyvals@#1@#3 }
      { \prop_new:c {xpg@alias@keyvals@#1@#3} }
   \prop_put:cnn { xpg@alias@keyvals@#1@#3 }
      {#2}{#4}
   \prop_put:cnn { xpg@alias@keyvals@#1@#4 }
      {#2}{#3}
}

% Patch xkeyval to record default values of keys
\pretocmd{\XKV@define@default}{%
   \csgdef{xpg@default@opt@\XKV@header #1}{#2}%
}{}{\xpg@warning{Patching xkeyval failed!}}

% Helper to get and register option keyvals
\def\xpg@parsevariantkeyvalue#1=#2@#3:#4\relax{%
   \def\@tmpa{#1}
   \def\@tmpb{variant}
   % variant values are stored in specific macros
   % (\xpg@main@langvariant, \xpg@other@langvariant
   % and \xpg@set@langvariant)
   \ifx\@tmpa\@tmpb\setkeys{#3}{#1=#2}\fi
   \tl_if_empty:nTF{#2}
      {
        \ifcsdef{xpg@default@opt@KV@#4@#1}%
           {\xpg@store@opt@keyval#1:\csuse{xpg@default@opt@KV@#4@#1}=:#4\relax}%
           {}%
      }
      { \xpg@store@opt@keyval#1:#2:#4\relax }
}%

% Store option keys and values
% This strips trailing '=' from values.
\def\xpg@store@opt@keyval#1:#2=:#3\relax{%
   \prop_if_exist:cF { xpg@current@options@#3 }
      { \prop_new:c {xpg@current@options@#3} }
   \prop_put:cnn { xpg@current@options@#3 }
      {#1}{#2}
}


\prg_set_conditional:Npnn \polyglossia@check@option@value:NNN #1#2#3 { p , T , F , TF }
{
  \prop_get:cnNTF {xpg@current@options@#1} {#2} \l_tmpa_tl
     {
        \exp_args:Nee \str_if_eq:NNTF{\l_tmpa_tl}{#3}
          {\prg_return_true:}
          {
            \prop_get:cnNTF {xpg@alias@keyvals@#1@#3} {#2} \l_tmpb_tl
               {
                \exp_args:Nne \clist_set:Nn{\l_tmpa_clist}{\l_tmpb_tl}
                \providetoggle{xpgvalfound}
                \togglefalse{xpgvalfound}
                \clist_map_inline:Nn \l_tmpa_clist {
                   \exp_args:Nee \str_if_eq:NNT{##1}{\l_tmpa_tl}
                      { \toggletrue{xpgvalfound} }
                }
                \iftoggle{xpgvalfound}{\prg_return_true:}{\prg_return_false:}
              }
              {
                \prg_return_false:
              }
         }
     }
     {
       \prg_return_false:
     }
}

% Test if option value is set
\newcommand*\iflanguageoption[5]{%
  \polyglossia@check@option@value:NNNTF{#1}{#2}{#3}{#4}{#5}%
}


% Append any variant to csv list of variants
\define@key{xpg@langvariant}{variant}{%
  \edef\xpg@vloaded{#1\ifx\xpg@vloaded\@empty\else,\xpg@vloaded\fi}%
}

\prg_set_conditional:Npnn \polyglossia@check@if@lang@loaded:N #1 { p , T , F , TF }{
  \cs_if_exist:cTF{#1}{
     \prg_return_true:
  }{
    \prg_return_false:
  }
}

% Test if language is loaded
\newcommand*\iflanguageloaded[3]{%
  \polyglossia@check@if@lang@loaded:NTF{#1@loaded}{#2}{#3}%
}

% Same for babellanguage is loaded
\newcommand*\ifbabellanguageloaded[3]{%
  \polyglossia@check@if@lang@loaded:NTF{#1@bbl@loaded}{#2}{#3}%
}

% Same for languageid
\DeclareDocumentCommand \iflanguageidloaded {mmmm}
{
    \str_case:nnTF {#1}
      {
        {bcp-47}    { \polyglossia@check@if@lang@loaded:NTF{#2@bcp@loaded}{#3}{#4} }
        {bcp47}     { \polyglossia@check@if@lang@loaded:NTF{#2@bcp@loaded}{#3}{#4} }
      }
      {}
      {
        \xpg@error{Invalid~ \string\iflanguageidloaded\space argument:~ #1}
      }
}

% Check if the current font has a given glyph
\prg_set_conditional:Npnn \polyglossia@check@if@char@available:N #1 { p , T , F , TF }
{
  \str_case_e:nnF{\c_sys_engine_str}{
    {luatex}{
             \int_compare:nNnTF { \directlua{polyglossia.check_char(0x#1)} } > { 0 }
                {\prg_return_true:}
                {\prg_return_false:}
            }
    {xetex}{
             \int_compare:nNnTF { \the\XeTeXcharglyph"#1 } > { 0 }
                {\prg_return_true:}
                {\prg_return_false:}
           }
  }
  {
    \xpg@warning{You’re running a TeX engine that is not LuaTeX or XeTeX.\MessageBreak
                 That is almost guaranteed to cause problems.}
  }
}

% Test if a char (by char code) is available in the current font
\newcommand*\xpg@if@char@available[3]{%
  \polyglossia@check@if@char@available:NTF{#1}{#2}{#3}%
}

\newcommand*\charifavailable[2]{%
   \xpg@if@char@available{#1}{\char"#1}{#2}%
}


\newcommand*{\xpg@set@language@nonaux}[2][]{%
   \@select@language[#1]{#2}%
}


\newcommand*{\xpg@set@language@aux}[2][]{%
   % Store babelname of current language (for external packages such as biblatex)
   \tl_if_blank:nTF {#1}{%
     \ifcsundef{#2@gbabelname}{%
        \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
     }{%
        \edef\babelname{\csuse{#2@gbabelname}}%
     }%
   }{%
     \edef\babelname{\prop_item:Nn{\polyglossia@langsetup}{#2/babelname}}%
   }%
   % Store BCP-47 id of current language
   \tl_if_blank:nTF {#1}{%
     \ifcsundef{#2@gbcp47id}{%
        \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
     }{%
        \csedef{bcp47id}{\csuse{#2@gbcp47id}}%
     }%
   }{%
     \csedef{bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
   }%
   \@select@language[#1]{#2}%
    % Write to the aux
   \if@filesw%
      \ifx#1\\\\%
          \protected@write\@auxout{}{\protect\selectlanguage*{#2}}%
          \addtocontents{toc}{\protect\selectlanguage*{#2}}%
          \addtocontents{lof}{\protect\selectlanguage*{#2}}%
          \addtocontents{lot}{\protect\selectlanguage*{#2}}%
       \else
          \protected@write\@auxout{}{\protect\selectlanguage*[#1]{#2}}%
          \addtocontents{toc}{\protect\selectlanguage*[#1]{#2}}%
          \addtocontents{lof}{\protect\selectlanguage*[#1]{#2}}%
          \addtocontents{lot}{\protect\selectlanguage*[#1]{#2}}%
       \fi
   \fi
}

% The bidi package swaps the output stream within RTL tables
% (to get the column order right). This also swaps group
% delimiters inserted to the aux files via otherlanguage (see #354).
% We therefore patch bidi and insert a bool that tells us
% whether we are in such a table.
\newbool{xpg@inbiditable}
\AtBeginDocument{%
  \@ifpackageloaded{bidi}{%
     \patchcmd{\@tabular}%
               {\if@RTLtab}%
               {\if@RTLtab\booltrue{xpg@inbiditable}}%
               {}% success
               {\xpg@warning{Patching bidi table failed!}}%
  }{}%
}

% Open a group in the aux file. This is to keep
% nested language options local (see #320).
% In bidi tables, the opening/closing needs to be swapped (see #354)
\newcommand*{\xpg@set@group@aux}{%
   \if@filesw%
      \ifbool{xpg@inbiditable}{%
        \protected@write\@auxout{}{\egroup}%
        \addtocontents{toc}{\egroup}%
        \addtocontents{lof}{\egroup}%
        \addtocontents{lot}{\egroup}%
      }{%
        \protected@write\@auxout{}{\bgroup}%
        \addtocontents{toc}{\bgroup}%
        \addtocontents{lof}{\bgroup}%
        \addtocontents{lot}{\bgroup}%
      }%
    \fi
}

% Close the group in the aux file.
% In bidi RTL tables, the opening/closing needs
% to be swapped (see #354).
\newcommand*{\xpg@unset@group@aux}{%
   \if@filesw%
      \ifbool{xpg@inbiditable}{%
        \protected@write\@auxout{}{\bgroup}%
        \addtocontents{toc}{\bgroup}%
        \addtocontents{lof}{\bgroup}%
        \addtocontents{lot}{\bgroup}%
      }{%
        \protected@write\@auxout{}{\egroup}%
        \addtocontents{toc}{\egroup}%
        \addtocontents{lof}{\egroup}%
        \addtocontents{lot}{\egroup}%
      }%
    \fi
}

\prg_set_conditional:Npnn \polyglossia@check@ifdefined:N #1 { p , T , F , TF }{
  \cs_if_exist:cTF {l@#1}
    {
      \cs_if_eq:cNTF {l@#1} \l@nohyphenation
        {
          \prg_return_false:
        }
        {
          % it's possible that sometimes \csname l@#1\endcsname becomes \relax
          \cs_if_eq:cNTF {l@#1} \relax
            { \prg_return_false: }
            { \prg_return_true: }
        }
    }
    {
      \prg_return_false:
    }
}

\def\polyglossia@luatex@load@lang#1{%
  % if \l@#1 is not properly defined, call lua function newloader(#1),
  % and assign the returned number to \l@#1
  \polyglossia@check@ifdefined:NF {#1}
    {
      \expandafter\chardef\csname l@#1\endcsname=
        \directlua{ tex.sprint(polyglossia.newloader'#1') }\relax
    }
}

% This check is also used by biblatex, so don't
% rename silently.
\newcommand\xpg@ifdefined[3]{%
    % With luatex, we first need to define \l@#1.
    \ifluatex
      \polyglossia@luatex@load@lang{#1}%
    \fi
    \polyglossia@check@ifdefined:NTF{#1}{#2}{#3}%
}%

% Set \bbl@hyphendata@\the\language, which is (lua)babel's
% hyphenation pattern hook
% FIXME Clarifiy why/when this is needed.
\newcommand*\xpg@set@bbl@hyphendata[1]{%
    \ifluatex%
        \ifcsdef{bbl@hyphendata@#1}{}{%
            \global\@namedef{bbl@hyphendata@\the\language}{}%
        }%
    \fi% 
}

% Set hyphenation patterns for a given language. This does the right
% thing both for XeTeX and LuaTeX
\newcommand*\xpg@set@hyphenation@patterns[1]{%
  \ifluatex
    \polyglossia@luatex@load@lang{#1}%
    \language=\csname l@#1\endcsname
  \else
    \ifxetex
      \language=\csname l@#1\endcsname
    \else
      \xpg@warning{You’re~running~a~TeX~engine~that~is~not~LuaTeX~or~XeTeX.\MessageBreak
        That~is~almost~guaranteed~to~cause~problems.}%
    \fi
  \fi
}


\newcommand*\@select@language[2][]{
   % hook for compatibility with biblatex
   \select@language{#2}
   \xpg@set@bbl@hyphendata{\the\language}
   \xpg@initial@setup%
   \select@@language[#1]{#2}%
   % Hook for external packages such as biblatex
   \polyglossia@language@switched%
   \polyglossia@lang@setpardirection:n{#2}%
   \csuse{captions#2}%
   \csuse{date#2}%
   % These are hooks for external packages which want to access variants
   % via babelname (such as biblatex)
   \cs_if_exist_use:c{captions@bbl@\babelname}%
   \cs_if_exist_use:c{date@bbl@\babelname}%
   \polyglossia@local@marks:n{#2}%
   \csuse{init@extras@#2}%
   \polyglossia@lang@indentfirst:n{#2}%
   \csuse{blockextras@#2}%
   % This is a hook for external packages which want to access variants
   % via babelname (such as biblatex)
   \cs_if_exist_use:c{blockextras@bbl@\babelname}%
 }

% hook for compatibility with biblatex
% (probably no longer used due to the
%  more general hook that follows, but
%  we keep it for backwards comp.)
\def\select@language#1{}

% Hook for external packages such as biblatex
\def\polyglossia@language@switched{}

\def\noextrascurrent#1{%
   \csuse{noextras@#1}%
   % This is a hook for external packages which want to access variants
   % via babelname (such as biblatex)
   \cs_if_exist_use:c{noextras@bbl@\babelname}
}

% Common code for `\select@language' and `\foreignlanguage'.
\newcommand{\select@@language}[2][]{%
  % disable the extras and number settings of the previous language
  \ifcsundef{languagename}{}{%
     \noextrascurrent{\languagename}%
     \csuse{no\languagename @numbers}%
     \ifxetex
        \str_if_eq:eeTF{\exp_args:Nne\prop_item:Nn{\polyglossia@langsetup}{\languagename/direction}}{RL}%
            {%
               \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/direction}}{RL}%
                  {}% RTL -> RTL
                  {\setlatin}% RTL -> LTR
            }{%
               \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/direction}}{RL}%
                  {\setnonlatin}% LTR -> RTL
                  {}% LTR -> LTR
           }%
     \fi
  }%
  \polyglossia@set@language@name[#1]{#2}%
  % Set the language's/script's font families
  \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#2/lcscript}}{latin}{\resetfontlatin}{\xpg@set@normalfont{#2}}%
  \xpg@select@fontfamily{#2}%
  \csuse@warn{#2@language}%
  \csuse{#2@numbers}%
  \use@localhyphenmins[#1]{#2}%
  \polyglossia@lang@frenchspacing:n{#2}
}


\let\xpg@pop@language\relax

\provideenvironment{otherlanguage}{}{}

\newbool{xpg@noset@groups}
\renewenvironment{otherlanguage}[2][]
{%
  % We usually embrace the switch in groups to keep the changes local.
  % We cannot do this if an LTR environmet starts in an RTL paragraph,
  % as bidi interferes here badly with its directionality smartness.
  \ifxetex
    \str_if_eq:eeT{\exp_args:Nne\prop_item:Nn{\polyglossia@langsetup}{\languagename/direction}}{RL}%
       {%
        \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#1/direction}}{RL}%
           {}% RTL -> RTL
           {\ifvmode\else\booltrue{xpg@noset@groups}\fi}% RTL -> LTR
       }%
  \fi%
  \ifbool{xpg@noset@groups}{}{\xpg@set@group@aux}%
  \selectlanguage[#1]{#2}%
}
{\ifbool{xpg@noset@groups}{}{\xpg@unset@group@aux}}

\newcommand{\setlocalhyphenmins}[3]{%
   \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
   }{%
     \xpg@warning{\string\setlocalhyphenmin\space~ useless~ for~ unknown~ language~ #1}%
   }%
}%

% \setlanghyphenmins[options]{lang}{l}{r}
\newcommand*\setlanghyphenmins[4][]{%
  % Check for real language name and options
  \edef\xpg@tmp@lang{#2}%
  \edef\xpg@tmp@opts{#1}%
  \ifcsdef{#2@alias@lang}{%
     \edef\xpg@tmp@lang{\csuse{#2@alias@lang}}%
     \ifcsdef{#2@alias@opts}{%
       \edef\xpg@tmp@opts{\csuse{#2@alias@opts},#1}%
     }{}%
  }{}%
  \bgroup
  \polyglossia@error@iflangnotloaded:n{\xpg@tmp@lang}
  \exp_args:Nne \setkeys{\xpg@tmp@lang}{\xpg@tmp@opts}%
  % Store BCP-47 id of language
  \tl_if_blank:nTF {\xpg@tmp@opts}{%
    \ifcsundef{\csname xpg@tmp@lang\endcsname @gbcp47id}{%
       \csedef{tmp@bcp47id}{\exp_args:Nne\prop_item:Nn{\polyglossia@langsetup}{\xpg@tmp@lang /bcp47}}%
    }{%
       \csedef{tmp@bcp47id}{\csuse{#2@gbcp47id}}%
    }%
  }{%
    \csedef{tmp@bcp47id}{\exp_args:Nne \prop_item:Nn{\polyglossia@langsetup}{\xpg@tmp@lang /bcp47}}%
  }%
  \xpg@warning{id: \csuse{tmp@bcp47id}}%
  \csgdef{\csname tmp@bcp47id\endcsname @hyphenmins}{{#3}{#4}}%
  \egroup
}

% \use@localhypenmins[options]{lang}
\newcommand*\use@localhyphenmins[2][]{%
  \bgroup
  \polyglossia@error@iflangnotloaded:n{#2}
  \setkeys{#2}{#1}%
  % Store BCP-47 id of language
  \tl_if_blank:nTF {#1}{%
    \ifcsundef{#2@gbcp47id}{%
       \csxdef{tmp@bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
    }{%
       \csxdef{tmp@bcp47id}{\csuse{#2@gbcp47id}}%
    }%
  }{%
    \csxdef{tmp@bcp47id}{\prop_item:Nn{\polyglossia@langsetup}{#2/bcp47}}%
  }%
  \egroup
  \ifcsundef{\csname tmp@bcp47id\endcsname @hyphenmins}{%
     \ifcsundef{#2hyphenmins}{}%
        {%
          \expandafter\expandafter\expandafter\set@hyphenmins\csname #2hyphenmins\endcsname\relax%
        }
   }{%
      \edef\tmpa{\csuse{\csname tmp@bcp47id\endcsname @hyphenmins}}%
      \expandafter\expandafter\expandafter\set@hyphenmins\tmpa\relax%
   }
   \ifluatex
     % Set \totalhyphenmin if specified
     \prop_get:NxNTF \polyglossia@langsetup {#2/totalhyphenmin} \l_tmpa_tl
     {
        \xpg@warning{totalhyphenmin: '\l_tmpa_tl'}
        \expandafter\hyphenationmin \l_tmpa_tl%
     }%
     {}%
   \fi
}

% Babel previously compiled in hyphenrules into the kernel (via hyphen.cfg)
% but this is no longer the case. In any case, we roll our own one now
% and possibly overwrite babel's.
\provideenvironment{hyphenrules}{}{}

% As opposed to the one inherited from switch.def/babel, our environment
% supports language options and aliases.
\renewenvironment{hyphenrules}[2][]
{%
  % We usually embrace the switch in groups to keep the changes local.
  % We cannot do this if an LTR environmet starts in an RTL paragraph,
  % as bidi interferes here badly with its directionality smartness.
  \ifxetex
    \str_if_eq:eeT{\exp_args:Nne\prop_item:Nn{\polyglossia@langsetup}{\languagename/direction}}{RL}%
       {%
        \str_if_eq:eeTF{\prop_item:Nn{\polyglossia@langsetup}{#1/direction}}{RL}%
           {}% RTL -> RTL
           {\ifvmode\else\booltrue{xpg@noset@groups}\fi}% RTL -> LTR
       }%
  \fi%
  \ifbool{xpg@noset@groups}{}{\xpg@set@group@aux}%
  % Check for real language name and options
  \edef\xpg@tmp@lang{#2}%
  \edef\xpg@tmp@opts{#1}%
  \ifcsdef{#2@alias@lang}{%
     \edef\xpg@tmp@lang{\csuse{#2@alias@lang}}%
     \ifcsdef{#2@alias@opts}{%
       \edef\xpg@tmp@opts{\csuse{#2@alias@opts},#1}%
     }{}%
  }{}%
  \tl_if_blank:nF {\xpg@tmp@opts}{%
     % Register the language options
     \polyglossia@set@lang@options:nn {\xpg@tmp@lang} {\xpg@tmp@opts}%
  }%
  % Now switch patterns
  \csuse@warn{\csuse{xpg@tmp@lang}@language}%
  % And activate hyphenmins
  \use@localhyphenmins[\xpg@tmp@opts]{\xpg@tmp@lang}%
}
{\ifbool{xpg@noset@groups}{}{\xpg@unset@group@aux}}

\AtEndPreamble{%
   \@ifpackageloaded{bidi}{%
      \providecommand*{\aemph}[1]{$\overline{\hboxR{#1}}$}%
   }{}%
   \@ifpackageloaded{luabidi}{%
      \providecommand*{\aemph}[1]{$\overline{\hbox{\RL{#1}}}$}%
   }{}%
}


% keys for main package
\keys_define:nn { polyglossia } {
  verbose
     .bool_set:N = \l_polyglossia_verbose_bool,
  verbose
     .default:n = true,
  % compatibility
  quiet
     .meta:n =  { verbose = false },

  localmarks
     .bool_set:N = \l_polyglossia_localmarks_bool,
  localmarks
     .default:n = true,
  % compatibility
  nolocalmarks
     .meta:n = { localmarks = false },
   
  babelshorthands
     .bool_set:N = \l_polyglossia_babelshorthands_bool,
  babelshorthands
     .default:n = true,

  luatexrenderer
     .cs_set:Np = \l_polyglossia_luatex_renderer,
  luatexrenderer
     .value_required:n = true,
}

\keys_set:nn { polyglossia } {
  localmarks = false,
  verbose = true,
  babelshorthands = false,
  luatexrenderer = Harfbuzz
}

% load by default latex
\setmainlanguage{latex}
% then process key in order to overwrite
\ProcessKeysOptions{polyglossia}

% Set the LuaTeX renderer. As opposed to fontspec, we use Harfbuzz by default.
% This can be changed via the luatexrenderer package option.
\ifluatex
  \exp_args:Nee \str_if_eq:nnF{\l_polyglossia_luatex_renderer}{none}
     {
         \xpg@info{Setting~ LuaTeX~ font~ renderer~ to~ \l_polyglossia_luatex_renderer}
         \exp_args:Nee \defaultfontfeatures{Renderer=\l_polyglossia_luatex_renderer}
     }
\fi

\bool_if:nTF \l_polyglossia_verbose_bool {} {
   \gdef\@latex@info#1{\relax}% no latex info
   \gdef\@font@info#1{\relax}% no latex font info
   \gdef\@font@warning#1{\relax}% no latex font warnings
   \gdef\zf@PackageInfo#1{\relax}% no fontspec info
   \gdef\xpg@info#1{\relax}% no polyglossia info
}

\bool_if:nTF \l_polyglossia_localmarks_bool {
  \polyglossia@enable@local@marks:
}{}

% compatibility
\newif\ifsystem@babelshorthands
\bool_if:nTF \l_polyglossia_babelshorthands_bool {
  \system@babelshorthandstrue
}{
  \system@babelshorthandsfalse
}

%
% FIXME these should also be loaded \AtEndOfPackage !!!
\def\xpg@option#1#2{%
  \ifcsundef{xpg@main@language}{\setdefaultlanguage}{\setotherlanguage}%
    [#1]{#2}}
\ExplSyntaxOff

%    \end{macrocode}
% \iffalse
%</polyglossia.sty>
%<*farsical.sty>
% \fi
% \clearpage
% 
% \subsection{farsical.sty}
%    \begin{macrocode}
\ProvidesPackage{farsical}
        [2019/12/12 v0.2 %
         Farsi (jalali) calendar]
\ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi
\RequirePackage{calc,arabicnumbers}

%TODO - rewrite completely using calc 
%%    - use Reingold & Dershowitz ME
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Modified from Arabiftoday.sty which is part of the Arabi package:
%%%  Copyright (C) 2006 Youssef Jabri
%%% itself a modification of the code in the FarsiTeX system:
%%%  Copyright (C) 1996 Hassan Abolhassani
%%%  Copyright (C) 1996-2001 Roozbeh Pournader <roozbeh@sharif.edu>
%%%  Copyright (C) 2000-2001 Behdad Esfahbod <behdad@bamdad.org>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifJALALI@leap \newif\ifJALALI@kabiseh
\newcount\JALALI@i  \newcount\JALALI@y  \newcount\JALALI@m  \newcount\JALALI@d
\newcount\JALALI@latini    \newcount\JALALI@farsii
\newcount\JALALI@latinii   \newcount\JALALI@farsiii
\newcount\JALALI@latiniii  \newcount\JALALI@farsiiii
\newcount\JALALI@latiniv   \newcount\JALALI@farsiiv
\newcount\JALALI@latinv    \newcount\JALALI@farsiv
\newcount\JALALI@latinvi   \newcount\JALALI@farsivi
\newcount\JALALI@latinvii  \newcount\JALALI@farsivii
\newcount\JALALI@latinviii \newcount\JALALI@farsiviii
\newcount\JALALI@latinix   \newcount\JALALI@farsiix
\newcount\JALALI@latinx    \newcount\JALALI@farsix
\newcount\JALALI@latinxi   \newcount\JALALI@farsixi
\newcount\JALALI@latinxii  \newcount\JALALI@farsixii
                           \newcount\JALALI@farsixiii

\newcount\JALALI@temp
\newcount\JALALI@temptwo
\newcount\JALALI@tempthree
\newcount\JALALI@yModHundred
\newcount\JALALI@thirtytwo
\newcount\JALALI@dn
\newcount\JALALI@sn
\newcount\JALALI@mminusone

% \ftoday renamed to \Jalalitoday - FC
\def\Jalalitoday{%
\JALALI@y=\year \JALALI@m=\month \JALALI@d=\day
%
\JALALI@temp=\JALALI@y
\divide\JALALI@temp by 100\relax
\multiply\JALALI@temp by 100\relax
\JALALI@yModHundred=\JALALI@y
\advance\JALALI@yModHundred by -\JALALI@temp\relax
%
\ifodd\JALALI@yModHundred
   \JALALI@leapfalse
\else
   \JALALI@temp=\JALALI@yModHundred
   \divide\JALALI@temp by 2\relax
   \ifodd\JALALI@temp\JALALI@leapfalse
   \else
      \ifnum\JALALI@yModHundred=0%
         \JALALI@temp=\JALALI@y
         \divide\JALALI@temp by 400\relax
         \multiply\JALALI@temp by 400\relax
         \ifnum\JALALI@y=\JALALI@temp\JALALI@leaptrue\else\JALALI@leapfalse\fi
      \else\JALALI@leaptrue
      \fi
   \fi
\fi
%
\JALALI@latini=31\relax
\ifJALALI@leap
  \JALALI@latinii = 29\relax
\else
  \JALALI@latinii = 28\relax
\fi
\JALALI@latiniii = 31\relax
\JALALI@latiniv  = 30\relax
\JALALI@latinv = 31\relax
\JALALI@latinvi = 30\relax
\JALALI@latinvii = 31\relax
\JALALI@latinviii = 31\relax
\JALALI@latinix = 30\relax
\JALALI@latinx = 31\relax
\JALALI@latinxi = 30\relax
\JALALI@latinxii = 31\relax
%
\JALALI@thirtytwo=32\relax
%
\JALALI@temp=\JALALI@y
\advance\JALALI@temp by -17\relax
\JALALI@temptwo=\JALALI@temp
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 33\relax
\advance\JALALI@temp by -\JALALI@temptwo
\ifnum\JALALI@temp=\JALALI@thirtytwo\JALALI@kabisehfalse
\else
   \JALALI@temptwo=\JALALI@temp
   \divide\JALALI@temptwo by 4\relax
   \multiply\JALALI@temptwo by 4\relax
   \advance\JALALI@temp by -\JALALI@temptwo
   \ifnum\JALALI@temp=\z@\JALALI@kabisehtrue\else\JALALI@kabisehfalse\fi
\fi
%
% --BE
% In fact farsii is equal to the Leap years from a fixed year to the last
% year minus the Kabise years from a fixed year to the last year plus a const.
%
\JALALI@tempthree=\JALALI@y                 % Number of Leap years
\advance\JALALI@tempthree by -1
\JALALI@temp=\JALALI@tempthree              % T := (MY-1) div 4
\divide\JALALI@temp by 4\relax
\JALALI@temptwo=\JALALI@tempthree           % T := T - ((MY-1) div 100)
\divide\JALALI@temptwo by 100\relax
\advance\JALALI@temp by -\JALALI@temptwo
\JALALI@temptwo=\JALALI@tempthree           % T := T + ((MY-1) div 400)
\divide\JALALI@temptwo by 400\relax
\advance\JALALI@temp by \JALALI@temptwo
\advance\JALALI@tempthree by -611       % Number of Kabise years
\JALALI@temptwo=\JALALI@tempthree           % T := T - ((SY+10) div 33) * 8
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 8\relax
\advance\JALALI@temp by -\JALALI@temptwo
\JALALI@temptwo=\JALALI@tempthree           %
\divide\JALALI@temptwo by 33\relax
\multiply\JALALI@temptwo by 33\relax
\advance\JALALI@tempthree by -\JALALI@temptwo
\ifnum\JALALI@tempthree=32\advance\JALALI@temp by 1\fi % if (SY+10) mod 33=32 then Inc(T);
\divide\JALALI@tempthree by 4\relax     % T := T - ((SY+10) mod 33) div 4
\advance\JALALI@temp by -\JALALI@tempthree
\advance\JALALI@temp by -137            % T := T - 137  Adjust the value
\JALALI@farsii=31
\advance\JALALI@farsii by -\JALALI@temp                 % now 31 - T is the farsii
%
\JALALI@farsiii = 30\relax
\ifJALALI@kabiseh
  \JALALI@farsiiii = 30\relax
\else
  \JALALI@farsiiii = 29\relax
\fi
\JALALI@farsiiv  = 31\relax
\JALALI@farsiv   = 31\relax
\JALALI@farsivi  = 31\relax
\JALALI@farsivii = 31\relax
\JALALI@farsiviii= 31\relax
\JALALI@farsiix  = 31\relax
\JALALI@farsix   = 30\relax
\JALALI@farsixi  = 30\relax
\JALALI@farsixii = 30\relax
\JALALI@farsixiii= 30\relax
%
\JALALI@dn= 0\relax
\JALALI@sn= 0\relax
\JALALI@mminusone=\JALALI@m
\advance\JALALI@mminusone by -1\relax
%
\JALALI@i=0\relax
\ifnum\JALALI@i < \JALALI@mminusone
\loop
\advance \JALALI@i by 1\relax
\advance\JALALI@dn by \csname JALALI@latin\romannumeral\the\JALALI@i\endcsname
\ifnum\JALALI@i<\JALALI@mminusone \repeat
\fi
\advance \JALALI@dn by \JALALI@d
%
\JALALI@i=1\relax
\JALALI@sn = \JALALI@farsii
\ifnum \JALALI@sn<\JALALI@dn
\loop
\advance \JALALI@i by 1\relax
\advance\JALALI@sn by \csname JALALI@farsi\romannumeral\the\JALALI@i\endcsname
\ifnum \JALALI@sn<\JALALI@dn \repeat
\fi
\ifnum \JALALI@i < 4
   \JALALI@m = 9 \advance\JALALI@m by \JALALI@i
   \advance \JALALI@y by -622\relax
\else
   \JALALI@m = \JALALI@i \advance \JALALI@m by -3\relax
   \advance \JALALI@y by -621\relax
\fi
\advance\JALALI@sn by -\csname JALALI@farsi\romannumeral\the\JALALI@i%
\endcsname
\ifnum\JALALI@i = 1
  \JALALI@d = \JALALI@dn \advance \JALALI@d by 30 \advance\JALALI@d by -\JALALI@farsii
\else
  \JALALI@d = \JALALI@dn \advance \JALALI@d by -\JALALI@sn
\fi
%% DATE FORMATTING
\if@RTL{\farsidigits{\number\JALALI@d}\space%
\Jalalimonth{\JALALI@m}\space\farsidigits{\number\JALALI@y}}%
\else
\number\JALALI@d\space\JalalimonthEnglish{\JALALI@m}%
\space\number\JALALI@y%
\fi}
%%%
\def\Jalalimonth#1{\ifcase#1\or فروردین\or
اردیبهشت\or خرداد\or تیر\or مرداد\or شهریور%
\or مهر\or آبان\or آذر\or دی\or بهمن\or اسفند%
\fi}
\def\JalalimonthEnglish#1{\ifcase#1%
\or Farvardīn\or Ordībehesht\or Khordād\or Tīr%
\or Mordād\or Shahrīvar\or Mihr\or Ābān\or Āzar%
\or Dai\or Bahman\or Esfand\fi}
%    \end{macrocode}
% \iffalse
%</farsical.sty>
%<*hebrewcal.sty>
% \fi
% \clearpage
% 
% \subsection{hebrewcal.sty}
%    \begin{macrocode}
\ProvidesPackage{hebrewcal}
        [2019/12/03 v2.7 %
         Hebrew calendar for polyglossia (adapted from hebcal.sty in Babel)]
\RequirePackage{xkeyval}
\ifluatex\RequirePackage{luabidi}\else\RequirePackage{bidi}\fi

\newif\if@xpg@hebrewcal@marcheshvan
\@xpg@hebrewcal@marcheshvanfalse

\DeclareOption{marcheshvan}{\@xpg@hebrewcal@marcheshvantrue}

\@ifundefined{if@xpg@hebrew@marcheshvan}{}{%
  \if@xpg@hebrew@marcheshvan
     \@xpg@hebrewcal@marcheshvantrue
  \fi
}

%% TODO rewrite this on the basis of Reingold & Dershowitz 
%%      on the model of hijrical (using calc)

\@ifundefined{@Remainder}{\input{cal-util.def}}{}

\define@boolkey{hebrew}[@hebrew@]{fullyear}[true]{}
\setkeys{hebrew}{fullyear=false}

\newcount\hebrewday  \newcount\hebrewmonth \newcount\hebrewyear
\def\hebrewdate#1#2#3{%
    \HebrewFromGregorian{#1}{#2}{#3}%
                        {\hebrewday}{\hebrewmonth}{\hebrewyear}%
    \if@RTL%
      \@FormatForHebrew{\hebrewday}{\hebrewmonth}{\hebrewyear}%
    \else%
      \@FormatForEnglish{\hebrewday}{\hebrewmonth}{\hebrewyear}%
    \fi}
\def\hebrewtoday{\hebrewdate{\day}{\month}{\year}}
% The command name is capitalised in the doc, and this is consistent
% with other names such as \Hijritoday and \Jalalitoday.
\let\Hebrewtoday=\hebrewtoday
\def\hebrewsetreg{%
    \HebrewFromGregorian{\day}{\month}{\year}%
                        {\hebrewday}{\hebrewmonth}{\hebrewyear}}
\def\HebrewYearName#1{{%
   \@tempcnta=#1\divide\@tempcnta by 1000\multiply\@tempcnta by 1000
   \ifnum#1=\@tempcnta\relax % divisible by 1000: disambiguate
     \Hebrewnumeral{#1}\ (לפ"ג)%
   \else % not divisible by 1000
     \ifnum#1<1000\relax     % first millennium: disambiguate
       \Hebrewnumeral{#1}\ (לפ"ג)%
     \else 
       \ifnum#1<5000
         \Hebrewnumeral{#1}%
       \else
         \ifnum#1<6000 % current millenium, print without thousands
           \@tempcnta=#1\relax
           \if@hebrew@fullyear\else\advance\@tempcnta by -5000\fi
           \Hebrewnumeral{\@tempcnta}%
         \else % #1>6000
           \Hebrewnumeral{#1}%
         \fi
       \fi
     \fi
   \fi}}
\def\HebrewMonthName#1#2{%
    \ifnum #1 = 7 %
    \@CheckLeapHebrewYear{#2}%
        \if@HebrewLeap אדר\ ב'%
           \else אדר%
        \fi%
    \else%
        \ifcase#1%
           % nothing for 0
           \or תשרי%
           \or\if@xpg@hebrewcal@marcheshvan מרחשון\else חשון\fi%
           \or כסלו%
           \or טבת%
           \or שבט%
           \or אדר\ א'%
           \or אדר\ ב'%
           \or ניסן%
           \or אייר%
           \or סיון%
           \or תמוז%
           \or אב%
           \or אלול%
        \fi%
    \fi}
\def\@FormatForHebrew#1#2#3{%
  \Hebrewnumeral{#1}~ב\HebrewMonthName{#2}{#3}~%
  \HebrewYearName{#3}}
\def\HebrewMonthNameInEnglish#1#2{%
    \ifnum #1 = 7%
    \@CheckLeapHebrewYear{#2}%
        \if@HebrewLeap Adar II\else Adar\fi%
    \else%
        \ifcase #1%
            % nothing for 0
            \or Tishrei%
            \or\if@xpg@hebrewcal@marcheshvan Marcheshvan\else Heshvan\fi%
            \or Kislev%
            \or Tebeth%
            \or Shebat%
            \or Adar I%
            \or Adar II%
            \or Nisan%
            \or Iyar%
            \or Sivan%
            \or Tammuz%
            \or Av%
            \or Elul%
        \fi
    \fi}
\def\@FormatForEnglish#1#2#3{%
    \HebrewMonthNameInEnglish{#2}{#3} \number#1,\ \number#3}
\newcount\@common
\newif\if@HebrewLeap
\def\@CheckLeapHebrewYear#1{%
    {%
        \countdef\tmpa = 0%       % \tmpa==\count0
        \countdef\tmpb = 1%       % \tmpb==\count1
        \tmpa = #1%
        \multiply \tmpa by 7%
        \advance \tmpa by 1%
        \@Remainder{\tmpa}{19}{\tmpb}%
        \ifnum \tmpb < 7%         % \tmpb = (7*year+1)%19
            \global\@HebrewLeaptrue%
        \else%
            \global\@HebrewLeapfalse%
        \fi}}
\def\@HebrewElapsedMonths#1#2{%
    {%
        \countdef\tmpa = 0%       % \tmpa==\count0
        \countdef\tmpb = 1%       % \tmpb==\count1
        \countdef\tmpc = 2%       % \tmpc==\count2
        \tmpa = #1%               %
        \advance \tmpa by -1%     %
        #2 = \tmpa%               % #2 = \tmpa = year-1
        \divide #2 by 19%         % Number of complete Meton cycles
        \multiply #2 by 235%      % #2 = 235*((year-1)/19)
        \@Remainder{\tmpa}{19}{\tmpb}% \tmpa = years%19-years this cycle
        \tmpc = \tmpb%            %
        \multiply \tmpb by 12%    %
        \advance #2 by \tmpb%     % add regular months this cycle
        \multiply \tmpc by 7%     %
        \advance \tmpc by 1%      %
        \divide \tmpc by 19%      % \tmpc = (1+7*((year-1)%19))/19 -
        \advance #2 by \tmpc%     %  add leap months
        \global\@common = #2}%
    #2 = \@common}
\def\@HebrewElapsedDays#1#2{%
    {%
        \countdef\tmpa = 0%       % \tmpa==\count0
        \countdef\tmpb = 1%       % \tmpb==\count1
        \countdef\tmpc = 2%       % \tmpc==\count2
        \@HebrewElapsedMonths{#1}{#2}%
        \tmpa = #2%               %
        \multiply \tmpa by 13753% %
        \advance \tmpa by 5604%   % \tmpa=MonthsElapsed*13758 + 5604
        \@Remainder{\tmpa}{25920}{\tmpc}% \tmpc == ConjunctionParts
        \divide \tmpa by 25920%
        \multiply #2 by 29%
        \advance #2 by 1%
        \advance #2 by \tmpa%     %  #2 = 1 + MonthsElapsed*29 +
        \@Remainder{#2}{7}{\tmpa}% %  \tmpa == DayOfWeek
        \ifnum \tmpc < 19440%
            \ifnum \tmpc < 9924%
            \else%                % New moon at 9 h. 204 p. or later
                \ifnum \tmpa = 2% % on Tuesday ...
                    \@CheckLeapHebrewYear{#1}% of a common year
                    \if@HebrewLeap%
                    \else%
                        \advance #2 by 1%
                    \fi%
                \fi%
            \fi%
            \ifnum \tmpc < 16789%
            \else%                 % New moon at 15 h. 589 p. or later
                \ifnum \tmpa = 1%  % on Monday ...
                    \advance #1 by -1%
                    \@CheckLeapHebrewYear{#1}% at the end of leap year
                    \if@HebrewLeap%
                        \advance #2 by 1%
                    \fi%
                \fi%
            \fi%
        \else%
            \advance #2 by 1%      %  new moon at or after midday
        \fi%
        \@Remainder{#2}{7}{\tmpa}%  %  \tmpa == DayOfWeek
        \ifnum \tmpa = 0%          %  if Sunday ...
            \advance #2 by 1%
        \else%                     %
            \ifnum \tmpa = 3%      %  Wednesday ...
                \advance #2 by 1%
            \else%
                \ifnum \tmpa = 5%  %  or Friday
                     \advance #2 by 1%
                \fi%
            \fi%
        \fi%
        \global\@common = #2}%
    #2 = \@common}
\def\@DaysInHebrewYear#1#2{%
    {%
        \countdef\tmpe = 12%   % \tmpe==\count12
        \@HebrewElapsedDays{#1}{\tmpe}%
        \advance #1 by 1%
        \@HebrewElapsedDays{#1}{#2}%
        \advance #2 by -\tmpe%
        \global\@common = #2}%
    #2 = \@common}
\def\@HebrewDaysInPriorMonths#1#2#3{%
    {%
        \countdef\tmpf= 14%    % \tmpf==\count14
        #3 = \ifcase #1%       % Days in prior month of regular year
               0 \or%          % no month number 0
               0 \or%          % Tishri
              30 \or%          % Heshvan
              59 \or%          % Kislev
              89 \or%          % Tebeth
             118 \or%          % Shebat
             148 \or%          % Adar I
             148 \or%          % Adar II
             177 \or%          % Nisan
             207 \or%          % Iyar
             236 \or%          % Sivan
             266 \or%          % Tammuz
             295 \or%          % Av
             325 \or%          % Elul
             400%              % Dummy
        \fi%
        \@CheckLeapHebrewYear{#2}%
        \if@HebrewLeap%            % in leap year
            \ifnum #1 > 6%         % if month after Adar I
                \advance #3 by 30% % add  30 days
            \fi%
        \fi%
        \@DaysInHebrewYear{#2}{\tmpf}%
        \ifnum #1 > 3%
            \ifnum \tmpf = 353%    %
                \advance #3 by -1% %
            \fi%                   %  Short Kislev
            \ifnum \tmpf = 383%    %
                \advance #3 by -1% %
            \fi%                   %
        \fi%
        \ifnum #1 > 2%
            \ifnum \tmpf = 355%    %
                \advance #3 by 1%  %
            \fi%                   %  Long Heshvan
            \ifnum \tmpf = 385%    %
                \advance #3 by 1%  %
            \fi%                   %
        \fi%
        \global\@common = #3}%
    #3 = \@common}
\def\@FixedFromHebrew#1#2#3#4{%
    {%
        #4 = #1%
        \@HebrewDaysInPriorMonths{#2}{#3}{#1}%
        \advance #4 by #1%         % Add days in prior months this year
        \@HebrewElapsedDays{#3}{#1}%
        \advance #4 by #1%         % Add days in prior years
        \advance #4 by -1373429%   % Subtract days before Gregorian
        \global\@common = #4}%     %   01.01.0001
    #4 = \@common}
\def\@GregorianDaysInPriorMonths#1#2#3{%
    {%
        #3 = \ifcase #1%
               0 \or%             % no month number 0
               0 \or%
              31 \or%
              59 \or%
              90 \or%
             120 \or%
             151 \or%
             181 \or%
             212 \or%
             243 \or%
             273 \or%
             304 \or%
             334%
        \fi%
        \@CheckIfGregorianLeap{#2}%
        \if@GregorianLeap%
            \ifnum #1 > 2%        % if month after February
                \advance #3 by 1% % add leap day
            \fi%
        \fi%
        \global\@common = #3}%
    #3 = \@common}
\def\@GregorianDaysInPriorYears#1#2{%
     {%
         \countdef\tmpc = 4%      % \tmpc==\count4
         \countdef\tmpb = 2%      % \tmpb==\count2
         \tmpb = #1%              %
         \advance \tmpb by -1%    %
         \tmpc = \tmpb%           % \tmpc = \tmpb = year-1
         \multiply \tmpc by 365%  % Days in prior years =
         #2 = \tmpc%              % = 365*(year-1) ...
         \tmpc = \tmpb%           %
         \divide \tmpc by 4%      % \tmpc = (year-1)/4
         \advance #2 by \tmpc%    % ... plus Julian leap days ...
         \tmpc = \tmpb%           %
         \divide \tmpc by 100%    % \tmpc = (year-1)/100
         \advance #2 by -\tmpc%   % ... minus century years ...
         \tmpc = \tmpb%           %
         \divide \tmpc by 400%    % \tmpc = (year-1)/400
         \advance #2 by \tmpc%    % ... plus 4-century years.
         \global\@common = #2}%
    #2 = \@common}
\def\@AbsoluteFromGregorian#1#2#3#4{%
    {%
        \countdef\tmpd = 0%       % \tmpd==\count0
        #4 = #1%                  % days so far this month
        \@GregorianDaysInPriorMonths{#2}{#3}{\tmpd}%
        \advance #4 by \tmpd%     % add days in prior months
        \@GregorianDaysInPriorYears{#3}{\tmpd}%
        \advance #4 by \tmpd%     % add days in prior years
        \global\@common = #4}%
    #4 = \@common}
\def\HebrewFromGregorian#1#2#3#4#5#6{%
    {%
        \countdef\tmpx= 17%        % \tmpx==\count17
        \countdef\tmpy= 18%        % \tmpy==\count18
        \countdef\tmpz= 19%        % \tmpz==\count19
        #6 = #3%                   %
        \global\advance #6 by 3761%  approximation from above
        \@AbsoluteFromGregorian{#1}{#2}{#3}{#4}%
        \tmpz = 1  \tmpy = 1%
        \@FixedFromHebrew{\tmpz}{\tmpy}{#6}{\tmpx}%
        \ifnum \tmpx > #4%              %
            \global\advance #6 by -1% Hyear = Gyear + 3760
            \@FixedFromHebrew{\tmpz}{\tmpy}{#6}{\tmpx}%
        \fi%                            %
        \advance #4 by -\tmpx%     % Days in this year
        \advance #4 by 1%          %
        #5 = #4%                   %
        \divide #5 by 30%          % Approximation for month from below
        \loop%                     % Search for month
            \@HebrewDaysInPriorMonths{#5}{#6}{\tmpx}%
            \ifnum \tmpx < #4%
                \advance #5 by 1%
                \tmpy = \tmpx%
        \repeat%
        \global\advance #5 by -1%
        \global\advance #4 by -\tmpy}}
\ProcessOptions*
%    \end{macrocode}
% \iffalse
%</hebrewcal.sty>
%<*hijrical.sty>
% \fi
% \clearpage
% 
% \subsection{hijrical.sty}
%    \begin{macrocode}
\ProvidesPackage{hijrical}
        [2010/07/12 v0.2 %
         Islamic calendar]
\RequirePackage{calc}
\RequirePackage{arabicnumbers}
\@ifpackageloaded{bidi}{}{\newif\if@RTL\@RTLfalse}
\@ifpackageloaded{l3calc}{\PackageError{hijrical}{\MessageBreak
Package l3calc is loaded, which replaces the functionality of
calc. Computation of Hijri dates will not work properly with
% FIXME by Arthur: François couldn’t possibly mean ‘l3calc’ on the
% following line :-)  Find out if he meant ‘calc’.
l3calc! The latest version of expl3 on CTAN no longer loads
l3calc. Please update expl3!
}{}}{}

\@ifundefined{@Remainder}{\input{cal-util.def}}{}

%% The following functions are straightforward implementation 
%% of Reingold & Dershowitz, Calendrical Calculations, The Millenium Edition
%%

\def\@FixedFromHijri#1#2#3#4{% year,month,day,counter
\@ifundefined{c@#4}{\newcounter{#4}}{}%
\setcounter{tmpA}{#2/2}% see errata of Reingold+Dershowitz
%\message{tmpA is \thetmpA}%
\setcounter{tmpB}{(3+11*#1)/30}%
%\message{tmpB is \thetmpB}%
\setcounter{#4}{227014+(#1-1)*354+\value{tmpB}+(29*(#2-1))+\value{tmpA}+#3}%
}

\newcounter{Hijriday}\newcounter{Hijrimonth}\newcounter{Hijriyear}

\def\HijriFromGregorian#1#2#3{% year,month,day
\@FixedFromGregorian{#1}{#2}{#3}{RDdate}%
\setcounter{Hijriyear}{(30*(\value{RDdate}-227015)+10646)/10631}%
\@FixedFromHijri{\value{Hijriyear}}{1}{1}{tmpx}%
%\message{tmpx is \thetmpx}%
\setcounter{tmpB}{\value{RDdate}-\value{tmpx}}%
%\message{tmpB is \thetmpB}%
\setcounter{Hijrimonth}{((11*\value{tmpB})+330)/325}%
\@FixedFromHijri{\value{Hijriyear}}{\value{Hijrimonth}}{1}{tmpy}%
%\message{tmpy is \thetmpy}%
\setcounter{Hijriday}{1+\value{RDdate}-\value{tmpy}}%
}

%\HijriFromGregorian{\year}{\month}{\day}%

%\def\PlainHijritoday{%
%\theHijriday.\theHijrimonth.\theHijriyear}

\def\Hijridate#1#2#3{%
    \HijriFromGregorian{#1}{#2}{#3}%
    \FormatHijriDate}

% added option \Hijritoday[n] (default 0) for adjusting the date + n days
\@ifundefined{@hijri@correction}{\gdef\@hijri@correction{0}}{}
\newcommand\Hijritoday[1][\@hijri@correction]{%
 \@ifundefined{c@adj@day}{\global\newcounter{adj@day}}{}%
 \setcounter{adj@day}{\the\day+#1}% 
 \Hijridate{\year}{\month}{\value{adj@day}}}
%\def\Hijritoday{\Hijridate{\year}{\month}{\day}}
\let\hijritoday=\Hijritoday
%FIXME necessary?
%\def\Hijrisetreg{%
% \HijriFromGregorian{\year}{\month}{\day}}

\def\HijriMonthTranslit#1{\ifcase#1\or Muḥarram\or Ṣafar\or Rabīʿ I\or Rabīʿ II\or%
Jumādā I\or Jumādā II\or Rajab\or Shaʿbān\or Ramaḍān\or%
Shawwāl\or Dhū ’l-Qaʿda\or Dhū ’l-Ḥijja\fi}

\def\HijriMonthArabic#1{\ifcase#1\or محرم\or صفر\or ربيع الأول\or ربيع الآخر\or%
جمادى الأولى\or جمادى الآخرة\or رجب\or شعبان\or رمضان\or%
شوال\or ذو القعدة\or ذو الحجة\fi}

%% This macro is now locale-aware!
\def\FormatHijriDate{%
  \@ifundefined{FormatHijriDate@\languagename}%
    {\if@RTL\FormatHijriDate@defaultRTL\else\FormatHijriDate@defaultLTR\fi}%
    {\csname FormatHijriDate@\languagename\endcsname}}

\newcommand\DefineFormatHijriDate[2]{%
   \@namedef{FormatHijriDate@#1}{#2}}

% we provide this as a reasonable default.
% Further definitions are in polyglossia’s language definition files.
\DefineFormatHijriDate{defaultRTL}{\@ensure@RTL{%
\arabicdigits{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\arabicdigits{\value{Hijriyear}}}}

\DefineFormatHijriDate{defaultLTR}{%
\number\value{Hijriday}\space\HijriMonthTranslit{\value{Hijrimonth}}\space\number\value{Hijriyear}}
%    \end{macrocode}
% \iffalse
%</hijrical.sty>
%<*polyglossia-french.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-french.lua}
%    \begin{macrocode}
require('polyglossia-punct')

local function set_left_space(lang, char, kern, rubber)
    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
end

local function set_right_space(lang, char, kern, rubber)
    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
end

local function activate_french_punct(thincolonspace, autospaceguillemets)
    -- We need different language tags here to make switching of options possible
    -- within a paragraph.
    local lang = "french"
    if thincolonspace then
        lang = lang.."-thincolon"
    end
    if autospaceguillemets then
        lang = lang.."-autospace"
    end

    polyglossia.activate_punct(lang)
    polyglossia.clear_spaced_characters(lang)

    if thincolonspace then
        set_left_space(lang, ':', 0.5)
    else
        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
    end

    set_left_space(lang, '!', 0.5)
    set_left_space(lang, '?', 0.5)
    set_left_space(lang, ';', 0.5)
    set_left_space(lang, '‼', 0.5)
    set_left_space(lang, '⁇', 0.5)
    set_left_space(lang, '⁈', 0.5)
    set_left_space(lang, '⁉', 0.5)
    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)

    if autospaceguillemets then
        set_left_space(lang, '»', 0.5)
        set_left_space(lang, '›', 0.5)
        set_right_space(lang, '«', 0.5)
        set_right_space(lang, '‹', 0.5)
    end
end

local function deactivate_french_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_french_punct   = activate_french_punct
polyglossia.deactivate_french_punct = deactivate_french_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-french.lua>
%<*polyglossia-korean.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-korean.lua}
%    \begin{macrocode}
--
-- polyglossia-korean.lua
--

local glyph_id = node.id"glyph"
local hbox_id  = node.id"hlist"
local vbox_id  = node.id"vlist"
local glue_id  = node.id"glue"
local penalty_id = node.id"penalty"
local disc_id  = node.id"disc"

--
-- attr_korean: variant = plain (0), classic (1), modern (2)
--
local attr_korean = luatexbase.attributes["xpg@attr@korean"]
local attr_josa   = luatexbase.attributes["xpg@attr@autojosa"]

--
-- characters after which linebreak is not allowed
--
local nobr_after = {
    [0x28] = 1, -- ( LEFT PARENTHESIS
    [0x3C] = 1, -- < LESS-THAN SIGN
    [0x5B] = 1, -- [ LEFT SQUARE BRACKET
    [0x60] = 1, -- ` GRAVE ACCENT
    [0x7B] = 1, -- { LEFT CURLY BRACKET
    [0xAB] = 1, -- « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
    [0x2018] = 1, -- ‘ LEFT SINGLE QUOTATION MARK
    [0x201C] = 1, -- “ LEFT DOUBLE QUOTATION MARK
    [0x2329] = 1, -- 〈 LEFT-POINTING ANGLE BRACKET
    [0x3008] = 1, -- 〈 LEFT ANGLE BRACKET
    [0x300A] = 1, -- 《 LEFT DOUBLE ANGLE BRACKET
    [0x300C] = 1, -- 「 LEFT CORNER BRACKET
    [0x300E] = 1, -- 『 LEFT WHITE CORNER BRACKET
    [0x3010] = 1, -- 【 LEFT BLACK LENTICULAR BRACKET
    [0x3014] = 1, -- 〔 LEFT TORTOISE SHELL BRACKET
    [0x3016] = 1, -- 〖 LEFT WHITE LENTICULAR BRACKET
    [0x3018] = 1, -- 〘 LEFT WHITE TORTOISE SHELL BRACKET
    [0x301A] = 1, -- 〚 LEFT WHITE SQUARE BRACKET
    [0x301D] = 1, -- 〝 REVERSED DOUBLE PRIME QUOTATION MARK
    [0xFE17] = 1, -- ︗ PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET
    [0xFE35] = 1, -- ︵ PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS
    [0xFE37] = 1, -- ︷ PRESENTATION FORM FOR VERTICAL LEFT CURLY BRACKET
    [0xFE39] = 1, -- ︹ PRESENTATION FORM FOR VERTICAL LEFT TORTOISE SHELL BRACKET
    [0xFE3B] = 1, -- ︻ PRESENTATION FORM FOR VERTICAL LEFT BLACK LENTICULAR BRACKET
    [0xFE3D] = 1, -- ︽ PRESENTATION FORM FOR VERTICAL LEFT DOUBLE ANGLE BRACKET
    [0xFE3F] = 1, -- ︿ PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET
    [0xFE41] = 1, -- ﹁ PRESENTATION FORM FOR VERTICAL LEFT CORNER BRACKET
    [0xFE43] = 1, -- ﹃ PRESENTATION FORM FOR VERTICAL LEFT WHITE CORNER BRACKET
    [0xFE47] = 1, -- ﹇ PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET
    [0xFE59] = 1, -- ﹙ SMALL LEFT PARENTHESIS
    [0xFE5B] = 1, -- ﹛ SMALL LEFT CURLY BRACKET
    [0xFE5D] = 1, -- ﹝ SMALL LEFT TORTOISE SHELL BRACKET
    [0xFF08] = 1, -- （ FULLWIDTH LEFT PARENTHESIS
    [0xFF3B] = 1, -- ［ FULLWIDTH LEFT SQUARE BRACKET
    [0xFF5B] = 1, -- ｛ FULLWIDTH LEFT CURLY BRACKET
    [0xFF5F] = 1, -- ｟ FULLWIDTH LEFT WHITE PARENTHESIS
    [0xFF62] = 1, -- ｢ HALFWIDTH LEFT CORNER BRACKET
}

--
-- characters before which linebreak is not allowed
--   (currently, not much differences among the followings)
--   1: normal chars
--   2: hangul jamo vowels and trailing consonants
--   3: kana small letters
--   0: dashes (supress visible spacing)
--
local nobr_before = setmetatable({
    [0x21] = 1, -- ! EXCLAMATION MARK
    [0x22] = 1, -- " QUOTATION MARK
    [0x27] = 1, -- ' APOSTROPHE
    [0x29] = 1, -- ) RIGHT PARENTHESIS
    [0x2C] = 1, -- , COMMA
    [0x2D] = 0, -- - HYPHEN-MINUS
    [0x2E] = 1, -- . FULL STOP
    [0x2F] = 0, -- / SOLIDUS
    [0x3A] = 0, -- : COLON
    [0x3B] = 1, -- ; SEMICOLON
    [0x3E] = 1, -- > GREATER-THAN SIGN
    [0x3F] = 1, -- ? QUESTION MARK
    [0x5C] = 0, -- \ REVERSE SOLIDUS
    [0x5D] = 1, -- ] RIGHT SQUARE BRACKET
    [0x7D] = 1, -- } RIGHT CURLY BRACKET
    [0x7E] = 0, -- ~ TILDE
    [0xB7] = 1, -- · MIDDLE DOT
    [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
    [0x2013] = 0, -- – EN DASH
    [0x2014] = 0, -- — EM DASH
    [0x2015] = 1, -- ― HORIZONTAL BAR
    [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
    [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
    [0x2025] = 1, -- ‥ TWO DOT LEADER
    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
    [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
    [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
    [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
    [0x3005] = 1, -- 々 IDEOGRAPHIC ITERATION MARK
    [0x3009] = 1, -- 〉 RIGHT ANGLE BRACKET
    [0x300B] = 1, -- 》 RIGHT DOUBLE ANGLE BRACKET
    [0x300D] = 1, -- 」 RIGHT CORNER BRACKET
    [0x300F] = 1, -- 』 RIGHT WHITE CORNER BRACKET
    [0x3011] = 1, -- 】 RIGHT BLACK LENTICULAR BRACKET
    [0x3015] = 1, -- 〕 RIGHT TORTOISE SHELL BRACKET
    [0x3017] = 1, -- 〗 RIGHT WHITE LENTICULAR BRACKET
    [0x3019] = 1, -- 〙 RIGHT WHITE TORTOISE SHELL BRACKET
    [0x301B] = 1, -- 〛 RIGHT WHITE SQUARE BRACKET
    [0x301C] = 1, -- 〜 WAVE DASH
    [0x301E] = 1, -- 〞 DOUBLE PRIME QUOTATION MARK
    [0x301F] = 1, -- 〟 LOW DOUBLE PRIME QUOTATION MARK
    [0x3035] = 1, -- 〵 VERTICAL KANA REPEAT MARK LOWER HALF
    [0x303B] = 1, -- 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
    [0x303C] = 1, -- 〼 MASU MARK
    [0x3041] = 3, -- ぁ HIRAGANA LETTER SMALL A
    [0x3043] = 3, -- ぃ HIRAGANA LETTER SMALL I
    [0x3045] = 3, -- ぅ HIRAGANA LETTER SMALL U
    [0x3047] = 3, -- ぇ HIRAGANA LETTER SMALL E
    [0x3049] = 3, -- ぉ HIRAGANA LETTER SMALL O
    [0x3063] = 3, -- っ HIRAGANA LETTER SMALL TU
    [0x3083] = 3, -- ゃ HIRAGANA LETTER SMALL YA
    [0x3085] = 3, -- ゅ HIRAGANA LETTER SMALL YU
    [0x3087] = 3, -- ょ HIRAGANA LETTER SMALL YO
    [0x308E] = 3, -- ゎ HIRAGANA LETTER SMALL WA
    [0x3095] = 3, -- ゕ HIRAGANA LETTER SMALL KA
    [0x3096] = 3, -- ゖ HIRAGANA LETTER SMALL KE
    [0x3099] = 1, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
    [0x309A] = 1, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
    [0x309B] = 1, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
    [0x309C] = 1, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
    [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
    [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
    [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
    [0x30A1] = 3, -- ァ KATAKANA LETTER SMALL A
    [0x30A3] = 3, -- ィ KATAKANA LETTER SMALL I
    [0x30A5] = 3, -- ゥ KATAKANA LETTER SMALL U
    [0x30A7] = 3, -- ェ KATAKANA LETTER SMALL E
    [0x30A9] = 3, -- ォ KATAKANA LETTER SMALL O
    [0x30C3] = 3, -- ッ KATAKANA LETTER SMALL TU
    [0x30E3] = 3, -- ャ KATAKANA LETTER SMALL YA
    [0x30E5] = 3, -- ュ KATAKANA LETTER SMALL YU
    [0x30E7] = 3, -- ョ KATAKANA LETTER SMALL YO
    [0x30EE] = 3, -- ヮ KATAKANA LETTER SMALL WA
    [0x30F5] = 3, -- ヵ KATAKANA LETTER SMALL KA
    [0x30F6] = 3, -- ヶ KATAKANA LETTER SMALL KE
    [0x30FB] = 1, -- ・ KATAKANA MIDDLE DOT
    [0x30FC] = 1, -- ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
    [0x30FD] = 1, -- ヽ KATAKANA ITERATION MARK
    [0x30FE] = 1, -- ヾ KATAKANA VOICED ITERATION MARK
    [0xFE30] = 1, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
    [0xFE31] = 1, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
    [0xFE32] = 1, -- ︲ PRESENTATION FORM FOR VERTICAL EN DASH
    [0xFE36] = 1, -- ︶ PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS
    [0xFE38] = 1, -- ︸ PRESENTATION FORM FOR VERTICAL RIGHT CURLY BRACKET
    [0xFE3A] = 1, -- ︺ PRESENTATION FORM FOR VERTICAL RIGHT TORTOISE SHELL BRACKET
    [0xFE3C] = 1, -- ︼ PRESENTATION FORM FOR VERTICAL RIGHT BLACK LENTICULAR BRACKET
    [0xFE3E] = 1, -- ︾ PRESENTATION FORM FOR VERTICAL RIGHT DOUBLE ANGLE BRACKET
    [0xFE40] = 1, -- ﹀ PRESENTATION FORM FOR VERTICAL RIGHT ANGLE BRACKET
    [0xFE42] = 1, -- ﹂ PRESENTATION FORM FOR VERTICAL RIGHT CORNER BRACKET
    [0xFE44] = 1, -- ﹄ PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
    [0xFE48] = 1, -- ﹈ PRESENTATION FORM FOR VERTICAL RIGHT SQUARE BRACKET
    [0xFE5A] = 1, -- ﹚ SMALL RIGHT PARENTHESIS
    [0xFE5C] = 1, -- ﹜ SMALL RIGHT CURLY BRACKET
    [0xFE5E] = 1, -- ﹞ SMALL RIGHT TORTOISE SHELL BRACKET
    [0xFF01] = 1, -- ！ FULLWIDTH EXCLAMATION MARK
    [0xFF09] = 1, -- ） FULLWIDTH RIGHT PARENTHESIS
    [0xFF0C] = 1, -- ， FULLWIDTH COMMA
    [0xFF0E] = 1, -- ． FULLWIDTH FULL STOP
    [0xFF1A] = 1, -- ： FULLWIDTH COLON
    [0xFF1B] = 1, -- ； FULLWIDTH SEMICOLON
    [0xFF1F] = 1, -- ？ FULLWIDTH QUESTION MARK
    [0xFF3D] = 1, -- ］ FULLWIDTH RIGHT SQUARE BRACKET
    [0xFF5D] = 1, -- ｝ FULLWIDTH RIGHT CURLY BRACKET
    [0xFF60] = 1, -- ｠ FULLWIDTH RIGHT WHITE PARENTHESIS
    [0xFF61] = 1, -- ｡ HALFWIDTH IDEOGRAPHIC FULL STOP
    [0xFF63] = 1, -- ｣ HALFWIDTH RIGHT CORNER BRACKET
    [0xFF64] = 1, -- ､ HALFWIDTH IDEOGRAPHIC COMMA
    [0xFF65] = 1, -- ･ HALFWIDTH KATAKANA MIDDLE DOT
    [0xFF9E] = 1, -- ﾞ HALFWIDTH KATAKANA VOICED SOUND MARK
    [0xFF9F] = 1, -- ﾟ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
}, { __index = function(_,c)
        if c >= 0x1160  and c <= 0x11FF  then return 2 end
        if c >= 0xD7B0  and c <= 0xD7FF  then return 2 end
        if c >= 0x302A  and c <= 0x302F  then return 1 end
        if c >= 0x31F0  and c <= 0x31FF  then return 3 end
        if c >= 0xFF67  and c <= 0xFF70  then return 3 end
        if c >= 0xFE00  and c <= 0xFE0F  then return 1 end
        if c >= 0xFE10  and c <= 0xFE19 and not (c == 0xFE17) then return 1 end
        if c >= 0xFE50  and c <= 0xFE58  then return 1 end
        if c >= 0xE0100 and c <= 0xE01EF then return 1 end
    end
})

--
-- whether 'c' is a cjk character
--
local function is_cjk (c)
    return c >= 0xAC00  and c <= 0xD7FF
    or     c >= 0x1100  and c <= 0x11FF
    or     c >= 0xA960  and c <= 0xA97F
    or     c >= 0x2E80  and c <= 0x9FFF
    or     c >= 0xF900  and c <= 0xFAFF
    or     c >= 0xFE10  and c <= 0xFE1F
    or     c >= 0xFE30  and c <= 0xFE6F
    or     c >= 0xFF00  and c <= 0xFFEF
    or     c >= 0x1F100 and c <= 0x1F2FF
    or     c >= 0x20000 and c <= 0x2FA1F
    or     nobr_after[c]  and c > 0x2014
    or     nobr_before[c] and c > 0x2014
end

--
-- classify cjk characters
--   1: openings
--   2: closings
--   3: centered chars
--   4: full stops
--   5: ellipses
--   6: exclamation and question marks
--   0: all others
--
local charclass = setmetatable({
    [0x2018] = 1, [0x201C] = 1, [0x2329] = 1, [0x3008] = 1,
    [0x300A] = 1, [0x300C] = 1, [0x300E] = 1, [0x3010] = 1,
    [0x3014] = 1, [0x3016] = 1, [0x3018] = 1, [0x301A] = 1,
    [0x301D] = 1, [0xFE17] = 1, [0xFE35] = 1, [0xFE37] = 1,
    [0xFE39] = 1, [0xFE3B] = 1, [0xFE3D] = 1, [0xFE3F] = 1,
    [0xFE41] = 1, [0xFE43] = 1, [0xFE47] = 1, [0xFF08] = 1,
    [0xFF3B] = 1, [0xFF5B] = 1, [0xFF5F] = 1, [0xFF62] = 1,
    [0x2019] = 2, [0x201D] = 2, [0x232A] = 2, [0x3001] = 2,
    [0x3009] = 2, [0x300B] = 2, [0x300D] = 2, [0x300F] = 2,
    [0x3011] = 2, [0x3015] = 2, [0x3017] = 2, [0x3019] = 2,
    [0x301B] = 2, [0x301E] = 2, [0x301F] = 2, [0xFE10] = 2,
    [0xFE11] = 2, [0xFE18] = 2, [0xFE36] = 2, [0xFE38] = 2,
    [0xFE3A] = 2, [0xFE3C] = 2, [0xFE3E] = 2, [0xFE40] = 2,
    [0xFE42] = 2, [0xFE44] = 2, [0xFE48] = 2, [0xFF09] = 2,
    [0xFF0C] = 2, [0xFF3D] = 2, [0xFF5D] = 2, [0xFF60] = 2,
    [0xFF63] = 2, [0xFF64] = 2, [0x00B7] = 3, [0x30FB] = 3,
    [0xFF1A] = 3, [0xFF1B] = 3, [0xFF65] = 3, [0x3002] = 4,
    [0xFE12] = 4, [0xFF0E] = 4, [0xFF61] = 4, [0x2015] = 5,
    [0x2025] = 5, [0x2026] = 5, [0xFE19] = 5, [0xFE30] = 5,
    [0xFE31] = 5, [0xFE15] = 6, [0xFE16] = 6, [0xFF01] = 6,
    [0xFF1F] = 6,
}, { __index = function() return 0 end })

--
-- table for spacing between char classes
--   1 stands for 0.5*fontsize when variant=classic
--
local intercharclass = { [0] =
    { [0] = nil,    {1,1},  nil,    {.5,.5} },
    { [0] = nil,    nil,    nil,    {.5,.5} },
    { [0] = {1,1},  {1,1},  nil,    {.5,.5}, nil,    {1,1},  {1,1} },
    { [0] = {.5,.5},{.5,.5},{.5,.5},{1,.5},  {.5,.5},{.5,.5},{.5,.5} },
    { [0] = {1,0},  {1,0},  nil,    {1.5,.5},nil,    {1,0},  {1,0} },
    { [0] = nil,    {1,1},  nil,    {.5,.5} },
    { [0] = {1,1},  {1,1},  nil,    {.5,.5} },
}

--
-- get a new penalty node
--
local function get_new_penalty (p)
    local penalty = node.new("penalty")
    penalty.penalty = p
    return penalty
end

--
-- get a new glue node
--
local function get_new_glue (...)
    local glue = node.new("glue")
    node.setglue(glue, ...)
    return glue
end

--
-- return 0.5*fontsize of given fontid
--   space: true if variant=modern; then 0.5*interword_space
--
local function get_font_size (fid, space)
    local size = font.getparameters(fid)
    if space then
        size = size and size.space or 196608
    else
        size = size and size.quad  or 655360
    end
    return size/2
end

--
-- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
--   when variant=classic/modern
--
local function glyph_to_box (head, curr, class)
    local g, h = curr
    local size = get_font_size(g.font)
    head, curr = node.remove(head, curr)
    g.next, g.prev = nil, nil
    local hss = get_new_glue(0, 65536, 65536, 2, 2)
    if class == 1 then
        h, hss.next, g.prev = hss, g, hss
    elseif class == 2 or class == 4 then
        h, g.next, hss.prev = g, hss, g
    else
        local hss2 = node.copy(hss)
        h, hss.next, g.prev, g.next, hss2.prev = hss, g, hss, hss2, g
    end
    h = nodes.simple_font_handler(h)
    local box = node.hpack(h, size, "exactly")
    if curr then
        head, curr = node.insert_before(head, curr, box)
    else
        head, curr = node.insert_after(head, node.tail(head), box)
    end
    return head, curr
end

--
-- insert spacing defined as charclass[a][b] between a and b
--   f:    fontid
--   var:  variant = plain, classic, modern
--   cc:   charclass of current char
--   nc:   charclass of next char
--   nobr: linebreak is not allowed
--
local function insert_cjk_penalty_glue (head, curr, f, var, cc, nc, nobr)
    if nobr or cc == 1 or nc > 1 then
        local penalty = get_new_penalty(10000)
        head, curr = node.insert_after(head, curr, penalty)
    end
    local factor = get_font_size(f, var == 2)
    local t = intercharclass[cc][nc]
    local glue = get_new_glue(t[1]*factor, nil, t[2]*factor)
    head, curr = node.insert_after(head, curr, glue)
    return head, curr
end

--
-- insert inter-character spacing in other normal cases
--   f:   fontid
--   var: variant = plain, classic, modern
--   x:   true between cjk and non-cjk (a little more spacing)
--
local function insert_penalty_glue (head, curr, f, var, x)
    if var ~= 1 then
        local penalty = get_new_penalty(50)
        head, curr = node.insert_after(head, curr, penalty)
    end
    local size, glue = get_font_size(f, x and var == 2)
    if x then
        glue = get_new_glue(size/2, size/4, size/8)
    else
        glue = get_new_glue(0, size/10, size/50)
    end
    head, curr = node.insert_after(head, curr, glue)
    return head, curr
end

--
-- main process for linebreak and inter-character spacing
--   lb: true if pre_linebreak_filter
--
local function korean_break (head, lb)
    local curr = head
    while curr do
        if curr.id == glyph_id then
            local var = node.has_attribute(curr, attr_korean)
            if var then
                local c, f = curr.char or 0, curr.font or 0
                local cc, cjkc = charclass[c], is_cjk(c)

                -- compress cjk punctuations when charclass is 1 thru 4
                if var > 0 and cc > 0 and cc < 5 then
                    head, curr = glyph_to_box(head, curr, cc)
                end

                local next = curr.next
                if next and next.id == glyph_id then
                    local n = next.char or 0
                    local nc = charclass[n]
                    local nobr = nobr_before[n] or nobr_after[c]

                    -- insert spacing as of intercharclass
                    if var > 0 and intercharclass[cc][nc] then
                        head, curr = insert_cjk_penalty_glue(head, curr, f, var, cc, nc, nobr)

                    -- or insert spacing when linebreak is allowed
                    elseif not nobr then
                        local cjkn = is_cjk(n)

                        -- if curr or next is cjk char
                        if cjkc or cjkn then

                            -- if between cjk and non-cjk
                            if var > 0 and not (cjkc and cjkn) and nobr_before[c] ~= 0 then
                                head, curr = insert_penalty_glue(head, curr, f, var, true)

                            -- or under pre_linebreak_filter
                            elseif lb then
                                head, curr = insert_penalty_glue(head, curr, f, var)
                            end
                        end
                    end
                end
            end
        end
        curr = curr.next
    end
    return head
end

--
-- process for reordering hangul tone marks (U+302E, U+302F)
--   some hangul fonts (eg. Noto CJK) are so designed that hangul tone marks
--   should be moved to the first position of a syllable.
--   Currently, this functionality is not provided by luaotfload.
--
local function reorder_tm (head)
    local curr, tone = node.slide(head)
    while curr do
        if curr.id == glyph_id and node.has_attribute(curr, attr_korean) then
            local f = font.getfont(curr.font) or font.fonts[curr.font]
            if f and f.hb then -- harfbuzz do the right thing
                tone = nil
            else
                local c, wd = curr.char or 0, curr.width or 0
                if (c == 0x302E or c == 0x302F) and wd > 0 then
                    tone = curr
                elseif tone and not nobr_before[c] then
                    head = node.remove(head, tone)
                    tone.next, tone.prev = nil, nil
                    head, curr = node.insert_before(head, curr, tone)
                    tone = nil
                end
            end
        end
        curr = curr.prev
    end
    return head
end

--
-- automatic josa selection
--
local josa_table = {
    --          consonant ㄹ, vowel,  other consonants
    [0xAC00] = {0xC774,       0xAC00, 0xC774}, -- 가 => 이, 가, 이
    [0xC740] = {0xC740,       0xB294, 0xC740}, -- 은 => 은, 는, 은
    [0xC744] = {0xC744,       0xB97C, 0xC744}, -- 을 => 을, 를, 을
    [0xC640] = {0xACFC,       0xC640, 0xACFC}, -- 와 => 과, 와, 과
    [0xC73C] = {nil,          nil,    0xC73C}, -- 으(로) =>   ,  , 으
    [0xC774] = {0xC774,       nil,    0xC774}, -- 이(라) => 이,  , 이
}

--
-- helper function for number-like characters
--
local function josa_char_num (t, c)
    c = c % 10 + 0x30
    return t[c] or 2
end

--
-- decide josa selection
--
local josa_code = setmetatable({
    [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1,
    [0x38] = 1, [0x4C] = 1, [0x4D] = 3, [0x4E] = 3, [0x6C] = 1,
    [0x6D] = 3, [0x6E] = 3, [0xFB02] = 1, [0xFB04] = 1,
},{ __index = function(t,c)
        if c >= 0xAC00 and c <= 0xD7A3 then
            c = (c - 0xAC00) % 28 + 0x11A7
        end
        if c >= 0x11A8 and c <= 0x11FF then
            if c == 0x11AF then return 1 end
            return 3
        end
        if c >= 0xD7CB and c <= 0xD7FB then return 3 end
        if c >= 0x2170 and c <= 0x217F then c = c - 0x10 end
        if c >= 0x2160 and c <= 0x216F then
            if c >= 0x216C then return 3 end
            return josa_char_num(t, c - 0x215F)
        end
        if c >= 0x2460 and c <= 0x2473 then return josa_char_num(t, c - 0x245F) end
        if c >= 0x2474 and c <= 0x2487 then return josa_char_num(t, c - 0x2473) end
        if c >= 0x2488 and c <= 0x249B then return josa_char_num(t, c - 0x2487) end
        if c >= 0x249C and c <= 0x24B5 then return t[c - 0x249C + 0x61] or 2 end
        if c >= 0x24B6 and c <= 0x24CF then return t[c - 0x24B6 + 0x61] or 2 end
        if c >= 0x24D0 and c <= 0x24E9 then return t[c - 0x24D0 + 0x61] or 2 end
        if c >= 0x3131 and c <= 0x318E then
            if c == 0x3139 then return 1 end
            if c >= 0x314F and c <= 0x3163 or c >= 0x3187 then return 2 end
            return 3
        end
        if c >= 0x3260 and c <= 0x327E then c = c - 0x60 end
        if c >= 0x3200 and c <= 0x321E then
            if c == 0x3203 then return 1 end
            if c >= 0x320E then return 2 end
            return 3
        end
        if c >= 0xFF10 and c <= 0xFF19 then return josa_char_num(t, c - 0xFF10) end
        if c >= 0xFF21 and c <= 0xFF3A then return t[c - 0xFF21 + 0x61] or 2 end
        if c >= 0xFF41 and c <= 0xFF5A then return t[c - 0xFF41 + 0x61] or 2 end
        return 2
    end
})

--
-- obtain char that comes just before the josa
--
local function get_prev_char (p)
    while p do
        if p.id == glyph_id then
            local pc = p.char or 0
            if not nobr_after[pc] then
                if not nobr_before[pc] or nobr_before[pc] >= 2 then
                    return pc
                end
            end
        elseif p.id == hbox_id or p.id == vbox_id then
            local pc = get_prev_char(node.slide(p.head))
            if pc then return pc end
        end
        p = p.prev
    end
end

--
-- main process of josa selection
--
local function auto_josa (head)
    local curr, tofree = head, {}
    while curr do
        if curr.id == glyph_id then
            local josa = node.has_attribute(curr, attr_josa)
            if josa then
                local cc = curr.char or 0
                if josa == 0 then
                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
                end
                if cc == 0xC774 then
                    local n = curr.next
                    if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
                    else
                        cc = 0xAC00
                    end
                end
                local new = josa_table[cc]
                if new then
                    cc = new[josa]
                    if cc then
                        curr.char = cc
                    else
                        head = node.remove(head, curr)
                        table.insert(tofree, curr)
                    end
                end
                node.unset_attribute(curr, attr_josa)
            end
        end
        curr = curr.next
    end
    for _,v in ipairs(tofree) do node.free(v) end
    return head
end

--
-- now register to luatex callbacks
--   As char value of glyphs can be changed by opentype GSUB process,
--   we have to occupy the first position among callback functions.
--
local prepend_to_callback
if luatexbase.base_add_to_callback then
    prepend_to_callback = function(name, func, desc)
        luatexbase.add_to_callback(name, func, desc, 1)
    end
else
    prepend_to_callback = function(name, func, desc)
        local t = { {func, desc} }
        for _,v in ipairs(luatexbase.callback_descriptions(name)) do
            table.insert(t, {luatexbase.remove_from_callback(name, v)})
        end
        for _,v in ipairs(t) do
            luatexbase.add_to_callback(name, v[1], v[2])
        end
    end
end

prepend_to_callback ("pre_linebreak_filter",
    function(head)
        head = auto_josa(head)
        head = korean_break(head, true)
        head = reorder_tm(head)
        return head
    end,
    "polyglossia.lang_korean")

prepend_to_callback ("hpack_filter",
    function(head)
        head = auto_josa(head)
        head = korean_break(head)
        head = reorder_tm(head)
        return head
    end,
    "polyglossia.lang_korean")

-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab
%    \end{macrocode}
% \iffalse
%</polyglossia-korean.lua>
%<*polyglossia-latin.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-latin.lua}
%    \begin{macrocode}
require('polyglossia-punct')

-- For ecclesiastic Latin (and sometimes for Italian) a very small space is
-- used for the punctuation. The ecclesiastic package uses a space of
-- 0.3\fontdimen2, where \fontdimen2 is a interword space, which is typically
-- between 1/4 and 1/3 of a quad. We choose a half of a \thinspace here.
local hairspace = 0.08333 -- 1/12

local function space_left(char)
    polyglossia.add_left_spaced_character('latin', char, hairspace, 'quad')
end

local function space_right(char)
    polyglossia.add_right_spaced_character('latin', char, hairspace, 'quad')
end

polyglossia.clear_spaced_characters('latin')
space_left('!')
space_left('?')
space_left('‼')
space_left('⁇')
space_left('⁈')
space_left('⁉')
space_left('‽') -- U+203D (interrobang)
space_left(':')
space_left(';')
space_left('»')
space_left('›')
space_right('«')
space_right('‹')

local function activate_latin_punct()
    polyglossia.activate_punct('latin')
end

local function deactivate_latin_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_latin_punct   = activate_latin_punct
polyglossia.deactivate_latin_punct = deactivate_latin_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-latin.lua>
%<*polyglossia-punct.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-punct.lua}
%    \begin{macrocode}
require('polyglossia') -- just in case...

local add_to_callback      = luatexbase.add_to_callback
local remove_from_callback = luatexbase.remove_from_callback
local priority_in_callback = luatexbase.priority_in_callback
local new_attribute        = luatexbase.new_attribute

local node = node

local insert_node_before = node.insert_before
local insert_node_after  = node.insert_after
local remove_node        = node.remove
local has_attribute      = node.has_attribute
local node_copy          = node.copy
local new_node           = node.new
local end_of_math        = node.end_of_math
local getnext            = node.getnext
local getprev            = node.getprev

-- node types according to node.types()
local glue_code    = node.id"glue"
local glyph_code   = node.id"glyph"
local penalty_code = node.id"penalty"
local kern_code    = node.id"kern"
local math_code    = node.id"math"

-- we need some node subtypes
local userkern = 1
local userskip = 0
local removable_skip = {
    [0]  = true, -- userskip
    [13] = true, -- spaceskip
    [14] = true, -- xspaceskip
}

-- we make a new node, so that we can copy it later on
local kern_node = new_node(kern_code)
kern_node.subtype = userkern -- this kern can be removed later on

local function get_kern_node(dim)
    local n = node_copy(kern_node)
    n.kern = dim
    return n
end

local glue_node = new_node(glue_code)
glue_node.subtype = userskip

local function get_glue_node(dim, stretch, shrink)
    local n   = node_copy(glue_node)
    n.width   = dim
    n.stretch = stretch
    n.shrink  = shrink
    return n
end

local penalty_node   = new_node(penalty_code)
penalty_node.penalty = 10000

local function get_penalty_node()
    return node_copy(penalty_node)
end

-- all possible space characters according to section 6.2 of the Unicode Standard
-- https://www.unicode.org/versions/Unicode12.0.0/ch06.pdf
local space_chars = {
    [0x20] = true, -- space
    [0xA0] = true, -- no-break space
    [0x1680] = true, -- ogham space mark
    [0x2000] = true, -- en quad
    [0x2001] = true, -- em quad
    [0x2002] = true, -- en space
    [0x2003] = true, -- em space
    [0x2004] = true, -- three-per-em-space
    [0x2005] = true, -- four-per-em space
    [0x2006] = true, -- six-per-em space
    [0x2007] = true, -- figure space
    [0x2008] = true, -- punctuation space
    [0x2009] = true, -- thin space
    [0x200A] = true, -- hair space
    [0x202F] = true, -- narrow no-break space
    [0x205F] = true, -- medium mathematical space
    [0x3000] = true -- ideographic space
}

-- all left bracket characters, referenced by their Unicode slot
local left_bracket_chars = {
    [0x28] = true, -- left parenthesis
    [0x5B] = true, -- left square bracket
    [0x7B] = true, -- left curly bracket
    [0x27E8] = true -- mathematical left angle bracket
}

-- all right bracket characters, referenced by their Unicode slot
local right_bracket_chars = {
    [0x29] = true,  -- right parenthesis
    [0x5D] = true,  -- right square bracket
    [0x7D] = true,  -- right curly bracket
    [0x27E9] = true -- mathematical right angle bracket
}

-- question and exclamation marks, referenced by their Unicode slot
local question_exclamation_chars = {
    [0x21] = true,   -- exclamation mark !
    [0x3F] = true,   -- question mark ?
    [0x203C] = true, -- double exclamation mark ‼
    [0x203D] = true, -- interrobang ‽
    [0x2047] = true, -- double question mark ⁇
    [0x2048] = true, -- question exclamation mark ⁈
    [0x2049] = true  -- exclamation question mark ⁉
}

-- from nodes-tst.lua, adapted
local function somespace(n)
    if n then
        local id, subtype = n.id, n.subtype
        if id == glue_code then
            -- it is dangerous to remove all the type of glue
            return removable_skip[subtype]
        elseif id == kern_code then
            -- remove only user's kern
            return subtype == userkern
        elseif id == glyph_code then
            return space_chars[n.char]
        end
    end
end

local function someleftbracket(n)
    if n then
        local id = n.id
        if id == glyph_code then
            return left_bracket_chars[n.char]
        end
    end
end

local function somerightbracket(n)
    if n then
        local id = n.id
        if id == glyph_code then
            return right_bracket_chars[n.char]
        end
    end
end

local function question_exclamation_sequence(n1, n2)
    if n1 and n2 then
        local id1 = n1.id
        local id2 = n2.id
        if id1 == glyph_code and id2 == glyph_code then
            return question_exclamation_chars[n1.char] and question_exclamation_chars[n2.char]
        end
    end
end

-- idem
local function somepenalty(n, value)
    if n then
        local id = n.id
        if id == penalty_code then
            if value then
                return n.penalty == value
            else
                return true
            end
        end
    end
end

local punct_attr = new_attribute("polyglossia_punct")

local lang_id      = {}
local lang_counter = 0
local left_space   = {}
local right_space  = {}

local function ensure_lang_id(lang)
    if not lang_id[lang] then
        lang_counter = lang_counter + 1
        lang_id[lang] = lang_counter
    end
    return lang_id[lang]
end

local function clear_spaced_characters(lang)
    local id = ensure_lang_id(lang)
    left_space[id]  = {}
    right_space[id] = {}
end

local function illegal_unit(unit)
    if unit then
        texio.write_nl('Illegal spacing unit "'..unit..'".')
    else
        texio.write_nl('Spacing unit is a nil value.')
    end
end

local function add_left_spaced_character(lang, char, kern, unit, rubber)
-- The parameter kern is a number meant as a fraction of the unit.
-- The unit can be "quad" (1em) or "space" (interword space).
-- The parameter rubber is a Boolean value indicating if the inserted space is
-- stretchable and shrinkable (only relevant if the unit is "space").
    local id = ensure_lang_id(lang)
    if unit == "quad" or unit == "space" then
        left_space[id][char] = {}
        left_space[id][char]["kern"] = kern
        left_space[id][char]["unit"] = unit
        left_space[id][char]["rubber"] = rubber
    else
        illegal_unit(unit)
    end
end

local function add_right_spaced_character(lang, char, kern, unit, rubber)
    local id = ensure_lang_id(lang)
    if unit == "quad" or unit == "space" then
        right_space[id][char] = {}
        right_space[id][char]["kern"] = kern
        right_space[id][char]["unit"] = unit
        right_space[id][char]["rubber"] = rubber
    else
        illegal_unit(unit)
    end
end

-- from typo-spa.lua, adapted
local function process(head)
    local current = head
    while current do
        local id = current.id
        if id == glyph_code then
            local attr = has_attribute(current, punct_attr)
            if attr then
                local char, leftspace, rightspace
                if current.char <= 0x10FFFF then -- greater values may cause problems with utf8.char
                    char = utf8.char(current.char)
                    leftspace  = left_space[attr][char]
                    rightspace = right_space[attr][char]
                end
                if leftspace or rightspace then
                    local fontparameters = fonts.hashes.parameters[current.font]
                    local unit, stretch, shrink, spacing_node
                    if leftspace and fontparameters then
                        local prev = getprev(current)
                        local space_exception = false
                        if prev then
                            -- do not add space after left (opening) bracket and between question/exclamation marks
                            space_exception = someleftbracket(prev) or question_exclamation_sequence(prev, current)
                            -- TODO: there is a question here: do we override a preceding space or not?...
                            while somespace(prev) do
                                head = remove_node(head, prev)
                                prev = getprev(current)
                            end
                            if somepenalty(prev, 10000) then
                                head = remove_node(head, prev)
                            end
                        end
                        if leftspace.unit == "quad" then
                            unit = fontparameters.quad
                            spacing_node = get_kern_node(leftspace.kern*unit)
                        elseif leftspace.unit == "space" then
                            unit = fontparameters.space
                            if leftspace.rubber then
                                stretch = leftspace.kern*fontparameters.space_stretch
                                shrink  = leftspace.kern*fontparameters.space_shrink
                                spacing_node = get_glue_node(leftspace.kern*unit, stretch, shrink)
                                head = insert_node_before(head, current, get_penalty_node())
                            else
                                spacing_node = get_kern_node(leftspace.kern*unit)
                            end
                        end
                        if not space_exception then
                            head = insert_node_before(head, current, spacing_node)
                        end
                    end
                    if rightspace and fontparameters then
                        local next = getnext(current)
                        local space_exception = false
                        if next then
                            -- do not add space before right (closing) bracket
                            space_exception = somerightbracket(next)
                            local nextnext = getnext(next)
                            if somepenalty(next, 10000) and somespace(nextnext) then
                                head, next = remove_node(head, next)
                            end
                            while somespace(next) do
                                head, next = remove_node(head, next)
                            end
                        end
                        if rightspace.unit == "quad" then
                            unit = fontparameters.quad
                            spacing_node = get_kern_node(rightspace.kern*unit)
                        elseif rightspace.unit == "space" then
                            unit = fontparameters.space
                            if rightspace.rubber then
                                stretch = rightspace.kern*fontparameters.space_stretch
                                shrink  = rightspace.kern*fontparameters.space_shrink
                                spacing_node = get_glue_node(rightspace.kern*unit, stretch, shrink)
                                if not space_exception then
                                    head, current = insert_node_after(head, current, get_penalty_node())
                                end
                            else
                                spacing_node = get_kern_node(rightspace.kern*unit)
                            end
                        end
                        if not space_exception then
                            head, current = insert_node_after(head, current, spacing_node)
                        end
                    end
                end
            end
        elseif id == math_code then
            -- warning: this is a feature of luatex > 0.76
            current = end_of_math(current) -- weird, can return nil .. no math end?
        end
        current = getnext(current) -- no error even if current is nil
    end
    return head
end

local function activate(lang)
    local id = ensure_lang_id(lang)
    -- We set the punctuation attribute to a language id here. This is
    -- important to be able to intermix languages with different spacings
    -- in one paragraph.
    tex.setattribute(punct_attr, id)
    for _, callback_name in ipairs{ "pre_linebreak_filter", "hpack_filter" } do
        if not priority_in_callback(callback_name, "polyglossia-punct.process") then
            add_to_callback(callback_name, process, "polyglossia-punct.process", 1)
        end
    end
end

local function deactivate()
    tex.setattribute(punct_attr, -0x7FFFFFFF) -- this value means "unset"
    -- Though it would make compilation slightly faster, it is not possible to
    -- safely uncomment the following lines. Imagine the following case: you
    -- start a paragraph by some spaced punctuation text, then, in the same
    -- paragraph, you change the language to something else, and thus call the
    -- following lines. This means that, at the end of the paragraph, the
    -- function won't be in the callback, so the beginning of the paragraph
    -- won't be processed by it.
    -- if priority_in_callback(callback_name, "polyglossia-punct.process") then
    --     remove_from_callback(callback_name, "polyglossia-punct.process")
    -- end
end

polyglossia.activate_punct             = activate
polyglossia.deactivate_punct           = deactivate
polyglossia.add_left_spaced_character  = add_left_spaced_character
polyglossia.add_right_spaced_character = add_right_spaced_character
polyglossia.clear_spaced_characters    = clear_spaced_characters
%    \end{macrocode}
% \iffalse
%</polyglossia-punct.lua>
%<*polyglossia-sanskrit.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-sanskrit.lua}
%    \begin{macrocode}
require('polyglossia-punct')

-- How do we now, in Lua, what a \thinspace is? In the LaTeX source (latex.ltx)
-- it is defined as:
-- \def\thinspace{\leavevmode@ifvmode\kern .16667em }
-- I see no way of seeing if it has been overriden or not. So we stick to this
-- value.
local thinspace = 0.16667 -- 1/6

local function space_left(char)
    polyglossia.add_left_spaced_character('sanskrit', char, thinspace, 'quad')
end

polyglossia.clear_spaced_characters('sanskrit')
space_left('!')
space_left('?')
space_left('‼')
space_left('⁇')
space_left('⁈')
space_left('⁉')
space_left('‽') -- U+203D (interrobang)
space_left(':')
space_left(';')
space_left('।') -- danda, U+0964
space_left('॥') -- double danda, U+0965

local function activate_sanskrit_punct()
    polyglossia.activate_punct('sanskrit')
end

local function deactivate_sanskrit_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_sanskrit_punct   = activate_sanskrit_punct
polyglossia.deactivate_sanskrit_punct = deactivate_sanskrit_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-sanskrit.lua>
%<*polyglossia-tibt.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-tibt.lua}
%    \begin{macrocode}
require('polyglossia') -- just in case...

local add_to_callback = luatexbase.add_to_callback
local remove_from_callback = luatexbase.remove_from_callback
local priority_in_callback = luatexbase.priority_in_callback

local next, type = next, type

local nodes, fonts, node = nodes, fonts, node

local nodecodes          = nodes.nodecodes --- <= preloaded node.types()

local insert_node_before = node.insert_before
local insert_node_after  = node.insert_after
local remove_node        = nodes.remove
local copy_node          = node.copy
local has_attribute      = node.has_attribute

local end_of_math        = node.end_of_math
if not end_of_math then -- luatex < .76
  local traverse_nodes = node.traverse_id
  local math_code      = nodecodes.math
  local end_of_math = function (n)
    for n in traverse_nodes(math_code, n.next) do
      return n
    end
  end
end

-- node types as of April 2013
local glyph_code         = nodecodes.glyph
local penalty_code       = nodecodes.penalty
local kern_code          = nodecodes.kern

-- we make a new node, so that we can copy it later on
local penalty_node  = node.new(penalty_code)
penalty_node.penalty = 50 -- corresponds to the penalty LaTeX sets at explicit hyphens

local function get_penalty_node()
  return copy_node(penalty_node)
end

local xpgtibtattr = luatexbase.attributes['xpg@tibteol']

local tsheg = unicode.utf8.byte('་')

-- from typo-spa.lua
local function process(head)
    local start = head
    -- head is always begin of par (whatsit), so we have at least two prev nodes
    -- penalty followed by glue
    while start do
        local id = start.id
        if id == glyph_code then 
            local attr = has_attribute(start, xpgtibtattr)
            if attr and attr > 0 then
                if start.char == tsheg then
                    if start.next then
                        insert_node_after(head,start,get_penalty_node())
                    end
                end
            end
        elseif id == math_code then
            -- warning: this is a feature of luatex > 0.76
            start = end_of_math(start) -- weird, can return nil .. no math end?
        end
        if start then
            start = start.next
        end
    end
    return head
end

local callback_name = "pre_linebreak_filter"

local function activate()
  if not priority_in_callback (callback_name, "polyglossia-tibt.process") then
    add_to_callback(callback_name, process, "polyglossia-tibt.process", 1)
  end
end

local function desactivate()
  if priority_in_callback (callback_name, "polyglossia-tibt.process") then
    remove_from_callback(callback_name, "polyglossia-tibt.process")
  end
end

polyglossia.activate_tibt_eol    = activate
polyglossia.desactivate_tibt_eol = desactivate
%    \end{macrocode}
% \iffalse
%</polyglossia-tibt.lua>
%<*polyglossia.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia.lua}
%    \begin{macrocode}

local module_name = "polyglossia"
local polyglossia_module = {
    name          = module_name,
    version       = 1.3,
    date          = "2013/05/11",
    description   = "Polyglossia",
    author        = "Elie Roux",
    copyright     = "Elie Roux",
    license       = "CC0"
}

luatexbase.provides_module(polyglossia_module)

local log_info = function(message, ...)
    luatexbase.module_info(module_name, message:format(...))
end
local log_warn = function(message, ...)
    luatexbase.module_warning(module_name, message:format(...))
end

polyglossia = polyglossia or {}
local polyglossia = polyglossia

local function select_language(lang, id)
    polyglossia.current_language = lang
end

local function set_default_language(lang, id)
    polyglossia.default_language = lang
end

local byte = utf8.codepoint -- use standard module of lua 5.3

local check_char

if luaotfload and luaotfload.aux and luaotfload.aux.font_has_glyph then
    local font_has_glyph = luaotfload.aux.font_has_glyph
    function check_char(chr)
        local codepoint = tonumber(chr) or byte(chr)
        if font_has_glyph(font.current(), codepoint) then
            tex.sprint('1')
        else
            tex.sprint('0')
        end
    end
else
    function check_char(chr) -- always in current font
        local fontid    = font.current()
        local fontdata  = font.getfont(fontid) or font.fonts[fontid]
        local chardata  = fontdata.characters
        local codepoint = tonumber(chr) or byte(chr)
        if chardata and chardata[codepoint] then
            tex.sprint('1')
        else
            tex.sprint('0')
        end
    end
end

local function load_tibt_eol()
    require('polyglossia-tibt')
end

-- predefined l@nohyphenation or LuaTeX's maximum value for \language
local nohyphid = luatexbase.registernumber'l@nohyphenation' or 16383

-- key `nohyphenation` is for .sty file when possibly undefined l@nohyphenation
local newloader_loaded_languages = { nohyphenation = nohyphid }

local newloader_available_languages = require'language.dat.lua'
-- Suggestion by Dohyun Kim on #129
local t = { }
for k, v in pairs(newloader_available_languages) do
    t[k] = v
    for _, vv in pairs(v.synonyms) do
        t[vv] = v
    end
end
newloader_available_languages = t

-- LaTeX's language register is \count19
local lang_register = 19

-- New hyphenation pattern loader: use language.dat.lua directly and the language identifiers
local function newloader(langentry)
    local loaded_language = newloader_loaded_languages[langentry]
    if loaded_language then
        local langid = lang.id(loaded_language)
        log_info('Language %s already loaded; id is %i', langentry, langid)
        return langid
    else
        local langdata = newloader_available_languages[langentry]
        if langdata then

            local special = langdata.special
            if special then
                -- language0 (USenglish) is already included in the format
                if special == 'language0' then
                    return 0

                -- disabled language should not be used for utf-8 text
                elseif special:find'^disabled:' then
                    log_warn('Hyphenation of language %s %s', langentry, special)
                    return nohyphid
                end
            end

            -- language info will be written into the .log file
            local s = { "Language data for " .. langentry }
            for k, v in pairs(langdata) do
                if type(v) == 'table' then -- for 'synonyms'
                    s[#s+1] = k .. "\t" .. table.concat(v,',')
                else
                    s[#s+1] = k .. "\t" .. tostring(v)
                end
            end
            log_info(table.concat(s,"\n"))

            --
            -- LaTeX's \newlanguage increases language register (count19),
            -- whereas LuaTeX's lang.new() increases its own language id.
            -- So when a user has declared, say, \newlanguage\lang@xyz, then
            -- these two numbers do not match each other. If we do not consider
            -- this possible situation, our newloader() function will
            -- unfortunately overwrite the language \lang@xyz.
            --
            -- Threfore here we will compare LaTeX's \newlanguage number with
            -- LuaTeX's lang.new() id and select the bigger one for our new
            -- language object. Also we will update LaTeX's language register
            -- by this new id, so that another possible \newlanguage should not
            -- overwrite our language object.
            --
            -- get next \newlanguage allocation number
            local langcnt = tex.count[lang_register] + 1
            -- get new lang object
            local langobject = lang.new()
            local langid = lang.id(langobject)
            -- get bigger one between \newlanguage and new lang obj id
            local newlangid = math.max(langcnt, langid)
            -- set language register for possible \newlanguage
            tex.setcount('global', lang_register, newlangid)
            -- get new lang object if needeed
            if langid ~= newlangid then
                langobject = lang.new(newlangid)
            end

            -- load hyphenation patterns and exceptions
            for _,v in ipairs{ 'patterns', 'hyphenation' } do
                local data = langdata[v]
                if data and data ~= '' then
                    -- cope with comma separated list, such as serbian
                    for _,vv in ipairs(data:explode',+') do
                        local filepath = kpse.find_file(vv)
                        if filepath then
                            local fh = io.open(filepath)
                            lang[v](langobject, fh:read'a')
                            fh:close()
                        else
                            log_warn('Hyphenation file %s not found', vv)
                        end
                    end
                end
            end

            newloader_loaded_languages[langentry] = langobject

            log_info('Language %s was not yet loaded; created with id %i',
                     langentry, newlangid)
            return newlangid
        else
            log_warn('Language %s not found in language.dat.lua', langentry)
            return nohyphid
        end
    end
end

polyglossia.select_language = select_language
polyglossia.set_default_language = set_default_language
polyglossia.check_char = check_char
polyglossia.load_tibt_eol = load_tibt_eol
polyglossia.newloader = newloader
polyglossia.newloader_loaded_languages = newloader_loaded_languages
-- global variables:
-- polyglossia.default_language
-- polyglossia.current_language
%    \end{macrocode}
% \iffalse
%</polyglossia.lua>
%<*babel-hebrewalph.def>
% \fi
% \clearpage
% 
% \subsection{babel-hebrewalph.def}
%    \begin{macrocode}
\ProvidesFile{babel-hebrewalph.def}
         [2010/03/02 %
         Babel definitions for Hebrew numerals^^J
         Adapted from hebrew.ldf (2005/03/30 v2.3h)]
\newif\if@gim@apost  % whether we print apostrophes (gereshayim)
\newif\if@gim@final  % whether we use final or initial letters
\newcommand*\hebrewnumeral[1]{%
  \expandafter\@hebrew@numeral\expandafter{\the\numexpr#1}%
}
\newcommand*\Hebrewnumeral[1]{%
  \expandafter\@Hebrew@numeral\expandafter{\the\numexpr#1}%
}
\newcommand*\Hebrewnumeralfinal[1]{%
  \expandafter\@Hebrew@numeralfinal\expandafter{\the\numexpr#1}%
}
\newrobustcmd*{\@hebrew@numeral}[1]      % no apostrophe, no final letters
 {{\@gim@finalfalse\@gim@apostfalse\@hebrew@@numeral{#1}}}
\newrobustcmd*{\@Hebrew@numeral}[1]      % apostrophe, no final letters
 {{\@gim@finalfalse\@gim@aposttrue\@hebrew@@numeral{#1}}}
\newrobustcmd*{\@Hebrew@numeralfinal}[1] % apostrophe, final letters
 {{\@gim@finaltrue\@gim@aposttrue\@hebrew@@numeral{#1}}}
\newcommand*{\@hebrew@@numeral}[1]{%
  \ifnum#1<\z@\space\xpg@warning{Illegal value (#1) for Hebrew numeral}%
  \else
    \@tempcnta=#1\@tempcntb=#1\relax
    \divide\@tempcntb by 1000
    \ifnum\@tempcntb=0\gim@nomil\@tempcnta\relax
    \else{\@gim@apostfalse\@gim@finalfalse\@hebrew@numeral\@tempcntb}׳%
          \multiply\@tempcntb by 1000\relax
          \advance\@tempcnta by -\@tempcntb\relax
          \gim@nomil\@tempcnta\relax
    \fi
  \fi
}
\def\hebrew@alph@zero{}
\newcommand*{\gim@nomil}[1]{\@tempcnta=#1\@gim@prevfalse
  \@tempcntb=\@tempcnta\divide\@tempcntb by 100\relax % hundreds digit
  \ifcase\@tempcntb                     % print nothing if no hundreds
     \or\gim@print{100}{ק}%
     \or\gim@print{200}{ר}%
     \or\gim@print{300}{ש}%
     \or\gim@print{400}{ת}%
     \or ת\@gim@prevtrue\gim@print{500}{ק}%
     \or ת\@gim@prevtrue\gim@print{600}{ר}%
     \or ת\@gim@prevtrue\gim@print{700}{ש}%
     \or ת\@gim@prevtrue\gim@print{800}{ת}%
     \or ת\@gim@prevtrue ת\gim@print{900}{ק}%
  \fi
  \@tempcntb=\@tempcnta\divide\@tempcntb by 10\relax      % tens digit
  \ifcase\@tempcntb                         % print nothing if no tens
      \or                                   % number between 10 and 19
              \ifnum\@tempcnta = 16 \gim@print {9}{ט}% tet-zayin
         \else\ifnum\@tempcnta = 15 \gim@print {9}{ט}% tet-vav
         \else                      \gim@print{10}{י}%
              \fi % \@tempcnta = 15
              \fi % \@tempcnta = 16
      \or\gim@print{20}{\if@gim@final ך\else כ\fi}%
      \or\gim@print{30}{ל}%
      \or\gim@print{40}{\if@gim@final ם\else מ\fi}%
      \or\gim@print{50}{\if@gim@final ן\else נ\fi}%
      \or\gim@print{60}{ס}%
      \or\gim@print{70}{ע}%
      \or\gim@print{80}{\if@gim@final ף\else פ\fi}%
      \or\gim@print{90}{\if@gim@final ץ\else צ\fi}%
  \fi
  \ifcase\@tempcnta
      \hebrew@alph@zero%  empty but can be defined if desired
      \or\gim@print{1}{א}%
      \or\gim@print{2}{ב}%
      \or\gim@print{3}{ג}%
      \or\gim@print{4}{ד}%
      \or\gim@print{5}{ה}%
      \or\gim@print{6}{ו}%
      \or\gim@print{7}{ז}%
      \or\gim@print{8}{ח}%
      \or\gim@print{9}{ט}%
  \fi
}
\newif\if@gim@prev % flag if a previous letter has been typeset
\newcommand*{\gim@print}[2]{%   #2 is a letter, #1 is its value.
  \advance\@tempcnta by -#1\relax% deduct the value from the remainder
  \ifnum\@tempcnta=0% if this is the last letter
     \if@gim@prev\if@gim@apost ״\fi#2%
     \else#2\if@gim@apost ׳\fi\fi%
  \else{\@gim@finalfalse#2}\@gim@prevtrue\fi}
\def\Alphfinal#1{\expandafter\@Alphfinal\csname c@#1\endcsname}%
\providecommand*{\@Alphfinal}[1]{\Hebrewnumeralfinal{#1}}
%    \end{macrocode}
% \iffalse
%</babel-hebrewalph.def>
%<*babelsh.def>
% \fi
% \clearpage
% 
% \subsection{babelsh.def}
%    \begin{macrocode}
\ifx\initiate@active@char\@undefined
\else
  \bbl@afterfi\endinput
\fi
\ProvidesFile{babelsh.def}
         [2019/09/30 %
         Babel common definitions for shorthands^^J
         Taken verbatim from babel files (2019/09/27 v3.34)]
%
% ------------------------------------------------------------------------------
%
% lines 52 to 56 from babel.sty
%
% ------------------------------------------------------------------------------
%
\def\bbl@stripslash{\expandafter\@gobble\string}
\def\bbl@add#1#2{%
  \bbl@ifunset{\bbl@stripslash#1}%
    {\def#1{#2}}%
    {\expandafter\def\expandafter#1\expandafter{#1#2}}}
%
% ------------------------------------------------------------------------------
%
% line 73 to 74 from babel.sty
%
% ------------------------------------------------------------------------------
%
\long\def\bbl@afterelse#1\else#2\fi{\fi#1}
\long\def\bbl@afterfi#1\fi{\fi#1}
%
% ------------------------------------------------------------------------------
%
% line 399 from babel.sty
%
% ------------------------------------------------------------------------------
%
\let\bbl@opt@shorthands\@nnil
%
% ------------------------------------------------------------------------------
%
% lines 432 to 445 from babel.sty
%
% ------------------------------------------------------------------------------
%
\ifx\bbl@opt@shorthands\@nnil
  \def\bbl@ifshorthand#1#2#3{#2}%
\else\ifx\bbl@opt@shorthands\@empty
  \def\bbl@ifshorthand#1#2#3{#3}%
\else
  \def\bbl@ifshorthand#1{%
    \bbl@xin@{\string#1}{\bbl@opt@shorthands}%
    \ifin@
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi}
  \edef\bbl@opt@shorthands{%
    \expandafter\bbl@sh@string\bbl@opt@shorthands\@empty}%
%
% ------------------------------------------------------------------------------
%
% line 450 from babel.sty
%
% ------------------------------------------------------------------------------
%
\fi\fi
%
% ------------------------------------------------------------------------------
%
% lines 389 to 424 from switch.def
%
% ------------------------------------------------------------------------------
%
\ifx\PackageError\@undefined
  \def\bbl@error#1#2{%
    \begingroup
      \newlinechar=`\^^J
      \def\\{^^J(babel) }%
      \errhelp{#2}\errmessage{\\#1}%
    \endgroup}
  \def\bbl@warning#1{%
    \begingroup
      \newlinechar=`\^^J
      \def\\{^^J(polyglossia) }%
      \message{\\#1}%
    \endgroup}
  \def\bbl@info#1{%
    \begingroup
      \newlinechar=`\^^J
      \def\\{^^J}%
      \wlog{#1}%
    \endgroup}
\else
  \def\bbl@error#1#2{%
    \begingroup
      \def\\{\MessageBreak}%
      \PackageError{polyglossia}{#1}{#2}%
    \endgroup}
  \def\bbl@warning#1{%
    \begingroup
      \def\\{\MessageBreak}%
      \PackageWarning{polyglossia}{#1}%
    \endgroup}
  \def\bbl@info#1{%
    \begingroup
      \def\\{\MessageBreak}%
      \PackageInfo{polyglossia}{#1}%
    \endgroup}
\fi
%
% ------------------------------------------------------------------------------
%
% lines 48 to 69 from babel.def
%
% ------------------------------------------------------------------------------
%
\ifx\bbl@ifshorthand\@undefined
  \let\bbl@opt@shorthands\@nnil
  \def\bbl@ifshorthand#1#2#3{#2}%
  \let\bbl@language@opts\@empty
  \ifx\babeloptionstrings\@undefined
    \let\bbl@opt@strings\@nnil
  \else
    \let\bbl@opt@strings\babeloptionstrings
  \fi
  \def\BabelStringsDefault{generic}
  \def\bbl@tempa{normal}
  \ifx\babeloptionmath\bbl@tempa
    \def\bbl@mathnormal{\noexpand\textormath}
  \fi
  \def\AfterBabelLanguage#1#2{}
  \ifx\BabelModifiers\@undefined\let\BabelModifiers\relax\fi
  \let\bbl@afterlang\relax
  \def\bbl@opt@safe{BR}
  \ifx\@uclclist\@undefined\let\@uclclist\@empty\fi
  \ifx\bbl@trace\@undefined\def\bbl@trace#1{}\fi
  \expandafter\newif\csname ifbbl@single\endcsname
\fi
%
% ------------------------------------------------------------------------------
%
% line 108 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@csarg#1#2{\expandafter#1\csname bbl@#2\endcsname}%

% ------------------------------------------------------------------------------
%
% lines 110 to 116 from babel.def
%
% ------------------------------------------------------------------------------
%

\def\bbl@loop#1#2#3{\bbl@@loop#1{#3}#2,\@nnil,}
\def\bbl@loopx#1#2{\expandafter\bbl@loop\expandafter#1\expandafter{#2}}
\def\bbl@@loop#1#2#3,{%
  \ifx\@nnil#3\relax\else
    \def#1{#3}#2\bbl@afterfi\bbl@@loop#1{#2}%
  \fi}
\def\bbl@for#1#2#3{\bbl@loopx#1{#2}{\ifx#1\@empty\else#3\fi}}

% ------------------------------------------------------------------------------
%
% lines 125 to 130 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@exp#1{%
  \begingroup
    \let\\\noexpand
    \def\<##1>{\expandafter\noexpand\csname##1\endcsname}%
    \edef\bbl@exp@aux{\endgroup#1}%
  \bbl@exp@aux}
%
% ------------------------------------------------------------------------------
%
% lines 144 to 149 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@ifunset#1{%
  \expandafter\ifx\csname#1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
%
% ------------------------------------------------------------------------------
%
% lines 234 to 243 from babel.def
%
% ------------------------------------------------------------------------------
%
\chardef\bbl@engine=%
  \ifx\directlua\@undefined
    \ifx\XeTeXinputencoding\@undefined
      \z@
    \else
      \tw@
    \fi
  \else
    \@ne
  \fi
%
% ------------------------------------------------------------------------------
%
% lines 255 to 258 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@withactive#1#2{%
  \begingroup
    \lccode`~=`#2\relax
    \lowercase{\endgroup#1~}}
%
% ------------------------------------------------------------------------------
%
% lines 293 to 301 from babel.def
%
% NOTE: In order to avoid importing more unneeded definitions, this macro
%       does nothing for us.
%
% ------------------------------------------------------------------------------
%
\def\bbl@usehooks#1#2{}
%
% ------------------------------------------------------------------------------
%
% lines 443 to 558 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@add@special#1{% 1:a macro like \", \?, etc.
  \bbl@add\dospecials{\do#1}% test @sanitize = \relax, for back. compat.
  \bbl@ifunset{@sanitize}{}{\bbl@add\@sanitize{\@makeother#1}}%
  \ifx\nfss@catcodes\@undefined\else % TODO - same for above
    \begingroup
      \catcode`#1\active
      \nfss@catcodes
      \ifnum\catcode`#1=\active
        \endgroup
        \bbl@add\nfss@catcodes{\@makeother#1}%
      \else
        \endgroup
      \fi
  \fi}
\def\bbl@remove@special#1{%
  \begingroup
    \def\x##1##2{\ifnum`#1=`##2\noexpand\@empty
                 \else\noexpand##1\noexpand##2\fi}%
    \def\do{\x\do}%
    \def\@makeother{\x\@makeother}%
  \edef\x{\endgroup
    \def\noexpand\dospecials{\dospecials}%
    \expandafter\ifx\csname @sanitize\endcsname\relax\else
      \def\noexpand\@sanitize{\@sanitize}%
    \fi}%
  \x}
\def\bbl@active@def#1#2#3#4{%
  \@namedef{#3#1}{%
    \expandafter\ifx\csname#2@sh@#1@\endcsname\relax
      \bbl@afterelse\bbl@sh@select#2#1{#3@arg#1}{#4#1}%
    \else
      \bbl@afterfi\csname#2@sh@#1@\endcsname
    \fi}%
  \long\@namedef{#3@arg#1}##1{%
    \expandafter\ifx\csname#2@sh@#1@\string##1@\endcsname\relax
      \bbl@afterelse\csname#4#1\endcsname##1%
    \else
      \bbl@afterfi\csname#2@sh@#1@\string##1@\endcsname
    \fi}}%
\def\initiate@active@char#1{%
  \bbl@ifunset{active@char\string#1}%
    {\bbl@withactive
      {\expandafter\@initiate@active@char\expandafter}#1\string#1#1}%
    {}}
\def\@initiate@active@char#1#2#3{%
  \bbl@csarg\edef{oricat@#2}{\catcode`#2=\the\catcode`#2\relax}%
  \ifx#1\@undefined
    \bbl@csarg\edef{oridef@#2}{\let\noexpand#1\noexpand\@undefined}%
  \else
    \bbl@csarg\let{oridef@@#2}#1%
    \bbl@csarg\edef{oridef@#2}{%
      \let\noexpand#1%
      \expandafter\noexpand\csname bbl@oridef@@#2\endcsname}%
  \fi
  \ifx#1#3\relax
    \expandafter\let\csname normal@char#2\endcsname#3%
  \else
    \bbl@info{Making #2 an active character}%
    \ifnum\mathcode`#2=\ifodd\bbl@engine"1000000 \else"8000 \fi
      \@namedef{normal@char#2}{%
        \textormath{#3}{\csname bbl@oridef@@#2\endcsname}}%
    \else
      \@namedef{normal@char#2}{#3}%
    \fi
    \bbl@restoreactive{#2}%
    \AtBeginDocument{%
      \catcode`#2\active
      \if@filesw
        \immediate\write\@mainaux{\catcode`\string#2\active}%
      \fi}%
    \expandafter\bbl@add@special\csname#2\endcsname
    \catcode`#2\active
  \fi
  \let\bbl@tempa\@firstoftwo
  \if\string^#2%
    \def\bbl@tempa{\noexpand\textormath}%
  \else
    \ifx\bbl@mathnormal\@undefined\else
      \let\bbl@tempa\bbl@mathnormal
    \fi
  \fi
  \expandafter\edef\csname active@char#2\endcsname{%
    \bbl@tempa
      {\noexpand\if@safe@actives
         \noexpand\expandafter
         \expandafter\noexpand\csname normal@char#2\endcsname
       \noexpand\else
         \noexpand\expandafter
         \expandafter\noexpand\csname bbl@doactive#2\endcsname
       \noexpand\fi}%
     {\expandafter\noexpand\csname normal@char#2\endcsname}}%
  \bbl@csarg\edef{doactive#2}{%
    \expandafter\noexpand\csname user@active#2\endcsname}%
  \bbl@csarg\edef{active@#2}{%
    \noexpand\active@prefix\noexpand#1%
    \expandafter\noexpand\csname active@char#2\endcsname}%
  \bbl@csarg\edef{normal@#2}{%
    \noexpand\active@prefix\noexpand#1%
    \expandafter\noexpand\csname normal@char#2\endcsname}%
  \expandafter\let\expandafter#1\csname bbl@normal@#2\endcsname
  \bbl@active@def#2\user@group{user@active}{language@active}%
  \bbl@active@def#2\language@group{language@active}{system@active}%
  \bbl@active@def#2\system@group{system@active}{normal@char}%
  \expandafter\edef\csname\user@group @sh@#2@@\endcsname
    {\expandafter\noexpand\csname normal@char#2\endcsname}%
  \expandafter\edef\csname\user@group @sh@#2@\string\protect@\endcsname
    {\expandafter\noexpand\csname user@active#2\endcsname}%
  \if\string'#2%
    \let\prim@s\bbl@prim@s
    \let\active@math@prime#1%
  \fi
  \bbl@usehooks{initiateactive}{{#1}{#2}{#3}}}
\@ifpackagewith{babel}{KeepShorthandsActive}%
  {\let\bbl@restoreactive\@gobble}%
  {\def\bbl@restoreactive#1{%
     \bbl@exp{%
%
% ------------------------------------------------------------------------------
%
% lines 561 to 755 from babel.def
%
% ------------------------------------------------------------------------------
%
       \\\AtEndOfPackage
         {\catcode`#1=\the\catcode`#1\relax}}}%
   \AtEndOfPackage{\let\bbl@restoreactive\@gobble}}
\def\bbl@sh@select#1#2{%
  \expandafter\ifx\csname#1@sh@#2@sel\endcsname\relax
    \bbl@afterelse\bbl@scndcs
  \else
    \bbl@afterfi\csname#1@sh@#2@sel\endcsname
  \fi}
\def\active@prefix#1{%
  \ifx\protect\@typeset@protect
  \else
    \ifx\protect\@unexpandable@protect
      \noexpand#1%
    \else
      \protect#1%
    \fi
    \expandafter\@gobble
  \fi}
\newif\if@safe@actives
\@safe@activesfalse
\def\bbl@restore@actives{\if@safe@actives\@safe@activesfalse\fi}
\def\bbl@activate#1{%
  \bbl@withactive{\expandafter\let\expandafter}#1%
    \csname bbl@active@\string#1\endcsname}
\def\bbl@deactivate#1{%
  \bbl@withactive{\expandafter\let\expandafter}#1%
    \csname bbl@normal@\string#1\endcsname}
\def\bbl@firstcs#1#2{\csname#1\endcsname}
\def\bbl@scndcs#1#2{\csname#2\endcsname}
\def\declare@shorthand#1#2{\@decl@short{#1}#2\@nil}
\def\@decl@short#1#2#3\@nil#4{%
  \def\bbl@tempa{#3}%
  \ifx\bbl@tempa\@empty
    \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@scndcs
    \bbl@ifunset{#1@sh@\string#2@}{}%
      {\def\bbl@tempa{#4}%
       \expandafter\ifx\csname#1@sh@\string#2@\endcsname\bbl@tempa
       \else
         \bbl@info
           {Redefining #1 shorthand \string#2\\%
            in language \CurrentOption}%
       \fi}%
    \@namedef{#1@sh@\string#2@}{#4}%
  \else
    \expandafter\let\csname #1@sh@\string#2@sel\endcsname\bbl@firstcs
    \bbl@ifunset{#1@sh@\string#2@\string#3@}{}%
      {\def\bbl@tempa{#4}%
       \expandafter\ifx\csname#1@sh@\string#2@\string#3@\endcsname\bbl@tempa
       \else
         \bbl@info
           {Redefining #1 shorthand \string#2\string#3\\%
            in language \CurrentOption}%
       \fi}%
    \@namedef{#1@sh@\string#2@\string#3@}{#4}%
  \fi}
\def\textormath{%
  \ifmmode
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi}
\def\user@group{user}
\def\language@group{english}
\def\system@group{system}
\def\useshorthands{%
  \@ifstar\bbl@usesh@s{\bbl@usesh@x{}}}
\def\bbl@usesh@s#1{%
  \bbl@usesh@x
    {\AddBabelHook{babel-sh-\string#1}{afterextras}{\bbl@activate{#1}}}%
    {#1}}
\def\bbl@usesh@x#1#2{%
  \bbl@ifshorthand{#2}%
    {\def\user@group{user}%
     \initiate@active@char{#2}%
     #1%
     \bbl@activate{#2}}%
    {\bbl@error
       {Cannot declare a shorthand turned off (\string#2)}
       {Sorry, but you cannot use shorthands which have been\\%
        turned off in the package options}}}
\def\user@language@group{user@\language@group}
\def\bbl@set@user@generic#1#2{%
  \bbl@ifunset{user@generic@active#1}%
    {\bbl@active@def#1\user@language@group{user@active}{user@generic@active}%
     \bbl@active@def#1\user@group{user@generic@active}{language@active}%
     \expandafter\edef\csname#2@sh@#1@@\endcsname{%
       \expandafter\noexpand\csname normal@char#1\endcsname}%
     \expandafter\edef\csname#2@sh@#1@\string\protect@\endcsname{%
       \expandafter\noexpand\csname user@active#1\endcsname}}%
  \@empty}
\newcommand\defineshorthand[3][user]{%
  \edef\bbl@tempa{\zap@space#1 \@empty}%
  \bbl@for\bbl@tempb\bbl@tempa{%
    \if*\expandafter\@car\bbl@tempb\@nil
      \edef\bbl@tempb{user@\expandafter\@gobble\bbl@tempb}%
      \@expandtwoargs
        \bbl@set@user@generic{\expandafter\string\@car#2\@nil}\bbl@tempb
    \fi
    \declare@shorthand{\bbl@tempb}{#2}{#3}}}
\def\languageshorthands#1{\def\language@group{#1}}
\def\aliasshorthand#1#2{%
  \bbl@ifshorthand{#2}%
    {\expandafter\ifx\csname active@char\string#2\endcsname\relax
       \ifx\document\@notprerr
         \@notshorthand{#2}%
       \else
         \initiate@active@char{#2}%
         \expandafter\let\csname active@char\string#2\expandafter\endcsname
           \csname active@char\string#1\endcsname
         \expandafter\let\csname normal@char\string#2\expandafter\endcsname
           \csname normal@char\string#1\endcsname
         \bbl@activate{#2}%
       \fi
     \fi}%
    {\bbl@error
       {Cannot declare a shorthand turned off (\string#2)}
       {Sorry, but you cannot use shorthands which have been\\%
        turned off in the package options}}}
\def\@notshorthand#1{%
  \bbl@error{%
    The character `\string #1' should be made a shorthand character;\\%
    add the command \string\useshorthands\string{#1\string} to
    the preamble.\\%
    I will ignore your instruction}%
   {You may proceed, but expect unexpected results}}
\newcommand*\shorthandon[1]{\bbl@switch@sh\@ne#1\@nnil}
\DeclareRobustCommand*\shorthandoff{%
  \@ifstar{\bbl@shorthandoff\tw@}{\bbl@shorthandoff\z@}}
\def\bbl@shorthandoff#1#2{\bbl@switch@sh#1#2\@nnil}
\def\bbl@switch@sh#1#2{%
  \ifx#2\@nnil\else
    \bbl@ifunset{bbl@active@\string#2}%
      {\bbl@error
         {I cannot switch `\string#2' on or off--not a shorthand}%
         {This character is not a shorthand. Maybe you made\\%
          a typing mistake? I will ignore your instruction}}%
      {\ifcase#1%
         \catcode`#212\relax
       \or
         \catcode`#2\active
       \or
         \csname bbl@oricat@\string#2\endcsname
         \csname bbl@oridef@\string#2\endcsname
       \fi}%
    \bbl@afterfi\bbl@switch@sh#1%
  \fi}
\def\babelshorthand{\active@prefix\babelshorthand\bbl@putsh}
\def\bbl@putsh#1{%
  \bbl@ifunset{bbl@active@\string#1}%
     {\bbl@putsh@i#1\@empty\@nnil}%
     {\csname bbl@active@\string#1\endcsname}}
\def\bbl@putsh@i#1#2\@nnil{%
  \csname\languagename @sh@\string#1@%
    \ifx\@empty#2\else\string#2@\fi\endcsname}
\ifx\bbl@opt@shorthands\@nnil\else
  \let\bbl@s@initiate@active@char\initiate@active@char
  \def\initiate@active@char#1{%
    \bbl@ifshorthand{#1}{\bbl@s@initiate@active@char{#1}}{}}
  \let\bbl@s@switch@sh\bbl@switch@sh
  \def\bbl@switch@sh#1#2{%
    \ifx#2\@nnil\else
      \bbl@afterfi
      \bbl@ifshorthand{#2}{\bbl@s@switch@sh#1{#2}}{\bbl@switch@sh#1}%
    \fi}
  \let\bbl@s@activate\bbl@activate
  \def\bbl@activate#1{%
    \bbl@ifshorthand{#1}{\bbl@s@activate{#1}}{}}
  \let\bbl@s@deactivate\bbl@deactivate
  \def\bbl@deactivate#1{%
    \bbl@ifshorthand{#1}{\bbl@s@deactivate{#1}}{}}
\fi
\newcommand\ifbabelshorthand[3]{\bbl@ifunset{bbl@active@\string#1}{#3}{#2}}
\def\bbl@prim@s{%
  \prime\futurelet\@let@token\bbl@pr@m@s}
\def\bbl@if@primes#1#2{%
  \ifx#1\@let@token
    \expandafter\@firstoftwo
  \else\ifx#2\@let@token
    \bbl@afterelse\expandafter\@firstoftwo
  \else
    \bbl@afterfi\expandafter\@secondoftwo
  \fi\fi}
\begingroup
  \catcode`\^=7  \catcode`\*=\active  \lccode`\*=`\^
  \catcode`\'=12 \catcode`\"=\active  \lccode`\"=`\'
  \lowercase{%
    \gdef\bbl@pr@m@s{%
      \bbl@if@primes"'%
        \pr@@@s
        {\bbl@if@primes*^\pr@@@t\egroup}}}
\endgroup
\initiate@active@char{~}
\declare@shorthand{system}{~}{\leavevmode\nobreak\ }
\bbl@activate{~}
%
% ------------------------------------------------------------------------------
%
% lines 890 to 927 from babel.def
%
% ------------------------------------------------------------------------------
%
\def\bbl@allowhyphens{\ifvmode\else\nobreak\hskip\z@skip\fi}
\def\bbl@t@one{T1}
\def\allowhyphens{\ifx\cf@encoding\bbl@t@one\else\bbl@allowhyphens\fi}
\newcommand\babelnullhyphen{\char\hyphenchar\font}
\def\babelhyphen{\active@prefix\babelhyphen\bbl@hyphen}
\def\bbl@hyphen{%
  \@ifstar{\bbl@hyphen@i @}{\bbl@hyphen@i\@empty}}
\def\bbl@hyphen@i#1#2{%
  \bbl@ifunset{bbl@hy@#1#2\@empty}%
    {\csname bbl@#1usehyphen\endcsname{\discretionary{#2}{}{#2}}}%
    {\csname bbl@hy@#1#2\@empty\endcsname}}
\def\bbl@usehyphen#1{%
  \leavevmode
  \ifdim\lastskip>\z@\mbox{#1}\else\nobreak#1\fi
  \nobreak\hskip\z@skip}
\def\bbl@@usehyphen#1{%
  \leavevmode\ifdim\lastskip>\z@\mbox{#1}\else#1\fi}
\def\bbl@hyphenchar{%
  \ifnum\hyphenchar\font=\m@ne
    \babelnullhyphen
  \else
    \char\hyphenchar\font
  \fi}
\def\bbl@hy@soft{\bbl@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}}
\def\bbl@hy@@soft{\bbl@@usehyphen{\discretionary{\bbl@hyphenchar}{}{}}}
\def\bbl@hy@hard{\bbl@usehyphen\bbl@hyphenchar}
\def\bbl@hy@@hard{\bbl@@usehyphen\bbl@hyphenchar}
\def\bbl@hy@nobreak{\bbl@usehyphen{\mbox{\bbl@hyphenchar}}}
\def\bbl@hy@@nobreak{\mbox{\bbl@hyphenchar}}
\def\bbl@hy@repeat{%
  \bbl@usehyphen{%
    \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}}
\def\bbl@hy@@repeat{%
  \bbl@@usehyphen{%
    \discretionary{\bbl@hyphenchar}{\bbl@hyphenchar}{\bbl@hyphenchar}}}
\def\bbl@hy@empty{\hskip\z@skip}
\def\bbl@hy@@empty{\discretionary{}{}{}}
\def\bbl@disc#1#2{\nobreak\discretionary{#2-}{}{#1}\bbl@allowhyphens}
%
% ------------------------------------------------------------------------------
%
% end of the code copied from babel files
%
% ------------------------------------------------------------------------------
%
\def\bbl@disc@german#1#2{%
  \nobreak\discretionary{#2-}{}{#1}}
%    \end{macrocode}
% \iffalse
%</babelsh.def>
%<*cal-util.def>
% \fi
% \clearpage
% 
% \subsection{cal-util.def}
%    \begin{macrocode}
%%%%%%%%%%%%% cal-util.def %%%%%%%%%%%%%%%%
% Macros shared by hijrical and hebrewcal %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the following is adapted from hebcal.sty in babel
\def\@Remainder#1#2#3{%
    #3 = #1%                   %  c = a
    \divide #3 by #2%          %  c = a/b
    \multiply #3 by -#2%       %  c = -b(a/b)
    \advance #3 by #1}%        %  c = a - b(a/b)
\newif\if@Divisible
\def\@CheckIfDivisible#1#2{%
    {%
      \countdef\tmpx=0%        % temporary variable
      \@Remainder{#1}{#2}{\tmpx}%
      \ifnum\tmpx=0%
          \global\@Divisibletrue%
      \else%
          \global\@Divisiblefalse%
      \fi}}
\newif\if@GregorianLeap
\def\@CheckIfGregorianLeap#1{%
   {%
   \@CheckIfDivisible{#1}{4}%
    \if@Divisible%
        \@CheckIfDivisible{#1}{100}%
        \if@Divisible%
            \@CheckIfDivisible{#1}{400}%
            \if@Divisible%
                \global\@GregorianLeaptrue%
            \else%
                \global\@GregorianLeapfalse%
            \fi%
        \else%
            \global\@GregorianLeaptrue%
        \fi%
    \else%
        \global\@GregorianLeapfalse%
    \fi%
    }}
%%

\newcounter{tmpA}\newcounter{tmpB}
\newcounter{tmpC}\newcounter{tmpD}
\newcounter{tmpE}\newcounter{tmpF}


%% This is an algorithm from Reingold & Dershowitz, 
%% Calendrical Calculations, The Millenium Edition
%%
\def\@FixedFromGregorian#1#2#3#4{%
 \setcounter{tmpA}{(#1-1)*365}%
 \setcounter{tmpB}{(#1-1)/4}%
 \setcounter{tmpC}{(#1-1)/100}%
 \setcounter{tmpD}{(#1-1)/400}%
 \setcounter{tmpE}{(367*#2-362)/12}%
 \ifnum#2<3%
    \setcounter{tmpF}{0}%
 \else%
      \@CheckIfGregorianLeap{#1}%
      \if@GregorianLeap%
        \setcounter{tmpF}{-1}%
      \else%
        \setcounter{tmpF}{-2}%
      \fi%
 \fi%
 \@ifundefined{c@#4}{\global\newcounter{#4}}{}%
 \setcounter{#4}{\value{tmpA}+\value{tmpB}-\value{tmpC}+\value{tmpD}+\value{tmpE}+\value{tmpF}+#3}%
}
%    \end{macrocode}
% \iffalse
%</cal-util.def>
%<*xgreek-fixes.def>
% \fi
% \clearpage
% 
% \subsection{xgreek-fixes.def}
%    \begin{macrocode}
% the following fixes are taken verbatim from xgreek.sty:
% \message{Package `xgreek' version 3.0.1 by Apostolos Syropoulos}
\global\lccode"0370="0371 \global\uccode"0370="0370
\global\lccode"0371="0371 \global\uccode"0371="0370
\global\lccode"0372="0373 \global\uccode"0372="0372
\global\lccode"0373="0373 \global\uccode"0373="0372
\global\lccode"0376="0377 \global\uccode"0376="0376
\global\lccode"0377="0377 \global\uccode"0377="0376
\global\lccode"03FD="037B \global\uccode"03FD="03FD
\global\lccode"037B="037B \global\uccode"037B="03FD
\global\lccode"03FE="037C \global\uccode"03FE="03FE
\global\lccode"037C="037C \global\uccode"037C="03FE
\global\lccode"03FF="037D \global\uccode"03FF="03FF
\global\lccode"037D="037D \global\uccode"037D="03FF
\global\lccode"0386="03AC \global\uccode"0386="0391
\global\lccode"0388="03AD \global\uccode"0388="0395
\global\lccode"0389="03AC \global\uccode"0389="0397
\global\lccode"038A="03AF \global\uccode"038A="0399
\global\lccode"038C="03CC \global\uccode"038C="039F
\global\lccode"038E="03CD \global\uccode"038E="03A5
\global\lccode"038F="03CE \global\uccode"038F="03A9
\global\lccode"0390="0390 \global\uccode"0390="03AA
\global\lccode"0391="03B1 \global\uccode"0391="0391
\global\lccode"0392="03B2 \global\uccode"0392="0392
\global\lccode"0393="03B3 \global\uccode"0393="0393
\global\lccode"0394="03B4 \global\uccode"0394="0394
\global\lccode"0395="03B5 \global\uccode"0395="0395
\global\lccode"0396="03B6 \global\uccode"0396="0396
\global\lccode"0397="03B7 \global\uccode"0397="0397
\global\lccode"0398="03B8 \global\uccode"0398="0398
\global\lccode"0399="03B9 \global\uccode"0399="0399
\global\lccode"039A="03BA \global\uccode"039A="039A
\global\lccode"039B="03BB \global\uccode"039B="039B
\global\lccode"039C="03BC \global\uccode"039C="039C
\global\lccode"039D="03BD \global\uccode"039D="039D
\global\lccode"039E="03BE \global\uccode"039E="039E
\global\lccode"039F="03BF \global\uccode"039F="039F
\global\lccode"03A0="03C0 \global\uccode"03A0="03A0
\global\lccode"03A1="03C1 \global\uccode"03A1="03A1
\global\lccode"03A3="03C3 \global\uccode"03A3="03A3
\global\lccode"03A4="03C4 \global\uccode"03A4="03A4
\global\lccode"03A5="03C5 \global\uccode"03A5="03A5
\global\lccode"03A6="03C6 \global\uccode"03A6="03A6
\global\lccode"03A7="03C7 \global\uccode"03A7="03A7
\global\lccode"03A8="03C8 \global\uccode"03A8="03A8
\global\lccode"03A9="03C9 \global\uccode"03A9="03A9
\global\lccode"03AA="03CA \global\uccode"03AA="03AA
\global\lccode"03AB="03CB \global\uccode"03AB="03AB
\global\lccode"03AC="03AC \global\uccode"03AC="0391
\global\lccode"03AD="03AD \global\uccode"03AD="0395
\global\lccode"03AE="03AE \global\uccode"03AE="0397
\global\lccode"03AF="03AF \global\uccode"03AF="0399
\global\lccode"03B0="03B0 \global\uccode"03B0="03AB
\global\lccode"03B1="03B1 \global\uccode"03B1="0391
\global\lccode"03B2="03B2 \global\uccode"03B2="0392
\global\lccode"03B3="03B3 \global\uccode"03B3="0393
\global\lccode"03B4="03B4 \global\uccode"03B4="0394
\global\lccode"03B5="03B5 \global\uccode"03B5="0395
\global\lccode"03B6="03B6 \global\uccode"03B6="0396
\global\lccode"03B7="03B7 \global\uccode"03B7="0397
\global\lccode"03B8="03B8 \global\uccode"03B8="0398
\global\lccode"03B9="03B9 \global\uccode"03B9="0399
\global\lccode"03BA="03BA \global\uccode"03BA="039A
\global\lccode"03BB="03BB \global\uccode"03BB="039B
\global\lccode"03BC="03BC \global\uccode"03BC="039C
\global\lccode"03BD="03BD \global\uccode"03BD="039D
\global\lccode"03BE="03BE \global\uccode"03BE="039E
\global\lccode"03BF="03BF \global\uccode"03BF="039F
\global\lccode"03C0="03C0 \global\uccode"03C0="03A0
\global\lccode"03C1="03C1 \global\uccode"03C1="03A1
\global\lccode"03C2="03C2 \global\uccode"03C2="03A3
\global\lccode"03C3="03C3 \global\uccode"03C3="03A3
\global\lccode"03C4="03C4 \global\uccode"03C4="03A4
\global\lccode"03C5="03C5 \global\uccode"03C5="03A5
\global\lccode"03C6="03C6 \global\uccode"03C6="03A6
\global\lccode"03C7="03C7 \global\uccode"03C7="03A7
\global\lccode"03C8="03C8 \global\uccode"03C8="03A8
\global\lccode"03C9="03C9 \global\uccode"03C9="03A9
\global\lccode"03CA="03CA \global\uccode"03CA="03AA
\global\lccode"03CB="03CB \global\uccode"03CB="03AB
\global\lccode"03CC="03CC \global\uccode"03CC="039F
\global\lccode"03CD="03CD \global\uccode"03CD="03A5
\global\lccode"03CE="03CE \global\uccode"03CE="03A9
\global\lccode"03D0="03D0 \global\uccode"03D0="0392
\global\lccode"03D1="03D1 \global\uccode"03D1="0398
\global\lccode"03D2="03C5 \global\uccode"03D2="03A5
\global\lccode"03D3="03CD \global\uccode"03D3="03A5
\global\lccode"03D4="03CB \global\uccode"03D4="03AB
\global\lccode"03D5="03C6 \global\uccode"03D5="03A6
\global\lccode"03D6="03C0 \global\uccode"03D6="03A0
\global\lccode"03DA="03DB \global\uccode"03DA="03DA
\global\lccode"03DB="03DB \global\uccode"03DB="03DA
\global\lccode"03DC="03DD \global\uccode"03DC="03DC
\global\lccode"03DD="03DD \global\uccode"03DD="03DC
\global\lccode"03DE="03DF \global\uccode"03DE="03DE
\global\lccode"03DF="03DF \global\uccode"03DF="03DE
\global\lccode"03E0="03E1 \global\uccode"03E0="03E0
\global\lccode"03E1="03E1 \global\uccode"03E1="03E0
\global\lccode"03F0="03BA \global\uccode"03F0="039A
\global\lccode"03F1="03C1 \global\uccode"03F1="03A1
\global\lccode"03F2="03F2 \global\uccode"03F2="03F9
\global\lccode"03F9="03F2 \global\uccode"03F9="03F9
\global\lccode"1F00="1F00 \global\uccode"1F00="0391
\global\lccode"1F01="1F01 \global\uccode"1F01="0391
\global\lccode"1F02="1F02 \global\uccode"1F02="0391
\global\lccode"1F03="1F03 \global\uccode"1F03="0391
\global\lccode"1F04="1F04 \global\uccode"1F04="0391
\global\lccode"1F05="1F05 \global\uccode"1F05="0391
\global\lccode"1F06="1F06 \global\uccode"1F06="0391
\global\lccode"1F07="1F07 \global\uccode"1F07="0391
\global\lccode"1F08="1F00 \global\uccode"1F08="0391
\global\lccode"1F09="1F01 \global\uccode"1F09="0391
\global\lccode"1F0A="1F02 \global\uccode"1F0A="0391
\global\lccode"1F0B="1F03 \global\uccode"1F0B="0391
\global\lccode"1F0C="1F04 \global\uccode"1F0C="0391
\global\lccode"1F0D="1F05 \global\uccode"1F0D="0391
\global\lccode"1F0E="1F06 \global\uccode"1F0E="0391
\global\lccode"1F0F="1F07 \global\uccode"1F0F="0391
\global\lccode"1F10="1F10 \global\uccode"1F10="0395
\global\lccode"1F11="1F11 \global\uccode"1F11="0395
\global\lccode"1F12="1F12 \global\uccode"1F12="0395
\global\lccode"1F13="1F13 \global\uccode"1F13="0395
\global\lccode"1F14="1F14 \global\uccode"1F14="0395
\global\lccode"1F15="1F15 \global\uccode"1F15="0395
\global\lccode"1F18="1F10 \global\uccode"1F18="0395
\global\lccode"1F19="1F11 \global\uccode"1F19="0395
\global\lccode"1F1A="1F12 \global\uccode"1F1A="0395
\global\lccode"1F1B="1F13 \global\uccode"1F1B="0395
\global\lccode"1F1C="1F14 \global\uccode"1F1C="0395
\global\lccode"1F1D="1F15 \global\uccode"1F1D="0395
\global\lccode"1F20="1F20 \global\uccode"1F20="0397
\global\lccode"1F21="1F21 \global\uccode"1F21="0397
\global\lccode"1F22="1F22 \global\uccode"1F22="0397
\global\lccode"1F23="1F23 \global\uccode"1F23="0397
\global\lccode"1F24="1F24 \global\uccode"1F24="0397
\global\lccode"1F25="1F25 \global\uccode"1F25="0397
\global\lccode"1F26="1F26 \global\uccode"1F26="0397
\global\lccode"1F27="1F27 \global\uccode"1F27="0397
\global\lccode"1F28="1F20 \global\uccode"1F28="0397
\global\lccode"1F29="1F21 \global\uccode"1F29="0397
\global\lccode"1F2A="1F22 \global\uccode"1F2A="0397
\global\lccode"1F2B="1F23 \global\uccode"1F2B="0397
\global\lccode"1F2C="1F24 \global\uccode"1F2C="0397
\global\lccode"1F2D="1F25 \global\uccode"1F2D="0397
\global\lccode"1F2E="1F26 \global\uccode"1F2E="0397
\global\lccode"1F2F="1F27 \global\uccode"1F2F="0397
\global\lccode"1F30="1F30 \global\uccode"1F30="0399
\global\lccode"1F31="1F31 \global\uccode"1F31="0399
\global\lccode"1F32="1F32 \global\uccode"1F32="0399
\global\lccode"1F33="1F33 \global\uccode"1F33="0399
\global\lccode"1F34="1F34 \global\uccode"1F34="0399
\global\lccode"1F35="1F35 \global\uccode"1F35="0399
\global\lccode"1F36="1F36 \global\uccode"1F36="0399
\global\lccode"1F37="1F37 \global\uccode"1F37="0399
\global\lccode"1F38="1F30 \global\uccode"1F38="0399
\global\lccode"1F39="1F31 \global\uccode"1F39="0399
\global\lccode"1F3A="1F32 \global\uccode"1F3A="0399
\global\lccode"1F3B="1F33 \global\uccode"1F3B="0399
\global\lccode"1F3C="1F34 \global\uccode"1F3C="0399
\global\lccode"1F3D="1F35 \global\uccode"1F3D="0399
\global\lccode"1F3E="1F36 \global\uccode"1F3E="0399
\global\lccode"1F3F="1F37 \global\uccode"1F3F="0399
\global\lccode"1F40="1F40 \global\uccode"1F40="039F
\global\lccode"1F41="1F41 \global\uccode"1F41="039F
\global\lccode"1F42="1F42 \global\uccode"1F42="039F
\global\lccode"1F43="1F43 \global\uccode"1F43="039F
\global\lccode"1F44="1F44 \global\uccode"1F44="039F
\global\lccode"1F45="1F45 \global\uccode"1F45="039F
\global\lccode"1F48="1F40 \global\uccode"1F48="039F
\global\lccode"1F49="1F41 \global\uccode"1F49="039F
\global\lccode"1F4A="1F42 \global\uccode"1F4A="039F
\global\lccode"1F4B="1F43 \global\uccode"1F4B="039F
\global\lccode"1F4C="1F44 \global\uccode"1F4C="039F
\global\lccode"1F4D="1F45 \global\uccode"1F4D="039F
\global\lccode"1F50="1F50 \global\uccode"1F50="03A5
\global\lccode"1F51="1F51 \global\uccode"1F51="03A5
\global\lccode"1F52="1F52 \global\uccode"1F52="03A5
\global\lccode"1F53="1F53 \global\uccode"1F53="03A5
\global\lccode"1F54="1F54 \global\uccode"1F54="03A5
\global\lccode"1F55="1F55 \global\uccode"1F55="03A5
\global\lccode"1F56="1F56 \global\uccode"1F56="03A5
\global\lccode"1F57="1F57 \global\uccode"1F57="03A5
\global\lccode"1F59="1F51 \global\uccode"1F59="03A5
\global\lccode"1F5B="1F53 \global\uccode"1F5B="03A5
\global\lccode"1F5D="1F55 \global\uccode"1F5D="03A5
\global\lccode"1F5F="1F57 \global\uccode"1F5F="03A5
\global\lccode"1F60="1F60 \global\uccode"1F60="03A9
\global\lccode"1F61="1F61 \global\uccode"1F61="03A9
\global\lccode"1F62="1F62 \global\uccode"1F62="03A9
\global\lccode"1F63="1F63 \global\uccode"1F63="03A9
\global\lccode"1F64="1F64 \global\uccode"1F64="03A9
\global\lccode"1F65="1F65 \global\uccode"1F65="03A9
\global\lccode"1F66="1F66 \global\uccode"1F66="03A9
\global\lccode"1F67="1F67 \global\uccode"1F67="03A9
\global\lccode"1F68="1F60 \global\uccode"1F68="03A9
\global\lccode"1F69="1F61 \global\uccode"1F69="03A9
\global\lccode"1F6A="1F62 \global\uccode"1F6A="03A9
\global\lccode"1F6B="1F63 \global\uccode"1F6B="03A9
\global\lccode"1F6C="1F64 \global\uccode"1F6C="03A9
\global\lccode"1F6D="1F65 \global\uccode"1F6D="03A9
\global\lccode"1F6E="1F66 \global\uccode"1F6E="03A9
\global\lccode"1F6F="1F67 \global\uccode"1F6F="03A9
\global\lccode"1F70="1F70 \global\uccode"1F70="0391
\global\lccode"1F71="1F71 \global\uccode"1F71="0391
\global\lccode"1F72="1F72 \global\uccode"1F72="0395
\global\lccode"1F73="1F73 \global\uccode"1F73="0395
\global\lccode"1F74="1F74 \global\uccode"1F74="0397
\global\lccode"1F75="1F75 \global\uccode"1F75="0397
\global\lccode"1F76="1F76 \global\uccode"1F76="0399
\global\lccode"1F77="1F77 \global\uccode"1F77="0399
\global\lccode"1F78="1F78 \global\uccode"1F78="039F
\global\lccode"1F79="1F79 \global\uccode"1F79="039F
\global\lccode"1F7A="1F7A \global\uccode"1F7A="03A5
\global\lccode"1F7B="1F7B \global\uccode"1F7B="03A5
\global\lccode"1F7C="1F7C \global\uccode"1F7C="03A9
\global\lccode"1F7D="1F7D \global\uccode"1F7D="03A9
\global\lccode"1F80="1F80 \global\uccode"1F80="1FBC
\global\lccode"1F81="1F81 \global\uccode"1F81="1FBC
\global\lccode"1F82="1F82 \global\uccode"1F82="1FBC
\global\lccode"1F83="1F83 \global\uccode"1F83="1FBC
\global\lccode"1F84="1F84 \global\uccode"1F84="1FBC
\global\lccode"1F85="1F85 \global\uccode"1F85="1FBC
\global\lccode"1F86="1F86 \global\uccode"1F86="1FBC
\global\lccode"1F87="1F87 \global\uccode"1F87="1FBC
\global\lccode"1F88="1F80 \global\uccode"1F88="1FBC
\global\lccode"1F89="1F81 \global\uccode"1F89="1FBC
\global\lccode"1F8A="1F82 \global\uccode"1F8A="1FBC
\global\lccode"1F8B="1F83 \global\uccode"1F8B="1FBC
\global\lccode"1F8C="1F84 \global\uccode"1F8C="1FBC
\global\lccode"1F8D="1F85 \global\uccode"1F8D="1FBC
\global\lccode"1F8E="1F86 \global\uccode"1F8E="1FBC
\global\lccode"1F8F="1F87 \global\uccode"1F8F="1FBC
\global\lccode"1F90="1F90 \global\uccode"1F90="1FCC
\global\lccode"1F91="1F91 \global\uccode"1F91="1FCC
\global\lccode"1F92="1F92 \global\uccode"1F92="1FCC
\global\lccode"1F93="1F93 \global\uccode"1F93="1FCC
\global\lccode"1F94="1F94 \global\uccode"1F94="1FCC
\global\lccode"1F95="1F95 \global\uccode"1F95="1FCC
\global\lccode"1F96="1F96 \global\uccode"1F96="1FCC
\global\lccode"1F97="1F97 \global\uccode"1F97="1FCC
\global\lccode"1F98="1F90 \global\uccode"1F98="1FCC
\global\lccode"1F99="1F91 \global\uccode"1F99="1FCC
\global\lccode"1F9A="1F92 \global\uccode"1F9A="1FCC
\global\lccode"1F9B="1F93 \global\uccode"1F9B="1FCC
\global\lccode"1F9C="1F94 \global\uccode"1F9C="1FCC
\global\lccode"1F9D="1F95 \global\uccode"1F9D="1FCC
\global\lccode"1F9E="1F96 \global\uccode"1F9E="1FCC
\global\lccode"1F9F="1F97 \global\uccode"1F9F="1FCC
\global\lccode"1FA0="1FA0 \global\uccode"1FA0="1FFC
\global\lccode"1FA1="1FA1 \global\uccode"1FA1="1FFC
\global\lccode"1FA2="1FA2 \global\uccode"1FA2="1FFC
\global\lccode"1FA3="1FA3 \global\uccode"1FA3="1FFC
\global\lccode"1FA4="1FA4 \global\uccode"1FA4="1FFC
\global\lccode"1FA5="1FA5 \global\uccode"1FA5="1FFC
\global\lccode"1FA6="1FA6 \global\uccode"1FA6="1FFC
\global\lccode"1FA7="1FA7 \global\uccode"1FA7="1FFC
\global\lccode"1FA8="1FA0 \global\uccode"1FA8="1FFC
\global\lccode"1FA9="1FA1 \global\uccode"1FA9="1FFC
\global\lccode"1FAA="1FA2 \global\uccode"1FAA="1FFC
\global\lccode"1FAB="1FA3 \global\uccode"1FAB="1FFC
\global\lccode"1FAC="1FA4 \global\uccode"1FAC="1FFC
\global\lccode"1FAD="1FA5 \global\uccode"1FAD="1FFC
\global\lccode"1FAE="1FA6 \global\uccode"1FAE="1FFC
\global\lccode"1FAF="1FA7 \global\uccode"1FAF="1FFC
\global\lccode"1FB0="1FB0 \global\uccode"1FB0="1FB8
\global\lccode"1FB1="1FB1 \global\uccode"1FB1="1FB9
\global\lccode"1FB2="1FB2 \global\uccode"1FB2="1FBC
\global\lccode"1FB3="1FB3 \global\uccode"1FB3="1FBC
\global\lccode"1FB4="1FB4 \global\uccode"1FB4="1FBC
\global\lccode"1FB6="1FB6 \global\uccode"1FB6="0391
\global\lccode"1FB7="1FB7 \global\uccode"1FB7="1FBC
\global\lccode"1FB8="1FB0 \global\uccode"1FB8="1FB8
\global\lccode"1FB9="1FB1 \global\uccode"1FB9="1FB9
\global\lccode"1FBA="1F70 \global\uccode"1FBA="0391
\global\lccode"1FBB="1F71 \global\uccode"1FBB="0391
\global\lccode"1FBC="1FB3 \global\uccode"1FBC="1FBC
\global\lccode"1FBD="1FBD \global\uccode"1FBD="1FBD
\global\lccode"1FC2="1FC2 \global\uccode"1FC2="1FCC
\global\lccode"1FC3="1FC3 \global\uccode"1FC3="1FCC
\global\lccode"1FC4="1FC4 \global\uccode"1FC4="1FCC
\global\lccode"1FC6="1FC6 \global\uccode"1FC6="0397
\global\lccode"1FC7="1FC7 \global\uccode"1FC7="1FCC
\global\lccode"1FC8="1F72 \global\uccode"1FC8="0395
\global\lccode"1FC9="1F73 \global\uccode"1FC9="0395
\global\lccode"1FCA="1F74 \global\uccode"1FCA="0397
\global\lccode"1FCB="1F75 \global\uccode"1FCB="0397
\global\lccode"1FCC="1FC3 \global\uccode"1FCC="1FCC
\global\lccode"1FD0="1FD0 \global\uccode"1FD0="1FD8
\global\lccode"1FD1="1FD1 \global\uccode"1FD1="1FD9
\global\lccode"1FD2="1FD2 \global\uccode"1FD2="03AA
\global\lccode"1FD3="1FD3 \global\uccode"1FD3="03AA
\global\lccode"1FD6="1FD6 \global\uccode"1FD6="0399
\global\lccode"1FD7="1FD7 \global\uccode"1FD7="03AA
\global\lccode"1FD8="1FD0 \global\uccode"1FD8="1FD8
\global\lccode"1FD9="1FD1 \global\uccode"1FD9="1FD9
\global\lccode"1FDA="1F76 \global\uccode"1FDA="0399
\global\lccode"1FDB="1F77 \global\uccode"1FDB="0399
\global\lccode"1FE0="1FE0 \global\uccode"1FE0="1FE8
\global\lccode"1FE1="1FE1 \global\uccode"1FE1="1FE9
\global\lccode"1FE2="1FE2 \global\uccode"1FE2="03AB
\global\lccode"1FE3="1FE3 \global\uccode"1FE3="03AB
\global\lccode"1FE4="1FE4 \global\uccode"1FE4="03A1
\global\lccode"1FE5="1FE5 \global\uccode"1FE5="03A1
\global\lccode"1FE6="1FE6 \global\uccode"1FE6="03A5
\global\lccode"1FE7="1FE7 \global\uccode"1FE7="03AB
\global\lccode"1FE8="1FE0 \global\uccode"1FE8="1FE8
\global\lccode"1FE9="1FE1 \global\uccode"1FE9="1FE9
\global\lccode"1FEA="1F7A \global\uccode"1FEA="03A5
\global\lccode"1FEB="1F7B \global\uccode"1FEB="03A5
\global\lccode"1FEC="1FE5 \global\uccode"1FEC="1FEC
\global\lccode"1FF2="1FF2 \global\uccode"1FF2="1FFC
\global\lccode"1FF3="1FF3 \global\uccode"1FF3="1FFC
\global\lccode"1FF4="1FF4 \global\uccode"1FF4="1FFC
\global\lccode"1FF6="1FF6 \global\uccode"1FF6="03A9
\global\lccode"1FF7="1FF7 \global\uccode"1FF7="1FFC
\global\lccode"1FF8="1F78 \global\uccode"1FF8="039F
\global\lccode"1FF9="1F79 \global\uccode"1FF9="039F
\global\lccode"1FFA="1F7C \global\uccode"1FFA="03A9
\global\lccode"1FFB="1F7D \global\uccode"1FFB="03A9
\global\lccode"1FFC="1FF3 \global\uccode"1FFC="1FFC
%    \end{macrocode}
% \iffalse
%</xgreek-fixes.def>
%<*gloss-acadien.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-acadien.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-acadien.ldf}[polyglossia: module for canadian (acadian) french]

% We provide this as a babel alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-acadien.ldf>
%<*gloss-aeb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-aeb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-aeb.ldf}[polyglossia: module for aeb (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-aeb.ldf>
%<*gloss-af.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-af.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-af.ldf}[polyglossia: module for af (afrikaans)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{afrikaans}

%    \end{macrocode}
% \iffalse
%</gloss-af.ldf>
%<*gloss-afb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-afb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-afb.ldf}[polyglossia: module for afb (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-afb.ldf>
%<*gloss-afrikaans.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-afrikaans.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-afrikaans.ldf}[polyglossia: module for afrikaans]

\PolyglossiaSetup{afrikaans}{
  bcp47=af,
  hyphennames={afrikaans,dutch},
  hyphenmins={2,2},
  langtag=AFK,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{afrikaans}{af}

\define@boolkey{afrikaans}[afrikaans@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{afrikaans}{babelshorthands=false}

\ifsystem@babelshorthands
  \setkeys{afrikaans}{babelshorthands=true}
\else
  \setkeys{afrikaans}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\afrikaans@shorthands{%
  \bbl@activate{"}%
  \def\language@group{afrikaans}%
  \declare@shorthand{afrikaans}{"-}{\nobreak-\bbl@allowhyphens}
  \declare@shorthand{afrikaans}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
  \declare@shorthand{afrikaans}{"|}{%
    \textormath{\discretionary{-}{}{\kern.03em}}{}}
  \declare@shorthand{afrikaans}{""}{\hskip\z@skip}
  \declare@shorthand{afrikaans}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
  \def\-{\bbl@allowhyphens\discretionary{-}{}{}\bbl@allowhyphens}%
}

\def\noafrikaans@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captionsafrikaans{%
    \def\prefacename{Voorwoord}%
    \def\refname{Verwysings}%
    \def\abstractname{Samevatting}%
    \def\bibname{Bibliografie}%
    \def\chaptername{Hoofstuk}%
    \def\appendixname{Bylae}%
    \def\contentsname{Inhoudsopgawe}%
    \def\listfigurename{Lys van figure}%
    \def\listtablename{Lys van tabelle}%
    \def\indexname{Inhoud}%
    \def\figurename{Figuur}%
    \def\tablename{Tabel}%
    \def\partname{Deel}%
    \def\enclname{Bylae(n)}%
    \def\ccname{a.\,a.}%
    \def\headtoname{Aan}%
    \def\pagename{Bladsy}%
    \def\seename{sien}%
    \def\alsoname{sien ook}%
    \def\proofname{Bewys}%
%   \def\glossaryname{}%
}

\def\dateafrikaans{%
    \def\today{\number\day~\ifcase\month\or
      Januarie\or Februarie\or Maart\or April\or Mei\or Junie\or
      Julie\or  Augustus\or September\or Oktober\or November\or
      Desember\fi
      \space \number\year}%
}

\def\noextras@afrikaans{%
  \ifafrikaans@babelshorthands\noafrikaans@shorthands\fi%
}

\def\blockextras@afrikaans{%
  \ifafrikaans@babelshorthands\afrikaans@shorthands\fi%
}

\def\inlineextras@afrikaans{%
  \ifafrikaans@babelshorthands\afrikaans@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-afrikaans.ldf>
%<*gloss-albanian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-albanian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-albanian.ldf}[polyglossia: module for albanian]

\PolyglossiaSetup{albanian}{
  bcp47=sq,
  hyphennames={albanian},
  langtag=SQI,
  hyphenmins={2,2},
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{albanian}{sq}

\def\captionsalbanian{%
   \def\refname{Referencat}%
   \def\abstractname{Përmbledhja}%
   \def\bibname{Bibliografia}%
   \def\prefacename{Parathenia}%
   \def\chaptername{Kapitulli}%
   \def\appendixname{Shtesa}%
   \def\contentsname{Përmbajtja}%
   \def\listfigurename{Figurat}%
   \def\listtablename{Tabelat}%
   \def\indexname{Indeksi}%
   \def\figurename{Figura}%
   \def\tablename{Tabela}%
   %\def\thepart{}%
   \def\partname{Pjesa}%
   \def\pagename{Faqe}%
   \def\seename{shiko}%
   \def\alsoname{shiko dhe}%
   %\def\enclname{}%
   %\def\ccname{}%
   %\def\headtoname{}%
   \def\proofname{Vërtetim}%
   \def\glossaryname{Përhasja e Fjalëve}%
   }
\def\datealbanian{%
   \def\today{{\number\day~\ifcase\month\or
    Janar\or Shkurt\or Mars\or Prill\or Maj\or
    Qershor\or Korrik\or Gusht\or Shtator\or Tetor\or Nëntor\or
    Dhjetor\fi \space \number\year}}}

%    \end{macrocode}
% \iffalse
%</gloss-albanian.ldf>
%<*gloss-am.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-am.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-am.ldf}[polyglossia: module for am (amharic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{amharic}

%    \end{macrocode}
% \iffalse
%</gloss-am.ldf>
%<*gloss-american.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-american.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-american.ldf}[polyglossia: module for american english]

% We provide this as a babel alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-american.ldf>
%<*gloss-amharic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-amharic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-amharic.ldf}[polyglossia: module for amharic]
\PolyglossiaSetup{amharic}{
  bcp47=am,
  script=Ethiopic,
  scripttag=ethi,
  langtag=AMH,
  hyphennames={amharic,nohyphenation},
  %hyphenmins={2,2},
  fontsetup=true,
  %TODO localalph=ethnum
}

% BCP-47 compliant aliases
\setlanguagealias*{amharic}{am}

\def\captionsamharic{%
   \def\refname{የነሥ ጹሁፍ ምንጭ}%
   \def\abstractname{አኅጽተሮ ጽሁፍ}%
   \def\bibname{ቢዋ መጽሃፍት}%
   \def\prefacename{መቅድም}%
   \def\chaptername{ክፍል}%
   \def\appendixname{መድበል}%
   \def\contentsname{ይዘት}%
   \def\listfigurename{የሥዕችሎ ማውጫ}%
   \def\listtablename{የሰንጠዥረ ማውጫ}%
   \def\indexname{ምህጻር ቃል}%
   \def\figurename{ሥዕል}%
   \def\tablename{ሰንጠረዥ}%
   %\def\thepart{}%
   \def\partname{ንዑስ ክፍል}%
   \def\pagename{ገጽ}%
   \def\seename{ይመልከቱ}%
   \def\alsoname{ይህምን ይመልከቱ}%
   \def\enclname{አባሪዎች}%
   \def\ccname{ግልባጭ}%
   \def\headtoname{ለ}%
   \def\proofname{ማረጋገጫ}%
   %\def\glossaryname{<++>}%
   }

\newcommand{\eth@monthname}[1]{\ifcase#1\or
  መስከረም\or
  ጥቅምት\or
  ህዳር\or
  ታህሳስ\or
  ጥር\or
  የካቲት\or
  መጋቢት\or
  ሚያዝያ\or
  ግንቦት\or
  ሰኔ\or
  ሐምሌ\or
  ነሐሴ\or
  ጰጉሜን\fi
}
\newcount\ethcnt@temp
\newcount\ethcnt@modtemp
\newcount\ethcnt@leap
\newcount\ethcnt@yminone
\newcount\ethcnt@days
\newcount\ethcnt@jdn
\newcount\ethcnt@cycle
\newcount\ethcnt@ethdays
\newcount\ethcnt@ethyear
\newcount\ethcnt@ethmonth
\newcount\ethcnt@ethday
\newcommand{\eth@modulo}[2]{%
  \ethcnt@modtemp=#1%
  \divide\ethcnt@modtemp by #2%
  \multiply\ethcnt@modtemp by #2%
  \advance#1 by -\ethcnt@modtemp
}
\def\dateamharic{%
  \def\today{{%
    \ethcnt@yminone=\year
    \advance\ethcnt@yminone by -1
    \ethcnt@leap=\year
    \divide\ethcnt@leap by 4
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 4
    \advance\ethcnt@leap by -\ethcnt@temp
    \ethcnt@temp=\year
    \divide\ethcnt@temp by 100
    \advance\ethcnt@leap by -\ethcnt@temp
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 100
    \advance\ethcnt@leap by \ethcnt@temp
    \ethcnt@temp=\year
    \divide\ethcnt@temp by 400
    \advance\ethcnt@leap by \ethcnt@temp
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 400
    \advance\ethcnt@leap by -\ethcnt@temp
    \ifnum\month<3
      \ethcnt@days=\month
      \advance\ethcnt@days by -1
      \multiply\ethcnt@days by 31
      \advance\ethcnt@days by \day
      \advance\ethcnt@days by -1
    \else
      \ethcnt@days=\month
      \advance\ethcnt@days by -1
      \multiply\ethcnt@days by 30
      \advance\ethcnt@days by \day
      \advance\ethcnt@days by \ethcnt@leap
      \advance\ethcnt@days by -3
      \ethcnt@temp=\month
      \multiply\ethcnt@temp by 3
      \advance\ethcnt@temp by -2
      \divide\ethcnt@temp by 5
      \advance\ethcnt@days by \ethcnt@temp
    \fi
    \ethcnt@jdn=\ethcnt@days
    \advance\ethcnt@jdn by 1721426
    \ethcnt@temp=\ethcnt@yminone
    \multiply\ethcnt@temp by 365
    \advance\ethcnt@jdn by \ethcnt@temp
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 4
    \advance\ethcnt@jdn by \ethcnt@temp
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 100
    \advance\ethcnt@jdn by -\ethcnt@temp
    \ethcnt@temp=\ethcnt@yminone
    \divide\ethcnt@temp by 400
    \advance\ethcnt@jdn by \ethcnt@temp
    \ethcnt@cycle=\ethcnt@jdn
    \advance\ethcnt@cycle by -1723856
    \eth@modulo{\ethcnt@cycle}{1461}%
    \ethcnt@ethdays=\ethcnt@cycle
    \eth@modulo{\ethcnt@ethdays}{365}%
    \ethcnt@temp=\ethcnt@cycle
    \divide\ethcnt@temp by 1460
    \multiply\ethcnt@temp by 365
    \advance\ethcnt@ethdays by \ethcnt@temp
    \ethcnt@ethyear=\ethcnt@jdn
    \advance\ethcnt@ethyear by -1723856
    \divide\ethcnt@ethyear by 1461
    \multiply\ethcnt@ethyear by 4
    \ethcnt@temp=\ethcnt@cycle
    \divide\ethcnt@temp by 365
    \advance\ethcnt@ethyear by \ethcnt@temp
    \divide\ethcnt@cycle by 1460
    \advance\ethcnt@ethyear by -\ethcnt@cycle
    \ethcnt@ethmonth=\ethcnt@ethdays
    \divide\ethcnt@ethmonth by 30
    \advance\ethcnt@ethmonth by 1
    \ethcnt@ethday=\ethcnt@ethdays
    \eth@modulo{\ethcnt@ethday}{30}%
    \advance\ethcnt@ethday by 1%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \eth@monthname{\ethcnt@ethmonth}\relax\space%
      \number\ethcnt@ethday\relax\space%
      \number\ethcnt@ethyear%
  }}%
}

\def\ethiop#1{\expandafter\@ethiop\csname c@#1\endcsname}
\def\@ethiop#1{{%
  \ifnum#1<1\relax\ethnum@err{#1}%
  \else\ifnum#1<10\relax\expandafter\ethnum@one\number #1%
  \else\ifnum#1<100\relax\expandafter\ethnum@two\number #1%
  \else\ifnum#1<1000\relax\expandafter\ethnum@three\number #1%
  \else\ifnum#1<10000\relax\expandafter\ethnum@four\number #1%
  \else\ifnum#1<100000\relax\expandafter\ethnum@five\number #1%
  \else\ifnum#1<1000000\relax\expandafter\ethnum@six\number #1%
  \else%
    \ethnum@err%
    \number#1%
  \fi\fi\fi\fi\fi\fi\fi%
}}
\let\ethnum\@ethiop
\newcommand{\ethnum@tens}[1]{%
  \ifcase#1\or ፲\or ፳\or ፴%
           \or ፵\or ፶\or ፷%
           \or ፸\or ፹\or ፺\fi%
}%
\newcommand{\ethnum@one}[1]{%
  \ifcase#1\or ፩\or ፪\or ፫%
           \or ፬\or ፭\or ፮%
           \or ፯\or ፰\or ፱\fi%
}%
\newcommand{\ethnum@two}[1]{%
  \ethnum@tens#1%
  \ethnum@one%
}
\newcommand{\ethnum@three}[1]{%
  \ifnum#1>1\relax\ethnum@one#1\fi%
  \ifnum#1>0\relax ፻\fi%
  \ethnum@two%
}
\newcommand{\ethnum@four}[1]{%
  \ethnum@tens#1%
  \ifnum#1>0\relax ፻\fi%
  \ethnum@three%
}
\newcommand{\ethnum@five}[1]{%
  \ifnum#1>1\relax\ethnum@one#1\fi%
  \ifnum#1>0\relax ፼\fi%
  \ethnum@four%
}
\newcommand{\ethnum@six}[1]{%
  \ethnum@tens#1%
  \ifnum#1>0\relax ፼\fi%
  \ethnum@five%
}

%    \end{macrocode}
% \iffalse
%</gloss-amharic.ldf>
%<*gloss-apd.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-apd.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-apd.ldf}[polyglossia: module for apd (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-apd.ldf>
%<*gloss-ar-IQ.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-IQ.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-IQ.ldf}[polyglossia: module for ar-IQ (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-IQ.ldf>
%<*gloss-ar-JO.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-JO.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-JO.ldf}[polyglossia: module for ar-JO (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-JO.ldf>
%<*gloss-ar-LB.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-LB.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-LB.ldf}[polyglossia: module for ar-LB (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-LB.ldf>
%<*gloss-ar-MR.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-MR.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-MR.ldf}[polyglossia: module for ar-MR (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-MR.ldf>
%<*gloss-ar-PS.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-PS.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-PS.ldf}[polyglossia: module for ar-PS (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-PS.ldf>
%<*gloss-ar-SY.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-SY.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-SY.ldf}[polyglossia: module for ar-SY (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-SY.ldf>
%<*gloss-ar-YE.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar-YE.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar-YE.ldf}[polyglossia: module for ar-YE (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar-YE.ldf>
%<*gloss-ar.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ar.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ar.ldf}[polyglossia: module for ar (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ar.ldf>
%<*gloss-arabic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-arabic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-arabic.ldf}[polyglossia: module for arabic]
\RequireBidi
\RequirePackage{arabicnumbers}
\RequirePackage{hijrical}

\PolyglossiaSetup{arabic}{
  bcp47=ar,
  script=Arabic,
  direction=RL,
  langtag=ARA,
  scripttag=arab,
  hyphennames={nohyphenation},
  fontsetup=true,
  envname=Arabic,
  localnumeral=arabicnumerals
  %TODO localalph={abjad,abjad}
}

% BCP-47 compliant aliases
\setlanguagealias*{arabic}{ar}
\setlanguagealias*[locale=mashriq]{arabic}{ar-IQ}
\setlanguagealias*[locale=default]{arabic}{ar-YE}
\setlanguagealias*[locale=mashriq]{arabic}{ar-LB}
\setlanguagealias*[locale=mashriq]{arabic}{ar-JO}
\setlanguagealias*[locale=default]{arabic}{afb}
\setlanguagealias*[locale=mauritania]{arabic}{ar-MR}
\setlanguagealias*[locale=default]{arabic}{arz}
\setlanguagealias*[locale=morocco]{arabic}{ary}
\setlanguagealias*[locale=algeria]{arabic}{arq}
\setlanguagealias*[locale=tunisia]{arabic}{aeb}
\setlanguagealias*[locale=mashriq]{arabic}{ar-SY}
\setlanguagealias*[locale=libya]{arabic}{ayl}
\setlanguagealias*[locale=default]{arabic}{apd}
\setlanguagealias*[locale=mashriq]{arabic}{ar-PS}

\define@boolkey{arabic}[arabic@]{abjadalph}[true]{}

\newif\ifeastern@numerals
\def\tmp@mashriq{mashriq}
\def\tmp@maghrib{maghrib}
\define@key{arabic}{numerals}[mashriq]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@mashriq%
    \eastern@numeralstrue%
  \else
    \ifx\@tmpa\tmp@maghrib\eastern@numeralsfalse\fi%
  \fi}

%this is needed for \abjad in arabicnumbers.sty
\def\tmp@true{true}
\define@key{arabic}{abjadjimnotail}[true]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@true\abjad@jim@notailtrue%
  \else
    \abjad@jim@notailfalse
  \fi}

\def\tmp@morocco{morocco}
\def\tmp@algeria{algeria}
\define@key{arabic}{locale}[default]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@morocco%
    \eastern@numeralsfalse%
    \SetLanguageKeys{arabic}{bcp47=ary}%
  \else
    \ifx\@tmpa\tmp@algeria%
      \eastern@numeralsfalse%
      \SetLanguageKeys{arabic}{bcp47=arq}%
    \fi%
  \fi%
  \gdef\@@arabic@month{\@arabic@month{#1}}}

\newif\if@hijrical
\def\tmp@hijri{hijri}
\def\tmp@islamic{islamic}
\define@key{arabic}{calendar}[gregorian]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@hijri\@hijricaltrue%
  \else
    \ifx\@tmpa\tmp@islamic\@hijricaltrue%
    \else\@hijricalfalse%
    \fi
  \fi}

\define@key{arabic}{hijricorrection}[0]{%
  \gdef\@hijri@correction{#1}}%

% Register default options
\xpg@initialize@gloss@options{arabic}{locale=default,calendar=gregorian,numerals=mashriq,hijricorrection=0,abjadjimnotail=false}
% Register alias options
\xpg@set@alias@values{arabic}{calendar}{islamic}{hijri}

\def\arabicgregmonth@default#1{\ifcase#1%
  % Egypt, Sudan, Yemen and Golf states
  \or يناير\or فبراير\or مارس\or أبريل\or مايو\or يونيو\or يوليو\or أغسطس\or سبتمبر\or أكتوبر\or نوفمبر\or ديسمبر\fi}
\def\arabicgregmonth@mashriq#1{\ifcase#1%
  % Iraq Syria Jordan Lebanon Palestine
  \or  كانون الثاني\or شباط\or آذار\or نيسان\or أيار\or حزيران\or تموز\or آب\or أيلول\or تشرين الأول\or تشرين الثاني\or كانون الأول\fi}
\def\arabicgregmonth@libya#1{\ifcase#1%
  %Lybia «تعرف في ليبيا بأسماء عربية وضعها معمر القذافي ترمز إلى فصول السنة وبعض الشخصيات التاريخية» (ar.wikipedia.org)
  \or أي النار\or النوار\or الربيع\or الطير\or الماء\or الصيف\or ناصر\or هانيبال\or الفاتح\or التمور\or الحرث\or الكانون\fi}
\def\arabicgregmonth@morocco#1{\ifcase#1%
  \or يناير\or فبراير\or مارس\or أبريل\or ماي\or يونيو\or يوليوز\or غشت\or شتنبر\or أكتوبر\or نونبر\or دجنبر\fi}
\def\arabicgregmonth@algeria#1{\ifcase#1%
  % Tunisia and Algeria
  \or جانفي\or فيفري\or مارس\or أفريل\or ماي\or جوان\or جويلية\or أوت\or سبتمبر\or أكتوبر\or نوفمبر\or ديسمبر\fi}
\let\arabicgregmonth@tunisia\arabicgregmonth@algeria
\def\arabicgregmonth@mauritania#1{\ifcase#1%
  \or يناير\or فبراير\or مارس\or إبريل\or مايو\or يونيو\or يوليو\or أغشت\or شتمبر\or أكتوبر\or نوفمبر\or دجمبر\fi}

\def\@arabic@month#1{\ifcsdef{arabicgregmonth@#1}{\expandafter\csname arabicgregmonth@#1\endcsname}%
{\xpg@warning{Option `locale=#1' is not defined for Arabic: using `default' instead}%
\arabicgregmonth@default}}

%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{arabic}{\@ensure@RTL{\arabicnumber{\value{Hijriday}}%
  \space\HijriMonthArabic{\value{Hijrimonth}}\space\arabicnumber{\value{Hijriyear}}}}

\def\captionsarabic{%
  \def\prefacename{\@ensure@RTL{مدخل}}%
  \def\refname{\@ensure@RTL{المراجع}}%
  \def\abstractname{\@ensure@RTL{ملخص}}%
  \def\bibname{\@ensure@RTL{المصادر}}%
  \def\chaptername{\@ensure@RTL{باب}}%
  \def\appendixname{\@ensure@RTL{الملاحق}}%
  \def\contentsname{\@ensure@RTL{المحتويات}}%
  %\def\contentsname{\@ensure@RTL{الفهرس}}%
  \def\listfigurename{\@ensure@RTL{قائمة الأشكال}}%
  \def\listtablename{\@ensure@RTL{قائمة الجداول}}%
  \def\indexname{\@ensure@RTL{الفهرس}}%
  \def\figurename{\@ensure@RTL{شكل}}%
  \def\tablename{\@ensure@RTL{جدول}}%
  \def\partname{\@ensure@RTL{القسم}}%
  \def\enclname{\@ensure@RTL{المرفقات}}%<-- Needs translation
  \def\ccname{\@ensure@RTL{نسخة ل‬}}% <<
  \def\headtoname{\@ensure@RTL{إلى}}%<-- Needs translation
  \def\pagename{\@ensure@RTL{صفحة}}%
  \def\seename{\@ensure@RTL{راجع}}%\alefhamza\nun\za\ra
  \def\alsoname{\@ensure@RTL{راجع أيضًا}}%<<\alefhamza\nun\za\ra
  \def\proofname{\@ensure@RTL{برهان}}%
  \def\glossaryname{\@ensure@RTL{قاموس}}%<<
}
\def\datearabic{%
 \def\today{%
  \if@hijrical%
    \Hijritoday[\@hijri@correction]%
  \else%
    \if@RTL%
       \arabicnumber\day\space\@@arabic@month{\month}%
        \space\arabicnumber\year%
    \else% in LR environment we format the gregorian date within \textenglish
       \ifcsdef{english@loaded}{\textenglish{\today}}%else US format
       {\normalfontlatin\ifcase\month\or January\or February\or March\or April\or May\or June\or%
       July\or August\or September\or October\or November\or December\fi%
       \space\number\day,\space\number\year}%
    \fi%
 \fi}}


\newcommand{\arabicnumerals}[2]{\arabicnumber{#2}}

\def\arabicnumber#1{%
  \ifeastern@numerals
    \@ensure@dir{\arabicdigits{\number#1}}%
  \else
    \number#1%
  \fi}

\def\@ornatebracearabic#1{\RL{\char"FD3F\@arabic#1\char"FD3E}}
\def\@ornatebracealph#1{\RL{\char"FD3F\@alph#1\char"FD3E}}

\def\abjadalph#1{\expandafter\arabic@abjad@alph{\number#1}}

% This is a poor man's Arabic alphanumeric. It just uses the alphabet and
% thus ends at 28.
\def\arabic@abjad@alph#1{\ifcase#1%
   \or ا\or ب\or\abjad@three\or د\or و\or ه‍\or ز%
   \or ح\or ط\or ي\or ك\or ل\or م\or ن%
   \or س\or ع\or ف\or ص\or ق\or ر\or ش%
   \or ت\or ث\or خ\or ذ\or ض\or ظ\or غ%
   \else\xpg@ill@value{#1}{arabic@abjad@alph}\fi%
}


\def\abjadmaghribi#1{%
\ifnum#1>1999\xpg@ill@value{#1}{abjad}%
\else
  \ifnum#1<\z@\space\xpg@ill@value{#1}{abjad}%
  \else
    \ifnum#1<10\expandafter\abj@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\abj@maghribi@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\abj@maghribi@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\abj@maghribi@num@iv\number#1%
          \fi
        \fi
      \fi
    \fi
  \fi
\fi
}

%maghribi س -> ص ص -> ض ش -> س ض -> ظ ظ -> غ غ -> ش
\def\abj@maghribi@num@ii#1{%
  \ifcase#1\or ي\or ك\or ل\or م\or ن%
           \or ص\or ع\or ف\or ض\fi
  \ifnum#1=\z@\abjad@zero\fi\abj@num@i}
\def\abj@maghribi@num@iii#1{%
  \ifcase#1\or ق\or ر\or س\or ت\or ث%
           \or خ\or ذ\or ظ\or غ\fi
  \ifnum#1=\z@\fi\abj@maghribi@num@ii}
\def\abj@maghribi@num@iv#1{%
  \ifcase#1\or ش\fi
  \ifnum#1=\z@\fi\abj@maghribi@num@iii}

\def\arabic@numbers{%
 \ifarabic@abjadalph
   \let\@alph\abjadalph%
   \let\@Alph\abjadalph%
 \else
   \let\@alph\abjad%
   \let\@Alph\abjad%
 \fi
}

\def\noarabic@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\arabic@globalnumbers{%
  \let\@arabic\arabicnumber%
  \renewcommand\thefootnote{\localnumeral*{footnote}}%
  \renewcommand\theequation{\localnumeral*{equation}}%
}

\def\noarabic@globalnumbers{%
   \let\@arabic\xpg@save@arabic%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@arabic{%
   \def\MakeUppercase##1{##1}%
   % TODO disable \@Roman and \@roman ?
}

\def\noextras@arabic{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase
}

%    \end{macrocode}
% \iffalse
%</gloss-arabic.ldf>
%<*gloss-armenian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-armenian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-armenian.ldf}[polyglossia: module for armenian]

\PolyglossiaSetup{armenian}{
  bcp47=hy,
  script=Armenian,
  scripttag=armn,
  langtag=HYE,
  hyphennames={armenian},
  hyphenmins={2,2},
  fontsetup=true,
  localnumeral=armeniannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{armenian}{hy}

\newif\if@eastern@armenian
\@eastern@armenianfalse
\define@choicekey*+{armenian}{variant}[\xpg@val\xpg@nr]{western,eastern}[western]{%
   \ifcase\xpg@nr\relax
      % western:
      \@eastern@armenianfalse%
   \or
      % eastern:
      \@eastern@armeniantrue%
   \fi
   \xpg@info{Option: Armenian, variant=\xpg@val}%
}{\xpg@warning{Unknown Armenian variant `#1'}}

\newif\if@armenian@numerals
\@armenian@numeralsfalse
\define@key{armenian}{numerals}[armenian]{%
  \ifstrequal{#1}{arabic}{\@armenian@numeralsfalse}{\@armenian@numeralstrue}%
}

% Register default options
\xpg@initialize@gloss@options{armenian}{numerals=armenian,variant=western}

% Taken from ArmTeX. Audit!
\def\captionsarmenian{%
   \def\refname{Հղումներ}%
   \def\abstractname{Սեղմագիր}%
   \def\bibname{Գրականություն}%
   \def\prefacename{Նախաբան}%
   \def\chaptername{Գլուխ}%
   \def\appendixname{Հավելված}%
   \def\contentsname{Բովանդակություն}%
   \def\listfigurename{Նկարների ցանկ}%
   \def\listtablename{Աղյուսակների ցանկ}%
   \def\indexname{Առարկայական ցանկ}%
   \def\figurename{Նկար}%
   \def\tablename{Աղյուսակ}%
   \def\partname{Մաս}%
   \def\pagename{էջ}%
   \def\seename{տե՛ս}%
   \def\alsoname{տե՛ս նաեւ}%
   \def\enclname{Կից՝}%
   \def\ccname{Կրկնօրինակը՝}%
% The \headtoname is empty: the typesetter should use the dative (trakan
% holov) of the recipient's name.
   \def\headtoname{}%
   \def\proofname{Ապացույց}%
   \def\glossaryname{Տերմինների ցանկ}%
}

\def\date@western@armenian{%
   \def\today{\ifcase\month\or
    Յունուար\or
    Փետրուար\or
    Մարտ\or
    Ապրիլ\or
    Մայիս\or
    Յունիս\or
    Յուլիս\or
    Օգոստոս\or
    Սեպտեմբեր\or
    Հոկտեմբեր\or
    Նոյեմբեր\or
    Դեկտեմբեր\fi
    \number\day,\space\number\year}%
}

\def\date@eastern@armenian{%
   \def\today{\ifcase\month\or
    Հունվար\or
    Փետրվար\or
    Մարտ\or
    Ապրիլ\or
    Մայիս\or
    Հունիս\or
    Հուլիս\or
    Օգոստոս\or
    Սեպտեմբեր\or
    Հոկտեմբեր\or
    Նոյեմբեր\or
    Դեկտեմբեր\fi
    \number\day,\space\number\year}%
}

\def\datearmenian{%
  \if@eastern@armenian
     \date@eastern@armenian%
  \else
     \date@western@armenian%
  \fi
}

\newcommand{\armeniannumerals}[2]{%
  \if@armenian@numerals
     \armeniannumber{#2}%
  \else
     #2%
  \fi%
}

\def\armenian@numbers{%
   \if@armenian@numerals
      \def\armenian@alph##1{\expandafter\armeniannumeral\expandafter{\the##1}}%
      \let\@alph\armenian@alph%
   \fi%
}

\def\noarmenian@numbers{%
  \let\@alph\latin@alph%
  \let\armenian@alph\@undefined%
}

\def\armenian@globalnumbers{%
  \if@armenian@numerals
    \let\@arabic\armeniannumber%
    \renewcommand\thefootnote{\localnumeral*{footnote}}%
    \renewcommand\theequation{\localnumeral*{equation}}%
  \fi
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\noarmenian@globalnumbers{
   \let\@arabic\xpg@save@arabic%
}

\protected\def\armeniannumber#1{\expandafter\@armeniannumber\expandafter{\number#1}}
\def\@armeniannumber#1{%
  \ifnum#1<\@ne\space\arm@ill@value{#1}%
  \else
    \ifnum#1<10\expandafter\arm@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\arm@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\arm@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\arm@num@iv\number#1%
          \else
             \space\arm@ill@value{#1}%
          \fi
        \fi
      \fi
    \fi
  \fi
}

\let\armeniannumeral=\armeniannumber
\def\arm@num@i#1{%
  \ifcase#1\or Ա\or Բ\or Գ\or Դ\or Ե\or Զ\or Է\or Ը\or Թ\fi}
\def\arm@num@ii#1{%
  \ifcase#1\or Ժ\or Ի\or Լ\or Խ\or Ծ\or Կ\or Հ\or Ձ\or Ղ\fi
  \arm@num@i}
\def\arm@num@iii#1{%
  \ifcase#1\or Ճ\or Մ\or Յ\or Ն\or Շ\or Ո\or Չ\or Պ\or Ջ\fi
  \arm@num@ii}
\def\arm@num@iv#1{%
  \ifcase#1\or Ռ\or Ս\or Վ\or Տ\or Ր\or Ց\or Ւ\or Փ\or Ք\fi
  \arm@num@iii}
\def\arm@ill@value#1{\xpg@warning{Illegal value (#1) for Armenian numeral}[$#1$]}

%    \end{macrocode}
% \iffalse
%</gloss-armenian.ldf>
%<*gloss-arq.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-arq.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-arq.ldf}[polyglossia: module for arq (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-arq.ldf>
%<*gloss-ary.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ary.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ary.ldf}[polyglossia: module for ary (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ary.ldf>
%<*gloss-arz.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-arz.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-arz.ldf}[polyglossia: module for arz (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-arz.ldf>
%<*gloss-ast.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ast.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ast.ldf}[polyglossia: module for ast (asturian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{asturian}

%    \end{macrocode}
% \iffalse
%</gloss-ast.ldf>
%<*gloss-asturian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-asturian.ldf}
%    \begin{macrocode}
% Translated by Xuacu <xuacusk8 at gmail dot com>
% Contributed by Kevin Godby <godbyk at gmail dot com>
%
\ProvidesFile{gloss-asturian.ldf}[polyglossia: module for asturian]
\PolyglossiaSetup{asturian}{
  bcp47=ast,
  hyphennames={asturian,catalan},
  hyphenmins={2,2},
  langtag=AST,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{asturian}{ast}

\def\captionsasturian{%
   \def\prefacename{Entamu}%
   \def\refname{Referencies}%
   \def\abstractname{Sumariu}%
   \def\bibname{Bibliografía}%
   \def\chaptername{Capítulu}%
   \def\appendixname{Apéndiz}%
   \def\contentsname{Conteníu}%
   \def\listfigurename{Llista de figures}%
   \def\listtablename{Llista de tables}%
   \def\indexname{Índiz}%
   \def\figurename{Figura}%
   \def\tablename{Tabla}%
   \def\partname{Parte}%
   \def\enclname{incl.}%
   \def\ccname{cc}%
   \def\headtoname{Pa}%
   \def\pagename{Páxina}%
   \def\seename{ver}%
   \def\alsoname{ver tamién}%
   \def\proofname{Demostración}%
   \def\glossaryname{Glosariu}%
   }
\def\dateasturian{%
   \def\today{\number\day~\ifcase\month\or
    de~xineru\or de~febreru\or de~marzu\or d'abril\or de~mayu\or de~xunu\or
    de~xunetu\or d'agostu\or de~setiembre\or d'ochobre\or de~payares\or
    d'avientu\fi\space de~\number\year}%
}

%    \end{macrocode}
% \iffalse
%</gloss-asturian.ldf>
%<*gloss-australian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-australian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-australian.ldf}[polyglossia: module for australian english]

% We provide this as a babel alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-australian.ldf>
%<*gloss-austrian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-austrian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-austrian.ldf}[polyglossia: module for austrian german (old spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-austrian.ldf>
%<*gloss-ayl.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ayl.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ayl.ldf}[polyglossia: module for ayl (arabic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{arabic}

%    \end{macrocode}
% \iffalse
%</gloss-ayl.ldf>
%<*gloss-bahasa.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bahasa.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bahasa.ldf}[polyglossia: module for bahasa indonesia]

% We provide this as a babel alias

\xpg@load@master@language{malay}

%    \end{macrocode}
% \iffalse
%</gloss-bahasa.ldf>
%<*gloss-bahasai.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bahasai.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bahasai.ldf}[polyglossia: module for bahasa indonesia]

% We only provide this gloss for babel compatibility. Since bahasai is 
% a malay variety, we use 'malay' with variant 'indonesian' now.

\xpg@load@master@language{malay}

%    \end{macrocode}
% \iffalse
%</gloss-bahasai.ldf>
%<*gloss-bahasam.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bahasam.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bahasam.ldf}[polyglossia: module for bahasa melayu]

% We only provide this gloss for babel compatibility. Since bahasam is 
% a malay variety, we use 'malay' with variant 'malaysian' now.

\xpg@load@master@language{malay}

%    \end{macrocode}
% \iffalse
%</gloss-bahasam.ldf>
%<*gloss-basque.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-basque.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-basque.ldf}[polyglossia: module for basque]
\PolyglossiaSetup{basque}{
  bcp47=eu,
  hyphennames={basque},
  hyphenmins={2,2},
  langtag=EUQ,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{basque}{eu}

\def\captionsbasque{%
   \def\refname{Erreferentziak}%
   \def\abstractname{Laburpena}%
   \def\bibname{Bibliografia}%
   \def\prefacename{Hitzaurrea}%
   \def\chaptername{Kapitulua}%
   \def\appendixname{Eranskina}%
   \def\contentsname{Gaien Aurkibidea}%
   \def\listfigurename{Irudien Zerrenda}%
   \def\listtablename{Taulen Zerrenda}%
   \def\indexname{Kontzeptuen Aurkibidea}%
   \def\figurename{Irudia}%
   \def\tablename{Taula}%
   \def\thepart{}%
   \def\partname{Atala}%
   \def\pagename{Orria}%
   \def\seename{Ikusi}%
   \def\alsoname{Ikusi, halaber}%
   \def\enclname{Erantsia}%
   \def\ccname{Kopia}%
   \def\headtoname{Nori}%
   \def\proofname{Frogapena}%
   \def\glossaryname{Glosarioa}%
   }
\def\datebasque{%
   \def\today{\number\year.eko\space\ifcase\month\or
    urtarrilaren\or otsailaren\or martxoaren\or apirilaren\or
    maiatzaren\or ekainaren\or uztailaren\or abuztuaren\or
    irailaren\or urriaren\or azaroaren\or
    abenduaren\fi~\number\day}}

%    \end{macrocode}
% \iffalse
%</gloss-basque.ldf>
%<*gloss-be-tarask.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-be-tarask.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-be-tarask.ldf}[polyglossia: module for be-tarask (belarusian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{belarusian}

%    \end{macrocode}
% \iffalse
%</gloss-be-tarask.ldf>
%<*gloss-be.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-be.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-be.ldf}[polyglossia: module for be (belarusian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{belarusian}

%    \end{macrocode}
% \iffalse
%</gloss-be.ldf>
%<*gloss-belarusian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-belarusian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-belarusian.ldf}[polyglossia: module for belarusian]

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{belarusian}{
  bcp47=be,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=BEL,
  hyphennames={belarusian},
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup,
  localnumeral=belarusiannumerals,
  Localnumeral=Belarusiannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*[spelling=classic]{belarusian}{be-tarask}
\setlanguagealias*{belarusian}{be}

\def\belarusian@spelling{modern}
\define@choicekey*+{belarusian}{spelling}[\xpg@val\xpg@nr]{modern,classic,tarask}[modern]{%
   \ifcase\xpg@nr\relax
      % modern:
      \def\belarusian@spelling{modern}%
      \SetLanguageKeys{belarusian}{bcp47=be}%
   \or
      % classic:
      \def\belarusian@spelling{tarask}%
      \SetLanguageKeys{belarusian}{bcp47=be-tarask}%
   \or
      % tarask:
      \def\belarusian@spelling{tarask}%
      \SetLanguageKeys{belarusian}{bcp47=be-tarask}%
   \fi
}{\xpg@warning{Unknown Belarusian spelling `#1'}}

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals
\define@choicekey*+{belarusian}{numerals}[\xpg@val\xpg@nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
   \ifcase\xpg@nr\relax
      % arabic:
      \cyrillic@numeralsfalse%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-trad:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-alph:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralstrue%
   \fi
   \xpg@info{Option: Belarusian, numerals=\xpg@val}%
}{\xpg@warning{Unknown Belarusian numerals value `#1'}}

\define@boolkey{belarusian}[belarusian@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{belarusian}{babelshorthands=false,numerals=arabic,spelling=modern}
% Register alias options
\xpg@set@alias@values{belarusian}{spelling}{classic}{tarask}

\ifsystem@babelshorthands
  \setkeys{belarusian}{babelshorthands=true}
\else
  \setkeys{belarusian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\belarusian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{belarusian}%
  \declare@shorthand{belarusian}{"`}{„}%
  \declare@shorthand{belarusian}{"'}{“}%
  \declare@shorthand{belarusian}{"<}{«}%
  \declare@shorthand{belarusian}{">}{»}%
  \declare@shorthand{belarusian}{""}{\hskip\z@skip}%
  \declare@shorthand{belarusian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{belarusian}{"=}{\nobreak-\hskip\z@skip}%
  \declare@shorthand{belarusian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
  \declare@shorthand{belarusian}{"-}{%
     \def\belarusian@sh@tmp{%
       \if\belarusian@sh@next-\expandafter\belarusian@sh@emdash%
       \else\expandafter\belarusian@sh@hyphen\fi%
     }%
     \futurelet\belarusian@sh@next\belarusian@sh@tmp%
  }%
  \def\belarusian@sh@hyphen{%
    \nobreak\-\bbl@allowhyphens}%
  \def\belarusian@sh@emdash##1##2{\cdash-##1##2}%
  \def\cdash##1##2##3{\def\tempx@{##3}%
  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
   \ifx\tempx@\tempa@\@Acdash\else
    \ifx\tempx@\tempb@\@Bcdash\else
     \ifx\tempx@\tempc@\@Ccdash\else
      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
    \cyrdash\hskip.2em\ignorespaces}%
  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z@skip\ignorespaces}%
  \def\@Ccdash{\leavevmode
   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
  \ifx\cyrdash\undefined
    \def\cyrdash{\hbox to.8em{\textendash\hss\textendash}}%
  \fi
  \declare@shorthand{belarusian}{",}{\nobreak\hskip.2em\ignorespaces}%
}

\def\nobelarusian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

% Taken from babel-belarusian
\def\captionsbelarusian@modern{%
    \def\prefacename{Прадмова}%
    \def\refname{Спіс літаратуры}%
    \def\abstractname{Анатацыя}%
    \def\bibname{Літаратура}%
    \def\chaptername{Глава}%
    \def\appendixname{Дадатак}%
    \def\contentsname{Змест}%
    \def\listfigurename{Спіс ілюстрацый}%
    \def\listtablename{Спіс табліц}%
    \def\indexname{Прадметны паказальнік}%
    \def\authorname{Паказальнік імён}%
    \def\figurename{Рыс.}%
    \def\tablename{Табліца}%
    \def\partname{Частка}%
    \def\enclname{укл.}%
    \def\ccname{зых.}%
    \def\headtoname{вх.}%
    \def\pagename{с.}%
    \def\seename{гл.}%
    \def\alsoname{гл.\ таксама}%
    \def\proofname{Доказ}%
    \def\glossaryname{Слоўнік тэрмінаў}%
    \def\acronymname{Абрэвіятуры}%
    \def\lstlistingname{Лістынг}%
    \def\lstlistlistingname{Лістынгі}%
    \def\notesname{Нататкі}%
}

\def\captionsbelarusian@tarask{%
    \def\prefacename{Прадмова}%
    \def\refname{Сьпіс літаратуры}%
    \def\abstractname{Анатацыя}%
    \def\bibname{Літаратура}%
    \def\chaptername{Глава}%
    \def\appendixname{Дадатак}%
    \def\contentsname{Зьмест}%
    \let\tocname=\contentsname
    \def\listfigurename{Сьпіс ілюстрацый}%
    \def\listtablename{Сьпіс табліц}%
    \def\indexname{Прадметны паказальнік}%
    \def\authorname{Паказальнік імён}%
    \def\figurename{Рыс.}%
    \def\tablename{Табліца}%
    \def\partname{Частка}%
    \def\enclname{укл.}%
    \def\ccname{зых.}%
    \def\headtoname{вх.}%
    \def\pagename{с.}%
    \def\seename{гл.}%
    \def\alsoname{гл.\ таксама}%
    \def\proofname{Доказ}%
    \def\glossaryname{Слоўнік тэрмінаў}%
    \def\acronymname{Абрэвіятуры}%
    \def\lstlistingname{Лістынг}%
    \def\lstlistlistingname{Лістынгі}%
    \def\nomname{Азначэньні}%
    \def\notesname{Нататкі}%
}

\def\captionsbelarusian{%
  \csuse{captionsbelarusian@\belarusian@spelling}%
}

\def\datebelarusian@modern{%
   \def\today{\number\day~\ifcase\month\or
    студзеня\or
    лютага\or
    сакавіка\or
    красавіка\or
    мая\or
    чэрвеня\or
    ліпеня\or
    жніўня\or
    верасня\or
    кастрычніка\or
    лістапада\or
    снежня\fi
    \space \number\year~г.}%
}

\def\datebelarusian@tarask{%
   \def\today{\number\day~\ifcase\month\or%
    студзеня\or
    лютага\or
    сакавіка\or
    красавіка\or
    траўня\or
    чэрвеня\or
    ліпеня\or
    жніўня\or
    верасьня\or
    кастрычніка\or
    лістапада\or
    сьнежня\fi%
    \space \number\year~г.}%
}

\def\datebelarusian{%
  \csuse{datebelarusian@\belarusian@spelling}%
}

\newcommand{\belarusiannumerals}[2]{\belarusiannumber{#2}}
\newcommand{\Belarusiannumerals}[2]{\Belarusiannumber{#2}}

\def\belarusiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \belarusian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Belarusiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \belarusian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\belarusiannumeral=\belarusiannumber
\let\Belarusiannumeral=\Belarusiannumber

\def\Asbuk#1{\expandafter\belarusian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\belarusian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}


% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\belarusian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{belarusian@asbuk@Alph}\fi%
}

\def\belarusian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{belarusian@asbuk@alph}\fi%
}

\def\belarusian@numbers{%
   \let\latin@alph\@alph
   \let\latin@Alph\@Alph
   \ifcyrillic@numerals%
     \def\belarusian@alph##1{\expandafter\belarusiannumeral\expandafter{\the##1}}%
     \def\belarusian@Alph##1{\expandafter\belarusiannumeral\expandafter{\the##1}}%
      \let\@alph\belarusian@alph%
      \let\@Alph\belarusian@Alph%
   \fi
}

\def\nobelarusian@numbers{%
   \let\@alph\latin@alph%
   \let\@Alph\latin@Alph%
}

\def\noextras@belarusian{%
   \ifcyrillic@numerals\nobelarusian@numbers\fi%
   \ifbelarusian@babelshorthands\nobelarusian@shorthands\fi%
}

\def\blockextras@belarusian{%
   \ifcyrillic@numerals\belarusian@numbers\fi%
   \ifbelarusian@babelshorthands\belarusian@shorthands\fi%
}

\def\inlineextras@belarusian{%
   \ifbelarusian@babelshorthands\belarusian@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-belarusian.ldf>
%<*gloss-bengali.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bengali.ldf}
%    \begin{macrocode}
% Translations provided by সাজেদুর রহিম জোয়ারদার <toshazed@gmail.com>
% TODO implement Bengali calendar

\ProvidesFile{gloss-bengali.ldf}[polyglossia: module for bengali]

\RequirePackage{devanagaridigits}
\RequirePackage{bengalidigits}

\PolyglossiaSetup{bengali}{
  bcp47=bn,
  script=Bengali,
  scripttag=beng,
  langtag=BEN,
  hyphennames={bengali},
  hyphenmins={2,2},%CHECK
  fontsetup=true,
  localnumeral=bengalinumerals
  %TODO nouppercase=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{bengali}{bn}

\newif\ifbengali@devanagari@numerals
\newif\ifbengali@bengali@numerals
\define@choicekey*+{bengali}{numerals}[\xpg@val\xpg@nr]{Devanagari,Bengali,Western}[Devanagari]{%
   \ifcase\xpg@nr\relax
      % Devanagari:
      \bengali@bengali@numeralsfalse%
      \bengali@devanagari@numeralstrue%
   \or
      % Bengali:
      \bengali@bengali@numeralstrue%
      \bengali@devanagari@numeralsfalse%
   \or
      % Western:
      \bengali@bengali@numeralsfalse%
      \bengali@devanagari@numeralsfalse%
   \fi
   \xpg@info{Option: Bengali, numerals=\xpg@val}%
}{\xpg@warning{Unknown Bengali numeral `#1'}}

\def\extras@bengali{}
\def\noextras@bengali{}

\define@boolkey{bengali}[bengali@]{changecounternumbering}[true]{}

% Register default options
\xpg@initialize@gloss@options{bengali}{changecounternumbering=false,numerals=Devanagari}

\def\captionsbengali{%
  \def\refname{তথ্যসূত্রসমূহ}%
  \def\abstractname{সারসংক্ষেপ}%
  \def\bibname{তথ্যবিবরণ}%
  \def\prefacename{পূর্বকথা}%
  \def\chaptername{অধ্যায়}%
  \def\appendixname{পরিশিষ্ট}%
  \def\contentsname{সূচীপত্র}%
  \def\listfigurename{ছবি/নকশা সমূহের তালিকা}%
  \def\listtablename{তালিকাসারণী}%
  \def\indexname{সূচক/নির্দেশক}%
  \def\figurename{চিত্র}%
  \def\tablename{সারণী}%
  %\def\thepart{}% TODO
  \def\partname{খন্ড}%
  \def\pagename{পৃষ্ঠা}%
  \def\seename{দেখুন}%
  \def\alsoname{আরও দেখুন}%
  \def\enclname{সংযুক্তি}%
  \def\ccname{অনুলিপি}%
  \def\headtoname{প্রতি}%
  \def\proofname{প্রমাণ}%
  \def\glossaryname{পরিভাষার শব্দসম্ভার}%
}
\def\datebengali{%
  \def\bengalimonth{%
    \ifcase\month\or
      জানুয়ারি\or
      ফেব্রুয়ারি\or
      মার্চ\or
      এপ্রিল\or
      মে\or
      জুন\or
      জুলাই\or
      আগস্ট\or
      সেপ্টেম্বর\or
      অক্টোবর\or
      নভেম্বর\or
      ডিসেম্বর\fi}%
  \def\today{\bengalinumber\day\space\bengalimonth\space\bengalinumber\year}%
}

\newcommand{\bengalinumerals}[2]{\bengalinumber{#2}}

\def\bengalinumber#1{%
  \ifbengali@devanagari@numerals
    \devanagaridigits{\number#1}%
  \else
    \ifbengali@bengali@numerals
      \bengalidigits{\number#1}%
    \else % Assumed Western
      \number#1%
    \fi
  \fi%
}

% Backwards compatibility. This command was never documented, but
% some people might use it nevertheless (see #381).
% This takes a counter.
\newcommand\bengalinumeral[1]{\localnumeral*[lang=bengali]{#1}}

\def\bengali@globalnumbers{%
   \ifbengali@changecounternumbering
     \let\@arabic\bengalinumber%
     \renewcommand\thefootnote{\localnumeral*{footnote}}%
  \fi
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\nobengali@globalnumbers{%
  \let\@arabic\xpg@save@arabic%
}

\def\blockextras@bengali{\extras@bengali}
\def\inlineextras@bengali{\extras@bengali}

%    \end{macrocode}
% \iffalse
%</gloss-bengali.ldf>
%<*gloss-bg.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bg.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bg.ldf}[polyglossia: module for bg (bulgarian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{bulgarian}

%    \end{macrocode}
% \iffalse
%</gloss-bg.ldf>
%<*gloss-bn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bn.ldf}[polyglossia: module for bn (bengali)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{bengali}

%    \end{macrocode}
% \iffalse
%</gloss-bn.ldf>
%<*gloss-bo.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bo.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bo.ldf}[polyglossia: module for bo (tibetan)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{tibetan}

%    \end{macrocode}
% \iffalse
%</gloss-bo.ldf>
%<*gloss-bosnian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bosnian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bosnian.ldf}[polyglossia: module for bosnian]

\PolyglossiaSetup{bosnian}{
  bcp47=bs,
  langtag=BOS,
  hyphennames={bosnian,croatian},
  hyphenmins={2,2}, % adapted from gloss-croatian
  frenchspacing=true, % adapted from gloss-croatian
  indentfirst=false, % adapted from gloss-croatian
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{bosnian}{bs}

% TODO: Add script=Cyrillic

% from babel-bosnian
\def\captionsbosnian{%
  \def\prefacename{Predgovor}%
  \def\refname{Literatura}%
  \def\abstractname{Sažetak}%
  \def\bibname{Bibliografija}%
  \def\chaptername{Poglavlje}%
  \def\appendixname{Dodatak}%
  \def\contentsname{Sadržaj}%
  \def\listfigurename{Popis slika}%
  \def\listtablename{Popis tablica}%
  \def\indexname{Indeks}%
  \def\figurename{Slika}%
  \def\tablename{Tablica}%
  \def\partname{Dio}%
  \def\enclname{Prilozi}%
  \def\ccname{Kopija}%
  \def\headtoname{Prima}%
  \def\pagename{Stranica}%
  \def\seename{Vidjeti}%
  \def\alsoname{Također vidjeti}%
  \def\proofname{Dokaz}%
  \def\glossaryname{Rječnik}%
}

\def\datebosnian{%
  \def\today{\number\day.~\ifcase\month\or
    januar\or februar\or mart\or april\or maj\or
    juni\or juli\or august\or septembar\or oktobar\or novembar\or
    decembar\fi \space \number\year.~}%
}

%    \end{macrocode}
% \iffalse
%</gloss-bosnian.ldf>
%<*gloss-br.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-br.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-br.ldf}[polyglossia: module for br (breton)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{breton}

%    \end{macrocode}
% \iffalse
%</gloss-br.ldf>
%<*gloss-brazil.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-brazil.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-brazil.ldf}[polyglossia: module for brazilian portuguese]

% We only provide this gloss for backwards compatibility. The name
% 'brazil' was selected in accordance with babel.
% Since brazil is a variety of portuguese, we use 'portuguese' now.

\xpg@load@master@language{portuguese}

%    \end{macrocode}
% \iffalse
%</gloss-brazil.ldf>
%<*gloss-breton.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-breton.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-breton.ldf}[polyglossia: module for breton]
\PolyglossiaSetup{breton}{
  bcp47=br,
  hyphennames={breton},
  hyphenmins={2,2},
  langtag=BRE,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{breton}{br}

\ifluatex
  % TODO
\else
  \newXeTeXintercharclass\breton@punctthin % ! ? ;
  \newXeTeXintercharclass\breton@punctthick % :
\fi

\def\breton@punctthinspace{{\unskip\thinspace}}
\def\breton@punctthickspace{{\unskip\nobreakspace}}

\def\breton@punctuation{%
  \ifluatex
    % TODO
  \else
    \XeTeXinterchartokenstate=1%
    \XeTeXcharclass `\! \breton@punctthin
    \XeTeXcharclass `\? \breton@punctthin
    \XeTeXcharclass `\; \breton@punctthin
    \XeTeXcharclass `\: \breton@punctthick
    \XeTeXinterchartoks \z@ \breton@punctthin = \breton@punctthinspace
    \XeTeXinterchartoks \z@ \breton@punctthick = \breton@punctthickspace
  \fi
}

\def\nobreton@punctuation{%
  \ifluatex
    % TODO
  \else
    \XeTeXcharclass `\! \z@
    \XeTeXcharclass `\? \z@
    \XeTeXcharclass `\; \z@
    \XeTeXcharclass `\: \z@
    \XeTeXinterchartokenstate=0%
  \fi
}


\def\captionsbreton{%
   \def\refname{Daveennoù}%
   \def\abstractname{Dvierrañ}%
   \def\bibname{Lennadurezh}%
   \def\prefacename{Rakskrid}%
   \def\chaptername{Pennad}%
   \def\appendixname{Stagadenn}%
   \def\contentsname{Taolenn}%
   \def\listfigurename{Listenn ar Figurennoù}%
   \def\listtablename{Listenn an taolennoù}%
   \def\indexname{Meneger}%
   \def\figurename{Figurenn}%
   \def\tablename{Taolenn}%
   \def\thepart{}%
   \def\partname{Lodenn}%
   \def\pagename{Pajenn}%
   \def\seename{Gwelout}%
   \def\alsoname{Gwelout ivez}%
   \def\enclname{Dielloù kevret}%
   \def\ccname{Eilskrid da}%
   \def\headtoname{evit}%
   \def\proofname{Proof}%
   \def\glossaryname{Glossary}%
   }
\def\datebreton{%
   \def\today{\ifnum\day=1\relax 1\/\textsuperscript{añ}\else
    \number\day\fi \space a\space viz\space\ifcase\month\or
    Genver\or C'hwevrer\or Meurzh\or Ebrel\or Mae\or Mezheven\or
    Gouere\or Eost\or Gwengolo\or Here\or Du\or Kerzu\fi
    \space\number\year}}

\def\noextras@breton{%
   \nobreton@punctuation%
   }

\def\blockextras@breton{%
   \breton@punctuation%
   }

\def\inlineextras@breton{%
   \breton@punctuation%
   }

%    \end{macrocode}
% \iffalse
%</gloss-breton.ldf>
%<*gloss-british.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-british.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-british.ldf}[polyglossia: module for british english]

% We provide this as a babel alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-british.ldf>
%<*gloss-bs.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bs.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bs.ldf}[polyglossia: module for bs (bosnian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{bosnian}

%    \end{macrocode}
% \iffalse
%</gloss-bs.ldf>
%<*gloss-bulgarian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-bulgarian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-bulgarian.ldf}[polyglossia: module for bulgarian]
\PolyglossiaSetup{bulgarian}{
  bcp47=bg,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=BGR,
  hyphennames={bulgarian},
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup
  %TODO localalph=bulgarian@alph
}

% BCP-47 compliant aliases
\setlanguagealias*{bulgarian}{bg}

\def\bulgarian@Alph#1{%
   \ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or Й\or К\or Л\or М\or Н\or
   О\or П\or Р\or С\or Т\or У\or Ф\or
   Х\or Ц\or Ч\or Ш\or Щ\or Ъ\or
   Ю\or Я\else
   \xpg@ill@value{#1}{bulgarian@Alph}\fi}%

\def\bulgarian@alph#1{%
   \ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or й\or к\or л\or м\or н\or
   о\or п\or р\or с\or т\or у\or ф\or
   х\or ц\or ч\or ш\or щ\or ъ\or ь\or
   ю\or я\else
   \xpg@ill@value{#1}{bulgarian@alph}\fi}%

\def\bulgarian@numbers{%
   \let\@Alph\bulgarian@Alph%
   \let\@alph\bulgarian@alph%
 }

\def\nobulgarian@numbers{%
   \let\@Alph\latin@Alph%
   \let\@alph\latin@alph%
}

\def\captionsbulgarian{%
   \def\refname{Литература}%
   \def\abstractname{Абстракт}%
   \def\bibname{Библиография}%
   \def\prefacename{Предговор}%
   \def\chaptername{Глава}%
   \def\appendixname{Приложение}%
   \def\contentsname{Съдържание}%
   \def\listfigurename{Списък на фигурите}%
   \def\listtablename{Списък на таблиците}%
   \def\indexname{Азбучен указател}%
   \def\figurename{Фигура}%
   \def\tablename{Таблица}%
   %\def\thepart{}%
   %\def\partname{}%
   \def\pagename{Стр.}%
   \def\seename{вж.}%
   \def\alsoname{вж.\ също и}%
   \def\enclname{Приложения}%
   \def\ccname{копия}%
   %\def\headtoname{}%
   \def\proofname{Proof}%
   \def\glossaryname{Glossary}%
}

\def\datebulgarian{%
   \def\today{\number\day~\ifcase\month\or
       януари\or
       февруари\or
       март\or
       април\or
       май\or
       юни\or
       юли\or
       август\or
       септември\or
       октомври\or
       ноември\or
       декември\fi%
       \ \number\year~г.}%
    \def\month@Roman{\expandafter\@Roman\month}%
    \def\todayRoman{\number\day.\,\month@Roman.\,\number\year~г.}%
    }

%    \end{macrocode}
% \iffalse
%</gloss-bulgarian.ldf>
%<*gloss-ca.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ca.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ca.ldf}[polyglossia: module for ca (catalan)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{catalan}

%    \end{macrocode}
% \iffalse
%</gloss-ca.ldf>
%<*gloss-canadian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-canadian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-canadian.ldf}[polyglossia: module for canadian english]

% We provide this as a babel alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-canadian.ldf>
%<*gloss-canadien.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-canadien.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-canadien.ldf}[polyglossia: module for canadian french]

% We provide this as a babel alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-canadien.ldf>
%<*gloss-catalan.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-catalan.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-catalan.ldf}[polyglossia: module for catalan]
\PolyglossiaSetup{catalan}{
  bcp47=ca,
  hyphennames={catalan},
  hyphenmins={2,2},
  langtag=CAT,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{catalan}{ca}

\define@boolkey{catalan}[catalan@]{babelshorthands}[true]{}
\ifsystem@babelshorthands
  \setkeys{catalan}{babelshorthands=true}
\else
  \setkeys{catalan}{babelshorthands=false}
\fi

% Register default options
\xpg@initialize@gloss@options{catalan}{babelshorthands=false}

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

%%% adapted from Babel's catalan.ldf
\newdimen\leftllkern \newdimen\rightllkern \newdimen\raiselldim

% we check if char · exists, and use it instead of raised dot:
\def\xpg@raiseddot{%
  \charifavailable{00B7}{\raise\raiselldim\hbox{.}}%
}

\def\lgem{%
  \ifmmode
    \csname normal@char\string"\endcsname l%
  \else
    \leftllkern=0pt\rightllkern=0pt\raiselldim=0pt%
    \setbox0\hbox{l}%
    \xpg@if@char@available{00B7}%
          {\setbox2\hbox{\char"00B7}\setbox1\hbox{l}}%
          {\setbox2\hbox{.}\setbox1\hbox{l\/}}%
    \setbox3\hbox{.}%
    \advance\raiselldim by \the\fontdimen5\the\font%
    \advance\raiselldim by -\ht2%
    \leftllkern=-.25\wd0%
    \advance\leftllkern by \wd1%
    \advance\leftllkern by -\wd0%
    \advance\leftllkern by -0.5\wd2%
    \advance\leftllkern by 0.5\wd3%
    \rightllkern=-.25\wd0%
    \advance\rightllkern by -\wd1%
    \advance\rightllkern by \wd0%
    \advance\rightllkern by -0.5\wd2%
    \advance\rightllkern by 0.5\wd3%
    \allowhyphens\discretionary{l-}{l}%
    {\hbox{l}\kern\leftllkern\xpg@raiseddot%
      \kern\rightllkern\hbox{l}}\allowhyphens
  \fi
}

\def\Lgem{%
  \ifmmode
    \csname normal@char\string"\endcsname L%
  \else
    \leftllkern=0pt\rightllkern=0pt\raiselldim=0pt%
    \setbox0\hbox{L}%
    \xpg@if@char@available{00B7}%
          {\setbox2\hbox{\char"00B7}\setbox1\hbox{L}}%
          {\setbox2\hbox{.}\setbox1\hbox{L\/}}%
    \setbox3\hbox{.}%
    \advance\raiselldim by .5\ht0%
    \advance\raiselldim by -.5\ht2%
    \leftllkern=-.125\wd0%
    \advance\leftllkern by \wd1%
    \advance\leftllkern by -\wd0%
    \advance\leftllkern by -0.5\wd2%
    \advance\leftllkern by 0.5\wd3%
    \rightllkern=-\wd0%
    \divide\rightllkern by 6%
    \advance\rightllkern by -\wd1%
    \advance\rightllkern by \wd0%
    \advance\rightllkern by -0.5\wd2%
    \advance\rightllkern by 0.5\wd3%
    \allowhyphens\discretionary{L-}{L}%
    {\hbox{L}\kern\leftllkern\xpg@raiseddot%
      \kern\rightllkern\hbox{L}}\allowhyphens
  \fi
}

\AtBeginDocument{%
  \let\lslash\l
  \let\Lslash\L
  \DeclareRobustCommand\l{\@ifnextchar.\bbl@l{\@ifnextchar·\bbl@l\lslash}}
  \DeclareRobustCommand\L{\@ifnextchar.\bbl@L{\@ifnextchar·\bbl@L\Lslash}}}
\def\bbl@l#1#2{\lgem}
\def\bbl@L#1#2{\Lgem}

\def\catalan@shorthands{%
  \bbl@activate{"}%
  \def\language@group{catalan}%
  \declare@shorthand{catalan}{"l}{\lgem{}}
  \declare@shorthand{catalan}{"L}{\Lgem{}}
}

\def\nocatalan@shorthands{%
    \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captionscatalan{%
   \def\refname{Referències}%
   \def\abstractname{Resum}%
   \def\bibname{Bibliografia}%
   \def\prefacename{Pròleg}%
   \def\chaptername{Capítol}%
   \def\appendixname{Apèndix}%
   \def\contentsname{Índex}%
   \def\listfigurename{Índex de figures}%
   \def\listtablename{Índex de taules}%
   \def\indexname{Índex alfabètic}%
   \def\figurename{Figura}%
   \def\tablename{Taula}%
   %\def\thepart{}%
   \def\partname{Part}%
   \def\pagename{Pàgina}%
   \def\seename{Vegeu}%
   \def\alsoname{Vegeu també}%
   \def\enclname{Adjunt}%
   \def\ccname{Còpies a}%
   \def\headtoname{A}%
   \def\proofname{Demostració}%
   \def\glossaryname{Glossari}%
   }
\def\datecatalan{%
   \def\today{\number\day~\ifcase\month\or
    de gener\or de febrer\or de març\or d'abril\or de maig\or
    de juny\or de juliol\or d'agost\or de setembre\or d'octubre\or
    de novembre\or de desembre\fi
    \space de~\number\year}}

\def\noextras@catalan{%
   \ifcatalan@babelshorthands\nocatalan@shorthands\fi%
}

\def\blockextras@catalan{%
   \ifcatalan@babelshorthands\catalan@shorthands\fi%
}

\def\inlineextras@catalan{%
   \ifcatalan@babelshorthands\catalan@shorthands\fi%
}
%    \end{macrocode}
% \iffalse
%</gloss-catalan.ldf>
%<*gloss-ckb-Arab.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ckb-Arab.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ckb-Arab.ldf}[polyglossia: module for ckb-Arab (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ckb-Arab.ldf>
%<*gloss-ckb-Latn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ckb-Latn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ckb-Latn.ldf}[polyglossia: module for ckb-Latn (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ckb-Latn.ldf>
%<*gloss-ckb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ckb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ckb.ldf}[polyglossia: module for ckb (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ckb.ldf>
%<*gloss-cop.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-cop.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-cop.ldf}[polyglossia: module for cop (coptic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{coptic}

%    \end{macrocode}
% \iffalse
%</gloss-cop.ldf>
%<*gloss-coptic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-coptic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-coptic.ldf}[polyglossia: module for coptic]
\PolyglossiaSetup{coptic}{
  bcp47=cop,
  script=Coptic,
  scripttag=copt,
  langtag=COP,
  hyphennames={coptic},
  hyphenmins={2,2},
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{coptic}{cop}

%\def\captionscoptic{%
%   \def\refname{<++>}%
%   \def\abstractname{<++>}%
%   \def\bibname{<++>}%
%   \def\prefacename{<++>}%
%   \def\chaptername{<++>}%
%   \def\appendixname{<++>}%
%   \def\contentsname{<++>}%
%   \def\listfigurename{<++>}%
%   \def\listtablename{<++>}%
%   \def\indexname{<++>}%
%   \def\figurename{<++>}%
%   \def\tablename{<++>}%
%   \def\thepart{}%
%   \def\partname{<++>}%
%   \def\pagename{<++>}%
%   \def\seename{<++>}%
%   \def\alsoname{<++>}%
%   \def\enclname{<++>}%
%   \def\ccname{<++>}%
%   \def\headtoname{<++>}%
%   \def\proofname{<++>}%
%   \def\glossaryname{<++>}%
%   }
%\def\datecoptic{%
%   \def\today{<++>}%
%   }

%    \end{macrocode}
% \iffalse
%</gloss-coptic.ldf>
%<*gloss-croatian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-croatian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-croatian.ldf}[polyglossia: module for croatian]
\PolyglossiaSetup{croatian}{
  bcp47=hr,
  langtag=HRV,
  hyphennames={croatian},
  hyphenmins={2,2}, % aligned with https://ctan.org/pkg/hrhyph patterns and http://lebesgue.math.hr/~nenad/Diplomski/Maja_Ribaric_2011.pdf
  frenchspacing=true, % recommendation from Damir Bralić
  indentfirst=false, % recommendation from Damir Bralić
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{croatian}{hr}

\ifluatex
  \RequirePackage{luavlna}
\fi

\define@boolkey{croatian}[croatian@]{babelshorthands}[true]{}

\define@boolkey{croatian}[croatian@]{disableligatures}[true]{}

\define@boolkey{croatian}[croatian@]{splithyphens}[true]{}

% Register default options
\xpg@initialize@gloss@options{croatian}{babelshorthands=false,disableligatures=false,splithyphens=true}

\ifsystem@babelshorthands
  \setkeys{croatian}{babelshorthands=true}
\else
  \setkeys{croatian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\croatian@@splhyphen#1{%
  \ifnum\hyphenchar \font>0%
    \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
    \nobreak\hskip\z@%
  \else%
    #1%
  \fi%
}

\def\croatian@splhyphen{%
  \croatian@@splhyphen{-}%
}

\def\croatian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{croatian}%
  \declare@shorthand{croatian}{"=}{\penalty\@M-\hskip\z@skip}%
  \declare@shorthand{croatian}{""}{\hskip\z@skip}%
  \declare@shorthand{croatian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{croatian}{"-}{\nobreak\-\bbl@allowhyphens}%
  \declare@shorthand{croatian}{"|}{%
      \textormath{\penalty\@M\discretionary{-}{}{\kern.03em}%
      \bbl@allowhyphens}{}%
  }%
  \declare@shorthand{croatian}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
  \declare@shorthand{croatian}{"`}{„}%
  \declare@shorthand{croatian}{"'}{”}%
  \declare@shorthand{croatian}{"<}{«}%
  \declare@shorthand{croatian}{">}{»}%
  \declare@shorthand{croatian}{"D}{\xpg@hr@lig{D}}%
  \declare@shorthand{croatian}{"d}{\xpg@hr@lig{d}}%
  \declare@shorthand{croatian}{"L}{\xpg@hr@lig{L}}%
  \declare@shorthand{croatian}{"l}{\xpg@hr@lig{l}}%
  \declare@shorthand{croatian}{"N}{\xpg@hr@lig{N}}%
  \declare@shorthand{croatian}{"n}{\xpg@hr@lig{n}}%
}

\def\nocroatian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\ifxetex
  % splithyphens
  \newXeTeXintercharclass\croatian@hyphen % -
  \newXeTeXintercharclass\croatian@nonsyllabicpreposition%
\fi

\def\croatian@hyphens{%
    \ifluatex
      \AfterPreamble{\enablesplithyphens{croatian}}%
    \else
      \XeTeXinterchartokenstate=1
      \XeTeXcharclass `\- \croatian@hyphen
      \XeTeXinterchartoks \z@ \croatian@hyphen = {\croatian@@splhyphen}% "-" -> "\croatian@@splhyphen-"
      % necessary if used together with vlna:
      \XeTeXinterchartoks \croatian@nonsyllabicpreposition \croatian@hyphen = {\croatian@@splhyphen}% "-" -> "\croatian@@splhyphen-"
    \fi%
}

\def\nocroatian@hyphens{%
    \ifluatex
      \AfterPreamble{\disablesplithyphens{croatian}}%
    \else
      \XeTeXcharclass `\- \z@
    \fi%
}

\newcommand*\hr@charifavailable[2]{%
   \ifcroatian@disableligatures
     \bgroup#2\egroup%
   \else
     \charifavailable{#1}{#2}%
   \fi%
}

% Provide croatian ligatures if available in current font
\def\xpg@hr@lig#1#2{%
 \bgroup%
  % 1. DŽ, Dž and dž
  \ifx#1D%
    \ifx#2Z\relax%
       \hr@charifavailable{01C4}{DŽ}%
    \else%
       \ifx#2z\relax
          \hr@charifavailable{01C5}{Dž}%
       \else
           D#2%
       \fi%
    \fi%
  \fi%
  \ifx#1d%
    \ifx#2z\relax
       \hr@charifavailable{01C6}{dž}%
    \else
       d#2%
    \fi%
  \fi%
  % 2. LJ, Lj and lj
  \ifx#1L%
    \ifx#2J\relax%
       \hr@charifavailable{01C7}{LJ}%
    \else%
       \ifx#2j\relax
          \hr@charifavailable{01C8}{Lj}%
       \else
           L#2%
       \fi%
    \fi%
  \fi%
  \ifx#1l%
    \ifx#2j\relax
       \hr@charifavailable{01C9}{lj}%
    \else
       l#2%
    \fi%
  \fi%
  % 2. NJ, Nj and nj
  \ifx#1N%
    \ifx#2J\relax%
       \hr@charifavailable{01CA}{NJ}%
    \else%
       \ifx#2j\relax
          \hr@charifavailable{01CB}{Nj}%
       \else
           N#2%
       \fi%
    \fi%
  \fi%
  \ifx#1n%
    \ifx#2j\relax
       \hr@charifavailable{01CC}{nj}%
    \else
       n#2%
    \fi%
  \fi%
  \egroup%
}

\def\captionscroatian{%
  \def\prefacename{Predgovor}%
  \def\refname{Literatura}%
  \def\abstractname{Sažetak}%
  \def\bibname{Bibliografija}%
  \def\chaptername{Poglav\hr@charifavailable{01C9}{lj}e}%
  \def\appendixname{Dodatak}%
  \def\contentsname{Sadržaj}%
  \def\listfigurename{Popis slika}%
  \def\listtablename{Popis tablica}%
  \def\indexname{Kazalo}%
  \def\figurename{Slika}%
  \def\tablename{Tablica}%
  \def\partname{Dio}%
  \def\enclname{Prilozi}%
  \def\ccname{Kopija}%
  \def\headtoname{Prima}%
  \def\pagename{Stranica}%
  \def\seename{Vidjeti}%
  \def\alsoname{Također vidjeti}%
  \def\proofname{Dokaz}%
  \def\glossaryname{Pojmovnik}%
}

\def\datecroatian{%
  \def\today{\number\day.~\ifcase\month\or
    siječnja\or veljače\or ožujka\or travnja\or svibnja\or
    lipnja\or srpnja\or kolovoza\or rujna\or listopada\or studenoga\or
    prosinca\fi \space \number\year.}%
}

\def\noextras@croatian{%
  \ifcroatian@babelshorthands\nocroatian@shorthands\fi%
  \nocroatian@hyphens%
}

\def\blockextras@croatian{%
  \ifcroatian@babelshorthands\croatian@shorthands\fi%
  \ifcroatian@splithyphens\croatian@hyphens\else\nocroatian@hyphens\fi%
}

\def\inlineextras@croatian{%
  \ifcroatian@babelshorthands\croatian@shorthands\fi%
  \ifcroatian@splithyphens\croatian@hyphens\else\nocroatian@hyphens\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-croatian.ldf>
%<*gloss-cy.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-cy.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-cy.ldf}[polyglossia: module for cy (welsh)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{welsh}

%    \end{macrocode}
% \iffalse
%</gloss-cy.ldf>
%<*gloss-cz.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-cz.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-cz.ldf}[polyglossia: module for cz (czech)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{czech}

%    \end{macrocode}
% \iffalse
%</gloss-cz.ldf>
%<*gloss-czech.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-czech.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-czech.ldf}[polyglossia: module for czech]

\PolyglossiaSetup{czech}{
  bcp47=cz,
  hyphennames={czech},
  hyphenmins={2,2},
  langtag=CSY,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{czech}{cz}

\ifluatex
  \RequirePackage{luavlna}
\fi

\define@boolkey{czech}[czech@]{babelshorthands}[true]{}

\define@boolkey{czech}[czech@]{splithyphens}[true]{}

\define@boolkey{czech}[czech@]{vlna}[true]{}

% Register default options
\xpg@initialize@gloss@options{czech}{babelshorthands=false,splithyphens=true,vlna=true}

\ifsystem@babelshorthands
  \setkeys{czech}{babelshorthands=true}
\else
  \setkeys{czech}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\cs@@splithyphen#1{%
  \ifnum\hyphenchar \font>0%
    \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
    \nobreak\hskip\z@%
  \else%
    #1%
  \fi%
}

\def\cs@splithyphen{%
  \cs@@splithyphen{-}%
}

\def\czech@shorthands{%
  \bbl@activate{"}%
  \def\language@group{czech}%
  \declare@shorthand{czech}{"=}{\cs@splithyphen}%
  \declare@shorthand{czech}{"`}{„}%
  \declare@shorthand{czech}{"'}{“}%
  \declare@shorthand{czech}{"<}{«}%
  \declare@shorthand{czech}{">}{»}%
}

\def\noczech@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\ifxetex
  % splithyphens
  \newXeTeXintercharclass\czech@hyphen % -
  % vlna
  \newXeTeXintercharclass\czech@openpunctuation
  \newXeTeXintercharclass\czech@nonsyllabicpreposition
  \ifdefined\e@alloc@intercharclass@top
    \chardef\czech@boundary=\e@alloc@intercharclass@top
  \else
    \ifdefined\XeTeXinterwordspaceshaping
      \chardef\czech@boundary=4095 %
      \def\newXeTeXintercharclass{%
        \e@alloc\XeTeXcharclass\chardef
              \xe@alloc@intercharclass\m@ne\@ucharclass@boundary}%
    \else
      \chardef\czech@boundary=255
    \fi
  \fi
\fi

\def\czech@hyphens{%
    \ifluatex
      \AfterPreamble{\enablesplithyphens{czech}}%
    \else
      \XeTeXinterchartokenstate=1
      \XeTeXcharclass `\- \czech@hyphen
      \XeTeXinterchartoks \z@ \czech@hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
      % necessary if used together with vlna:
      \XeTeXinterchartoks \czech@nonsyllabicpreposition \czech@hyphen = {\cs@@splithyphen}% "-" -> "\cs@@splithyphen-"
    \fi%
}

\def\noczech@hyphens{%
    \ifluatex
      \AfterPreamble{\disablesplithyphens{czech}}%
    \else
      \XeTeXcharclass `\- \z@
    \fi%
}

% Add nonbreakable space after single-letter word to
% prevent them to land at the end of a line
% vlna code taken and adapted from xevlna.sty
\ifxetex
    \def\czech@nointerchartoks{\let\czech@interchartoks\czech@PreCSpreposition}%
    \def\czech@PreCSpreposition{%
       \def\next{}%
       \ifnum\catcode`\ =10 % nothing will be done in verbatim
       \ifmmode % nothing in math
       \else
          \let\czech@interchartoks\czech@nointerchartoks
          \let\next\czech@ExamineCSpreposition
       \fi\fi
       \next%
    }%
    \def\czech@ExamineCSpreposition #1{#1\futurelet\next\czech@ProcessCSpreposition}%
    \def\czech@ProcessCSpreposition{\ifx\next\czech@XeTeXspace\nobreak\fi}%
    \futurelet\czech@XeTeXspace{ }\czech@nointerchartoks
\fi

\def\czech@vlna{%
    \ifluatex
       \preventsingleon
    \else
        % Code taken and adapted from xevlna.sty
        \XeTeXinterchartokenstate=1
        \XeTeXcharclass `\( \czech@openpunctuation
        \XeTeXcharclass `\[ \czech@openpunctuation
        \XeTeXcharclass `\„ \czech@openpunctuation
        \XeTeXcharclass `\» \czech@openpunctuation
        \XeTeXcharclass `\K \czech@nonsyllabicpreposition
        \XeTeXcharclass `\k \czech@nonsyllabicpreposition
        \XeTeXcharclass `\S \czech@nonsyllabicpreposition
        \XeTeXcharclass `\s \czech@nonsyllabicpreposition
        \XeTeXcharclass `\V \czech@nonsyllabicpreposition
        \XeTeXcharclass `\v \czech@nonsyllabicpreposition
        \XeTeXcharclass `\Z \czech@nonsyllabicpreposition
        \XeTeXcharclass `\z \czech@nonsyllabicpreposition
        \XeTeXcharclass `\O \czech@nonsyllabicpreposition
        \XeTeXcharclass `\o \czech@nonsyllabicpreposition
        \XeTeXcharclass `\U \czech@nonsyllabicpreposition
        \XeTeXcharclass `\u \czech@nonsyllabicpreposition
        \XeTeXcharclass `\A \czech@nonsyllabicpreposition
        \XeTeXcharclass `\a \czech@nonsyllabicpreposition
        \XeTeXcharclass `\I \czech@nonsyllabicpreposition
        \XeTeXcharclass `\i \czech@nonsyllabicpreposition
        \XeTeXinterchartoks \czech@boundary \czech@nonsyllabicpreposition {\czech@interchartoks}%
        \XeTeXinterchartoks \czech@openpunctuation \czech@nonsyllabicpreposition {\czech@interchartoks}%
    \fi
}

\def\noczech@vlna{%
    \ifluatex
        \preventsingleoff
    \else
        \XeTeXcharclass`\(\z@
        \XeTeXcharclass`\[\z@
        \XeTeXcharclass`\„\z@
        \XeTeXcharclass`\»\z@
        \XeTeXcharclass`\K\z@
        \XeTeXcharclass`\k\z@
        \XeTeXcharclass`\S\z@
        \XeTeXcharclass`\s\z@
        \XeTeXcharclass`\V\z@
        \XeTeXcharclass`\v\z@
        \XeTeXcharclass`\Z\z@
        \XeTeXcharclass`\z\z@
        \XeTeXcharclass`\O\z@
        \XeTeXcharclass`\o\z@
        \XeTeXcharclass`\U\z@
        \XeTeXcharclass`\u\z@
        \XeTeXcharclass`\A\z@
        \XeTeXcharclass`\a\z@
        \XeTeXcharclass`\I\z@
        \XeTeXcharclass`\i\z@
    \fi
}


\def\captionsczech{%
   \def\refname{Reference}%
   \def\abstractname{Abstrakt}%
   \def\bibname{Literatura}%
   \def\prefacename{Předmluva}%
   \def\chaptername{Kapitola}%
   \def\appendixname{Dodatek}%
   \def\contentsname{Obsah}%
   \def\listfigurename{Seznam obrázků}%
   \def\listtablename{Seznam tabulek}%
   \def\indexname{Index}%
   \def\figurename{Obrázek}%
   \def\tablename{Tabulka}%
   %\def\thepart{}%
   \def\partname{Část}%
   \def\pagename{Strana}%
   \def\seename{viz}%
   \def\alsoname{viz}%
   \def\enclname{Příloha}%
   \def\ccname{Na vědomí:}%
   \def\headtoname{Komu}%
   \def\proofname{Důkaz}%
   \def\glossaryname{Slovník}%was Glosář
}

\def\dateczech{%
   \def\today{\number\day.~\ifcase\month\or
    ledna\or února\or března\or dubna\or května\or
    června\or července\or srpna\or září\or
    října\or listopadu\or prosince\fi
    \space \number\year}%
}

\def\noextras@czech{%
  \ifczech@babelshorthands\noczech@shorthands\fi%
  \noczech@hyphens%
  \noczech@vlna%
  \ifxetex\XeTeXinterchartokenstate=0\fi%
}

\def\blockextras@czech{%
  \ifczech@babelshorthands\czech@shorthands\fi%
  \ifczech@vlna\czech@vlna\else\noczech@vlna\fi%
  \ifczech@splithyphens\czech@hyphens\else\noczech@hyphens\fi%
}

\def\inlineextras@czech{%
  \ifczech@babelshorthands\czech@shorthands\fi%
  \ifczech@vlna\czech@vlna\else\noczech@vlna\fi%
  \ifczech@splithyphens\czech@hyphens\else\noczech@hyphens\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-czech.ldf>
%<*gloss-da.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-da.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-da.ldf}[polyglossia: module for da (danish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{danish}

%    \end{macrocode}
% \iffalse
%</gloss-da.ldf>
%<*gloss-danish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-danish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-danish.ldf}[polyglossia: module for danish]
\PolyglossiaSetup{danish}{
  bcp47=da,
  hyphennames={danish},
  hyphenmins={2,3},
  langtag=DAN,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{danish}{da}

\def\captionsdanish{%
  \def\prefacename{Forord}%
  \def\refname{Litteratur}%
  \def\abstractname{Resumé}%
  \def\bibname{Litteratur}%
  \def\chaptername{Kapitel}%
  \def\appendixname{Bilag}%
  \def\contentsname{Indhold}%
  \def\listfigurename{Figurer}%
  \def\listtablename{Tabeller}%
  \def\indexname{Indeks}%
  \def\figurename{Figur}%
  \def\tablename{Tabel}%
  \def\partname{Del}%
  \def\enclname{Vedlagt}%
  \def\ccname{Kopi til}%   or    Kopi sendt til
  \def\headtoname{Til}% in letter
  \def\pagename{Side}%
  \def\seename{Se}%
  \def\alsoname{Se også}%
  \def\proofname{Bevis}%
  \def\glossaryname{Gloseliste}%
}

\def\datedanish{%
  \def\today{\number\day.~\ifcase\month\or
    januar\or februar\or marts\or april\or maj\or juni\or
    juli\or august\or september\or oktober\or november\or december\fi
    \space\number\year}%
}

%    \end{macrocode}
% \iffalse
%</gloss-danish.ldf>
%<*gloss-de-AT-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-AT-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT-1901.ldf}[polyglossia: module for de-AT-1901 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-AT-1901.ldf>
%<*gloss-de-AT-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-AT-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT-1996.ldf}[polyglossia: module for de-AT-1996 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-AT-1996.ldf>
%<*gloss-de-AT.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-AT.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT.ldf}[polyglossia: module for de-AT (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-AT.ldf>
%<*gloss-de-CH-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-CH-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH-1901.ldf}[polyglossia: module for de-CH-1901 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-CH-1901.ldf>
%<*gloss-de-CH-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-CH-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH-1996.ldf}[polyglossia: module for de-CH-1996 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-CH-1996.ldf>
%<*gloss-de-CH.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-CH.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH.ldf}[polyglossia: module for de-CH (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-CH.ldf>
%<*gloss-de-DE-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-DE-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE-1901.ldf}[polyglossia: module for de-DE-1901 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-DE-1901.ldf>
%<*gloss-de-DE-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-DE-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE-1996.ldf}[polyglossia: module for de-DE-1996 (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-DE-1996.ldf>
%<*gloss-de-DE.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-DE.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE.ldf}[polyglossia: module for de-DE (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-DE.ldf>
%<*gloss-de-Latf-AT-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-AT-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT-1901-Latf.ldf}[polyglossia: module for de-AT-1901-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-AT-1901.ldf>
%<*gloss-de-Latf-AT-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-AT-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT-1996-Latf.ldf}[polyglossia: module for de-AT-1996-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-AT-1996.ldf>
%<*gloss-de-Latf-AT.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-AT.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-AT-Latf.ldf}[polyglossia: module for de-AT-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-AT.ldf>
%<*gloss-de-Latf-CH-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-CH-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH-1901-Latf.ldf}[polyglossia: module for de-CH-1901-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-CH-1901.ldf>
%<*gloss-de-Latf-CH-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-CH-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH-1996-Latf.ldf}[polyglossia: module for de-CH-1996-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-CH-1996.ldf>
%<*gloss-de-Latf-CH.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-CH.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-CH-Latf.ldf}[polyglossia: module for de-CH-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-CH.ldf>
%<*gloss-de-Latf-DE-1901.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-DE-1901.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE-1901-Latf.ldf}[polyglossia: module for de-DE-1901-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-DE-1901.ldf>
%<*gloss-de-Latf-DE-1996.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-DE-1996.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE-1996-Latf.ldf}[polyglossia: module for de-DE-1996-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-DE-1996.ldf>
%<*gloss-de-Latf-DE.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf-DE.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-DE-Latf.ldf}[polyglossia: module for de-DE-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf-DE.ldf>
%<*gloss-de-Latf.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de-Latf.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de-Latf.ldf}[polyglossia: module for de-Latf (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de-Latf.ldf>
%<*gloss-de.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-de.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-de.ldf}[polyglossia: module for de (german)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-de.ldf>
%<*gloss-divehi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-divehi.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-divehi.ldf}[polyglossia: module for divehi]

\RequireBidi
\PolyglossiaSetup{divehi}{
  bcp47=dv,
  script=Thaana,
  scripttag=thaa,
  langtag=DIV,% TODO Support DHV as well?
  direction=RL,
  hyphennames={nohyphenation},
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{divehi}{dv}

%\def\captionsdivehi{%
%   \def\refname{<++>}%
%   \def\abstractname{<++>}%
%   \def\bibname{<++>}%
%   \def\prefacename{<++>}%
%   \def\chaptername{<++>}%
%   \def\appendixname{<++>}%
%   \def\contentsname{<++>}%
%   \def\listfigurename{<++>}%
%   \def\listtablename{<++>}%
%   \def\indexname{<++>}%
%   \def\figurename{<++>}%
%   \def\tablename{<++>}%
%   \def\thepart{}%
%   \def\partname{<++>}%
%   \def\pagename{<++>}%
%   \def\seename{<++>}%
%   \def\alsoname{<++>}%
%   \def\enclname{<++>}%
%   \def\ccname{<++>}%
%   \def\headtoname{<++>}%
%   \def\proofname{<++>}%
%   \def\glossaryname{<++>}%
%   }
%\def\datedivehi{\def\today{<++>}}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@divehi{%
   \def\MakeUppercase##1{##1}%
}

\def\noextras@divehi{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-divehi.ldf>
%<*gloss-dsb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-dsb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-dsb.ldf}[polyglossia: module for dsb (sorbian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-dsb.ldf>
%<*gloss-dutch.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-dutch.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-dutch.ldf}[polyglossia: module for dutch]
\PolyglossiaSetup{dutch}{
  bcp47=nl,
  hyphennames={dutch},
  hyphenmins={2,2},
  langtag=NLD,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{dutch}{nl}

\define@boolkey{dutch}[dutch@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{dutch}{babelshorthands=false}

\ifsystem@babelshorthands
  \setkeys{dutch}{babelshorthands=true}
\else
  \setkeys{dutch}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\dutch@shorthands{%
  \bbl@activate{"}%
  \def\language@group{dutch}%
  \declare@shorthand{dutch}{"-}{\nobreak-\bbl@allowhyphens}
  \declare@shorthand{dutch}{"~}{\textormath{\leavevmode\hbox{-}}{-}}
  \declare@shorthand{dutch}{"|}{%
    \textormath{\discretionary{-}{}{\kern.03em}}{}}
  \declare@shorthand{dutch}{""}{\hskip\z@skip}
  \declare@shorthand{dutch}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
  \def\-{\bbl@allowhyphens\discretionary{-}{}{}\bbl@allowhyphens}%
}

\def\nodutch@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
  \def\-{\discretionary{-}{}{}}% << original def in latex.ltx
}

\def\captionsdutch{%
    \def\prefacename{Voorwoord}%
    \def\refname{Referenties}%
    \def\abstractname{Samenvatting}%
    \def\bibname{Bibliografie}%
    \def\chaptername{Hoofdstuk}%
    \def\appendixname{Bijlage}%
    \def\contentsname{Inhoudsopgave}%
    \def\listfigurename{Lijst van figuren}%
    \def\listtablename{Lijst van tabellen}%
    \def\indexname{Index}%
    \def\figurename{Figuur}%
    \def\tablename{Tabel}%
    \def\partname{Deel}%
    \def\enclname{Bijlage(n)}%
    \def\ccname{cc}%
    \def\headtoname{Aan}%
    \def\pagename{Pagina}%
    \def\seename{zie}%
    \def\alsoname{zie ook}%
    \def\proofname{Bewijs}%
    \def\glossaryname{Verklarende woordenlijst}%
}

\def\datedutch{%
    \def\today{\number\day~\ifcase\month%
      \or januari\or februari\or maart\or april\or mei\or juni\or
      juli\or augustus\or september\or oktober\or november\or
      december\fi
      \space \number\year}%
}

\def\noextras@dutch{%
  \ifdutch@babelshorthands\nodutch@shorthands\fi%
}

\def\blockextras@dutch{%
  \ifdutch@babelshorthands\dutch@shorthands\fi%
}

\def\inlineextras@dutch{%
  \ifdutch@babelshorthands\dutch@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-dutch.ldf>
%<*gloss-dv.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-dv.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-dv.ldf}[polyglossia: module for dv (divehi)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{divehi}

%    \end{macrocode}
% \iffalse
%</gloss-dv.ldf>
%<*gloss-el-monoton.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-el-monoton.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-el-monoton.ldf}[polyglossia: module for el-monoton (greek)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{greek}

%    \end{macrocode}
% \iffalse
%</gloss-el-monoton.ldf>
%<*gloss-el-polyton.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-el-polyton.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-el-polyton.ldf}[polyglossia: module for el-polyton (greek)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{greek}

%    \end{macrocode}
% \iffalse
%</gloss-el-polyton.ldf>
%<*gloss-el.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-el.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-el.ldf}[polyglossia: module for el (greek)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{greek}

%    \end{macrocode}
% \iffalse
%</gloss-el.ldf>
%<*gloss-en-AU.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en-AU.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en-AU.ldf}[polyglossia: module for en-AU (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en-AU.ldf>
%<*gloss-en-CA.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en-CA.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en-CA.ldf}[polyglossia: module for en-CA (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en-CA.ldf>
%<*gloss-en-GB.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en-GB.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en-GB.ldf}[polyglossia: module for en-GB (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en-GB.ldf>
%<*gloss-en-NZ.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en-NZ.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en-NZ.ldf}[polyglossia: module for en-NZ (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en-NZ.ldf>
%<*gloss-en-US.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en-US.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en-US.ldf}[polyglossia: module for en-US (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en-US.ldf>
%<*gloss-en.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-en.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-en.ldf}[polyglossia: module for en (english)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-en.ldf>
%<*gloss-english.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-english.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-english.ldf}[polyglossia: module for english]

\PolyglossiaSetup{english}{
  bcp47=en-US,
  hyphennames={english,american,usenglish,USenglish},
  hyphenmins={2,3},
  langtag=ENG,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{english}{en}
\setlanguagealias*[variant=australian]{english}{en-AU}
\setlanguagealias*[variant=newzealand]{english}{en-NZ}
\setlanguagealias*[variant=us]{english}{en-US}
\setlanguagealias*[variant=british]{english}{en-GB}
\setlanguagealias*[variant=canadian]{english}{en-CA}

% Babel aliases
\setlanguagealias[variant=us]{english}{american}
\setlanguagealias[variant=australian]{english}{australian}
\setlanguagealias[variant=british]{english}{british}
\setlanguagealias[variant=canadian]{english}{canadian}
\setlanguagealias[variant=newzealand]{english}{newzealand}

\providebool{british@hyphen}
\providebool{english@ordinalmonthday}
\providebool{british@dateformat}

% US English (\l@english) is default
% Initialize its settings
\def\english@variant{english}
\british@hyphenfalse
\english@ordinalmonthdayfalse
\british@dateformatfalse

% Option ordinalmonthday
\define@boolkey{english}[english@]{ordinalmonthday}[true]{}

\define@choicekey*+{english}{variant}[\xpg@val\xpg@nr]{uk,british,us,american,usmax,australian,newzealand,canadian}[us]{%
   \ifcase\xpg@nr\relax
      % uk:
      \british@hyphentrue
      \british@dateformattrue
      \english@ordinalmonthdaytrue
      \SetLanguageKeys{english}{babelname=british,bcp47=en-GB}%
      \xpg@info{Option: English, variant=british}%
   \or
      % british:
      \british@hyphentrue
      \british@dateformattrue
      \english@ordinalmonthdaytrue
      \SetLanguageKeys{english}{babelname=british,bcp47=en-GB}%
      \xpg@info{Option: english variant=british}%
   \or
      % us:
      \british@hyphenfalse
      \british@dateformatfalse
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=american,bcp47=en-US}%
      \xpg@info{Option: English, variant=american}%
   \or
      % american:
      \british@hyphenfalse
      \british@dateformatfalse
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=american,bcp47=en-US}%
      \xpg@info{Option: English, variant=american}%
   \or
      % usmax:
      \british@hyphenfalse
      \british@dateformatfalse
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=american,bcp47=en-US}%
      \xpg@info{Option: english variant=american (with additional patterns)}%
      \xpg@ifdefined{usenglishmax}{}%
         {\xpg@warning{No hyphenation patterns were loaded for "US English Max"\MessageBreak
                       I will use the standard patterns for US English instead}%
          \adddialect\l@usenglishmax\l@english\relax%
         }%
      \def\english@variant{usenglishmax}%
   \or
      % australian:
      % These use the british hyphenation patterns
      % but date formats without ordinals
      \british@hyphentrue
      \british@dateformattrue
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=australian,bcp47=en-AU}%
      \xpg@info{Option: English, variant=australian}%
      \adddialect\l@australian\l@english%
   \or
      % newzealand:
      % These use the british hyphenation patterns
      % but date formats without ordinals
      \british@hyphentrue
      \british@dateformattrue
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=newzealand,bcp47=en-NZ}%
      \xpg@info{Option: English, variant=newzealand}%
      \adddialect\l@newzealand\l@english%
   \or
      % canadian:
      % This is currently equivalent to usenglish (as in babel)
      \british@hyphenfalse
      \british@dateformatfalse
      \english@ordinalmonthdayfalse
      \SetLanguageKeys{english}{babelname=canadian,bcp47=en-CA}%
      \xpg@info{Option: English, variant=american}%
      \adddialect\l@canadian\l@english%
   \fi
   \ifbritish@hyphen
      \xpg@ifdefined{ukenglish}{}%
         {\xpg@warning{No hyphenation patterns were loaded for British English\MessageBreak
                       I will use the patterns for US English instead}%
          \adddialect\l@ukenglish\l@english\relax%
         }%
      \def\english@variant{ukenglish}%
   \fi
}{\xpg@warning{Unknown English variant `#1'}}

% Register default options
\xpg@initialize@gloss@options{english}{variant=us,ordinalmonthday=false}
% Register alias options
\xpg@set@alias@values{english}{variant}{us}{american}
\xpg@set@alias@values{english}{variant}{uk}{british}

\ifxetex
   % Check if \l@english is defined. If not, try to set it to some variety
   % (specific order as in the csv list below), or null language if everything fails
   \xpg@ifdefined{english}{}{%
      \def\do##1{%
         \xpg@ifdefined{#1}%
            {\csletcs{l@english}{l@#1}\listbreak}%
            {%
               \xpg@warning{No hyphenation patterns for English found"\MessageBreak
                            I will use the 'null' language instead}%
               \adddialect\l@english0
            }%
      }%
      \docsvlist{british, american, usenglishmax, australian, newzealand}
      \xpg@ifdefined{english}{}{}
   }%
\fi

\def\english@language{%
   \polyglossia@setup@language@patterns{\english@variant}%
}%

\def\captionsenglish{%
   \def\prefacename{Preface}%
   \def\refname{References}%
   \def\abstractname{Abstract}%
   \def\bibname{Bibliography}%
   \def\chaptername{Chapter}%
   \def\appendixname{Appendix}%
   \def\contentsname{Contents}%
   \def\listfigurename{List of Figures}%
   \def\listtablename{List of Tables}%
   \def\indexname{Index}%
   \def\figurename{Figure}%
   \def\tablename{Table}%
   \def\partname{Part}%
   \def\enclname{encl}%
   \def\ccname{cc}%
   \def\headtoname{To}%
   \def\pagename{Page}%
   \def\seename{see}%
   \def\alsoname{see also}%
   \def\proofname{Proof}%
}
\def\dateenglish{%
   \def\english@day{%
     \ifenglish@ordinalmonthday
       \ifcase\day\or
        1st\or 2nd\or 3rd\or 4th\or 5th\or
        6th\or 7th\or 8th\or 9th\or 10th\or
        11th\or 12th\or 13th\or 14th\or 15th\or
        16th\or 17th\or 18th\or 19th\or 20th\or
        21st\or 22nd\or 23rd\or 24th\or 25th\or
        26th\or 27th\or 28th\or 29th\or 30th\or
        31st\fi
     \else\number\day\fi}%
     \def\english@month{\ifcase\month\or
      January\or February\or March\or April\or May\or June\or
      July\or August\or September\or October\or November\or December\fi}%
   \def\today{%
    \ifbritish@dateformat
      \english@day\space\english@month\space\number\year
    \else
      \english@month\space\english@day,\space\number\year
    \fi}%
}

%    \end{macrocode}
% \iffalse
%</gloss-english.ldf>
%<*gloss-eo.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-eo.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-eo.ldf}[polyglossia: module for eo (esperanto)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{esperanto}

%    \end{macrocode}
% \iffalse
%</gloss-eo.ldf>
%<*gloss-es-ES.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-es-ES.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-es-ES.ldf}[polyglossia: module for es-ES (spanish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{spanish}

%    \end{macrocode}
% \iffalse
%</gloss-es-ES.ldf>
%<*gloss-es-MX.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-es-MX.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-es-MX.ldf}[polyglossia: module for es-MX (spanish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{spanish}

%    \end{macrocode}
% \iffalse
%</gloss-es-MX.ldf>
%<*gloss-es.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-es.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-es.ldf}[polyglossia: module for es (spanish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{spanish}

%    \end{macrocode}
% \iffalse
%</gloss-es.ldf>
%<*gloss-esperanto.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-esperanto.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-esperanto.ldf}[polyglossia: module for esperanto]
\PolyglossiaSetup{esperanto}{
  bcp47=eo,
  hyphennames={esperanto},
  hyphenmins={2,2},
  langtag=NTO,
  fontsetup=true,
  %TODO localalph={esperanto@alph,esperanto@Alph}
}

% BCP-47 compliant aliases
\setlanguagealias*{esperanto}{eo}

\def\captionsesperanto{%
   \def\refname{Citaĵoj}%
   \def\abstractname{Resumo}%
   \def\bibname{Bibliografio}%
   \def\prefacename{Antaŭparolo}%
   \def\chaptername{Ĉapitro}%
   \def\appendixname{Apendico}%
   \def\contentsname{Enhavo}%
   \def\listfigurename{Listo de figuroj}%
   \def\listtablename{Listo de tabeloj}%
   \def\indexname{Indekso}%
   \def\figurename{Figuro}%
   \def\tablename{Tabelo}%
   %\def\thepart{}%
   %\def\partname{}%
   \def\pagename{Paĝo}%
   \def\seename{vidu}%
   \def\alsoname{Parto}%
   \def\enclname{Aldono(j)}%
   \def\ccname{Kopie al}%
   \def\headtoname{Al}%
   \def\proofname{Pruvo}%
   \def\glossaryname{Glosaro}%
   }
\def\dateesperanto{%   
   \def\today{\number\day{–a}~de~\ifcase\month\or
    januaro\or februaro\or marto\or aprilo\or majo\or junio\or
    julio\or aŭgusto\or septembro\or oktobro\or novembro\or
    decembro\fi,\space \number\year}%
   \def\hodiau{la \today}%
   \def\hodiaun{la \number\day{–an}~de~\ifcase\month\or
      januaro\or februaro\or marto\or aprilo\or majo\or junio\or
      julio\or aŭgusto\or septembro\or oktobro\or novembro\or
      decembro\fi, \space \number\year}%
    }
\def\esperanto@alph#1{%
   \ifcase#1\or a\or b\or c\or ĉ\or d\or e\or f\or g\or ĝ\or
     h\or ĥ\or i\or j\or ĵ\or k\or l\or m\or n\or o\or
     p\or r\or s\or ŝ\or t\or u\or ŭ\or v\or z\else\xpg@ill@value{#1}{esperanto@alph}\fi}%
\def\esperanto@Alph#1{%
   \ifcase#1\or A\or B\or C\or Ĉ\or D\or E\or F\or G\or Ĝ\or
     H\or Ĥ\or I\or J\or Ĵ\or K\or L\or M\or N\or O\or
     P\or R\or S\or Ŝ\or T\or U\or Ŭ\or V\or Z\else\xpg@ill@value{#1}{esperanto@Alph}\fi}%

\def\esperanto@numbers{%
   \let\@Alph\esperanto@Alph%
   \let\@alph\esperanto@alph%
 }

\def\noesperanto@numbers{%
   \let\@Alph\latin@Alph% 
   \let\@alph\latin@alph%
}

%    \end{macrocode}
% \iffalse
%</gloss-esperanto.ldf>
%<*gloss-estonian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-estonian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-estonian.ldf}[polyglossia: module for estonian]
\PolyglossiaSetup{estonian}{
  bcp47=et,
  hyphennames={estonian},
  hyphenmins={2,2},
  langtag=ETI,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{estonian}{et}

\def\captionsestonian{%
   \def\refname{Viited}%
   \def\abstractname{Kokkuvõte}%
   \def\bibname{Kirjandus}%
   \def\prefacename{Sissejuhatus}%
   \def\chaptername{Peatükk}%
   \def\appendixname{Lisa}%
   \def\contentsname{Sisukord}%
   \def\listfigurename{Joonised}%
   \def\listtablename{Tabelid}%
   \def\indexname{Indeks}%
   \def\figurename{Joonis}%
   \def\tablename{Tabel}%
   %\def\thepart{}%
   \def\partname{Osa}%
   \def\pagename{Lk.}%
   \def\seename{vt.}%
   \def\alsoname{vt. ka}%
   \def\enclname{Lisa(d)}%
   \def\ccname{Koopia(d)}%
   %\def\headtoname{}%
   \def\proofname{Korrektuur}%
   \def\glossaryname{Glossary}% <-- need translation
   }
\def\dateestonian{%
   \def\today{\number\day.\space\ifcase\month\or
    jaanuar\or veebruar\or märts\or aprill\or mai\or juuni\or
    juuli\or august\or september\or oktoober\or november\or
    detsember\fi\space\number\year.\space a.}}

%    \end{macrocode}
% \iffalse
%</gloss-estonian.ldf>
%<*gloss-et.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-et.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-et.ldf}[polyglossia: module for et (estonian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{estonian}

%    \end{macrocode}
% \iffalse
%</gloss-et.ldf>
%<*gloss-eu.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-eu.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-eu.ldf}[polyglossia: module for eu (basque)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{basque}

%    \end{macrocode}
% \iffalse
%</gloss-eu.ldf>
%<*gloss-fa.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fa.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fa.ldf}[polyglossia: module for fa (persian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{persian}

%    \end{macrocode}
% \iffalse
%</gloss-fa.ldf>
%<*gloss-farsi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-farsi.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-farsi.ldf}[polyglossia: module for farsi]

% We only provide this gloss for babel compatibility.
% The proper English language name is Persian.

\xpg@load@master@language{persian}

%    \end{macrocode}
% \iffalse
%</gloss-farsi.ldf>
%<*gloss-fi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fi.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fi.ldf}[polyglossia: module for fi (finnish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{finnish}

%    \end{macrocode}
% \iffalse
%</gloss-fi.ldf>
%<*gloss-finnish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-finnish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-finnish.ldf}[polyglossia: module for finnish]
\PolyglossiaSetup{finnish}{
  bcp47=fi,
  hyphennames={finnish},
  hyphenmins={2,2},
  langtag=FIN,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{finnish}{fi}

\define@boolkey{finnish}[finnish@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{finnish}{babelshorthands=false}

\ifsystem@babelshorthands
  \setkeys{finnish}{babelshorthands=true}
\else
  \setkeys{finnish}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
    \input{babelsh.def}%
    \initiate@active@char{"}%
    \shorthandoff{"}%
}{}

\def\finnish@shorthands{%
  \bbl@activate{"}%
  \def\language@group{finnish}%
  \declare@shorthand{finnish}{"-}{\nobreak-\bbl@allowhyphens}
  \declare@shorthand{finnish}{"|}{\textormath{\penalty@M\discretionary{-}{}{\kern.03em}}{}}%
  \declare@shorthand{finnish}{""}{\hskip\z@skip}%
  \declare@shorthand{finnish}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{finnish}{"=}{\penalty@M-\hskip\z@skip}%
  \declare@shorthand{finnish}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
}

\def\nofinnish@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captionsfinnish{%
   \def\refname{Viitteet}%
   \def\abstractname{Tiivistelmä}%
   \def\bibname{Kirjallisuutta}%
   \def\prefacename{Esipuhe}%
   \def\chaptername{Luku}%
   \def\appendixname{Liite}%
   \def\contentsname{Sisällys}%
   \def\listfigurename{Kuvat}%
   \def\listtablename{Taulukot}%
   \def\indexname{Hakemisto}%
   \def\figurename{Kuva}%
   \def\tablename{Taulukko}%
   %\def\thepart{}%
   \def\partname{Osa}%
   \def\pagename{Sivu}%
   \def\seename{katso}%
   \def\alsoname{katso myös}%
   \def\enclname{Liitteet}%
   \def\ccname{Jakelu}%
   \def\headtoname{Vastaanottaja}%
   \def\proofname{Todistus}%
   \def\glossaryname{Sanasto}%
}
\def\datefinnish{%
   \def\today{\number\day.~\ifcase\month\or
    tammikuuta\or helmikuuta\or maaliskuuta\or huhtikuuta\or
    toukokuuta\or kesäkuuta\or heinäkuuta\or elokuuta\or
    syyskuuta\or lokakuuta\or marraskuuta\or joulukuuta\fi
    \space\number\year}}

\def\noextras@finnish{%
  \iffinnish@babelshorthands\nofinnish@shorthands\fi%
}

\def\blockextras@finnish{%
  \iffinnish@babelshorthands\finnish@shorthands\fi%
}

\def\inlineextras@finnish{%
  \iffinnish@babelshorthands\finnish@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-finnish.ldf>
%<*gloss-fr-CA.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fr-CA.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fr-CA.ldf}[polyglossia: module for fr-CA (french)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-fr-CA.ldf>
%<*gloss-fr-CH.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fr-CH.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fr-CH.ldf}[polyglossia: module for fr-CH (french)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-fr-CH.ldf>
%<*gloss-fr-FR.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fr-FR.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fr-FR.ldf}[polyglossia: module for fr-FR (french)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-fr-FR.ldf>
%<*gloss-fr.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fr.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fr.ldf}[polyglossia: module for fr (french)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{french}

%    \end{macrocode}
% \iffalse
%</gloss-fr.ldf>
%<*gloss-french.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-french.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-french.ldf}[polyglossia: module for french]

\PolyglossiaSetup{french}{%
  bcp47=fr-FR,
  language=French,
  script=Latin,
  langtag=FRA,
  hyphennames={french,francais},
  frenchspacing=true,
  indentfirst=true,
  hyphenmins={2,2},
  fontsetup=true}

% BCP-47 compliant aliases
\setlanguagealias*{french}{fr}
\setlanguagealias*[variant=french]{french}{fr-FR}
\setlanguagealias*[variant=canadian]{french}{fr-CA}
\setlanguagealias*[variant=swiss]{french}{fr-CH}

% Babel aliases
\setlanguagealias[variant=acadian]{french}{acadien}
\setlanguagealias[variant=canadian]{french}{canadien}

\def\french@variant{french}
\define@choicekey*+{french}{variant}[\xpg@val\xpg@nr]{french,canadian,acadian,swiss}[french]{%
   \ifcase\xpg@nr\relax
      % french:
      \def\french@variant{french}%
      \SetLanguageKeys{french}{babelname=french,bcp47=fr-FR}%
      \french@thincolonspacefalse
   \or
      % canadian:
      \def\french@variant{canadien}%
      \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA}%
      \xpg@ifdefined{canadien}{}%
      {\xpg@warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
        I will use the standard patterns for French instead}%
      \adddialect\l@canadien\l@french\relax}%
      \french@thincolonspacefalse
   \or
      % acadian:
      \def\french@variant{acadian}%
      \SetLanguageKeys{french}{babelname=canadien,bcp47=fr-CA}%
      \xpg@ifdefined{acadian}{}%
      {\xpg@warning{No hyphenation patterns were loaded for "French (Canada)"\MessageBreak
        I will use the standard patterns for French instead}%
      \adddialect\l@acadian\l@french\relax}%
      \french@thincolonspacefalse
   \or
      % swiss:
      \def\french@variant{swissfrench}%
      \SetLanguageKeys{french}{babelname=french,bcp47=fr-CH}%
      \adddialect\l@swissfrench\l@french\relax%
      \french@thincolonspacetrue
   \fi
   \xpg@info{Option: French, variant=\xpg@val}%
}{\xpg@warning{Unknown French variant `#1'}}


\def\french@language{%
   \polyglossia@setup@language@patterns{\french@variant}%
}%

\ifluatex
  \directlua{require('polyglossia-french')}%
\else
  \newXeTeXintercharclass\french@openbrackets % ( [ {
  \newXeTeXintercharclass\french@closebrackets % ) ] }
  \newXeTeXintercharclass\french@questionexclamation % ! ? et autres
  \newXeTeXintercharclass\french@punctthin % ; (et :)
  \newXeTeXintercharclass\french@punctthick % :
  \newXeTeXintercharclass\french@punctguillstart % « ‹
  \newXeTeXintercharclass\french@punctguillend % » ›
\fi

\def\xpg@unskip{\ifhmode\ifdim\lastskip>\z@\unskip\fi\fi}

% Save original footnote definition
% Do this at the end of the preamble to catch other
% packages' footnote changes (#391)
\AtEndPreamble{%
  \let\xpg@orig@makefntext\@makefntext
}

\define@boolkey{french}[french@]{frenchfootnote}[true]{%
  \AfterPreamble{%
    \iffrench@frenchfootnote
      \ifdefstring{\xpg@main@language}{french}{%
         \ifx\@makefntext\undefined\else
             \long\def\french@makefntext##1{%
                \parindent1em \noindent\quad%
                \ifx\@thefnmark\empty\else%
                \@thefnmark.\space\fi ##1%
             }
             \let\@makefntext\french@makefntext
         \fi
      }{\xpg@warning{Option 'frenchfootnote' only supported if French is main language!}}%
    \else
       \let\@makefntext\xpg@orig@makefntext
    \fi
  }%
}

\define@boolkey{french}[french@]{autospacing}[true]{}
\french@autospacingtrue

\define@boolkey{french}[french@]{frenchpart}[true]{}
\french@frenchparttrue

\newif\iffrench@autospaceguillemets
\define@boolkey{french}[french@]{autospaceguillemets}[true]{}
\french@autospaceguillemetstrue

\newif\iffrench@thincolonspace
\define@boolkey{french}[french@]{thincolonspace}[true]{}
\french@thincolonspacefalse

% Backwards compatibility
\define@boolkey{french}[french@]{automaticspacesaroundguillemets}[true]{%
   \iffrench@automaticspacesaroundguillemets
       \setkeys{french}{autospaceguillemets=true}%
   \else
       \setkeys{french}{autospaceguillemets=false}%
   \fi
}

% name is for compatibility with babel
\let\french@ttfamilyORI\ttfamily
\DeclareRobustCommand\french@ttfamilyFB{\nofrench@punctuation\french@ttfamilyORI}

% Allow to switch on autospacing in ttfamily context
\define@boolkey{french}[french@]{autospacetypewriter}[true]{}
\french@autospacetypewriterfalse

% This is how babel-french has it
\define@boolkey{french}[french@]{OriginalTypewriter}[true]{%
   \iffrench@OriginalTypewriter
       \setkeys{french}{autospacetypewriter=false}%
   \else
       \setkeys{french}{autospacetypewriter=true}%
   \fi
}

% Configuration of item labels
\def\french@itemi{\textemdash}
\def\french@itemii{\textemdash}
\def\french@itemiii{\textemdash}
\def\french@itemiv{\textemdash}

\define@key{french}{itemlabels}[\textemdash]{%
  \def\french@itemi{#1}
  \def\french@itemii{#1}
  \def\french@itemiii{#1}
  \def\french@itemiv{#1}
}

\define@key{french}{itemlabeli}[\textemdash]{%
  \def\french@itemi{#1}
}

\define@key{french}{itemlabelii}[\textemdash]{%
  \def\french@itemii{#1}
}

\define@key{french}{itemlabeliii}[\textemdash]{%
  \def\french@itemiii{#1}
}

\define@key{french}{itemlabeliv}[\textemdash]{%
  \def\french@itemiv{#1}
}

\define@boolkey{french}[french@]{frenchitemlabels}[true]{%
  \AfterPreamble{%
    \iffrench@frenchitemlabels
      \ifdefstring{\xpg@main@language}{french}{%
         \renewcommand{\labelitemi}{\french@itemi}%
         \renewcommand{\labelitemii}{\french@itemii}%
         \renewcommand{\labelitemiii}{\french@itemiii}%
         \renewcommand{\labelitemiv}{\french@itemiv}%
      }{\xpg@warning{Option 'frenchitemlabels' only supported if French is main language!}}%
    \else
       \let\@makefntext\xpg@orig@makefntext
    \fi
  }%
}

% Register default options
\xpg@initialize@gloss@options{french}{variant=french,autospacing=true,thincolonspace=false,
                                      autospaceguillemets=true,autospacetypewriter=false,
                                      frenchfootnote=false,frenchitemlabels=false,
                                      itemlabels=\textemdash,itemlabeli=\textemdash,itemlabelii=\textemdash,
                                      itemlabeliii=\textemdash,itemlabeliv=\textemdash}
% Register alias options
\xpg@set@alias@values{french}{variant}{canadian}{acadian}


\def\french@fontsetup{%
  \unless\iffrench@autospacetypewriter
    \let\ttfamily\french@ttfamilyFB
  \fi
}


\def\nofrench@fontsetup{%
  \let\ttfamily\french@ttfamilyORI
}

\def\xpg@french@thinsp{\kern 0.5\fontdimen2\font\nobreak\hskip\z@skip}

\def\french@punctuation{%
    \lccode"2019="2019
    \ifluatex
      \iffrench@thincolonspace
        \iffrench@autospaceguillemets
          \directlua{polyglossia.activate_french_punct(true, true)}%
        \else
          \directlua{polyglossia.activate_french_punct(true, false)}%
        \fi
      \else
        \iffrench@autospaceguillemets
          \directlua{polyglossia.activate_french_punct(false, true)}%
        \else
          \directlua{polyglossia.activate_french_punct(false, false)}%
        \fi
      \fi
    \else
      \XeTeXinterchartokenstate=1
      \XeTeXcharclass `\! \french@questionexclamation
      \XeTeXcharclass `\? \french@questionexclamation
      \XeTeXcharclass `\‼ \french@questionexclamation
      \XeTeXcharclass `\⁇ \french@questionexclamation
      \XeTeXcharclass `\⁈ \french@questionexclamation
      \XeTeXcharclass `\⁉ \french@questionexclamation
      \XeTeXcharclass `\‽ \french@questionexclamation % U+203D (interrobang)
      \XeTeXcharclass `\; \french@punctthin
      \iffrench@thincolonspace
        \XeTeXcharclass `\: \french@punctthin
      \else
        \XeTeXcharclass `\: \french@punctthick
      \fi
      \XeTeXcharclass `\« \french@punctguillstart
      \XeTeXcharclass `\» \french@punctguillend
      \XeTeXcharclass `\‹ \french@punctguillstart
      \XeTeXcharclass `\› \french@punctguillend
      \XeTeXcharclass `\( \french@openbrackets
      \XeTeXcharclass `\) \french@closebrackets
      \XeTeXcharclass `\[ \french@openbrackets
      \XeTeXcharclass `\] \french@closebrackets
      \XeTeXcharclass `\{ \french@openbrackets
      \XeTeXcharclass `\} \french@closebrackets
      \XeTeXcharclass `\⟨ \french@openbrackets
      \XeTeXcharclass `\⟩ \french@closebrackets
      \XeTeXinterchartoks \z@ \french@questionexclamation = {\xpg@french@thinsp}%
      \XeTeXinterchartoks \z@ \french@punctthin = {\xpg@french@thinsp}%
      \XeTeXinterchartoks \z@ \french@punctthick = {\nobreakspace}%
      \XeTeXinterchartoks \xpg@boundaryclass \french@questionexclamation = {\xpg@unskip\xpg@french@thinsp}%
      \XeTeXinterchartoks \xpg@boundaryclass \french@punctthin = {\xpg@unskip\xpg@french@thinsp}%
      \XeTeXinterchartoks \xpg@boundaryclass \french@punctthick = {\xpg@unskip\nobreakspace}%
      \iffrench@autospaceguillemets
        \let\xpg@french@guillspace\xpg@french@thinsp%
        \XeTeXinterchartoks \french@punctguillstart \z@ = {\xpg@french@guillspace}% "«a" -> "«\,a"
        \XeTeXinterchartoks \french@punctguillstart \french@punctguillstart = {\xpg@french@guillspace}% "«‹" -> "«\,‹"
 %      \XeTeXinterchartoks \z@ \french@punctguillstart = {\nobreakspace}% "a«" unchanged?
 %      \XeTeXinterchartoks \french@punctguillend \z@ = {\nobreakspace}% "»a" unchanged?
        \XeTeXinterchartoks \z@ \french@punctguillend = {\xpg@french@guillspace}% "a»" -> "a\,»"
        \XeTeXinterchartoks \french@punctguillstart \xpg@boundaryclass = {\xpg@french@guillspace\ignorespaces}% "«  " -> "«\,"
        \XeTeXinterchartoks \xpg@boundaryclass \french@punctguillend = {\xpg@unskip\xpg@french@guillspace}% "  »" -> "\,»"
        \XeTeXinterchartoks \french@closebrackets \french@punctguillend = {\xpg@french@guillspace}% ")»" -> ")\,»"
        \XeTeXinterchartoks \french@questionexclamation \french@punctguillend  = {\xpg@french@guillspace}% "?»" -> "?\,»"
        \XeTeXinterchartoks \french@punctthin \french@punctguillend  = {\xpg@french@guillspace}% ";»" -> ";\,»"
        \XeTeXinterchartoks \french@punctguillend \french@punctguillend  = {\xpg@french@guillspace}% "›»" -> "›\,»"
     \else
       \def\xpg@french@guillspace{}%
     \fi
     \XeTeXinterchartoks \french@punctguillend \french@questionexclamation = {\xpg@french@thinsp}% "»?" -> "»\,?"
     \XeTeXinterchartoks \french@punctguillend \french@punctthin = {\xpg@french@thinsp}% "»;" -> "»\,;"
     \XeTeXinterchartoks \french@punctguillend \french@punctthick = {\nobreakspace}% "»:" -> "» :"
     \XeTeXinterchartoks \french@questionexclamation \french@punctthin = {\xpg@french@thinsp}% "?;" -> "?\,;"
     \XeTeXinterchartoks \french@questionexclamation \french@punctthick = {\xpg@french@thinsp}% "?:" -> "?\,:"
     \XeTeXinterchartoks \french@openbrackets \french@questionexclamation = {\xpg@unskip}% "(?" -> "(?" and not "( ?"
     \XeTeXinterchartoks \french@openbrackets \french@punctthin = {\xpg@unskip}% "(;" -> "(;" and not "( ;"
     \XeTeXinterchartoks \french@punctthin \french@closebrackets = {\xpg@unskip}% "?)" -> "?)" (code not need, just for symetry with previous one)
     \XeTeXinterchartoks \french@closebrackets \french@punctthin = {\xpg@french@thinsp}% ")?" -> ")\,?"
     \XeTeXinterchartoks \french@closebrackets \french@punctthick = {\nobreakspace}% "):" -> ") :"
    \fi
}

\def\nofrench@punctuation{%
    \lccode"2019=\z@
    \ifluatex
      \directlua{polyglossia.deactivate_french_punct()}%
    \else
      \XeTeXcharclass `\! \z@
      \XeTeXcharclass `\? \z@
      \XeTeXcharclass `\‼ \z@
      \XeTeXcharclass `\⁇ \z@
      \XeTeXcharclass `\⁈ \z@
      \XeTeXcharclass `\⁉ \z@
      \XeTeXcharclass `\‽ \z@
      \XeTeXcharclass `\; \z@
      \XeTeXcharclass `\: \z@
      \XeTeXcharclass `\« \z@
      \XeTeXcharclass `\» \z@
      \XeTeXcharclass `\‹ \z@
      \XeTeXcharclass `\› \z@
      \XeTeXcharclass `\( \z@
      \XeTeXcharclass `\) \z@
      \XeTeXcharclass `\[ \z@
      \XeTeXcharclass `\] \z@
      \XeTeXcharclass `\{ \z@
      \XeTeXcharclass `\} \z@
      \XeTeXcharclass `\⟨ \z@
      \XeTeXcharclass `\⟩ \z@
      \XeTeXinterchartokenstate=0
    \fi
}

\def\captionsfrench{%
   \def\refname{Références}%
   \def\abstractname{Résumé}%
   \def\bibname{Bibliographie}%
   \def\prefacename{Préface}%
   \def\chaptername{Chapitre}%
   \def\appendixname{Annexe}%
   \def\contentsname{Table des matières}%
   \def\listfigurename{Table des figures}%
   \def\listtablename{Liste des tableaux}%
   \def\indexname{Index}%
   \def\figurename{\textsc{Fig.}}%
   \def\tablename{\textsc{Tab.}}%
   \iffrench@frenchpart
     \def\partname{partie}%
   \else
     \def\partname{Partie}%
   \fi%
   \def\pagename{page}%
   \def\seename{voir}%
   \def\alsoname{voir aussi}%
   \def\enclname{P.~J. }%
   \def\ccname{Copie à }%
   \def\headtoname{}%
   \def\proofname{Démonstration}%
}

\def\datefrench{%
   \def\today{\ifx\ier\undefined\def\ier{er}\fi
      \ifnum\day=1\relax 1\ier%
      \else \number\day\fi
      \space \ifcase\month%
      \or janvier\or février\or mars\or avril\or mai\or juin\or
      juillet\or août\or septembre\or octobre\or novembre\or
      décembre\fi
      \space \number\year}}

\def\xpg@french@part{\ifcase\value{part}\or Première\or Deuxième\or%
   Troisième\or Quatrième\or Cinquième\or Sixième\or%
   Septième\or Huitième\or Neuvième\or Dixième\or Onzième\or%
   Douzième\or Treizième\or Quatorzième\or Quinzième\or%
   Seizième\or Dix-septième\or Dix-huitième\or Dix-neuvième\or%
   Vingtième\fi}%

\def\french@capsformat{%
   % Change part heading
   % With titlesec
   \ifcsdef{titleformat}{%
     \ifcsdef{H@old@part}{% Hyperref
        \let\xpg@save@part@format\H@old@part%
        \patchcmd{\H@old@part}%
                  {\partname\nobreakspace\thepart}%
                  {\xpg@french@part\nobreakspace\partname}%
                  {}%
                  {\xpg@warning{Failed to patch part for French}}%
     }{% not hyperref
       \ifcsdef{@part}{%
          \let\xpg@save@part@format\@part%
          \patchcmd{\@part}%
                    {\partname\nobreakspace\thepart}%
                    {\xpg@french@part\nobreakspace\partname}%
                    {}%
                    {\xpg@warning{Failed to patch part for French}}%
       }{}%
     }%
   }{% (not \ifdefined\titleformat)
     % With KOMA
     \ifcsdef{sectionformat}{%
        \ifcsdef{partformat}{%
          \let\xpg@save@part@format\partformat%
          \renewcommand{\partformat}{\xpg@french@part~\partname}%
        }{}%
     }{%  (not \ifdefined\sectionformat)
       % With memoir
       \ifcsdef{@memptsize}{%
         \ifcsdef{H@old@part}{% Hyperref
           \let\xpg@save@part@format\H@old@part%
           \patchcmd{\H@old@part}{\printpartname \partnamenum \printpartnum}%
                            {\partnamefont\xpg@french@part\partnamenum\printpartname}%
                            {}%
                            {\xpg@warning{Failed to patch part for French}}%
          }{% not hyperref
            \ifcsdef{@part}{%
              \let\xpg@save@part@format\@part%
              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
                               {\partnamefont\xpg@french@part\partnamenum\printpartname}%
                               {}%
                               {\xpg@warning{Failed to patch part for French}}%
             }{}%
          }%
       }{%  (not \ifdefined\@memptsize)
         % With standard classes
         \ifcsdef{H@old@part}{% Hyperref
           \let\xpg@save@part@format\H@old@part%
           \patchcmd{\H@old@part}%
                    {\partname\nobreakspace\thepart}%
                    {\xpg@french@part\nobreakspace\partname}%
                    {}%
                    {\xpg@warning{Failed to patch part for French}}%
         }{% not hyperref
            \ifcsdef{@part}{%
              \let\xpg@save@part@format\@part%
              \patchcmd{\@part}%
                       {\partname\nobreakspace\thepart}%
                       {\xpg@french@part\nobreakspace\partname}%
                       {}%
                       {\xpg@warning{Failed to patch part for French}}%
            }{}%  (end \ifdefined \H@old@part)
         }%  (end \ifdefined\@part)
       }% (end \ifdefined\@memptsize)
     }% (end \ifdefined\sectionformat)
   }% (end \ifdefined\titleformat)
}

\def\nofrench@capsformat{%
   % Reset chapter and part heading
   \ifcsdef{titleformat}{%
      % With titlesec
     \ifcsdef{xpg@save@part@format}{%
        \ifcsdef{H@old@part}{\let\@H@old@part\xpg@save@part@format}{\let\@part\xpg@save@part@format}
     }{}%
   }{% (not \ifdefined\titleformat)
     \ifcsdef{sectionformat}{%
        % With KOMA
        \ifcsdef{xpg@save@part@format}{%
           \let\partformat\xpg@save@part@format
        }{}%
     }{%
        % With memoir and standard classes
        \ifcsdef{xpg@save@part@format}{%
           \ifcsdef{H@old@part}{\let\@H@old@part\xpg@save@part@format}{\let\@part\xpg@save@part@format}
        }{}%
     }% (end \ifdefined\sectionformat)
   }% (end \ifdefined\titleformat)
}

\def\noextras@french{%
   \nofrench@punctuation%
   \nofrench@fontsetup%
   \nofrench@capsformat%
}

\def\blockextras@french{%
   \iffrench@autospacing
      \french@punctuation%
   \fi
   \french@fontsetup%
   \iffrench@frenchpart
     \french@capsformat%
   \fi%
}

\def\inlineextras@french{%
   \iffrench@autospacing
      \french@punctuation%
   \fi
   \french@fontsetup%
}

\def\NoAutoSpacing{%
  \nofrench@punctuation%
}

\def\AutoSpacing{%
  \french@punctuation%
}

\def\ier{\textsuperscript{er}}
\def\iers{\textsuperscript{ers}}
\def\iere{\textsuperscript{re}}
\def\ieres{\textsuperscript{res}}
\def\ieme{\textsuperscript{e}}
\def\iemes{\textsuperscript{es}}
\def\nd{\textsuperscript{nd}}
\def\nds{\textsuperscript{nds}}
\def\nde{\textsuperscript{nde}}
\def\ndes{\textsuperscript{ndes}}
\def\no{\textsuperscript{o}}
\def\nos{\textsuperscript{os}}

\def\mme{M\textsuperscript{me}\space}
\def\mmes{M\textsuperscript{mes}\space}
\def\mr{M.\space}
\def\mrs{MM.\space}

%    \end{macrocode}
% \iffalse
%</gloss-french.ldf>
%<*gloss-friulan.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-friulan.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-friulan.ldf}[polyglossia: module for friulan]

% We only provide this gloss for babel compatibility.

\xpg@load@master@language{friulian}

%    \end{macrocode}
% \iffalse
%</gloss-friulan.ldf>
%<*gloss-friulian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-friulian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-friulian.ldf}[polyglossia: module for friulian]

\PolyglossiaSetup{friulian}{%
  bcp47=fur,
  language=Friulian,
  babelname=friulan,
  hyphennames={friulan,furlan},
  hyphenmins={2,2},
  langtag=FRL,
  indentfirst=false,
  fontsetup=true,
  frenchspacing=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{friulian}{fur}

% Babel and backwards compat. alias
\setlanguagealias{friulian}{friulan}

\def\captionsfriulian{%
    \def\prefacename{Prefazion}%
    \def\refname{Riferiments}%
    \def\abstractname{Somari}%
    \def\bibname{Bibliografie}%
    \def\chaptername{Cjapitul}%
    \def\appendixname{Zonte}%
    \def\contentsname{Tabele gjenerâl}%
    \def\listfigurename{Liste des figuris}%
    \def\listtablename{Liste des tabelis}%
    \def\indexname{Tabele analitiche}%
    \def\figurename{Figure}%
    \def\tablename{Tabele}%
    \def\partname{Part}%
    \def\enclname{Zonte(is)}%
    \def\ccname{Cun copie a}%
    \def\headtoname{Par}%
    \def\pagename{Pagjine}%
    \def\seename{cjale}%
    \def\alsoname{cjale ancje}%
    \def\proofname{Dimostrazion}%
    \def\glossaryname{Glossari}%
  }
  
\def\datefriulian{%
  \def\today{\number\day\space di\space\ifcase\month\or
      Genâr\or Fevrâr\or Març\or Avril\or Mai\or Jugn\or
      Lui\or Avost\or Setembar\or Otobar\or Novembar\or Dicembar%
      \fi\space dal\space\number\year}}

\AtEndPreamble{% the user or the class might define different values
  \edef\xpgfu@savedvalues{%
    \clubpenalty=\the\clubpenalty\space
    \@clubpenalty=\the\@clubpenalty\space
    \widowpenalty=\the\widowpenalty\space
    \finalhyphendemerits=\the\finalhyphendemerits}
}


\def\noextras@friulian{%
   \lccode\string"2019=\z@
}

\def\blockextras@friulian{%
   \lccode\string"2019=\string"2019
   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000
   \finalhyphendemerits=50000000
}

\def\inlineextras@friulian{%
   \lccode\string"2019=\string"2019
}

%    \end{macrocode}
% \iffalse
%</gloss-friulian.ldf>
%<*gloss-fur.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-fur.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-fur.ldf}[polyglossia: module for fur (friulian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{friulian}

%    \end{macrocode}
% \iffalse
%</gloss-fur.ldf>
%<*gloss-ga.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ga.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ga.ldf}[polyglossia: module for ga (gaelic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{gaelic}

%    \end{macrocode}
% \iffalse
%</gloss-ga.ldf>
%<*gloss-gaelic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-gaelic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-gaelic.ldf}[polyglossia: module for gaelic]

\PolyglossiaSetup{gaelic}{
  bcp47=ga,
  language=Irish,
  babelname=irish,
  hyphennames={irish},
  hyphenmins={2,2},
  langtag=IRI,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=irish]{gaelic}{ga}
\setlanguagealias*[variant=scottish]{gaelic}{gd} 
% Babel aliases
\setlanguagealias[variant=irish]{gaelic}{irish}
\setlanguagealias[variant=scottish]{gaelic}{scottish}

\def\gaelic@variant{irish}
\define@choicekey*+{gaelic}{variant}[\xpg@val\xpg@nr]{irish,scottish}[irish]{%
   \ifcase\xpg@nr\relax
      % irish:
      \gdef\gaelic@variant{irish}%
      \SetLanguageKeys{gaelic}{language=Irish,langtag=IRI,babelname=irish,bcp47=ga}%
      \xpg@fontsetup@latin{gaelic}%
   \or
      % scottish:
      \gdef\gaelic@variant{scottish}%
      \SetLanguageKeys{gaelic}{language=Gaelic,langtag=GAE,babelname=scottish,bcp47=gd}%
      \xpg@fontsetup@latin{gaelic}%
   \fi
   \xpg@info{Option: gaelic, variant=\xpg@val}%
}{\xpg@warning{Unknown gaelic variant `#1'}}

% Register default options
\xpg@initialize@gloss@options{gaelic}{variant=irish}

\def\captionsgaelic@irish{%
   \def\refname{Tagairtí}%
   \def\abstractname{Achoimre}%
   \def\bibname{Leabharliosta}%
   \def\prefacename{Réamhrá}%    <-- also "Brollach"
   \def\refname{Tagairtí}%
   \def\chaptername{Tagairtí}%
   \def\appendixname{Aguisín}%
   \def\contentsname{Clár Ábhair}%
   \def\listfigurename{Léaráidí}%
   \def\listtablename{Táblaí}%
   \def\indexname{Innéacs}%
   \def\figurename{Léaráid}%
   \def\tablename{Tábla}%
   %\def\thepart{}%
   \def\partname{Cuid}%
   \def\pagename{Leathanach}%
   \def\seename{féach}%
   \def\alsoname{féach freisin}%
   \def\enclname{faoi iamh}%
   \def\ccname{cc}%
   \def\headtoname{Go}%
   \def\proofname{Cruthúnas}%
   \def\glossaryname{Glossary}%
}

\def\captionsgaelic@scottish{%
   \def\refname{Iomraidh}%
   \def\abstractname{Brìgh}%
   \def\bibname{Leabhraichean}%
   \def\prefacename{Preface}%    <-- needs translation
   \def\chaptername{Caibideil}%
   \def\appendixname{Ath-sgr`ıobhadh}%
   \def\contentsname{Clàr-obrach}%
   \def\listfigurename{Liosta Dhealbh}%
   \def\listtablename{Liosta Chlàr}%
   \def\indexname{Clàr-innse}%
   \def\figurename{Dealbh}%
   \def\tablename{Clàr}%
   %\def\thepart{}%
   \def\partname{Cuid}%
   \def\pagename{t.d.}%
   \def\seename{see}%    <-- needs translation
   \def\alsoname{see also}%    <-- needs translation
   \def\enclname{a-staigh}%
   \def\ccname{lethbhreac gu}%
   \def\headtoname{gu}%
   \def\proofname{Proof}%    <-- needs translation 
   \def\glossaryname{Glossary}%    <-- needs translation
}

\def\captionsgaelic{%
  \csname captionsgaelic@\gaelic@variant\endcsname%
}

\def\dategaelic@irish{%
   \def\today{%
    \number\day\space \ifcase\month\or
    Eanáir\or Feabhra\or Márta\or Aibreán\or
    Bealtaine\or Meitheamh\or Iúil\or Lúnasa\or
    Meán Fómhair\or Deireadh Fómhair\or
    Mí na Samhna\or Mí na Nollag\fi
    \space \number\year}%
}

\def\dategaelic@scottish{%
   \def\today{%
    \number\day\space \ifcase\month\or
    am Faoilteach\or an Gearran\or am Màrt\or an Giblean\or
    an Cèitean\or an t-Òg mhios\or an t-Iuchar\or
    Lùnasdal\or an Sultuine\or an Dàmhar\or
    an t-Samhainn\or an Dubhlachd\fi
    \space \number\year}%
}

\def\dategaelic{%
  \csname dategaelic@\gaelic@variant\endcsname%
}

%    \end{macrocode}
% \iffalse
%</gloss-gaelic.ldf>
%<*gloss-galician.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-galician.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-galician.ldf}[polyglossia: module for galician]
\PolyglossiaSetup{galician}{
  bcp47=gl,
  hyphennames={galician},
  hyphenmins={2,2},
  langtag=GAL,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{galician}{gl}

\def\captionsgalician{%
   \def\refname{Referencias}%
   \def\abstractname{Resumo}%
   \def\bibname{Bibliografía}%
   \def\prefacename{Prefacio}%
   \def\chaptername{Capítulo}%
   \def\appendixname{Apéndice}%
   \def\contentsname{Índice Xeral}%
   \def\listfigurename{Índice de Figuras}%
   \def\listtablename{Índice de Táboas}%
   \def\indexname{Índice de Materias}%
   \def\figurename{Figura}%
   \def\tablename{Táboa}%
   %\def\thepart{}%
   \def\partname{Parte}%
   \def\pagename{Páxina}%
   \def\seename{véxase}%
   \def\alsoname{véxase tamén}%
   \def\enclname{Adxunto}%
   \def\ccname{Copia a}%
   \def\headtoname{A}%
   \def\proofname{Demostración}%
   \def\glossaryname{Glosario}%
   }
\def\dategalician{%
   \def\today{\number\day~de\space\ifcase\month\or
    xaneiro\or febreiro\or marzo\or abril\or maio\or xuño\or
    xullo\or agosto\or setembro\or outubro\or novembro\or decembro\fi
    \space de~\number\year}}

%    \end{macrocode}
% \iffalse
%</gloss-galician.ldf>
%<*gloss-gd.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-gd.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-gd.ldf}[polyglossia: module for gd (gaelic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{gaelic}

%    \end{macrocode}
% \iffalse
%</gloss-gd.ldf>
%<*gloss-georgian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-georgian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-georgian.ldf}[polyglossia: module for georgian]

\PolyglossiaSetup{georgian}{
  bcp47=ka,
  script=Georgian,
  scripttag=geor,
  langtag=KAT,
  hyphennames={georgian},
  fontsetup=true,
  localnumeral=georgiannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{georgian}{ka}

\newif\ifgeorgian@numerals
\define@key{georgian}{numerals}[arabic]{%
   \ifstrequal{#1}{georgian}%
      {\georgian@numeralstrue}%
      {\georgian@numeralsfalse}%
}

\define@boolkey{georgian}[georgian@]{babelshorthands}[true]{}

\define@boolkey{georgian}[georgian@]{oldmonthnames}[true]{}

% Register default options
\xpg@initialize@gloss@options{georgian}{babelshorthands=false,oldmonthnames=false,numerals=arabic}

\ifsystem@babelshorthands
  \setkeys{georgian}{babelshorthands=true}
\else
  \setkeys{georgian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\georgian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{georgian}%
  \declare@shorthand{georgian}{"`}{„}%
  \declare@shorthand{georgian}{"'}{“}%
  \declare@shorthand{georgian}{"<}{«}%
  \declare@shorthand{georgian}{">}{»}%
  \declare@shorthand{georgian}{""}{\hskip\z@skip}%
  \declare@shorthand{georgian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{georgian}{"=}{\nobreak-\hskip\z@skip}%
  \declare@shorthand{georgian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
  \declare@shorthand{georgian}{"-}{%
    \def\georgian@sh@tmp{%
      \if\georgian@sh@next-\expandafter\georgian@sh@emdash%
      \else\expandafter\georgian@sh@hyphen\fi%
    }%
    \futurelet\georgian@sh@next\georgian@sh@tmp}%
  \def\georgian@sh@hyphen{%
    \nobreak\-\bbl@allowhyphens}%
  \def\georgian@sh@emdash##1##2{\cdash-##1##2}%
  \def\cdash##1##2##3{\def\tempx@{##3}%
  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
   \ifx\tempx@\tempa@\@Acdash\else
    \ifx\tempx@\tempb@\@Bcdash\else
     \ifx\tempx@\tempc@\@Ccdash\else
      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
    \cyrdash\hskip.2em\ignorespaces}%
  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z@skip\ignorespaces}%
  \def\@Ccdash{\leavevmode
   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
  \ifx\cyrdash\undefined
    \def\cyrdash{\hbox to.8em{\textendash\hss\textendash}}%
  \fi
  \declare@shorthand{georgian}{",}{\nobreak\hskip.2em\ignorespaces}%
}

\def\nogeorgian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captionsgeorgian{%
    \def\prefacename{წინასიტყვაობა}%
    \def\refname{ლიტერატურა}%
    \def\abstractname{ანოტაცია}%
    \def\bibname{ლიტერატურა}%
    \def\chaptername{თავი}%
    \def\appendixname{დანართი}%
    \@ifundefined{thechapter}
      {\def\contentsname{შინაარსი}}%
      {\def\contentsname{შინაარსი}}%
    \let\tocname=\contentsname
    \def\listfigurename{სურათი}%
    \def\listtablename{ცხრილი}%
    \def\indexname{საძიებელი}%
    \def\authorname{სახელთა საძიებელი}%
    \def\figurename{სურ.}%
    \def\tablename{ცხრ.}%
    \def\partname{ნაწილი}%
    \def\enclname{ჩათვ.}%
    \def\ccname{წყარ.}%
    \def\headtoname{შ.}%
    \def\pagename{გვ.}%
    \def\seename{იხ.}%
    \def\alsoname{იხ.\ ასევე}%
    \def\proofname{დამტკიცება}%
    \def\glossaryname{ტერმინები}%
}%

\def\dategeorgian{%
   \def\today{\number\day~\ifcase\month\or
    იანვარი\or
    თებერვალი\or
    მარტი\or
    აპრილი\or
    მაისი\or
    ივნისი\or
    ივლისი\or
    აგვისტო\or
    სექტემბერი\or
    ოქტომბერი\or
    ნოემბერი\or
    დეკემბერი\fi
    \space \number\year~წ.}%
    \ifgeorgian@oldmonthnames
       \dategeorgian@old%
    \fi
}

\def\dategeorgian@old{%
   \def\today{\number\day~\ifcase\month\or
    აპნისი\or
    სურწყუნისი\or
    მირკანი\or
    იგრიკა\or
    ვარდობისთვე\or
    თიბათვე\or
    მკათათვე\or
    მარიამობისთვე\or
    ახალწლისა ენკენისთვე\or
    ღვინობისთვე\or
    გიორგობისთვე\or
    ქრისტეშობისთვე\fi
    \space \number\year~წ.}%
}

\def\georgian@numbers{%
   \ifgeorgian@numerals%
     \def\georgian@alph##1{\expandafter\georgiannumeral\expandafter{\the##1}}%
     \let\@alph\georgian@@alph%
   \fi
}

\def\nogeorgian@numbers{%
   \let\@alph\latin@alph%
   \let\georgian@alph\@undefined%
}

\def\georgian@globalnumbers{%
  \ifgeorgian@numerals
    \let\@arabic\georgiannumber%
    \renewcommand\thefootnote{\localnumeral*{footnote}}%
    \renewcommand\theequation{\localnumeral*{equation}}%
  \fi
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\nogeorgian@globalnumbers{
   \let\@arabic\xpg@save@arabic%
}

\newcommand{\georgiannumerals}[2]{%
  \ifgeorgian@numerals
     \georgiannumber{#2}%
  \else
     #2%
  \fi%
}

\protected\def\georgiannumber#1{\expandafter\@georgiannumber\expandafter{\number#1}}
\def\@georgiannumber#1{%
  \ifnum#1<\@ne\space\geor@ill@value{#1}%
  \else
    \ifnum#1<10\expandafter\geor@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\geor@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\geor@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\geor@num@iv\number#1%
          \else
             \space\geor@ill@value{#1}%
          \fi
        \fi
      \fi
    \fi
  \fi
}

\let\georgiannumeral=\georgiannumber
\def\geor@num@i#1{% 1--9
  \ifcase#1\or ა\or ბ\or გ\or დ\or ე\or ვ\or ზ\or ჱ\or თ\fi}
\def\geor@num@ii#1{% 10--90
  \ifcase#1\or ი\or კ\or ლ\or მ\or ნ\or ჲ\or ო\or პ\or ჟ\fi
  \geor@num@i}
\def\geor@num@iii#1{% 100--900
  \ifcase#1\or რ\or ს\or ტ\or ჳ\or ფ\or ქ\or ღ\or ყ\or შ\fi
  \geor@num@ii}
\def\geor@num@iv#1{% 1000--9000
  \ifcase#1\or ჩ\or ც\or ძ\or წ\or ჭ\or ხ\or ჴ\or ჯ\or ჰ\fi
  \geor@num@iii}
\def\geor@ill@value#1{\xpg@warning{Illegal value (#1) for Georgian numeral}[$#1$]}

\def\noextras@georgian{%
   \ifgeorgian@numerals\nogeorgian@numbers\fi%
   \ifgeorgian@babelshorthands\nogeorgian@shorthands\fi%
}

\def\blockextras@georgian{%
   \ifgeorgian@numerals\georgian@numbers\fi%
   \ifgeorgian@babelshorthands\georgian@shorthands\fi%
}

\def\inlineextras@georgian{%
   \ifgeorgian@babelshorthands\georgian@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-georgian.ldf>
%<*gloss-german.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-german.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-german.ldf}[polyglossia: module for german]

\PolyglossiaSetup{german}{
  bcp47=de-DE,
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup=true,
  langtag=DEU,
  babelname=ngerman
}

% BCP-47 compliant aliases
\setlanguagealias*{german}{de}
\setlanguagealias*[variant=swiss,spelling=new]{german}{de-CH}
\setlanguagealias*[variant=austrian,spelling=new]{german}{de-AT}
\setlanguagealias*[variant=german,spelling=new]{german}{de-DE}
\setlanguagealias*[variant=swiss,spelling=new,script=blackletter]{german}{de-Latf-CH}
\setlanguagealias*[variant=german,spelling=new,script=blackletter]{german}{de-Latf-DE}
\setlanguagealias*[variant=austrian,spelling=new,script=blackletter]{german}{de-Latf-AT}
\setlanguagealias*[variant=austrian,spelling=old]{german}{de-AT-1901}
\setlanguagealias*[variant=swiss,spelling=new]{german}{de-CH-1996}
\setlanguagealias*[variant=austrian,spelling=new]{german}{de-AT-1996}
\setlanguagealias*[variant=german,spelling=old]{german}{de-DE-1901}
\setlanguagealias*[variant=swiss,spelling=old,script=blackletter]{german}{de-Latf-CH-1901}
\setlanguagealias*[variant=swiss,spelling=old]{german}{de-CH-1901}
\setlanguagealias*[variant=austrian,spelling=old,script=blackletter]{german}{de-Latf-AT-1901}
\setlanguagealias*[variant=swiss,spelling=new,script=blackletter]{german}{de-Latf-CH-1996}
\setlanguagealias*[script=blackletter]{german}{de-Latf}
\setlanguagealias*[variant=german,spelling=new]{german}{de-DE-1996}
\setlanguagealias*[variant=german,spelling=old,script=blackletter]{german}{de-Latf-DE-1901}
\setlanguagealias*[variant=german,spelling=new,script=blackletter]{german}{de-Latf-DE-1996}
\setlanguagealias*[variant=austrian,spelling=new,script=blackletter]{german}{de-Latf-AT-1996}

% Babel aliases
\setlanguagealias[variant=austrian,spelling=old]{german}{austrian}
\setlanguagealias[variant=austrian,spelling=new]{german}{naustrian}
\setlanguagealias[variant=german,spelling=old]{german}{germanb}
\setlanguagealias[variant=german,spelling=new]{german}{ngerman}
\setlanguagealias[variant=swiss,spelling=old]{german}{swissgerman}
\setlanguagealias[variant=swiss,spelling=new]{german}{nswissgerman}

\newif\if@german@oldspelling
\@german@oldspellingfalse
\define@choicekey*+{german}{spelling}[\xpg@val\xpg@nr]{new,old,1901,1996}[new]{%
   \ifcase\xpg@nr\relax
      % new:
      \@german@oldspellingfalse
   \or
      % old:
      \@german@oldspellingtrue
   \or
      % 1901:
      \@german@oldspellingtrue
   \or
      % 1996:
      \@german@oldspellingfalse
   \fi
   \german@set@babelname%
   \xpg@info{Option: German, spelling=\xpg@val}%
}{\xpg@warning{Unknown German spelling `#1'}}

\newif\if@austrian@locale
\@austrian@localefalse
\newif\if@swiss@locale
\@swiss@localefalse
\define@choicekey*+{german}{variant}[\xpg@val\xpg@nr]{german,austrian,swiss}[german]{%
   \ifcase\xpg@nr\relax
      % german:
      \@swiss@localefalse%
      \@austrian@localefalse%
   \or
      % austrian:
      \@austrian@localetrue%
      \@swiss@localefalse%
   \or
      % swiss:
      \@swiss@localetrue%
      \@austrian@localefalse%
      \xpg@ifdefined{swissgerman}{}%
         {%
           \xpg@warning{No hyphenation patterns were loaded for "Swiss German (Old Spelling)"\MessageBreak
	                I will use the standard patterns for German (old spelling) instead}%
	                \adddialect\l@swissgerman\l@german\relax%
         }%
   \fi
   \german@set@babelname%
   \xpg@info{Option: German, variant=\xpg@val}%
}{\xpg@warning{Unknown German variant `#1'}}

\def\german@set@babelname{%
  \if@german@oldspelling
     \if@swiss@locale
         \if@german@blackletter
           \SetLanguageKeys{german}{babelname=swissgerman,bcp47=de-Latf-CH-1901}%
         \else
           \SetLanguageKeys{german}{babelname=swissgerman,bcp47=de-CH-1901}%
         \fi
     \else
     \if@austrian@locale
         \if@german@blackletter
            \SetLanguageKeys{german}{babelname=austrian,bcp47=de-Latf-AT-1901}%
         \else
            \SetLanguageKeys{german}{babelname=austrian,bcp47=de-AT-1901}%
         \fi
     \else
         \if@german@blackletter
            \SetLanguageKeys{german}{babelname=german,bcp47=de-Latf-DE-1901}%
         \else
            \SetLanguageKeys{german}{babelname=german,bcp47=de-DE-1901}%
         \fi
     \fi\fi
  \else
     \if@swiss@locale
         \if@german@blackletter
           \SetLanguageKeys{german}{babelname=nswissgerman,bcp47=de-Latf-CH}%
         \else
           \SetLanguageKeys{german}{babelname=nswissgerman,bcp47=de-CH}%
         \fi
     \else
     \if@austrian@locale
         \if@german@blackletter
           \SetLanguageKeys{german}{babelname=naustrian,bcp47=de-Latf-AT}%
         \else
           \SetLanguageKeys{german}{babelname=naustrian,bcp47=de-AT}%
         \fi
     \else
         \if@german@blackletter
           \SetLanguageKeys{german}{babelname=ngerman,bcp47=de-Latf-DE}%
         \else
           \SetLanguageKeys{german}{babelname=ngerman,bcp47=de-DE}%
         \fi
     \fi\fi
  \fi
}

\newif\if@german@blackletter
\define@choicekey*+{german}{script}[\xpg@val\xpg@nr]{latin,blackletter,fraktur}[latin]{%
   \ifcase\xpg@nr\relax
      % latin:
      \@german@blackletterfalse%
   \or
      % blackletter:
      \@german@blacklettertrue%
   \or
      % fraktur:
      \@german@blacklettertrue%
   \fi
   \german@set@babelname%
   \xpg@info{Option: German, script=\xpg@val}%
}{\xpg@warning{Unknown German script `#1'}}

% Option defunc'ed, as bot XeTeX and LuaTeX meanwhile
% use the experimental German hyphenation patterns by default.
\define@boolkey{german}[german@]{latesthyphen}[true]{}

\define@boolkey{german}[german@]{babelshorthands}[true]{}

\setkeys{german}{spelling,script,variant}

% Register default options
\xpg@initialize@gloss@options{german}{variant=german,spelling=new,script=latin,latesthyphen=false,babelshorthands=false}
% Register alias options
\xpg@set@alias@values{german}{spelling}{new}{1996}
\xpg@set@alias@values{german}{spelling}{old}{1901}
\xpg@set@alias@values{german}{script}{blackletter}{fraktur}

\ifsystem@babelshorthands
  \setkeys{german}{babelshorthands=true}
\else
  \setkeys{german}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\german@shorthands{%
  \bbl@activate{"}%
  \def\language@group{german}%
  \declare@shorthand{german}{"`}{„}%
  \declare@shorthand{german}{"'}{“}%
  \declare@shorthand{german}{"<}{«}%
  \declare@shorthand{german}{">}{»}%
  \declare@shorthand{german}{"c}{\textormath{\bbl@disc@german ck}{c}}%
  \declare@shorthand{german}{"C}{\textormath{\bbl@disc@german CK}{C}}%
  \declare@shorthand{german}{"F}{\textormath{\bbl@disc@german F{FF}}{F}}%
  \declare@shorthand{german}{"l}{\textormath{\bbl@disc@german l{ll}}{l}}%
  \declare@shorthand{german}{"L}{\textormath{\bbl@disc@german L{LL}}{L}}%
  \declare@shorthand{german}{"m}{\textormath{\bbl@disc@german m{mm}}{m}}%
  \declare@shorthand{german}{"M}{\textormath{\bbl@disc@german M{MM}}{M}}%
  \declare@shorthand{german}{"n}{\textormath{\bbl@disc@german n{nn}}{n}}%
  \declare@shorthand{german}{"N}{\textormath{\bbl@disc@german N{NN}}{N}}%
  \declare@shorthand{german}{"p}{\textormath{\bbl@disc@german p{pp}}{p}}%
  \declare@shorthand{german}{"P}{\textormath{\bbl@disc@german P{PP}}{P}}%
  \declare@shorthand{german}{"r}{\textormath{\bbl@disc@german r{rr}}{r}}%
  \declare@shorthand{german}{"R}{\textormath{\bbl@disc@german R{RR}}{R}}%
  \declare@shorthand{german}{"t}{\textormath{\bbl@disc@german t{tt}}{t}}%
  \declare@shorthand{german}{"T}{\textormath{\bbl@disc@german T{TT}}{T}}%
  \declare@shorthand{german}{"f}{\texorpdfstring{\textormath{\bbl@discff}{f}}{f}}%
  \def\bbl@discff{\penalty\@M
    \afterassignment\bbl@insertff \cslet{bbl@nextff}{ }}%
  \def\bbl@insertff{%
    \if f\bbl@nextff
      \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {\relax\discretionary{ff-}{f}{ff}\allowhyphens}{f\bbl@nextff}}%
  \cslet{bbl@nextff}{f}%
  \declare@shorthand{german}{"-}{\nobreak\-\nobreak\hskip\z@skip}%
  \declare@shorthand{german}{"|}{\textormath{\penalty\@M\discretionary{-}{}{\kern.03em}}{}}%
  \declare@shorthand{german}{""}{\hskip\z@skip}%
  \declare@shorthand{german}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{german}{"=}{\penalty\@M-\hskip\z@skip}%
  \declare@shorthand{german}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
  \def\ck{\allowhyphens\discretionary{k-}{k}{ck}\allowhyphens}%
}

\def\nogerman@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captions@german{%
  \def\prefacename{Vorwort}%
  \def\refname{Literatur}%
  \def\abstractname{Zusammenfassung}%
  \def\bibname{Literaturverzeichnis}%
  \def\chaptername{Kapitel}%
  \def\appendixname{Anhang}%
  \def\contentsname{Inhaltsverzeichnis}%
  \def\listfigurename{Abbildungsverzeichnis}%
  \def\listtablename{Tabellenverzeichnis}%
  \def\indexname{Index}%
  \def\figurename{Abbildung}%
  \def\tablename{Tabelle}%
  \def\partname{Teil}%
  \def\enclname{Anlage(n)}%
  \def\ccname{Verteiler}%
  \def\headtoname{An}%
  \def\pagename{Seite}%
  \def\seename{siehe}%
  \def\alsoname{siehe auch}%
  \def\proofname{Beweis}%
  \def\glossaryname{Glossar}%
}
\def\date@german{%   
  \def\today{\number\day.%
    \space \ifcase\month%
    \or\if@austrian@locale Jänner\else Januar\fi\or Februar\or März\or%
    April\or Mai\or Juni\or Juli\or August\or September\or Oktober\or%
    November\or Dezember\fi
    \space \number\year}%
}

\def\captions@german@austrian{%
  \def\enclname{Beilage(n)}%
}

\def\captions@german@swiss{%
  \def\enclname{Beilage(n)}%
}

%%Strings for Fraktur contributed by Gerrit <z0idberg . gmx . de>
\def\captions@german@blackletter{%
  \captions@german%
  \def\abstractname{Zuſammenfaſſung}%
  \def\seename{ſiehe}%
  \def\alsoname{ſiehe auch}%
  \def\glossaryname{Gloſſar}%
}

\def\date@german@blackletter{%
  \def\today{\number\day.%
    \space \ifcase\month%
    \or\if@austrian@locale Jänner\else Januar\fi\or Februar\or März\or%
    April\or Mai\or Juni\or Juli\or Auguſt\or September\or Oktober\or%
    November\or Dezember\fi
    \space \number\year}%
}

\def\captionsgerman{%
  \if@german@blackletter\captions@german@blackletter\else\captions@german\fi
  \if@austrian@locale\captions@german@austrian\fi
  \if@swiss@locale\captions@german@swiss\fi
}

\def\dategerman{%
  \if@german@blackletter\date@german@blackletter\else\date@german\fi
}

\def\german@language{%
  \if@german@oldspelling
      \if@swiss@locale
          \polyglossia@setup@language@patterns{swissgerman}%
      \else
          \polyglossia@setup@language@patterns{german}%
      \fi
      \if@austrian@locale
         \adddialect\l@austrian\l@german%
      \fi
  \else
      \polyglossia@setup@language@patterns{ngerman}%
      \if@austrian@locale
         \adddialect\l@naustrian\l@ngerman%
      \fi
      \if@swiss@locale
         \adddialect\l@nswissgerman\l@ngerman%
      \fi
  \fi
}

\def\noextras@german{%
  \ifgerman@babelshorthands\nogerman@shorthands\fi%
}

\def\blockextras@german{%
  \ifgerman@babelshorthands\german@shorthands\fi%
}

\def\inlineextras@german{%
  \ifgerman@babelshorthands\german@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-german.ldf>
%<*gloss-germanb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-germanb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-germanb.ldf}[polyglossia: module for german (old spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-germanb.ldf>
%<*gloss-gl.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-gl.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-gl.ldf}[polyglossia: module for gl (galician)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{galician}

%    \end{macrocode}
% \iffalse
%</gloss-gl.ldf>
%<*gloss-grc.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-grc.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-grc.ldf}[polyglossia: module for grc (greek)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{greek}

%    \end{macrocode}
% \iffalse
%</gloss-grc.ldf>
%<*gloss-greek.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-greek.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-greek.ldf}[polyglossia: module for greek]

\PolyglossiaSetup{greek}{
  bcp47=el-monoton,
  script=Greek,
  scripttag=grek,
  langtag=ELL,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
  localnumeral=greeknumerals,
  Localnumeral=Greeknumerals
  %TODO localalph={greek@alph,greek@Alph}
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=ancient]{greek}{grc}
\setlanguagealias*[varant=polytonic]{greek}{el-polyton}
\setlanguagealias*[variant=monotonic]{greek}{el-monoton}
\setlanguagealias*{greek}{el}

% Babel aliases
\setlanguagealias[variant=polytonic]{greek}{polutonikogreek}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The code in this file was initially adapted from the antomega
%% module for greek. Currently large parts of it derive from the 
%% package xgreek.sty (c) Apostolos Syropoulos 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this file imported from xgreek fixes the \lccode and \uccode of Greek letters:
\input{xgreek-fixes.def}

\def\tmp@mono{mono}
\def\tmp@monotonic{monotonic}
\def\tmp@poly{poly}
\def\tmp@polytonic{polytonic}
\def\tmp@ancient{ancient}
\def\tmp@ancientgreek{ancientgreek}

\def\greek@variant{monogreek}

\define@key{greek}{variant}[monotonic]{%
  \def\@tmpa{#1}%
  \xpg@ifdefined{greek}{}{%
      \xpg@nopatterns{greek}%
      \adddialect\l@greek\l@nohyphenation
  }%
  \ifx\@tmpa\tmp@poly\def\@tmpa{polytonic}\fi
  \ifx\@tmpa\tmp@ancientgreek\def\@tmpa{ancient}\fi
  \ifx\@tmpa\tmp@polytonic%
    \xpg@ifdefined{polygreek}{}%
      {\xpg@warning{No hyphenation patterns were loaded for Polytonic Greek\MessageBreak
	            I will use the patterns loaded for \string\l@greek\space instead}%
      \adddialect\l@polygreek\l@greek\relax}%
    \def\greek@variant{polygreek}%
    \def\captionsgreek{\polygreekcaptions}%
    \def\dategreek{\datepolygreek}%
    \SetLanguageKeys{greek}{babelname=polutonikogreek,bcp47=el-polyton}%
    \xpg@info{Option: Polytonic Greek}%
  \else
    \ifx\@tmpa\tmp@ancient
      \xpg@ifdefined{ancientgreek}{}%
        {\xpg@warning{No hyphenation patterns were loaded for Ancient Greek\MessageBreak
	              I will use the patterns loaded for \string\l@greek\space instead}%
         \adddialect\l@ancientgreek\l@greek\relax}%
      \def\greek@variant{ancientgreek}%
      \def\captionsgreek{\ancientgreekcaptions}%
      \def\dategreek{\dateancientgreek}%
      \SetLanguageKeys{greek}{babelname=greek,bcp47=grc}%
      \xpg@info{Option: Ancient Greek}%
    \else %monotonic
      \xpg@ifdefined{monogreek}{}%
        {\xpg@warning{No hyphenation patterns were loaded for Monotonic Greek\MessageBreak
	              I will use the patterns loaded for \string\l@greek\space instead}%
         \adddialect\l@monogreek\l@greek\relax}%
      \def\greek@variant{monogreek}% monotonic
      \def\captionsgreek{\monogreekcaptions}%
      \def\dategreek{\datemonogreek}%
      \SetLanguageKeys{greek}{babelname=greek,bcp47=el-monoton}%
      \xpg@info{Option: Monotonic Greek}%
    \fi
  \fi}

\def\greek@language{%
  \polyglossia@setup@language@patterns{\greek@variant}%
}


\newif\if@greek@numerals
\define@key{greek}{numerals}[greek]{%
  \ifstrequal{#1}{arabic}{\@greek@numeralsfalse}{\@greek@numeralstrue}%
}

\define@boolkey{greek}{attic}[true]{\xpg@warning{Greek option `attic' is no longer required.}}

% Register default options
\xpg@initialize@gloss@options{greek}{variant=monotonic,numerals=greek}
% Register alias options
\xpg@set@alias@values{greek}{variant}{monotonic}{mono}
\xpg@set@alias@values{greek}{variant}{polytonic}{poly}

\def\monogreekcaptions{%
   \def\refname{Αναφορές}%
   \def\abstractname{Περίληψη}%
   \def\bibname{Βιβλιογραφία}%
   \def\prefacename{Πρόλογος}%
   \def\chaptername{Κεφάλαιο}%
   \def\appendixname{Παράρτημα}%
   \def\contentsname{Περιεχόμενα}%
   \def\listfigurename{Κατάλογος σχημάτων}%
   \def\listtablename{Κατάλογος πινάκων}%
   \def\indexname{Ευρετήριο}%
   \def\figurename{Σχήμα}%
   \def\tablename{Πίνακας}%
   \def\partname{Μέρος}%
   \def\pagename{Σελίδα}%
   \def\seename{βλέπε}%
   \def\alsoname{βλέπε επίσης}%
   \def\enclname{Συνημμένα}%
   \def\ccname{Κοινοποίηση}%
   \def\headtoname{Προς}%
   \def\proofname{Απόδειξη}%
   \def\glossaryname{Γλωσσάρι}}%

\def\datemonogreek{%   
   \def\today{\number\day\space%
      \greek@month%
      \space\number\year}%
   \def\greektoday{\greeknumber\day\space%
      \greek@month%
      \space\greeknumber\year}%
   \def\Greektoday{\Greeknumber\day\space%
      \greek@month%
      \space\Greeknumber\year}%
   \def\greek@month{\ifcase\month\or%
      Ιανουαρίου\or
      Φεβρουαρίου\or
      Μαρτίου\or
      Απριλίου\or
      Μαΐου\or
      Ιουνίου\or
      Ιουλίου\or
      Αυγούστου\or
      Σεπτεμβρίου\or
      Οκτωβρίου\or
      Νοεμβρίου\or
      Δεκεμβρίου\fi}}%

\def\polygreekcaptions{%
   \def\refname{Ἀναφορές}%
   \def\abstractname{Περίληψη}%
   \def\bibname{Βιβλιογραφία}%
   \def\prefacename{Πρόλογος}%
   \def\chaptername{Κεφάλαιο}%
   \def\appendixname{Παράρτημα}%
   \def\contentsname{Περιεχόμενα}%
   \def\listfigurename{Κατάλογος σχημάτων}%
   \def\listtablename{Κατάλογος πινάκων}%
   \def\indexname{Εὑρετήριο}%
   \def\figurename{Σχῆμα}%
   \def\tablename{Πίνακας}%
   \def\partname{Μέρος}%
   \def\pagename{Σελίδα}%
   \def\seename{βλέπε}%
   \def\alsoname{βλέπε ἐπίσης}%
   \def\enclname{Συνημμένα}%
   \def\ccname{Κοινοποίηση}%
   \def\headtoname{Πρὸς}%
   \def\proofname{Ἀπόδειξη}}%

\def\datepolygreek{%   
   \def\today{\number\day\space%
      \greek@month%
      \space\number\year}%
   \def\greektoday{\greeknumber\day\space%
      \greek@month%
      \space\greeknumber\year}%
   \def\Greektoday{\Greeknumber\day\space%
      \greek@month%
      \space\Greeknumber\year}%
   \def\greek@month{\ifcase\month\or%
      Ἰανουαρίου\or
      Φεβρουαρίου\or
      Μαρτίου\or
      Ἀπριλίου\or
      Μαΐου\or
      Ἰουνίου\or
      Ἰουλίου\or
      Αὐγούστου\or
      Σεπτεμβρίου\or
      Ὀκτωβρίου\or
      Νοεμβρίου\or
      Δεκεμβρίου\fi}}%

% this is copied verbatim from xgreek.sty:      
\def\ancientgreekcaptions{%
  \def\prefacename{Προοίμιον}%
  \def\refname{Αναφοραί}%
  \def\abstractname{Περίληψις}%
  \def\bibname{Βιβλιογραφία}%
  \def\chaptername{Κεφάλαιον}%
  \def\appendixname{Παράρτημα}%
  \def\contentsname{Περιεχόμενα}%
  \def\listfigurename{Κατάλογος σχημάτων}%
  \def\listtablename{Κατάλογος πινάκων}%
  \def\indexname{Εὑρετήριον}%
  \def\figurename{Σχήμα}%
  \def\tablename{Πίναξ}%
  \def\partname{Μέρος}%
  \def\enclname{Συνημμένως}%
  \def\ccname{Κοινοποίησις}%
  \def\headtoname{Πρὸς}%
  \def\pagename{Σελὶς}%
  \def\seename{ὅρα}%
  \def\alsoname{ὅρα ὡσαύτως}%
  \def\proofname{Ἀπόδειξις}%
  \def\glossaryname{Γλωσσάριον}%
  \def\refname{Ἀναφοραὶ}%
  \def\indexname{Εὑρετήριο}%
  \def\figurename{Σχῆμα}%
  \def\headtoname{Πρὸς}}%

\def\dateancientgreek{%
  \def\today{\number\day\space%
      \greek@month%
      \space\number\year}%
   \def\greektoday{\greeknumber\day\space%
      \greek@month%
      \space\greeknumber\year}%
   \def\Greektoday{\Greeknumber\day\space%
      \greek@month%
      \space\Greeknumber\year}%
   \def\greek@month{\ifcase\month\or%
      Ἰανουαρίου\or
      Φεβρουαρίου\or
      Μαρτίου\or
      Ἀπριλίου\or
      Μαΐου\or
      Ἰουνίου\or
      Ἰουλίου\or
      Αὐγούστου\or
      Σεπτεμβρίου\or
      Ὀκτωβρίου\or
      Νοεμβρίου\or
      Δεκεμβρίου\fi}}

% the code for alphabetic numbers and attic numerals 
\newrobustcmd\anw@print{}
\newrobustcmd\anw@false{%
  \renewrobustcmd\anw@print{}}
\newrobustcmd\anw@true{%
   \renewrobustcmd\anw@print{ʹ}}
\anw@true

\newcommand{\greeknumerals}[2]{\greeknumber{#2}}
\newcommand{\Greeknumerals}[2]{\Greeknumber{#2}}

\protected\def\greeknumber#1{\expandafter\@greeknumber\expandafter{\number#1}}
\def\@greeknumber#1{%
  \ifnum#1<\@ne\space\gr@ill@value{#1}%
  \else
    \ifnum#1<10\expandafter\gr@num@i\number#1%
    \else
      \ifnum#1<100\expandafter\gr@num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\gr@num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\gr@num@iv\number#1%
          \else
            \ifnum#1<100000\expandafter\gr@num@v\number#1%
            \else
              \ifnum#1<1000000\expandafter\gr@num@vi\number#1%
              \else
                \space\gr@ill@value{#1}%
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}
\protected\def\Greeknumber#1{\expandafter\@Greeknumber\expandafter{\number#1}}
\def\@Greeknumber#1{%
  \ifnum#1<\@ne\space\gr@ill@value{#1}%
  \else
    \ifnum#1<10\expandafter\gr@Num@i\number#1%
    \else
      \ifnum#1<100\expandafter\gr@Num@ii\number#1%
      \else
        \ifnum#1<\@m\expandafter\gr@Num@iii\number#1%
        \else
          \ifnum#1<\@M\expandafter\gr@Num@iv\number#1%
          \else
            \ifnum#1<100000\expandafter\gr@Num@v\number#1%
            \else
              \ifnum#1<1000000\expandafter\gr@Num@vi\number#1%
              \else
                \space\gr@ill@value{#1}%
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}
\let\greeknumeral=\greeknumber
\let\Greeknumeral=\Greeknumber
\def\gr@num@i#1{%
  \ifcase#1\or α\or β\or γ\or δ\or ε\or Ϛ\or ζ\or η\or θ\fi
  \ifnum#1=\z@\else\anw@true\fi\anw@print}
\def\gr@num@ii#1{%
  \ifcase#1\or ι\or κ\or λ\or μ\or ν\or ξ\or ο\or π\or ϟ\fi
  \ifnum#1=\z@\else\anw@true\fi\gr@num@i}
\def\gr@num@iii#1{%
  \ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or ϡ\fi
  \ifnum#1=\z@\anw@false\else\anw@true\fi\gr@num@ii}
\def\gr@num@iv#1{%
  \ifnum#1=\z@\else ͵\fi
  \ifcase#1\or α\or β\or γ\or δ\or ε\or Ϛ\or ζ\or η\or θ\fi
  \gr@num@iii}
\def\gr@num@v#1{%
  \ifnum#1=\z@\else ͵\fi
  \ifcase#1\or ι\or κ\or λ\or μ\or ν\or ξ\or ο\or π\or ϟ\fi
  \gr@num@iv}
\def\gr@num@vi#1{%
  ͵\ifcase#1\or ρ\or σ\or τ\or υ\or φ\or χ\or ψ\or ω\or ϡ\fi
  \gr@num@v}
\def\gr@Num@i#1{%
  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
  \ifnum#1=\z@\else\anw@true\fi\anw@print}
\def\gr@Num@ii#1{%
  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
  \ifnum#1=\z@\else\anw@true\fi\gr@Num@i}
\def\gr@Num@iii#1{%
  \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
  \ifnum#1=\z@\anw@false\else\anw@true\fi\gr@Num@ii}
\def\gr@Num@iv#1{%
  \ifnum#1=\z@\else ͵\fi
  \ifcase#1 \or Α\or Β\or Γ\or Δ\or Ε\or \MakeUppercase{Ϛ}\or Ζ\or Η\or θ\fi
  \gr@Num@iii}
\def\gr@Num@v#1{%
  \ifnum#1=\z@\else ͵\fi
  \ifcase#1 \or Ι\or Κ\or Λ\or Μ\or Ν\or Ξ\or Ο\or Π\or \MakeUppercase{ϟ}\fi
\gr@Num@iv}
  \def\gr@Num@vi#1{%
͵ \ifcase#1 \or Ρ\or Σ\or Τ\or Υ\or Φ\or Χ\or Ψ\or Ω\or \MakeUppercase{ϡ}\fi
  \gr@Num@v}
\def\gr@ill@value#1{\xpg@warning{Illegal value (#1) for Greek numeral}[$#1$]}

%%%% Attic numerals (no longer optional)
\newcount\@attic@num
\DeclareRobustCommand*{\@@atticnum}[1]{%
        \@attic@num#1\relax
        \ifnum\@attic@num<\@ne%
          \space%
          \xpg@warning{Illegal value (\the\@attic@num) for acrophonic Attic numeral}%
        \else\ifnum\@attic@num>249999%
          \space%
	  \xpg@warning{Illegal value (\the\@attic@num) for acrophonic Attic numeral}%
        \else
            \@whilenum\@attic@num>49999\do{%
               \char"10147\advance\@attic@num-50000}%
            \@whilenum\@attic@num>9999\do{%
               M\advance\@attic@num-\@M}%
            \ifnum\@attic@num>4999%
               \char"10146\advance\@attic@num-5000%
            \fi\relax
            \@whilenum\@attic@num>999\do{%
               Χ\advance\@attic@num-\@m}%
            \ifnum\@attic@num>499%
               \char"10145\advance\@attic@num-500%
            \fi\relax
            \@whilenum\@attic@num>99\do{%
               Η\advance\@attic@num-100}%
            \ifnum\@attic@num>49%
               \char"10144\advance\@attic@num-50%
            \fi\relax
            \@whilenum\@attic@num>9\do{%
               Δ\advance\@attic@num by-10}%
            \@whilenum\@attic@num>4\do{%
               Π\advance\@attic@num-5}%
            \ifcase\@attic@num\or Ι\or ΙΙ\or ΙΙΙ\or ΙΙΙΙ\fi%
   \fi\fi}
\def\@atticnum#1{%
     \expandafter\@@atticnum\expandafter{\the#1}}
\def\atticnumeral#1{%
     \@attic@num#1\relax
     \@atticnum{\@attic@num}}
\let\atticnum=\atticnumeral

\def\greek@numbers{%
   \if@greek@numerals
      \def\greek@alph##1{\expandafter\greeknumeral\expandafter{\the##1}}%
      \def\greek@Alph##1{\expandafter\Greeknumeral\expandafter{\the##1}}%
      \let\@alph\greek@alph%
      \let\@Alph\greek@Alph%
   \fi}

\def\nogreek@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
  \let\greek@alph\@undefined%
  \let\greek@Alph\@undefined%
  }

%    \end{macrocode}
% \iffalse
%</gloss-greek.ldf>
%<*gloss-he.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-he.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-he.ldf}[polyglossia: module for he (hebrew)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{hebrew}

%    \end{macrocode}
% \iffalse
%</gloss-he.ldf>
%<*gloss-hebrew.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hebrew.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hebrew.ldf}[polyglossia: module for hebrew]

\RequireBidi
\RequirePackage{hebrewcal}

\PolyglossiaSetup{hebrew}{
  bcp47=he,
  script=Hebrew,
  direction=RL,
  scripttag=hebr,
  langtag=IWR,
  hyphennames={nohyphenation},
  fontsetup=true,
  localnumeral=hebrewnumerals
  %TODO localalph={hebrewnumeral,Hebrewnumeral}
  %digits = hebrewnumber
}

% BCP-47 compliant aliases
\setlanguagealias*{hebrew}{he}

\newif\if@calendar@hebrew
\def\tmp@hebrew{hebrew}
\define@key{hebrew}{calendar}[gregorian]{%
	\message{Setting \string\if@calendar@hebrew}
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@hebrew%
    \@calendar@hebrewtrue%
	\else%
    \@calendar@hebrewfalse%
	\fi}

\newif\if@xpg@hebrew@marcheshvan
\@xpg@hebrew@marcheshvanfalse

\define@boolkey{hebrew}[@xpg@hebrew@]{marcheshvan}[true]{}

% hebrewcal.sty also defines the boolean key fullyear (default=false)

\newif\if@hebrew@numerals
\def\tmp@hebrew{hebrew}
\define@key{hebrew}{numerals}[arabic]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@hebrew%
	  \@hebrew@numeralstrue%
	\else%
    \@hebrew@numeralsfalse%
	\fi}

\setkeys{hebrew}{numerals}

% Register default options
\xpg@initialize@gloss@options{hebrew}{numerals=arabic,calendar=gregorian,marcheshvan=false}

\def\captionshebrew{%
  \def\prefacename{מבוא}%
  \def\refname{מקורות}%
  \def\abstractname{תקציר}%
  \def\bibname{ביבליוגרפיה}%
  \def\chaptername{פרק}%
  \def\appendixname{נספח}%
  \def\contentsname{תוכן העניינים}%
  \def\listfigurename{רשימת האיורים}%
  \def\listtablename{רשימת הטבלאות}%
  \def\indexname{מפתח}%
  \def\figurename{איור}%
  \def\tablename{טבלה}%
  \def\partname{חלק}%
  \def\enclname{רצ"ב}%
  \def\ccname{העתקים}%
  \def\headtoname{אל}%
  \def\pagename{עמוד}%
  \def\psname{נ.ב.}%
  \def\seename{ראה}%
  \def\alsoname{ראה גם}% check
  \def\proofname{הוכחה}
  \def\glossaryname{מילון מונחים}% check
}
\def\datehebrew{%
  \def\today{%
    \if@calendar@hebrew%
      \hebrewtoday%
    \else%
      \hebrewnumber\day%
      \space ב\hebrewgregmonth{\month}\space%
      \hebrewnumber\year%
     \fi}%
}

\def\hebrewgregmonth#1{\ifcase#1%
  \or ינואר% יאנואר
    \or פברואר\or מרץ% מרס / מארס
    \or אפריל\or מאי% מי
    \or יוני\or יולי\or אוגוסט %אבגוסט
    \or ספטמבר\or אוקטובר\or נובמבר\or דצמבר\fi}

\input{babel-hebrewalph.def}

\newcommand{\hebrewnumerals}[2]{\hebrewnumber{#2}}

\def\hebrewnumber#1{%
   \if@hebrew@numerals
     \hebrewnumeral{#1}%
   \else
     \number#1%
   \fi
}

\ifxetex
  \let\xpg@orig@DigitsDotDashInterCharToks\DigitsDotDashInterCharToks%
\fi

\def\hebrew@ltr@numbers{%
    \ifxetex
       % Bidi inserts an RTL mark (0x200f) between number and number separator (- .),
       % forcing numbers to RTL. This is wrong for Hebrew.
       % So we defunc the respective command.
       \renewcommand*{\DigitsDotDashInterCharToks}{}%
    \fi%
}

\def\nohebrew@ltr@numbers{%
    \ifxetex
      % Restore bidi's \DigitsDotDashInterCharToks
      \let\DigitsDotDashInterCharToks\xpg@orig@DigitsDotDashInterCharToks%
    \fi%
}

\def\hebrew@numbers{%
   \let\@alph\hebrewnumeral%
   \let\@Alph\Hebrewnumeral%
   % Prevent bidi from setting the numbers RTL
   \hebrew@ltr@numbers%
}

\def\nohebrew@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
  % Restore previous bidi numbers definition
  \nohebrew@ltr@numbers
}

\def\hebrew@globalnumbers{%
   \let\@arabic\hebrewnumber%
   \renewcommand\thefootnote{\localnumeral*{footnote}}%
   % Prevent bidi from setting the numbers RTL
   \hebrew@ltr@numbers%
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\nohebrew@globalnumbers{%
  \let\@arabic\xpg@save@arabic%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@hebrew{%
   \def\MakeUppercase##1{##1}%
}

\def\noextras@hebrew{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-hebrew.ldf>
%<*gloss-hi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hi.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hi.ldf}[polyglossia: module for hi (hindi)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{hindi}

%    \end{macrocode}
% \iffalse
%</gloss-hi.ldf>
%<*gloss-hindi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hindi.ldf}
%    \begin{macrocode}
% UTF-8 strings kindly provided by Zdenĕk Wagner, 10-03-2008
% with corrections and additional contributions by Anshuman Pandey
% TODO: add option for velthuis transliteration with link to
% Velthuis Devanagari project.

\ProvidesFile{gloss-hindi.ldf}[polyglossia: module for hindi]
\RequirePackage{devanagaridigits}
\PolyglossiaSetup{hindi}{
  bcp47=hi,
  script=Devanagari,
  scripttag=deva,
  langtag=HIN,
%%  hyphennames={hindi,!sanskrit}, TODO: implement fallback patterns (with ! prefix)
  fontsetup=true,
  localnumeral=hindinumerals
  %TODO nouppercase=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{hindi}{hi}

\ifx\l@hindi\@undefined%
  \ifx\l@sanskrit\@undefined%
    \xpg@nopatterns{Hindi}%
    \adddialect\l@hindi\l@nohyphenation%
  \else
    \xpg@warning{No hyphenation patterns were loaded for Hindi\MessageBreak
    I will use the patterns for Sanskrit instead}
    \adddialect\l@hindi\l@sanskrit%
  \fi
\fi

\def\hindi@language{%
  \polyglossia@setup@language@patterns{hindi}%
}

\def\tmp@western{Western}
\newif\ifhindi@devanagari@numerals
\hindi@devanagari@numeralstrue

\define@key{hindi}{numerals}[Devanagari]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@western
    \hindi@devanagari@numeralsfalse
  \fi%
}

% Register default options
\xpg@initialize@gloss@options{hindi}{numerals=Devanagari}

\newcommand{\hindinumerals}[2]{\hindinumber{#2}}

\def\hindinumber#1{%
  \ifhindi@devanagari@numerals
    \devanagaridigits{\number#1}%
  \else
    \number#1%
  \fi}

\def\captionshindi{%
     \def\abstractname{सारांश}%
     \def\appendixname{परिशिष्ट}%
     \def\bibname{संदर्भ ग्रंथ}%
     \def\ccname{}%
     \def\chaptername{अध्याय}%
     \def\contentsname{विषय सूची}%
     \def\enclname{}%
     \def\figurename{चित्र}% रेखाचित्र
     \def\headpagename{पृष्ठ}%
     \def\headtoname{}%
     \def\indexname{सूची}%
     %              सूचक
     %              अनुक्रमणिका
     %              अनुक्रमणि
     \def\listfigurename{चित्रों की सूची}%
     \def\listtablename{तालिकाओं की सूची}%
     \def\pagename{पृष्ठ}%
     \def\partname{खण्ड}%
     \def\prefacename{प्रस्तावना}% प्राक्कथन
     \def\refname{हवाले}%
     \def\tablename{तालिका}%
     \def\seename{देखिए}%
     \def\alsoname{और देखिए}%
     \def\alsoseename{और देखिए}%
}
\def\datehindi{%
  \def\today{\hindinumber\day\space\ifcase\month\or
    जनवरी\or
    फ़रवरी\or
    मार्च\or
    अपरैल\or
    मई\or
    जून\or
    जलाई\or
    अगस्त\or
    सितम्बर\or
    अक्तूबर\or
    नवम्बर\or
    दिसम्बर\fi
    \space\hindinumber\year}%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@hindi{%
  \def\MakeUppercase##1{##1}%
}

\def\noextras@hindi{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-hindi.ldf>
%<*gloss-hr.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hr.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hr.ldf}[polyglossia: module for hr (croatian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{croatian}

%    \end{macrocode}
% \iffalse
%</gloss-hr.ldf>
%<*gloss-hsb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hsb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hsb.ldf}[polyglossia: module for hsb (sorbian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-hsb.ldf>
%<*gloss-hu.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hu.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hu.ldf}[polyglossia: module for hu (hungarian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{hungarian}

%    \end{macrocode}
% \iffalse
%</gloss-hu.ldf>
%<*gloss-hungarian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hungarian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hungarian.ldf}[polyglossia: module for hungarian]

\PolyglossiaSetup{hungarian}{
  bcp47=hu,
  babelname=magyar,
  hyphennames={hungarian,magyar},
  langtag=HUN,
  hyphenmins={2,2},
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{hungarian}{hu}

\frenchspacing

% Babel and backwards compat. alias
\setlanguagealias{hungarian}{magyar}

\newif\if@hungarian@swapcaptions
\newif\if@hungarian@swapheadings
\newif\if@hungarian@swapheaders
\define@choicekey*+{hungarian}{swapstrings}[\xpg@val\xpg@nr]{all,captions,headings,headers,hheaders,none}[all]{%
   \ifcase\xpg@nr\relax
      % all:
      \@hungarian@swapcaptionstrue%
      \@hungarian@swapheadingstrue%
      \@hungarian@swapheaderstrue%
   \or
      % captions:
      \@hungarian@swapcaptionstrue%
      \@hungarian@swapheadingsfalse%
      \@hungarian@swapheadersfalse%
   \or
      % headings:
      \@hungarian@swapcaptionsfalse%
      \@hungarian@swapheadingstrue%
      \@hungarian@swapheadersfalse%
   \or
      % headers:
      \@hungarian@swapcaptionsfalse%
      \@hungarian@swapheadingsfalse%
      \@hungarian@swapheaderstrue%
   \or
      % hheaders:
      \@hungarian@swapcaptionsfalse%
      \@hungarian@swapheadingstrue%
      \@hungarian@swapheaderstrue%
   \or
      % none:
      \@hungarian@swapcaptionsfalse%
      \@hungarian@swapheadingsfalse%
      \@hungarian@swapheadersfalse%
   \fi
   \xpg@info{Option: Hungarian, swapstrings=\xpg@val}%
}{\xpg@warning{Unknown Hungarian swapstrings value `#1'}}

% Register default options
\xpg@initialize@gloss@options{hungarian}{swapstrings=all}

\def\hungarian@language{%
   \polyglossia@setup@language@patterns{hungarian}%
   \xpg@ifdefined{hungarian}{\adddialect\l@magyar\l@hungarian}{}%
}%

\def\captionshungarian{%
   \def\refname{Hivatkozások}%
   \def\abstractname{Kivonat}%
   \def\bibname{Irodalomjegyzék}%
   \def\prefacename{Előszó}%
   \def\chaptername{fejezet}%
   \def\appendixname{Függelék}%
   \def\contentsname{Tartalomjegyzék}%
   \def\listfigurename{Ábrák jegyzéke}%
   \def\listtablename{Táblázatok jegyzéke}%
   \def\indexname{Tárgymutató}%
   \def\figurename{ábra}%
   \def\tablename{táblázat}%
   %\def\thepart{}%
   \def\partname{rész}%
   \def\pagename{oldal}%
   \def\seename{lásd}%
   \def\alsoname{lásd még}%
   \def\enclname{Melléklet}%
   \def\ccname{Körlevél–címzettek}%
   \def\headtoname{Címzett}%
   \def\proofname{Bizonyítás}%
   \def\glossaryname{Szójegyzék}%
}

\def\datehungarian{%   
   \def\today{%
    \number\year.\nobreakspace\ifcase\month\or
    január\or február\or március\or
    április\or május\or június\or
    július\or augusztus\or szeptember\or
    október\or november\or december\fi
    \space\number\day.}%
   \def\ondatehungarian{%
    \number\year.\nobreakspace\ifcase\month\or
    január\or február\or március\or
    április\or május\or június\or
    július\or augusztus\or szeptember\or
    október\or november\or december\fi
      \space\ifcase\day\or
      1-jén\or  2-án\or  3-án\or  4-én\or  5-én\or
      6-án\or  7-én\or  8-án\or  9-én\or 10-én\or
     11-én\or 12-én\or 13-án\or 14-én\or 15-én\or
     16-án\or 17-én\or 18-án\or 19-én\or 20-án\or
     21-én\or 22-én\or 23-án\or 24-én\or 25-én\or
     26-án\or 27-én\or 28-án\or 29-én\or 30-án\or
     31-én\fi}%
   \let\ontoday\ondatehungarian%
   \let\ondatemagyar\ondatehungarian%
}

% Save original capsformats
\let\xpg@save@fnum@table\fnum@table
\let\xpg@save@fnum@figure\fnum@figure

\def\hungarian@capsformat{%
  %
  % Change captions
  \if@hungarian@swapcaptions
     % change 'ábra x.x' to 'x.x. ábra'
     \def\fnum@figure{\thefigure.~\figurename}
     %
     % change 'táblázat x.x' to 'x.x. táblázat'
     \def\fnum@table{\thetable.~\tablename}
  \fi
  %
  % change chapter and part headings
  \if@hungarian@swapheadings
     % With titlesec
     \ifcsdef{titleformat}{%
       \ifcsdef{@part}{%
          \let\xpg@save@part@format\@part%
          \patchcmd{\@part}%
                    {\partname\nobreakspace\thepart}%
                    {\thepart.\nobreakspace\partname}%
                    {}%
                    {\xpg@warning{Failed to patch part for Hungarian}}%
       }{}%
       \ifcsdef{chapter}{%
          \titleformat\chapter[display]%
             {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6}
             {\thechapter.\space\@chapapp}{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit}
       }{}%
     }{% (not \ifdefined\titleformat)
       % With KOMA
       \ifcsdef{sectionformat}{%
          \ifcsdef{partformat}{%
            \let\xpg@save@part@format\partformat%
            \renewcommand{\partformat}{\thepart.~\partname}%
          }{}%
          \ifcsdef{chapterformat}{%
            \let\xpg@save@chap@format\chapterformat%
            \renewcommand{\chapterformat}{\mbox{\thechapter\autodot%
                                          \IfUsePrefixLine{\nobreakspace\chapapp}{\enskip}}}%
          }{}%
       }{%  (not \ifdefined\sectionformat)
         % With memoir
         \ifcsdef{@memptsize}{%
           \ifcsdef{@makechapterhead}{%
              \let\xpg@save@chap@format\@makechapterhead%
              \patchcmd{\@makechapterhead}{\printchaptername \chapternamenum \printchapternum}%
                       {\printchapternum.\chapternamenum\printchaptername}%
                       {}%
                       {\xpg@warning{Failed to patch chapter for Hungarian}}%
           }{}%
           \ifcsdef{@part}{%
              \let\xpg@save@part@format\@part%
              \patchcmd{\@part}{\printpartname \partnamenum \printpartnum}%
                               {\printpartnum.\partnamenum\printpartname}%
                               {}%
                               {\xpg@warning{Failed to patch part for Hungarian}}%
           }{}%
         }{%  (not \ifdefined\@memptsize)
           % With standard classes
            \ifcsdef{@makechapterhead}{%
              \let\xpg@save@chap@format\@makechapterhead%
              \patchcmd{\@makechapterhead}%
                       {\@chapapp\space \thechapter}%
                       {\thechapter.\space \@chapapp}%
                       {}%
                       {\xpg@warning{Failed to patch chapter for Hungarian}}%
            }{}%
            \ifcsdef{@part}{%
              \let\xpg@save@part@format\@part%
              \patchcmd{\@part}%
                       {\partname\nobreakspace\thepart}%
                       {\thepart.\nobreakspace\partname}%
                       {}%
                       {\xpg@warning{Failed to patch part for Hungarian}}%
            }{}%  (end \ifdefined\@part)
          }% (end \ifdefined\@memptsize)
        }% (end \ifdefined\sectionformat)
     }% (end \ifdefined\titleformat)
  \fi% (end \if@hungarian@swapheadings)
  %
  % Change running headers
  \if@hungarian@swapheaders
    \ifcsdef{chapterformat}{%
      % With KOMA
      \let\xpg@save@chaptermark@format\chaptermarkformat%
      \renewcommand*\chaptermarkformat{%
         \thechapter\autodot\ \IfChapterUsesPrefixLine{\chapapp\enskip}{}}
    }{% (not \ifdefined\chapterformat)
      \ifcsdef{@memptsize}{%
        % With memoir
        \let\xpg@save@chaptermark@format\chaptermark%
        \renewcommand*\chaptermark[1]{%
          \markboth{\memUChead{%
            \ifnum \c@secnumdepth >\m@ne
              \ifbool{@mainmatter}{%
                \thechapter.\ \@chapapp\ %
              }{}%
            \fi
            ##1}}{}}%
      }{% (not \ifdefined\@memptsize)
        % With standard classes
        \ifcsdef{chaptermark}{%
          \ifpatchable{\chaptermark}%
               {\@chapapp\ \thechapter.}%
               {\let\xpg@save@chaptermark@format\chaptermark%
                \patchcmd{\chaptermark}%
                    {\@chapapp\ \thechapter.}%
                    {\thechapter.\ \@chapapp}%
                    {}%
                    {\xpg@warning{Failed to patch chaptermark for Hungarian}}}%
               {}%
        }{}% (end \ifdefined\chaptermark)
      }% (end \ifdefined\@memptsize)
    }% (end \ifdefined\chapterformat)
  \fi% (end \if@hungarian@swapheaders)
}

\def\nohungarian@capsformat{%
   %
   % Reset changes of \hungarian@capsformat
   \let\fnum@table\xpg@save@fnum@table%
   \let\fnum@figure\xpg@save@fnum@figure%
   %
   % Reset chapter and part heading
   \ifcsdef{titleformat}{%
      % With titlesec
     \ifcsdef{xpg@save@part@format}{%
        \let\@part\xpg@save@part@format
     }{}%
     \ifcsdef{chapter}{%
        \titleformat\chapter[display]%
          {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6}
          {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit}
     }{}%
   }{% (not \ifdefined\titleformat)
     \ifcsdef{sectionformat}{%
        % With KOMA
        \ifcsdef{xpg@save@part@format}{%
           \let\partformat\xpg@save@part@format
        }{}%
        \ifcsdef{xpg@save@chap@format}{%
           \let\chapterformat\xpg@save@chap@format
        }{}%
     }{%
        % With memoir and standard classes
        \ifcsdef{xpg@save@part@format}{%
           \let\@part\xpg@save@part@format
        }{}%
        \ifcsdef{xpg@save@chap@format}{%
          \let\@makechapterhead\xpg@save@chap@format
        }{}%
     }% (end \ifdefined\sectionformat)
   }% (end \ifdefined\titleformat)
  %
  % Reset headers
  \ifcsdef{chaptermarkformat}{%
     % With KOMA
     \ifcsdef{xpg@save@chaptermark@format}{%
       \let\chaptermarkformat\xpg@save@chaptermark@format%
     }{}%
  }{%
     \ifcsdef{chaptermark}{%
       % With memoir and standard classes
       \ifcsdef{xpg@save@chaptermark@format}{%
         \let\chaptermark\xpg@save@chaptermark@format%
       }{}%
     }{}% (end \ifdefined\chaptermark)
  }% (end \ifdefined\chapterformat)
}

\def\blockextras@hungarian{%
   \hungarian@capsformat%
}

\def\noextras@hungarian{%
   \nohungarian@capsformat%
   \let\ontoday\@undefined%
}

%    \end{macrocode}
% \iffalse
%</gloss-hungarian.ldf>
%<*gloss-hy.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-hy.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-hy.ldf}[polyglossia: module for hy (armenian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{armenian}

%    \end{macrocode}
% \iffalse
%</gloss-hy.ldf>
%<*gloss-ia.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ia.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ia.ldf}[polyglossia: module for ia (interlingua)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{interlingua}

%    \end{macrocode}
% \iffalse
%</gloss-ia.ldf>
%<*gloss-icelandic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-icelandic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-icelandic.ldf}[polyglossia: module for icelandic]
\PolyglossiaSetup{icelandic}{
  bcp47=is,
  hyphennames={icelandic},
  hyphenmins={2,2},
  langtag=ISL,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{icelandic}{is}

\def\captionsicelandic{%
   \def\refname{Heimildir}%
   \def\abstractname{Útdráttur}%
   \def\bibname{Heimildir}%
   \def\prefacename{Formáli}%
   \def\chaptername{Kafli}%
   \def\appendixname{Viðauki}%
   \def\contentsname{Efnisyfirlit}%
   \def\listfigurename{Myndaskrá}%
   \def\listtablename{Töfluskrá}%
   \def\indexname{Atriðisorðaskrá}%
   \def\figurename{Mynd}%
   \def\tablename{Tafla}%
   %\def\thepart{}%
   \def\partname{Hluti}%
   \def\pagename{Blaðsíða}%
   \def\seename{Sjá}%
   \def\alsoname{Sjá einnig}%
   \def\enclname{Hjálagt}%
   \def\ccname{Samrit}%
   \def\headtoname{Til:}%
   \def\proofname{Sönnun}%
   \def\glossaryname{Orðalisti}%
   }

\def\dateicelandic{%
   \def\today{\number\day.~\ifcase\month\or
    janúar\or febrúar\or mars\or apríl\or maí\or
    júní\or júlí\or ágúst\or september\or
    október\or nóvember\or desember\fi
    \space\number\year}%
    }

%    \end{macrocode}
% \iffalse
%</gloss-icelandic.ldf>
%<*gloss-id.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-id.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-id.ldf}[polyglossia: module for id (malay)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{malay}

%    \end{macrocode}
% \iffalse
%</gloss-id.ldf>
%<*gloss-interlingua.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-interlingua.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-interlingua.ldf}[polyglossia: module for interlingua]
\PolyglossiaSetup{interlingua}{
  bcp47=ia,
  hyphennames={interlingua},
  hyphenmins={2,2},
  langtag=INA,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{interlingua}{ia}

\def\captionsinterlingua{%
   \def\refname{Referentias}%
   \def\abstractname{Summario}%
   \def\bibname{Bibliographia}%
   \def\prefacename{Prefacio}%
   \def\chaptername{Capitulo}%
   \def\appendixname{Appendice}%
   \def\contentsname{Contento}%
   \def\listfigurename{Lista de figuras}%
   \def\listtablename{Lista de tabellas}%
   \def\indexname{Indice}%
   \def\figurename{Figura}%
   \def\tablename{Tabella}%
   \def\partname{Parte}%
   %\def\thepart{}%
   \def\pagename{Pagina}%
   \def\seename{vide}%
   \def\alsoname{vide etiam}%
   \def\enclname{Incluso}%
   \def\ccname{Copia}%
   \def\headtoname{A}%
   \def\proofname{Prova}%
   \def\glossaryname{Glossario}%
   }
\def\dateinterlingua{%
   \def\today{le~\number\day\space de \ifcase\month\or
    januario\or februario\or martio\or april\or maio\or junio\or
    julio\or augusto\or septembre\or octobre\or novembre\or
    decembre\fi
    \space \number\year}}

%    \end{macrocode}
% \iffalse
%</gloss-interlingua.ldf>
%<*gloss-irish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-irish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-irish.ldf}[polyglossia: module for irish]

% We only provide this gloss for babel compatibility. Since irish is 
% a gaelic variety, we use 'gaelic' with variant 'irish' now.

\xpg@load@master@language{gaelic}

%    \end{macrocode}
% \iffalse
%</gloss-irish.ldf>
%<*gloss-is.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-is.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-is.ldf}[polyglossia: module for is (icelandic)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{icelandic}

%    \end{macrocode}
% \iffalse
%</gloss-is.ldf>
%<*gloss-it.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-it.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-it.ldf}[polyglossia: module for it (italian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{italian}

%    \end{macrocode}
% \iffalse
%</gloss-it.ldf>
%<*gloss-italian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-italian.ldf}
%    \begin{macrocode}
% !TEX encoding = UTF-8 Unicode
\ProvidesFile{gloss-italian.ldf}[polyglossia: module for italian]
\PolyglossiaSetup{italian}{
  bcp47=it,
  hyphennames={italian},
  hyphenmins={2,2},
  langtag=ITA,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{italian}{it}


%%% CHANGES START %%% by Enrico Gregorio
\define@boolkey{italian}[italian@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{italian}{babelshorthands=false}

\ifsystem@babelshorthands
  \setkeys{italian}{babelshorthands=true}
\else
  \setkeys{italian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\italian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{italian}%
  \declare@shorthand{italian}{"}{%
    \relax\ifmmode
      \def\xpgit@next{''}%
    \else
      \def\xpgit@next{\futurelet\xpgit@temp\xpgit@cwm}%
    \fi
  \xpgit@next}%
}

%%% By Enrico Gregorio and Claudio Beccari %%%
\def\xpgit@@cwm{\nobreak\discretionary{-}{}{}\nobreak\hskip\z@skip}
\def\xpgit@cwm{\let\xpgit@@next\relax
  \ifcat\noexpand\xpgit@temp a%
    \def\xpgit@@next{\xpgit@@cwm}%
  \else
    \if\noexpand\xpgit@temp \string|%
      \def\xpgit@@next##1{\xpgit@@cwm}%
    \else
      \if\noexpand\xpgit@temp \string<%
        \def\xpgit@@next##1{«\ignorespaces}%
      \else
        \if\noexpand\xpgit@temp \string>%
          \def\xpgit@@next##1{\unskip »}%
        \else
          \if\noexpand\xpgit@temp\string/%
            \def\xpgit@@next##1{\slash}%
          \else
            \ifx\xpgit@temp"%
              \def\xpgit@@next##1{?}%
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
  \xpgit@@next}

\def\noitalian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}
%%% CHANGES END %%%

%%% ORIGINAL %%% by Claudio Beccari
\def\captionsitalian{%
  \def\prefacename{Prefazione}%
  \def\refname{Riferimenti bibliografici}%
  \def\abstractname{Sommario}%
  \def\bibname{Bibliografia}%
  \def\chaptername{Capitolo}%
  \def\appendixname{Appendice}%
  \def\contentsname{Indice}%
  \def\listfigurename{Elenco delle figure}%
  \def\listtablename{Elenco delle tabelle}%
  \def\indexname{Indice analitico}%
  \def\figurename{Figura}%
  \def\tablename{Tabella}%
  \def\partname{Parte}%
  \def\enclname{Allegati}%
  \def\ccname{e~p.~c.}%
  \def\headtoname{Per}%
  \def\pagename{Pag.}%    % in Italian the abbreviation is preferred
  \def\seename{vedi}%
  \def\alsoname{vedi anche}%
  \def\proofname{Dimostrazione}%
  \def\glossaryname{Glossario}%
   }
\def\dateitalian{%
   \def\today{\number\day~\ifcase\month\or
    gennaio\or febbraio\or marzo\or aprile\or maggio\or giugno\or
    luglio\or agosto\or settembre\or ottobre\or novembre\or
    dicembre\fi\space \number\year}}
%%% ORIGINAL END %%%

%%% CHANGES START %%% by Enrico Gregorio
\let\xpgit@savedvalues\empty
\AtEndPreamble{% the user or the class might define different values
  \edef\xpgit@savedvalues{%
    \clubpenalty=\the\clubpenalty\space
    \@clubpenalty=\the\@clubpenalty\space
    \widowpenalty=\the\widowpenalty\space
    \finalhyphendemerits=\the\finalhyphendemerits}
}


\def\noextras@italian{%
   \lccode\string"2019=\z@%
   \ifitalian@babelshorthands\noitalian@shorthands\fi%
   \xpgit@savedvalues%
}

\def\blockextras@italian{%
   \lccode\string"2019=\string"2019%
   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000%
   \finalhyphendemerits=50000000%
   \ifitalian@babelshorthands\italian@shorthands\fi%
}

\def\inlineextras@italian{%
   \lccode\string"2019=\string"2019%
   \ifitalian@babelshorthands\italian@shorthands\fi%
}
%%% CHANGES END %%%
%    \end{macrocode}
% \iffalse
%</gloss-italian.ldf>
%<*gloss-ja.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ja.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ja.ldf}[polyglossia: module for ja (japanese)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{japanese}

%    \end{macrocode}
% \iffalse
%</gloss-ja.ldf>
%<*gloss-japanese.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-japanese.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-japanese.ldf}[polyglossia: module for japanese]

\PolyglossiaSetup{japanese}{
	bcp47=ja,
	script=CJK,
	language=Japanese,
	langtag=JAN,
	hyphennames={nohyphenation},
	frenchspacing=false,
	fontsetup=true,
	localnumeral=japanesenumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{japanese}{ja}

\def\japanese@capsformat{%
	\def\@seccntformat##1{%
		\csname pre##1\endcsname%
		\csname the##1\endcsname%
		\csname post##1\endcsname%
	}%
	\def\postsection{節\space}%
	\def\postsubsection{節\space}%
	\def\postsubsubsection{節\space}%
	\def\presection{第}%
	\def\presubsection{第}%
	\def\presubsubsection{第}%
}

\def\captionsjapanese{%
	\def\refname{参考文献}%
	\def\abstractname{概要}%
	\def\bibname{文献目録}%
	\def\prefacename{端書き}%
	\def\chaptername##1##2{第##1##2 章}%
	\def\appendixname{付録}%
	\def\contentsname{目次}%
	\def\listfigurename{図目次}%
	\def\listtablename{表目次}%
	\def\indexname{索引}%
	\def\figurename{図}%
	\def\tablename{表}%
	\def\partname##1##2{第##1##2 部}%
	\def\pagename##1##2{第##1##2 頁}%
	\def\seename{参照}%
	\def\alsoname{参照}%
	\def\enclname{添付}%
	\def\ccname{同報}%
	\def\headtoname{宛先}%
	\def\proofname{証明}%
	\def\glossaryname{用語集}%
 }

\newif\if@WameiReki \@WameiRekifalse%
\newif\if@WameiTosi \@WameiTosifalse%
\newif\if@WameiTuki \@WameiTukifalse%
\newif\if@WameiHi \@WameiHifalse%
\newif\if@IzumoTuki \@IzumoTukifalse%
\newcount\c@TempJNum%

\def\@JapaneseDigit#1{%
	\ifcase#1\or 一\or 二\or 三\or 四\or 五\or%
		六\or 七\or 八\or 九\or 十\or%
		十一\or 十二\or 十三\or 十四\or 十五\or%
		十六\or 十七\or 十八\or 十九\or 廿\or%
		廿一\or 廿二\or 廿三\or 廿四\or 廿五\or%
		廿六\or 廿七\or 廿八\or 廿九\or 丗\or%
		丗一\or 丗二\or 丗三\or 丗四\or 丗五\or%
		丗六\or 丗七\or 丗八\or 丗九\or 四十\or%
		四十一\or 四十二\or 四十三\or 四十四\or 四十五\or%
		四十六\or 四十七\or 四十八\or 四十九\or 五十\or%
		五十一\or 五十二\or 五十三\or 五十四\or 五十五\or%
		五十六\or 五十七\or 五十八\or 五十九\or 六十\or%
		六十一\or 六十二\or 六十三\or 六十四\or 六十五\or%
		六十六\or 六十七\or 六十八\or 六十九\or 七十\or%
		七十一\or 七十二\or 七十三\or 七十四\or 七十五\or%
		七十六\or 七十七\or 七十八\or 七十九\or 八十\or%
		八十一\or 八十二\or 八十三\or 八十四\or 八十五\or%
		八十六\or 八十七\or 八十八\or 八十九\or 九十\or%
		九十一\or 九十二\or 九十三\or 九十四\or 九十五\or%
		九十六\or 九十七\or 九十八\or 九十九%
	\else
		\@ctrerr%
	\fi\relax%
}

\def\@JapaneseNum#1{%
	\c@TempJNum=#1\divide\c@TempJNum by 1000\relax%
	\ifnum\c@TempJNum=\z@\c@TempJNum=#1%
		\divide\c@TempJNum by 100\relax%
		\ifnum\c@TempJNum=\z@\@JapaneseDigit{#1}\relax%
		\else
			\ifcase\c@TempJNum\or 百\or 二百\or 三百\or 四百\or 五百\or
				六百\or 七百\or 八百\or 九百%
			\fi
			\c@TempJNum=#1\divide\c@TempJNum by 100\multiply\c@TempJNum by -100\advance\c@TempJNum#1\@JapaneseDigit\c@TempJNum\relax%
		\fi%
	\else
		\ifcase\c@TempJNum\or 千\or 二千\or 三千\or 四千\or 五千\or
			六千\or 七千\or 八千\or 九千%
		\fi
		\c@TempJNum=#1\divide\c@TempJNum by 1000\multiply\c@TempJNum by -1000\advance\c@TempJNum#1\divide\c@TempJNum by 100\relax%
		\ifnum\c@TempJNum=\z@\c@TempJNum=#1%
			\divide\c@TempJNum by 100\multiply\c@TempJNum by -100\advance\c@TempJNum#1\@JapaneseDigit\c@TempJNum\relax%
		\else
			\ifcase\c@TempJNum\or 百\or 二百\or 三百\or 四百\or 五百\or
				六百\or 七百\or 八百\or 九百%
			\fi
			\c@TempJNum=#1\divide\c@TempJNum by 100\multiply\c@TempJNum by -100\advance\c@TempJNum#1\@JapaneseDigit\c@TempJNum\relax%
		\fi
	\fi
}

\def\@japanesenumber#1{%
	\@tempcnta=#1%
	\ifnum\@tempcnta=\z@{〇}%
	\else
		\ifnum\@tempcnta<\z@{負}%
			\multiply\@tempcnta by -1%
		\fi
		\@tempcntb=\@tempcnta\divide\@tempcntb by 10000\relax%
		\ifnum\@tempcntb=\z@\@JapaneseNum%
			\@tempcnta%
		\else
			\@tempcntb=\@tempcnta\divide\@tempcntb by 100000000\relax%
			\ifnum\@tempcntb=\z@\@tempcntb=\@tempcnta%
				\divide\@tempcntb by 10000%
				\@JapaneseNum\@tempcntb{万}\@tempcntb=\@tempcnta%
				\divide\@tempcntb by 10000\multiply\@tempcntb by -10000%
				\advance\@tempcntb\@tempcnta\relax\@JapaneseNum\@tempcntb%
			\else
				\@JapaneseNum\@tempcntb{億}\@tempcntb=\@tempcnta%
				\divide\@tempcntb by 100000000\multiply\@tempcntb by -100000000%
				\advance\@tempcntb\@tempcnta\divide\@tempcntb by 10000\relax%
				\ifnum\@tempcntb=\z@%
				\else
					\@JapaneseNum\@tempcntb{万}%
				\fi
				\@tempcntb=\@tempcnta\divide\@tempcntb by 10000%
				\multiply\@tempcntb by -10000\advance\@tempcntb\@tempcnta%
				\@JapaneseNum\@tempcntb%
			\fi
		\fi
	\fi
}

\def\japanesenumber#1{%
	\expandafter\@japanesenumber\csname c@#1\endcsname%
}

\newcommand{\japanesenumerals}[2]{\@japanesenumber{#2}}

\def\datejapanese{%
	{%
		\ifnum\year<1868%
			\xdef\the@WarekiCur{}%
		\else
			\ifnum\year<1912%
				\xdef\the@WarekiCur{明治}\advance\year-1867\relax%
			\else
				\ifnum\year<1926%
					\xdef\the@WarekiCur{大正}\advance\year-1911\relax%
  				\else
					\ifnum\year<1989%
						\xdef\the@WarekiCur{昭和}\advance\year-1925\relax%
  					\else
						\xdef\the@WarekiCur{平成}\advance\year-1988\relax%
					\fi
				\fi
			\fi
		\fi
		\xdef\the@WameiTosi{\the\year}%
	}%
	\def\西暦{\@WameiRekifalse \@WameiTukifalse \@WameiHifalse}%
	\def\和暦{\@WameiRekitrue \@WameiTosifalse \@WameiTukifalse \@WameiHifalse}%
	\def\和名暦{\@WameiTositrue \@WameiTukitrue \@WameiHitrue}%
	\def\数字暦{\@WameiTosifalse \@WameiTukifalse \@WameiHifalse}%
	\def\出雲月{\@IzumoTukitrue}%
	\def\大和月{\@IzumoTukifalse}%
	\def\today{%
		\if@WameiReki%
			\the@WarekiCur%
			\if@WameiTosi%
				\@JapaneseNum\the@WameiTosi%
			\else
				\,\the@WameiTosi%
			\fi
		\else
			\number\year\,%
		\fi
		{年}%
		\if@WameiTuki%
			\ifcase\month\or 睦月\or 如月\or 弥生\or 卯月\or 皐月\or
				水無月\or 文月\or 葉月\or 長月\or
				\if@IzumoTuki 神在月\else 神無月\fi
				\or 霜月\or 師走%
			\fi
		\else
			\,\number\month\,%
		{月}%
		\fi
		\if@WameiHi%
			\@JapaneseNum\day%
		\else
			\,\number\day\,%
		\fi
		{日}%
	}%
}

\def\noextras@japanese{%
	\japanese@capsformat%
}

\def\blockextras@japanese{%
	\japanese@capsformat%
}

\def\inlineextras@japanese{%
	\japanese@capsformat%
}
% Based on contributions of Toru Inagaki, Norio Iwase, François Charette

%    \end{macrocode}
% \iffalse
%</gloss-japanese.ldf>
%<*gloss-ka.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ka.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ka.ldf}[polyglossia: module for ka (georgian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{georgian}

%    \end{macrocode}
% \iffalse
%</gloss-ka.ldf>
%<*gloss-kannada.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kannada.ldf}
%    \begin{macrocode}
%% gloss-kannada.ldf
%% Copyright 2011 Aravinda VK <hallimanearavind AT gmail.com>,
%%                Shankar Prasad <prasad.mvs AT gmail.com>,
%%                Team Sanchaya <dev AT lists.sanchaya.net>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
% 
% The Current Maintainer of this work is Aravinda VK <hallimanearavind AT gmail.com>.
%
% This work consists of the file gloss-kannada.ldf
\ProvidesFile{gloss-kannada.ldf}[polyglossia: module for kannada]

\PolyglossiaSetup{kannada}{
  bcp47=kn,
  script=Kannada,
  scripttag=knda,
  langtag=KAN,
  hyphennames={kannada},
  hyphenmins={2,2}, 
  fontsetup=true,
  localnumeral=kannadanumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{kannada}{kn}

%% Defining Kannada digits equivalents to english
\def\kannadadigits#1{\expandafter\@kannada@digits #1@}
\def\@kannada@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1೦\else\ifx1#1೧\else\ifx2#1೨\else\ifx3#1೩\else\ifx4#1೪\else\ifx5#1೫\else\ifx6#1೬\else\ifx7#1೭\else\ifx8#1೮\else\ifx9#1೯\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@kannada@digits
  \fi
}

%% \kannada@numerals variable will be set to true or false depending on the option provided in \setmainlanguage
%% \kannada@numerals true by default or when we set \setmainlanguage[numerals=Kannada]{kannada}
%% \kannada@numerals false when we set \setmainlanguage[numerals=Western]{kannada}
\def\tmp@western{Western}
\newif\ifkannada@numerals
\kannada@numeralstrue

\define@key{kannada}{numerals}[Kannada]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@western
    \kannada@numeralsfalse
  \fi}

  
\def\captionskannada{%
  \def\prefacename{ಮುನ್ನುಡಿ}%
  \def\refname{ಉಲ್ಲೇಖಗಳು}%
  \def\abstractname{ಸಾರಾಂಶ}%
  \def\bibname{ಗ್ರಂಥಸೂಚಿ}%
  \def\chaptername{ಅಧ್ಯಾಯ}%
  \def\appendixname{ಅನುಬಂಧ}%
  \def\contentsname{ವಿಷಯಗಳು}%
  \def\listfigurename{ಚಿತ್ರಗಳ ಪಟ್ಟಿ}%
  \def\listtablename{ಕೋಷ್ಟಕಗಳ ಪಟ್ಟಿ}%
  \def\indexname{ಸೂಚಿ}%
  \def\figurename{ಚಿತ್ರ}%
  \def\tablename{ಕೋಷ್ಟಕ}%
  \def\partname{ಭಾಗ}%
  \def\enclname{encl}%
  \def\ccname{cc}%
  \def\headtoname{ಗೆ}%
  \def\pagename{ಪುಟ}%
  \def\seename{ನೋಡು}%
  \def\alsoname{ಇದನ್ನೂ ಸಹ ನೋಡು}%
  \def\proofname{ಕರಡುಪ್ರತಿ}%
}

\def\datekannada{%
  \def\kannadamonth{%
    \ifcase\month\or
    ಜನವರಿ\or
    ಫೆಬ್ರವರಿ\or
    ಮಾರ್ಚ್\or
    ಏಪ್ರಿಲ್\or
    ಮೇ\or
    ಜೂನ್\or
    ಜುಲೈ\or
    ಆಗಷ್ಟ್\or
    ಸೆಪ್ಟೆಂಬರ್\or
    ಅಕ್ಟೋಬರ್\or
    ನವಂಬರ್\or
    ಡಿಸಂಬರ್\fi}%
  \def\today{\kannadanumber\day\space\kannadamonth\space\kannadanumber\year}%
}

\newcommand{\kannadanumerals}[2]{\kannadanumber{#2}}

%% Based on the settings displays respective numbers
\def\kannadanumber#1{%
  \ifkannada@numerals
  \kannadadigits{\number#1}%
  \else
  \number#1%
  \fi
}

%    \end{macrocode}
% \iffalse
%</gloss-kannada.ldf>
%<*gloss-khmer.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-khmer.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-khmer.ldf}[polyglossia: module for Khmer]
\PolyglossiaSetup{khmer}{
  bcp47=km,
  script=Khmer,%
  scripttag=khmr,%
  langtag=KHM,%
  hyphennames={nohyphenation},%
  fontsetup=true,%
  localnumeral=khmernumerals%
}
\newif\if@khmer@numerals
\def\tmp@khmer{khmer}
\define@key{khmer}{numerals}[arabic]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@khmer\@khmer@numeralstrue%
  \else\@khmer@numeralsfalse\fi%
}
\setkeys{khmer}{numerals}
\def\captionskhmer{%
  \def\prefacename{អារម្ភកថា}%
  \def\refname{ឯកសារយោង}%
  \def\abstractname{សង្ខេប}%
  \def\bibname{គន្ថនិទ្ទេស}%
  \def\chaptername{ជំពូក}%
  \def\appendixname{សេចក្ដីបន្ថែម}%
  \def\contentsname{មាតិការ}%
  \def\listfigurename{បញ្ជីរូបភាព}%
  \def\listtablename{បញ្ជីតារាង}%
  \def\indexname{សន្ទស្សន៍}%
  \def\figurename{រូប}%
  \def\tablename{តារាង}%
  \def\partname{ផ្នែក}%
  \def\pagename{ទំព័រ}%
  \def\seename{មើល}%
  \def\alsoname{មើលបន្ថែម}%
  \def\enclname{ឯកសារភ្ជាប់}%
  \def\ccname{ចម្លងជួន}%
  \def\headtoname{ផ្ញើរទៅ}%
  \def\proofname{សម្រាយ}%
  \def\glossaryname{សទានុក្រម}%
}
\def\datekhmer{%
  \def\khmer@month{%
    \ifcase\month\or%
    មករា\or%
    កុម្ភៈ\or%
    មិនា\or%
    មេសា\or%
    ឧសភា\or%
    មិថុនា\or%
    កក្កដា\or%
    សីហា\or%
    កញ្ញា\or%
    តុលា\or%
    វិច្ឆិកា\or%
    ធ្នូ\fi}%
  \def\today{\khmernumber\day\space\khmer@month\space\khmernumber\year}%
}
\def\khmerdigits#1{\expandafter\@khmer@digits #1@}
\def\@khmer@digits#1{%
  \ifx @#1% then terminate
  \else\ifx0#1០%
  \else\ifx1#1១%
  \else\ifx2#1២%
  \else\ifx3#1៣%
  \else\ifx4#1៤%
  \else\ifx5#1៥%
  \else\ifx6#1៦%
  \else\ifx7#1៧%
  \else\ifx8#1៨%
  \else\ifx9#1៩%
  \else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@khmer@digits%
    \fi
}

\newcommand{\khmernumerals}[2]{\khmernumber{#2}}

\def\khmernumber#1{%
  \if@khmer@numerals%
    \khmerdigits{\number#1}%
  \else%
    \number#1%
  \fi}
\def\khmer@globalnumbers{%
  \let\orig@arabic\@arabic%
  \let\@arabic\khmernumber%
  \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
}
\def\nokhmer@globalnumbers{%
  \let\@arabic\orig@arabic%
}
\def\thepart{\arabic{part}}
\def\@khmeralph#1{%
\ifcase#1%
\or ក\or ខ\or គ\or ឃ\or ង%
\or ច\or ឆ\or ជ\or ឈ\or ញ%
\or ដ\or ឋ\or ឌ\or ឍ\or ណ%
\or ត\or ថ\or ទ\or ធ\or ន%
\or ប\or ផ\or ព\or ភ\or ម%
\or យ\or រ\or ល\or វ\or ស\or ហ\or ឡ\or អ%
\else\xpg@ill@value{#1}{@khmeralph}\fi}
\def\khmerAlph#1{\expandafter\@khmerAlph\csname c@#1\endcsname}
\def\@khmerAlph#1{%
\ifcase#1%
\or ក\or ខ\or គ\or ឃ\or ង%
\or ច\or ឆ\or ជ\or ឈ\or ញ%
\or ដ\or ឋ\or ឌ\or ឍ\or ណ%
\or ត\or ថ\or ទ\or ធ\or ន%
\or ប\or ផ\or ព\or ភ\or ម%
\or យ\or រ\or ល\or វ\or ស\or ហ\or ឡ\or អ%
\else\xpg@ill@value{#1}{@khmeralph}\fi}
\def\khmer@numbers{%
  \if@khmer@numerals
    \let\@alph\@khmeralph%
    \let\@Alph\@khmerAlph%
  \fi%
}
\def\nokhmer@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}
\def\blockextras@khmer{%
  \XeTeXlinebreaklocale "kh" % 
  \XeTeXlinebreakskip = 0pt plus 1pt minus 1pt
%  \let\orig@baselinestretch\baselinestretch%
%  \renewcommand{\baselinestretch}{1.2}% not work
}
\def\noblockextras@khmer{% 
  \XeTeXlinebreaklocale "en"%
%  \let\baselinestretch\orig@baselinestretch%
}
\@ifclassloaded{beamer}{%
  \usefonttheme{professionalfonts}%
  \def\factname{ស្វ័យសត្យ}%
  \def\lemmaname{បទគន្លិះ}%
  \def\theoremname{ទ្រឹស្ដីបទ}%
  \def\corollaryname{អនុសាធ្យ}%
  \def\problemname{ចំណោទ}%
  \def\solutionname{ដំណោះស្រាយ}%
  \def\definitionname{និយមន័យ}%
  \def\examplename{ឧទាហរណ៏}%
  \uselanguage{khmer}%
  \languagepath{khmer}%
  \deftranslation[to=khmer]{Fact}{\factname}%
  \deftranslation[to=khmer]{Lemma}{\lemmaname}%
  \deftranslation[to=khmer]{Theorem}{\theoremname}%
  \deftranslation[to=khmer]{Corollary}{\corollaryname}%
  \deftranslation[to=khmer]{Problem}{\problemname}%
  \deftranslation[to=khmer]{Solution}{\solutionname}%
  \deftranslation[to=khmer]{Definition}{\definitionname}%
  \deftranslation[to=khmer]{Definitions}{\definitionname}%
  \deftranslation[to=khmer]{Example}{\examplename}%
  \deftranslation[to=khmer]{Examples}{\examplename}%
  \AtEndDocument{\immediate\write\@auxout{\string\@writefile{nav}%
    {\noexpand\headcommand{\noexpand\def\noexpand%
    \inserttotalframenumber{\localnumeral*{framenumber}}}}}}%
}{}
%    \end{macrocode}
% \iffalse
%</gloss-khmer.ldf>
%<*gloss-km.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-km.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-km.ldf}[polyglossia: module for km (khmer)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{khmer}

%    \end{macrocode}
% \iffalse
%</gloss-km.ldf>
%<*gloss-kmr-Arab.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kmr-Arab.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-kmr-Arab.ldf}[polyglossia: module for kmr-Arab (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-kmr-Arab.ldf>
%<*gloss-kmr-Latn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kmr-Latn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-kmr-Latn.ldf}[polyglossia: module for kmr-Latn (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-kmr-Latn.ldf>
%<*gloss-kmr.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kmr.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-kmr.ldf}[polyglossia: module for kmr (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-kmr.ldf>
%<*gloss-kn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-kn.ldf}[polyglossia: module for kn (kannada)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kannada}

%    \end{macrocode}
% \iffalse
%</gloss-kn.ldf>
%<*gloss-ko.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ko.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ko.ldf}[polyglossia: module for ko (korean)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{korean}

%    \end{macrocode}
% \iffalse
%</gloss-ko.ldf>
%<*gloss-korean.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-korean.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-korean.ldf}[polyglossia: module for Korean]

\PolyglossiaSetup{korean}{
  bcp47=ko,
    script=Hangul,
    scripttag=hang,
    language=Korean,
    langtag=KOR,
    hyphennames={nohyphenation},
    frenchspacing=true,
    fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{korean}{ko}

% variant : plain (0), classic (1), or modern (2)
\define@choicekey{korean}{variant}[\xpg@val\xpg@nr]{plain,classic,modern}[plain]{%
    \let\xpg@korean@variant\xpg@nr
}
% captions : hangul (0) or hanja (1)
\define@choicekey{korean}{captions}[\xpg@val\xpg@nr]{hangul,hanja}[hangul]{%
    \let\xpg@korean@captions\xpg@nr
}
% swapstrings: all (0), headings (1), headers (2), or none (3)
\newif\if@korean@swapheadings
\newif\if@korean@swapheaders
\define@choicekey*+{korean}{swapstrings}[\xpg@val\xpg@nr]{all,headings,headers,none}[all]{%
   \ifcase\xpg@nr\relax
      % all:
      \@korean@swapheadingstrue%
      \@korean@swapheaderstrue%
   \or
      % headings:
      \@korean@swapheadingstrue%
      \@korean@swapheadersfalse%
   \or
      % headers:
      \@korean@swapheadingsfalse%
      \@korean@swapheaderstrue%
   \or
      % none:
      \@korean@swapheadingsfalse%
      \@korean@swapheadersfalse%
   \fi
   \xpg@info{Option: Korean, swapstrings=\xpg@val}%
}{\xpg@warning{Unknown Korean swapstrings value `#1'}}

% Register default options
\xpg@initialize@gloss@options{korean}{variant=plain,swapstrings=all,captions=hangul}

\def\captionskorean{%
    \ifcase\xpg@korean@captions\relax
        \captions@korean@hangul
    \else
        \captions@korean@hanja
    \fi
    \def\seename{$\rightarrow$}%
    \def\alsoname{$\Rightarrow$}%
}
\def\captions@korean@hangul{%
    \def\koreanTHEname{제}%
    \def\partname{편}%
    \def\chaptername{장}%
    \def\refname{참고문헌}%
    \def\abstractname{요약}%
    \def\bibname{참고문헌}%
    \def\prefacename{서문}%
    \def\appendixname{부록}%
    \def\contentsname{차례}%
    \def\listfigurename{그림 차례}%
    \def\listtablename{표 차례}%
    \def\indexname{찾아보기}%
    \def\figurename{그림}%
    \def\tablename{표}%
    \def\pagename{페이지}%
    \def\enclname{동봉}%
    \def\proofname{증명}%
    \def\headtoname{수신:}%
    \def\ccname{사본}%
    \def\glossaryname{용어집}%
}
\def\captions@korean@hanja{%
    \def\koreanTHEname{第}%
    \def\partname{篇}%
    \def\chaptername{章}%
    \def\refname{參考文獻}%
    \def\abstractname{要約}%
    \def\bibname{參考文獻}%
    \def\prefacename{序文}%
    \def\appendixname{附錄}%
    \def\contentsname{目次}%
    \def\listfigurename{圖版 目次}%
    \def\listtablename{表 目次}%
    \def\indexname{索引}%
    \def\figurename{圖版}%
    \def\tablename{表}%
    \def\pagename{面}%
    \def\enclname{同封}%
    \def\proofname{證明}%
    \def\headtoname{受信:}%
    \def\ccname{寫本}%
    \def\glossaryname{用語集}%
}

\def\korean@appendix@chapapp{\appendixname}% to exclude appendix

\def\korean@headingsformat{%
  % change chapter and part headings
  \if@korean@swapheadings
    % With titlesec
    \ifdefined\titleformat
      \ifdefined\@part
        \let\xpg@save@part@format\@part
        \patchcmd{\@part}%
                 {\partname\nobreakspace\thepart}%
                 {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                 {}%
                 {\xpg@warning{Failed to patch part for Korean}}%
      \fi
      \ifdefined\chapter
        \titleformat\chapter[display]%
          {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6}%
          {%
            \ifx\@chapapp\korean@appendix@chapapp
              \appendixname\space \thechapter
            \else
              \koreanTHEname\space \thechapter\space \@chapapp
            \fi
          }{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit}%
      \fi
    \else % (not \ifdefined\titleformat)
      % With KOMA
      \ifdefined\sectionformat
        \ifdefined\partformat
          \let\xpg@save@part@format\partformat
          \renewcommand*{\partformat}{\koreanTHEname~\thepart~\partname}%
        \fi
        \ifdefined\chapterformat
          \let\xpg@save@chap@format\chapterformat
          \renewcommand*{\chapterformat}{\mbox{%
            \IfChapterUsesPrefixLine
            {%
              \ifx\@chapapp\korean@appendix@chapapp
                \chapappifchapterprefix\nobreakspace \thechapter\autodot
              \else
                \koreanTHEname\nobreakspace \thechapter\nobreakspace \chapappifchapterprefix{}%
              \fi
            }%
            {\thechapter\autodot\enskip}%
          }}%
        \fi
      \else % (not \ifdefined\sectionformat)
        % With memoir
        \ifdefined\@memptsize
          \ifdefined\@makechapterhead
            \let\xpg@save@chap@format\@makechapterhead
            \patchcmd{\@makechapterhead}%
                     {\printchaptername \chapternamenum \printchapternum}%
                     {%
                       \ifx\@chapapp\korean@appendix@chapapp
                         \printchaptername\relax\chapternamenum \printchapternum
                       \else
                         \printkoreanchapterthe \printchapternum\chapternamenum \printchaptername
                       \fi
                     }%
                     {}%
                     {\xpg@warning{Failed to patch chapter for Korean}}%
            \ifdefined\printkoreanchapterthe\else
              \def\printkoreanchapterthe{%
                \ifpatchable\printchaptername\@chapapp
                  {\chapnamefont\koreanTHEname\chapternamenum}{}}%
            \fi
          \fi
          \ifdefined\@part
            \let\xpg@save@part@format\@part
            \patchcmd{\@part}%
                     {\printpartname \partnamenum \printpartnum}%
                     {\printkoreanpartthe \printpartnum\partnamenum \printpartname}%
                     {}%
                     {\xpg@warning{Failed to patch part for Korean}}%
            \ifdefined\printkoreanpartthe\else
              \def\printkoreanpartthe{\partnamefont\koreanTHEname\partnamenum}%
            \fi
          \fi
        \else % (not \ifdefined\@memptsize)
          % With standard classes
          \ifdefined\@makechapterhead
            \let\xpg@save@chap@format\@makechapterhead
            \patchcmd{\@makechapterhead}%
                     {\@chapapp\space \thechapter}%
                     {%
                       \ifx\@chapapp\korean@appendix@chapapp
                         \appendixname\space \thechapter
                       \else
                         \koreanTHEname\space \thechapter\space \@chapapp
                       \fi
                     }%
                     {}%
                     {\xpg@warning{Failed to patch chapter for Korean}}%
          \fi
          \ifdefined\@part
            \let\xpg@save@part@format\@part
            \patchcmd{\@part}%
                     {\partname\nobreakspace\thepart}%
                     {\koreanTHEname\nobreakspace \thepart\nobreakspace \partname}%
                     {}%
                     {\xpg@warning{Failed to patch part for Korean}}%
          \fi % (end \ifdefined\@part)
        \fi % (end \ifdefined\@memptsize)
      \fi % (end \ifdefined\sectionformat)
    \fi % (end \ifdefined\titleformat)
  \fi % (end \if@korean@swapheadings)
  %
  % Change running headers
  \if@korean@swapheaders
    \ifdefined\chapterformat
      % With KOMA
      \let\xpg@save@chaptermark@format\chaptermarkformat
      \renewcommand*\chaptermarkformat{%
        \IfChapterUsesPrefixLine
        {%
          \ifx\@chapapp\korean@appendix@chapapp
            \chapappifchapterprefix\ \thechapter\autodot
          \else
            \koreanTHEname\ \thechapter\ \chapappifchapterprefix{}%
          \fi
        }%
        {\thechapter\autodot}%
        \enskip
      }%
    \else % (not \ifdefined\chapterformat)
      \ifdefined\@memptsize
        % With memoir
        \let\xpg@save@chaptermark@format\chaptermark
        \patchcmd{\chaptermark}%
                 {\@chapapp\ \@nameuse{thechapter}}%
                 {%
                   \ifx\@chapapp\korean@appendix@chapapp
                     \appendixname\ \@nameuse{thechapter}%
                   \else
                     \koreanTHEname\ \@nameuse{thechapter}\ \@chapapp
                   \fi
                 }%
                 {}%
                 {}%
      \else % (not \ifdefined\@memptsize)
        % With standard classes
        \ifdefined\chaptermark
          \let\xpg@save@chaptermark@format\chaptermark
          \patchcmd{\chaptermark}%
                   {\@chapapp\ \thechapter}%
                   {%
                     \ifx\@chapapp\korean@appendix@chapapp
                       \appendixname\ \thechapter
                     \else
                       \koreanTHEname\ \thechapter\ \@chapapp
                     \fi
                   }%
                   {}%
                   {}%
        \fi % (end \ifdefined\chaptermark)
      \fi % (end \ifdefined\@memptsize)
    \fi % (end \ifdefined\chapterformat)
  \fi % (end \if@korean@swapheaders)
}

\def\nokorean@headingsformat{%
  % Reset chapter and part heading
  \ifdefined\titleformat
    % With titlesec
    \ifdefined\xpg@save@part@format
      \let\@part\xpg@save@part@format
    \fi
    \ifdefined\chapter
      \titleformat\chapter[display]%
        {\@ifundefined{ttl@fil}{\raggedright}{\ttl@fil}\ttl@fonts\ttl@sizes6}%
        {\@chapapp\space\thechapter}{.8\baselineskip}{\ttl@sizes\z@\ttl@passexplicit}%
    \fi
  \else % (not \ifdefined\titleformat)
    \ifdefined\sectionformat
      % With KOMA
      \ifdefined\xpg@save@part@format
        \let\partformat\xpg@save@part@format
      \fi
      \ifdefined\xpg@save@chap@format
        \let\chapterformat\xpg@save@chap@format
      \fi
    \else
      % With memoir and standard classes
      \ifdefined\xpg@save@part@format
        \let\@part\xpg@save@part@format
      \fi
      \ifdefined\xpg@save@chap@format
        \let\@makechapterhead\xpg@save@chap@format
      \fi
    \fi % (end \ifdefined\sectionformat)
  \fi % (end \ifdefined\titleformat)
  %
  % Reset headers
  \ifdefined\chaptermarkformat
    % With KOMA
    \ifdefined\xpg@save@chaptermark@format
      \let\chaptermarkformat\xpg@save@chaptermark@format
    \fi
  \else
    \ifdefined\chaptermark
      % With memoir and standard classes
      \ifdefined\xpg@save@chaptermark@format
        \let\chaptermark\xpg@save@chaptermark@format
      \fi
    \fi % (end \ifdefined\chaptermark)
  \fi % (end \ifdefined\chapterformat)
}

\def\datekorean{%
    \ifcase\xpg@korean@captions\relax
        \def\today{\the\year 년 \the\month 월 \the\day 일}%
    \else
        \def\today{\the\year 年 \the\month 月 \the\day 日}%
    \fi
}

\def\koreanAlph#1{\expandafter\@koreanAlph\csname c@#1\endcsname}
\def\@koreanAlph#1{%
    \ifcase#1\or 가\or 나\or 다\or 라\or 마\or 바\or 사\or 아\or 자\or
    차\or 카\or 타\or 파\or 하\else\xpg@ill@value{#1}{@koreanAlph}\fi
}

\def\koreanalph#1{\expandafter\@koreanalph\csname c@#1\endcsname}
\def\@koreanalph#1{%
    \ifcase#1\or ㄱ\or ㄴ\or ㄷ\or ㄹ\or ㅁ\or ㅂ\or ㅅ\or ㅇ\or ㅈ\or
    ㅊ\or ㅋ\or ㅌ\or ㅍ\or ㅎ\else\xpg@ill@value{#1}{@koreanalph}\fi
}

\def\korean@numbers{%
    \let\@alph\@koreanalph
    \let\@Alph\@koreanAlph
}
\def\nokorean@numbers{%
    \let\@alph\latin@alph
    \let\@Alph\latin@Alph
}
\let\nokorean@globalnumbers\nokorean@numbers

\ifxetex
    \def\inlineextras@korean{%
        \ifcase\xpg@korean@variant\relax
            \XeTeXinterchartokenstate\z@
            \XeTeXlinebreakpenalty 50
        \or
            \setvariantkoreaninterchartoks
            \setvariantkoreancharclasses
            \def\XPGKOhalfdim{\dimexpr.5em\relax}%
            \XeTeXinterchartokenstate\@ne
            \XeTeXlinebreakpenalty \z@
        \else
            \setvariantkoreaninterchartoks
            \setvariantkoreancharclasses
            \def\XPGKOhalfdim{\dimexpr.5\fontdimen\tw@\font\relax}%
            \XeTeXinterchartokenstate\@ne
            \XeTeXlinebreakpenalty 50
        \fi
        \XeTeXlinebreakskip 0pt plus.05em minus .01em
        \XeTeXlinebreaklocale "ko"
    }
    \def\noextras@korean{%
        \ifcase\xpg@korean@variant\relax
        \else
            \unsetvariantkoreaninterchartoks
            \unsetvariantkoreancharclasses
        \fi
        \XeTeXinterchartokenstate\z@
        \XeTeXlinebreakpenalty\z@
        \XeTeXlinebreakskip\z@skip
        \XeTeXlinebreaklocale "en"
        \noextras@korean@common
    }
\else % luatex
    \def\inlineextras@korean{\xpg@attr@korean\xpg@korean@variant\relax}
    \def\noextras@korean{%
        \unsetattribute\xpg@attr@korean
        \noextras@korean@common
    }
\fi

\def\blockextras@korean{%
    \inlineextras@korean
    \korean@headingsformat
}

\def\noextras@korean@common{%
    \nokorean@headingsformat
}

\ifluatex % luatex
\protected\def\inhibitglue{\hskip\z@skip}
\ifdefined\newattribute\else
    \let\newattribute\newluatexattribute
    \let\unsetattribute\unsetluatexattribute
\fi
\newattribute\xpg@attr@korean
\newattribute\xpg@attr@autojosa
% user commands for Josa
% Josa : particles in Korean grammar that immediately follow a noun or pronoun.
%        Josa might vary depending on previous character.
\protected\def\rieul{\global\let\xpg@josa@zwang\@ne}
\protected\def\jung {\global\let\xpg@josa@zwang\tw@}
\protected\def\jong {\global\let\xpg@josa@zwang\thr@@}
\protected\def\은{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 은\endgroup\xpg@reset@josa}
\let\는\은
\protected\def\을{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 을\endgroup\xpg@reset@josa}
\let\를\을
\protected\def\와{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 와\endgroup\xpg@reset@josa}
\let\과\와
\protected\def\가{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 가\endgroup\xpg@reset@josa}
\protected\def\이{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 이\endgroup\xpg@reset@josa}
\protected\def\라{\이 라}
\protected\def\으{\begingroup\xpg@attr@autojosa\xpg@josa@zwang 으\endgroup\xpg@reset@josa}
\protected\def\로{\으 로}
\def\xpg@reset@josa {\global\let\xpg@josa@zwang\z@}\xpg@reset@josa
% load lua file for korean
\directlua{ require "polyglossia-korean" }
%    \end{macrocode}
% \iffalse
%</gloss-korean.ldf>
%<*gloss-ku-Arab.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ku-Arab.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ku-Arab.ldf}[polyglossia: module for ku-Arab (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ku-Arab.ldf>
%<*gloss-ku-Latn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ku-Latn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ku-Latn.ldf}[polyglossia: module for ku-Latn (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ku-Latn.ldf>
%<*gloss-ku.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ku.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ku.ldf}[polyglossia: module for ku (kurdish)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-ku.ldf>
%<*gloss-kurdish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kurdish.ldf}
%    \begin{macrocode}
% Created on September 1, 2019
% Last updated on May 17, 2020
% Sina Ahmadi (ahmadi.sina@outlook.com)
% For more information, visit the Kurdish XeLaTeX Users Group at https://github.com/KurdishXeLaTeX
\ProvidesFile{gloss-kurdish.ldf}[polyglossia: module for Kurdish]

\RequireBidi
\RequirePackage{arabicnumbers}
\RequirePackage{farsical}
\RequirePackage{hijrical}

\PolyglossiaSetup{kurdish}{
  bcp47=ckb,
  script=Arabic,
  direction=RL,
  scripttag=arab,
  langtag=KUR,
  hyphennames={nohyphenation},
  fontsetup=true,
  localnumeral=kurdishnumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{kurdish}{ku}
\setlanguagealias*[variant=kurmanji,script=Latin]{kurdish}{kmr-Latn}
\setlanguagealias*[variant=sorani]{kurdish}{ckb}
\setlanguagealias*[variant=kurmanji,script=Arabic]{kurdish}{kmr-Arab}
\setlanguagealias*[script=Latin]{kurdish}{ku-Latn}
\setlanguagealias*[variant=sorani,script=Arabic]{kurdish}{ckb-Arab}
\setlanguagealias*[variant=sorani,script=Latin]{kurdish}{ckb-Latn}
\setlanguagealias*[script=Arabic]{kurdish}{ku-Arab}
\setlanguagealias*[variant=kurmanji]{kurdish}{kmr}

% Babel aliases
\setlanguagealias[variant=kurmanji]{kurdish}{kurmanji}

\newif\if@kurdish@kurmanji
\def\kurdish@variant{sorani}
\define@choicekey*+{kurdish}{variant}[\xpg@val\xpg@nr]{sorani,kurmanji}[sorani]{%
   \ifcase\xpg@nr\relax
      % sorani:
      \def\kurdish@variant{sorani}%
      \@kurdish@kurmanjifalse%
   \or
      % kurmanji:
      \def\kurdish@variant{kurmanji}%
      \@kurdish@kurmanjitrue%
   \fi
   \kurdish@set@variety%
   \xpg@info{Option: kurdish, variant=\xpg@val}%
}{\xpg@warning{Unknown Kurdish variant `#1'}}

\newif\if@kurdish@latin
\newif\if@kurdish@arabic
\define@choicekey*+{kurdish}{script}[\xpg@val\xpg@nr]{Arabic,Latin}{%
   \ifcase\xpg@nr\relax
      % Arabic:
      \@kurdish@latinfalse%
      \@kurdish@arabictrue%
   \or
      % Latin:
      \@kurdish@latintrue%
      \@kurdish@arabicfalse%
   \fi
   \kurdish@set@variety%
   \xpg@info{Option: kurdish, script=\xpg@val}%
}{\xpg@warning{Unknown Kurdish script `#1'}}


\newif\if@western@numerals
\newif\if@force@western@numerals
\def\kurdish@script{arabic}
\def\kurdish@pattern{nohyphenation}

\def\kurdish@set@variety{%
  \if@kurdish@latin% Latin explicitly set
     \@western@numeralstrue%
     \if@kurdish@kurmanji
         \def\kurdish@pattern{kurmanji}%
         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji,bcp47=kmr-Latn}%
     \else
         \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurdish,bcp47=ckb-Arab}%
     \fi
     \def\kurdish@script{latin}
     \xpg@fontsetup@latin{kurdish}%
  \else
     \if@kurdish@arabic% Arabic explicitly set
        \if@kurdish@kurmanji
            \if@force@western@numerals\else\@western@numeralsfalse\fi%
            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurmanji,bcp47=kmr-Arab}%
            \def\kurdish@script{arabic}%
        \else
            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab}%
        \fi
        \xpg@fontsetup@nonlatin{kurdish}%
     \else% sorani=Arabic, kurmanji=Latin
        \if@kurdish@kurmanji
            \@western@numeralstrue%
            \SetLanguageKeys{kurdish}{script=Latin,direction=LR,scripttag=latn,babelname=kurmanji,bcp47=kmr-Latn}%
            \xpg@fontsetup@latin{kurdish}%
            \def\kurdish@script{latin}
        \else
            \SetLanguageKeys{kurdish}{script=Arabic,direction=RL,scripttag=arab,babelname=kurdish,bcp47=ckb-Arab}%
            \xpg@fontsetup@nonlatin{kurdish}%
        \fi
     \fi
  \fi
}

\def\tmp@western{western}
\define@key{kurdish}{numerals}[eastern]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@western\@western@numeralstrue\@force@western@numeralstrue\else%
    \@western@numeralsfalse%
  \fi%
}

%this is needed for \abjad in arabicnumbers.sty
\def\tmp@true{true}
\define@key{kurdish}{abjadjimnotail}[true]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@true\abjad@jim@notailtrue%
  \else
    \abjad@jim@notailfalse
  \fi%
}

% NOT YET USED
\define@key{kurdish}{locale}[default]{%
  \def\@kurdish@locale{#1}}

%TODO add option for CALENDAR

% Register default options
\xpg@initialize@gloss@options{kurdish}{variant=sorani,locale=default,script=Arabic,abjadjimnotail=false,numerals=eastern}

\def\kurdish@language{%
   \polyglossia@setup@language@patterns{\kurdish@pattern}%
}%

\def\kurdishNativemonth#1{\ifcase#1%
  \or رێبەندان\or رەشەمێ\or خاكەلێوە\or گوڵان\or جۆزەردان\or پووشپەڕ\or خەرمانان\or گەلاوێژ\or رەزبەر\or گەڵارێزان\or سەرماوەز\or بەفرانبار\fi}
\def\kurdishmonth#1{\ifcase#1%
  \or كانوونی دووهەم\or شوبات\or ئازار\or نیسان\or ئایار\or حوزەیران\or تەممووز\or ئاب\or ئەیلوول\or تشرینی یەكەم\or تشرینی دووهەم\or كانوونی یەكەم\fi}

%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{kurdish}{%
  \@ensure@RTL{%
    \kurdishnumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\kurdishnumber{\value{Hijriyear}}%
  }%
}

\def\captionskurdish@sorani@arabic{%
  \def\prefacename{\@ensure@RTL{پێشەكی}}%
  \def\refname{\@ensure@RTL{سەرچاوەکان}}%
  \def\abstractname{\@ensure@RTL{پوختە}}%
  \def\bibname{\@ensure@RTL{کتێبنامە}}%
  \def\chaptername{\@ensure@RTL{بەندی}}%
  \def\appendixname{\@ensure@RTL{پاشکۆ}}%
  \def\contentsname{\@ensure@RTL{نێوەڕۆک}}%
  \def\listfigurename{\@ensure@RTL{لیستی وێنەکان}}%
  \def\listtablename{\@ensure@RTL{لیستی خشتەکان}}%
  \def\indexname{\@ensure@RTL{پێنوێن}}%
  \def\figurename{\@ensure@RTL{وێنەی}}%
  \def\tablename{\@ensure@RTL{خشتەی}}%
  \def\partname{\@ensure@RTL{بەشی}}%
  \def\enclname{\@ensure@RTL{هاوپێچ}}%
  \def\ccname{\@ensure@RTL{ڕوونووس}}%
  \def\headtoname{\@ensure@RTL{بۆ}}%
  \def\pagename{\@ensure@RTL{لاپەڕە}}%
  \def\seename{\@ensure@RTL{چاو لێکەن}}%
  \def\alsoname{\@ensure@RTL{هەروەها چاو لێکەن}}%
  \def\proofname{\@ensure@RTL{سەلماندن}}%
  \def\glossaryname{\@ensure@RTL{فەرهەنگۆک}}%
}

\def\captionskurdish@sorani@latin{%
  \def\prefacename{Pêşekî}%
  \def\refname{Serçawekan}%
  \def\abstractname{Puxte}%
  \def\bibname{Kitêbname}%
  \def\chaptername{Bendî}%
  \def\appendixname{Paşko}%
  \def\contentsname{Nêweřok}%
  \def\listfigurename{Lîstî Wênekan}%
  \def\listtablename{Lîstî Xiştekan}%
  \def\indexname{Pêřist}%
  \def\figurename{Wêney}%
  \def\tablename{Xiştey}%
  \def\partname{Beşî}%
  \def\enclname{Hawpêç}%
  \def\ccname{Řûnûs}%
  \def\headtoname{Bo}%
  \def\pagename{Lapeře}%
  \def\seename{Çaw lêken}%
  \def\alsoname{Herweha çaw lêken}%
  \def\proofname{Selmandin}%
  \def\glossaryname{Ferhengok}%
}

\def\captionskurdish@kurmanji@latin{%
  \def\prefacename{Peşgotin}%
  \def\refname{Jêder}%
  \def\abstractname{Kurtebîr}%
  \def\bibname{Çavkanîya Pirtukan}%
  \def\chaptername{Serê}%
  \def\appendixname{Tebînîya}%
  \def\contentsname{Navêrok}%
  \def\listfigurename{Hejmara Dimena}%
  \def\listtablename{Hejmara Kevalen}%
  \def\indexname{Endeks}%
  \def\figurename{Dimenê}%
  \def\tablename{Kevala}%
  \def\partname{Bêşa}%
  \def\enclname{Dumahik}%
  \def\ccname{Belavker}%
  \def\headtoname{Ji bo}%
  \def\pagename{Rûpelê}%
  \def\seename{binêra}%
  \def\alsoname{li vêya jî binêra}%
  \def\proofname{Delîl}%
  \def\glossaryname{Çavkanîya lêkolînê}%
}

\def\captionskurdish@kurmanji@arabic{%
  \def\prefacename{\@ensure@RTL{پێشگۆتن}}%
  \def\refname{\@ensure@RTL{ژێدەر}}%
  \def\abstractname{\@ensure@RTL{کورتەبیر}}%
  \def\bibname{\@ensure@RTL{چاڤکانییا پرتووکان}}%
  \def\chaptername{\@ensure@RTL{سەرێ}}%
  \def\appendixname{\@ensure@RTL{پاشکۆ}}%
  \def\contentsname{\@ensure@RTL{ناڤێرۆک}}%
  \def\listfigurename{\@ensure@RTL{هەژمارا دیمەنا}}%
  \def\listtablename{\@ensure@RTL{هەژمارا کەڤالێن}}%
  \def\indexname{\@ensure@RTL{پێرست}}%
  \def\figurename{\@ensure@RTL{دیمەنێ}}%
  \def\tablename{\@ensure@RTL{کەڤالا}}%
  \def\partname{\@ensure@RTL{بەشا}}%
  \def\enclname{\@ensure@RTL{دوماهک}}%
  \def\ccname{\@ensure@RTL{بەلاڤکەر}}%
  \def\headtoname{\@ensure@RTL{ژ بۆ}}%
  \def\pagename{\@ensure@RTL{رووپەلێ}}%
  \def\seename{\@ensure@RTL{بنێرا}}%
  \def\alsoname{\@ensure@RTL{لە ڤێیا ژ بنێرا}}%
  \def\proofname{\@ensure@RTL{دەلیل}}%
  \def\glossaryname{\@ensure@RTL{چاڤکانییا لێکۆلینێ}}%
}

\def\captionskurdish{%
  \csname captionskurdish@\kurdish@variant @\kurdish@script\endcsname%
}

\def\datekurdish@sorani@arabic{%
   \def\today{\@ensure@RTL{\kurdishnumber\day{ی}\space\kurdishmonth{\month}{ی}\space\kurdishnumber\year}}%
}

\def\datekurdish@sorani@latin{%
  \def\today{%
     \number\day ~\ifcase\month\or
      \januaryname\or \februaryname\or \marchname\or \aprilname\or
      \mayname\or \junename\or \julyname\or \augustname\or
      \septembername\or \octobername\or \novembername\or
      \decembername\or \@ctrerr\fi~\number\year}%
  \def\ontoday{%
      \number\day î~\ifcase\month\or
      \januaryname\or \februaryname\or \marchname\or \aprilname\or
      \mayname\or \junename\or \julyname\or \augustname\or
      \septembername\or \octobername\or \novembername\or
      \decembername\or \@ctrerr\fi î~\number\year}%
  \def\januaryname{Kanûnî Yekem}%
  \def\februaryname{Şubat}%
  \def\marchname{Azar}%
  \def\aprilname{Nîsan}%
  \def\mayname{Ayar}%
  \def\junename{Huzeyran}%
  \def\julyname{Temmûz}%
  \def\augustname{Ab}%
  \def\septembername{Eylûl}%
  \def\octobername{Tişrînî Yekem}%
  \def\novembername{Tişrînî Dûhem}%
  \def\decembername{Kanûnî Dûhem}%
}

\def\datekurdish@kurmanji@latin{%
  \def\today{%
     \number\day ~\ifcase\month\or
      \januaryname\or \februaryname\or \marchname\or \aprilname\or
      \mayname\or \junename\or \julyname\or \augustname\or
      \septembername\or \octobername\or \novembername\or
      \decembername\or \@ctrerr\fi~\number\year}%
  \def\ontoday{%
      \number\day ê~\ifcase\month\or
      \januaryname\or \februaryname\or \marchname\or \aprilname\or
      \mayname\or \junename\or \julyname\or \augustname\or
      \septembername\or \octobername\or \novembername\or
      \decembername\or \@ctrerr\fi ê~\number\year}%
  \def\januaryname{Çileya Paşîn}%
  \def\februaryname{Sibat}%
  \def\marchname{Adar}%
  \def\aprilname{Nîsan}%
  \def\mayname{Gulan}%
  \def\junename{Hezîran}%
  \def\julyname{Tîrmeh}%
  \def\augustname{Tebax}%
  \def\septembername{Îlon}%
  \def\octobername{Çiriya Pêşîn}%
  \def\novembername{Çiriya Paşîn}%
  \def\decembername{Çileya Pêşîn}%
}

\def\kurdishmonthkurmanji#1{\ifcase#1%
  چلەیا پاشین \or شبات \or ئادار \or نیسان \or گولان \or حەزیران \or تیرمەهـ \or تەباخ \or ئیلۆن \or چریا پێشین \or چریا پاشین \or چلەیا پێشین\fi}

\def\datekurdish@kurmanji@arabic{%
   \def\today{\@ensure@RTL{\kurdishnumber\day\space\kurdishmonthkurmanji{\month}\space\kurdishnumber\year}}%
}

% TODO: babel-kurmanji has these "alternative" month names
% How to integrate them ("montnames=alternative" is not really good)?
% It seems the month name question is all but straightforward:
% https://en.wikipedia.org/wiki/Kurdish_calendar#Names
%\def\datekurdish@kurmanji@alternate{%
%  \datekurdish@kurmanji
%  \def\januaryname{Rêbendan}%
%  \def\februaryname{Reşemih}%
%  \def\aprilname{Cotan}%           % Avrêl
%  \def\junename{Pûşper}%
%  \def\augustname{Gelavêj}%
%  \def\septembername{Gelarezan}%   % Rezber
%  \def\octobername{Kewçêr}%
%  \def\novembername{Sermawez}%
%  \def\decembername{Berfandar}%
%}

\def\datekurdish{%
  \csname datekurdish@\kurdish@variant @\kurdish@script\endcsname%
}

\newcommand{\kurdishnumerals}[2]{\kurdishnumber{#2}}

\def\kurdishnumber#1{%
  \if@western@numerals
    \number#1%
  \else
    \xpg@if@char@available{06F0}%
          {\farsidigits{\number#1}}%
          {\arabicdigits{\number#1}}%
  \fi
}

%\def\kurdishnum#1{\expandafter\kurdishnumber\csname c@#1\endcsname}
%\def\kurdishbracenum#1{(\expandafter\kurdishnumber\csname c@#1\endcsname)}
%\def\kurdishornatebracenum#1{\char"FD3E\expandafter\kurdishnumber\csname c@#1\endcsname\char"FD3F}
%\def\kurdishalph#1{\expandafter\@farsialph\csname c@#1\endcsname}

\def\kurdish@numbers{%
  \if@western@numerals%
  \else%
     \let\@alph\abjad%
     \let\@Alph\abjad%
  \fi%
}

\def\nokurdish@numbers{%
  \let\@alph\@latinalph%
  \let\@Alph\@latinAlph%
}

\def\kurdish@globalnumbers{%
   \let\@arabic\kurdishnumber%
   \renewcommand\thefootnote{\localnumeral*{footnote}}%
   \renewcommand\theequation{\localnumeral*{equation}}%
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\nokurdish@globalnumbers{
   \let\@arabic\xpg@save@arabic%
   \renewcommand\thefootnote{\protect\number{\c@footnote}}%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@kurdish{%
   \def\MakeUppercase##1{##1}%
}

\def\noextras@kurdish{%
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-kurdish.ldf>
%<*gloss-kurmanji.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-kurmanji.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-kurmanji.ldf}[polyglossia: module for kurmanji kurdish]

% We provide this gloss for babel compatibility.

\xpg@load@master@language{kurdish}

%    \end{macrocode}
% \iffalse
%</gloss-kurmanji.ldf>
%<*gloss-la-x-classic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-la-x-classic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-la-xclassic.ldf}[polyglossia: module for la-xclassic (latin)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-la-x-classic.ldf>
%<*gloss-la-x-ecclesia.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-la-x-ecclesia.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-la-xecclesiastic.ldf}[polyglossia: module for la-xecclesiastic (latin)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-la-x-ecclesia.ldf>
%<*gloss-la-x-medieval.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-la-x-medieval.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-la-xmedieval.ldf}[polyglossia: module for la-xmedieval (latin)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-la-x-medieval.ldf>
%<*gloss-la.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-la.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-la.ldf}[polyglossia: module for la (latin)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-la.ldf>
%<*gloss-lao.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lao.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lao.ldf}[polyglossia: module for Lao]

\PolyglossiaSetup{lao}{
  bcp47=lo,
  script=Lao,
  scripttag=lao,
  langtag=LAO,
  hyphennames={lao},
  hyphenmins={1,1},
  fontsetup=true,
  localnumeral=laonumerals
  %TODO localalph={xxx@alph,xxx@Alph}
  %TODO localdigits=laonumber
}

% BCP-47 compliant aliases
\setlanguagealias*{lao}{lo}

\newif\if@lao@numerals
\def\tmp@lao{lao}
\define@key{lao}{numerals}[arabic]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@lao\@lao@numeralstrue\else
	  \@lao@numeralsfalse\fi
}

% Register default options
\xpg@initialize@gloss@options{lao}{numerals=arabic}

% Translations provided by Brian Wilson <bountonw at gmail.com>
\def\captionslao{%
  \def\prefacename{ຄໍານໍາ}%
  \def\refname{ໜັງສືອ້າງອີງ}%
  \def\abstractname{ບົດຫຍໍ້ຄວາມ}%
  \def\bibname{ເອກະສານອ້າງອີງ}%
  \def\chaptername{ບົດທີ}%
  \def\appendixname{ພາກຄັດຕິດ}%
  \def\contentsname{ສາລະບານ}%
  \def\listfigurename{ສາລະບານຮູບ}%
  \def\listtablename{ສາລະບານຕາຕະລາງ}%
  \def\indexname{ດັດຊະນີ}%
  \def\figurename{ຮູບທີ}%
  \def\tablename{ຕາຕະລາງທີ}%
  \def\partname{ພາກ}%
  \def\pagename{ໜ້າ}%
  \def\seename{ອ່ານ}%
  \def\alsoname{ອ່ານເພີ່ມ}%
  \def\enclname{ເອກະສານປະກອບ}%
  \def\ccname{ສໍາເນົາເຖິງ}%
  \def\headtoname{ຮຽນ}%
  \def\proofname{ຂໍ້ພິສູດ}%
  \def\glossaryname{ປະມວນສັບ}% 
}
\def\datelao{%   
   \def\lao@month{%
     \ifcase\month\or
      ມັງກອນ\or
      ກຸມພາ\or
      ມີນາ\or
      ເມສາ\or
      ພຶດສະພາ\or
      ມິຖຸນາ\or
      ກໍລະກົດ\or
      ສິງຫາ\or
      ກັນຍາ\or
      ຕຸລາ\or
      ພະຈິກ\or
      ທັນວາ\fi}%
   \def\today{\laonumber\day \space \lao@month \space \laonumber\year}%
}

\def\laodigits#1{\expandafter\@lao@digits #1@}
\def\@lao@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1໐\else\ifx1#1໑\else\ifx2#1໒\else\ifx3#1໓\else\ifx4#1໔\else\ifx5#1໕\else\ifx6#1໖\else\ifx7#1໗\else\ifx8#1໘\else\ifx9#1໙\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@lao@digits
  \fi
}

\newcommand{\laonumerals}[2]{\laonumber{#2}}

\def\laonumber#1{%
  \if@lao@numerals
    \laodigits{\number#1}%
  \else
    \number#1%
  \fi}

\def\lao@globalnumbers{%
   \let\orig@arabic\@arabic%
   \let\@arabic\laonumber%
   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
}
\def\nolao@globalnumbers{%
   \let\@arabic\orig@arabic%
}

%    \end{macrocode}
% \iffalse
%</gloss-lao.ldf>
%<*gloss-latex.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latex.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latex.ldf}[polyglossia: module for default language]

\PolyglossiaSetup{latex}{
  hyphennames={english},
  hyphenmins={2,3},
  langtag=ENG,
  fontsetup=true,
}

\def\captionslatex{%
   \def\prefacename{Preface}%
   \def\refname{References}%
   \def\abstractname{Abstract}%
   \def\bibname{Bibliography}%
   \def\chaptername{Chapter}%
   \def\appendixname{Appendix}%
   \def\contentsname{Contents}%
   \def\listfigurename{List of Figures}%
   \def\listtablename{List of Tables}%
   \def\indexname{Index}%
   \def\figurename{Figure}%
   \def\tablename{Table}%
   \def\partname{Part}%
   \def\enclname{encl}%
   \def\ccname{cc}%
   \def\headtoname{To}%
   \def\pagename{Page}%
   \def\seename{see}%
   \def\alsoname{see also}%
   \def\proofname{Proof}%
}

%    \end{macrocode}
% \iffalse
%</gloss-latex.ldf>
%<*gloss-latin.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latin.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latin.ldf}[polyglossia: module for Latin v.2.3 2020-03-08]

\ExplSyntaxOn

\PolyglossiaSetup {latin}
  {
    bcp47 = la,
    hyphenmins = {2,2},
    frenchspacing = true,
    fontsetup = true,
    langtag = LAT
  }

% BCP-47 compliant aliases
\setlanguagealias*{latin}{la}
\setlanguagealias*[variant=classic]{latin}{la-x-classic}
\setlanguagealias*[variant=ecclesiastic]{latin}{la-x-ecclesia}
\setlanguagealias*[variant=medieval]{latin}{la-x-medieval}

% Babel aliases
\setlanguagealias[variant=classic]{latin}{classiclatin}
\setlanguagealias[variant=ecclesiastic]{latin}{ecclesiasticlatin}
\setlanguagealias[variant=medieval]{latin}{medievallatin}


%%%%% Variables and commands concerning spelling

\bool_new:N \l_polyglossia_latin_use_j_bool
\bool_new:N \l_polyglossia_latin_use_v_bool
\bool_new:N \l_polyglossia_latin_use_digraphs_bool
\bool_new:N \l_polyglossia_latin_capitalize_month_bool

\cs_new:Npn \polyglossia_latin_classical_character_codes:
  {
    \char_set_lccode:nn {`\V} {`\u}
    \char_set_uccode:nn {`\u} {`\V}
    \char_set_uccode:nn {`\ú} {`\V}
    \char_set_uccode:nn {`\ū} {`\V}
    \char_set_uccode:nn {`\ŭ} {`\V}
  }

\cs_new:Npn \polyglossia_latin_modern_character_codes:
  {
    \char_set_lccode:nn {`\V} {`\v}
    \char_set_uccode:nn {`\u} {`\U}
    \char_set_uccode:nn {`\ú} {`\Ú}
    \char_set_uccode:nn {`\ū} {`\Ū}
    \char_set_uccode:nn {`\ŭ} {`\Ŭ}
  }


%%%%% Messages and commands concerning hyphenation

\msg_new:nnn {polyglossia} {latin / missing modern patterns}
  {
    The~hyphenation~patterns~for~modern~Latin~were~not~found~\msg_line_context:.
  }

\msg_new:nnn {polyglossia} {latin / missing patterns}
  {
    The~"#1"~hyphenation~patterns~were~not~found~\msg_line_context:.~
    I~will~use~the~patterns~for~modern~Latin~instead.
  }

\cs_new:Npn \polyglossia_latin_use_modern_patterns:
  {
    \xpg@ifdefined {latin}
      {
        \def \latin@language
          {
            \polyglossia@setup@language@patterns {latin}
            \str_case:Vn \l_polyglossia_latin_variant_str
              {
                {classic}      { \adddialect \l@classiclatin \l@latin }
                {medieval}     { \adddialect \l@medievallatin \l@latin }
                {ecclesiastic} { \adddialect \l@ecclesiasticlatin \l@latin }
              }
          }
      }
      {
        \msg_warning:nn {polyglossia} {latin / missing modern patterns}
        \str_case:Vn \l_polyglossia_latin_variant_str
          {
            {classic}      { \adddialect \l@classiclatin \l@nohyphenation }
            {medieval}     { \adddialect \l@medievallatin \l@nohyphenation }
            {modern}       { \adddialect \l@latin \l@nohyphenation }
            {ecclesiastic} { \adddialect \l@ecclesiasticlatin \l@nohyphenation }
          }
      }
  }

\cs_new:Npn \polyglossia_latin_set_patterns:n #1
% #1 may be "classiclatin" or "liturgicallatin"
  {
    \xpg@ifdefined {#1}
      {
        \def \latin@language
          {
            \polyglossia@setup@language@patterns {#1}
            \str_case:Vn \l_polyglossia_latin_variant_str
              {
                {classic}      {
                                 \str_if_eq:nnF {#1} {classiclatin}
                                   {
                                     \adddialect \l@classiclatin  { \use:c {l@#1} }
                                   }
                               }
                {medieval}     { \adddialect \l@medievallatin { \use:c {l@#1} } }
                {modern}       { \adddialect \l@latin { \use:c {l@#1} } }
                {ecclesiastic} { \adddialect \l@ecclesiasticlatin { \use:c {l@#1} } }
              }
          }
      }
      {
        \msg_warning:nnn {polyglossia} {latin / missing patterns} {#1}
        \polyglossia_latin_use_modern_patterns:
      }
  }


%%%%% Settings for the spacing of the punctuation for ecclesiastical Latin

\bool_new:N \g_polyglossia_latin_punctuation_spacing_bool

\sys_if_engine_luatex:TF
  {
    \directlua { require('polyglossia-latin') }
  }
  {
    \newXeTeXintercharclass \g_polyglossia_latin_question_exclamation_class
    \newXeTeXintercharclass \g_polyglossia_latin_colon_semicolon_class
    \newXeTeXintercharclass \g_polyglossia_latin_opening_guillemet_class
    \newXeTeXintercharclass \g_polyglossia_latin_closing_guillemet_class
    \newXeTeXintercharclass \g_polyglossia_latin_opening_bracket_class
    \newXeTeXintercharclass \g_polyglossia_latin_closing_bracket_class

    \cs_new:Npn \polyglossia_latin_insert_punctuation_space:
      {
        \nobreak
        \skip_horizontal:n { 0.08333 \fontdimen6 \font } % 1/12 quad
      }
    \cs_new:Npn \polyglossia_latin_replace_preceding_space:
      {
        \dim_compare:nNnT {\lastskip} > {\c_zero_dim} {\unskip}
        \polyglossia_latin_insert_punctuation_space:
      }
    \cs_new:Npn \polyglossia_latin_replace_following_space:
      {
        \polyglossia_latin_insert_punctuation_space:
        \ignorespaces
      }
  }

\cs_new:Npn \polyglossia_latin_punctuation_spacing:
  {
    \sys_if_engine_luatex:TF
      {
        \directlua { polyglossia.activate_latin_punct() }
      }
      {
        \XeTeXinterchartokenstate = 1
        \XeTeXcharclass `\! \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\? \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\‼ \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\⁇ \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\⁈ \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\⁉ \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\‽ \g_polyglossia_latin_question_exclamation_class
        \XeTeXcharclass `\; \g_polyglossia_latin_colon_semicolon_class
        \XeTeXcharclass `\: \g_polyglossia_latin_colon_semicolon_class
        \XeTeXcharclass `\« \g_polyglossia_latin_opening_guillemet_class
        \XeTeXcharclass `\» \g_polyglossia_latin_closing_guillemet_class
        \XeTeXcharclass `\‹ \g_polyglossia_latin_opening_guillemet_class
        \XeTeXcharclass `\› \g_polyglossia_latin_closing_guillemet_class
        \XeTeXcharclass `\( \g_polyglossia_latin_opening_bracket_class
        \XeTeXcharclass `\) \g_polyglossia_latin_closing_bracket_class
        \XeTeXcharclass `\[ \g_polyglossia_latin_opening_bracket_class
        \XeTeXcharclass `\] \g_polyglossia_latin_closing_bracket_class
        \XeTeXcharclass `\{ \g_polyglossia_latin_opening_bracket_class
        \XeTeXcharclass `\} \g_polyglossia_latin_closing_bracket_class
        \XeTeXcharclass `\⟨ \g_polyglossia_latin_opening_bracket_class
        \XeTeXcharclass `\⟩ \g_polyglossia_latin_closing_bracket_class

        % question or exclamation mark followed by a closing guillemet
        \XeTeXinterchartoks \g_polyglossia_latin_question_exclamation_class \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % question or exclamation mark followed by a colon or semicolon
        \XeTeXinterchartoks \g_polyglossia_latin_question_exclamation_class \g_polyglossia_latin_colon_semicolon_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % colon or semicolon followed by a closing guillemet
        \XeTeXinterchartoks \g_polyglossia_latin_colon_semicolon_class \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing bracket followed by a question or exclamation mark
        \XeTeXinterchartoks \g_polyglossia_latin_closing_bracket_class \g_polyglossia_latin_question_exclamation_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing bracket followed by a colon or semicolon
        \XeTeXinterchartoks \g_polyglossia_latin_closing_bracket_class \g_polyglossia_latin_colon_semicolon_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing bracket followed by a closing guillemet
        \XeTeXinterchartoks \g_polyglossia_latin_closing_bracket_class \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % opening guillemet followed by a space
        \XeTeXinterchartoks \g_polyglossia_latin_opening_guillemet_class \xpg@boundaryclass =
          {
            \polyglossia_latin_replace_following_space:
          }
        % opening guillemet followed by an opening guillemet
        \XeTeXinterchartoks \g_polyglossia_latin_opening_guillemet_class \g_polyglossia_latin_opening_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % opening guillemet followed by an ordinary character
        \XeTeXinterchartoks \g_polyglossia_latin_opening_guillemet_class \z@ =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing guillemet followed by a closing guillemet
        \XeTeXinterchartoks \g_polyglossia_latin_closing_guillemet_class \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing guillemet followed by a question or exclamation mark
        \XeTeXinterchartoks \g_polyglossia_latin_closing_guillemet_class \g_polyglossia_latin_question_exclamation_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % closing guillemet followed by a colon or semicolon
        \XeTeXinterchartoks \g_polyglossia_latin_closing_guillemet_class \g_polyglossia_latin_colon_semicolon_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % space followed by a question or exclamation mark
        \XeTeXinterchartoks \xpg@boundaryclass \g_polyglossia_latin_question_exclamation_class =
          {
            \polyglossia_latin_replace_preceding_space:
          }
        % space followed by a colon or semicolon
        \XeTeXinterchartoks \xpg@boundaryclass \g_polyglossia_latin_colon_semicolon_class =
          {
            \polyglossia_latin_replace_preceding_space:
          }
        % space followed by closing guillemet
        \XeTeXinterchartoks \xpg@boundaryclass \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_replace_preceding_space:
          }
        % ordinary character followed by a question or exclamation mark
        \XeTeXinterchartoks \z@ \g_polyglossia_latin_question_exclamation_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % ordinary character followed by a colon or semicolon
        \XeTeXinterchartoks \z@ \g_polyglossia_latin_colon_semicolon_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
        % ordinary character followed by closing guillemet
        \XeTeXinterchartoks \z@ \g_polyglossia_latin_closing_guillemet_class =
          {
            \polyglossia_latin_insert_punctuation_space:
          }
      }
  }

\cs_new:Npn \polyglossia_latin_no_punctuation_spacing:
  {
    \sys_if_engine_luatex:TF
      {
        \directlua { polyglossia.deactivate_latin_punct() }
      }
      {
        \XeTeXcharclass `\! \z@
        \XeTeXcharclass `\? \z@
        \XeTeXcharclass `\‼ \z@
        \XeTeXcharclass `\⁇ \z@
        \XeTeXcharclass `\⁈ \z@
        \XeTeXcharclass `\⁉ \z@
        \XeTeXcharclass `\‽ \z@
        \XeTeXcharclass `\; \z@
        \XeTeXcharclass `\: \z@
        \XeTeXcharclass `\« \z@
        \XeTeXcharclass `\» \z@
        \XeTeXcharclass `\‹ \z@
        \XeTeXcharclass `\› \z@
        \XeTeXcharclass `\( \z@
        \XeTeXcharclass `\) \z@
        \XeTeXcharclass `\[ \z@
        \XeTeXcharclass `\] \z@
        \XeTeXcharclass `\{ \z@
        \XeTeXcharclass `\} \z@
        \XeTeXcharclass `\⟨ \z@
        \XeTeXcharclass `\⟩ \z@
        \XeTeXinterchartokenstate = 0
      }
  }


%%%%% Messages and commands concerning footnotes

% Save original footnote definition
% Do this at the end of the preamble to catch other
% packages' footnote changes (#391)
\AtEndPreamble{%
  \cs_if_exist:NT \@makefntext
    {
      \cs_set_eq:NN \polyglossia_latin_original_footnote:n \@makefntext
    }
}

% This is the footnote style as defined by the "ecclesiastic" package.
\cs_new:Npn \polyglossia_latin_variant_footnote:n #1
  {
    \parindent 1em
    \noindent
    \hbox { \normalfont \@thefnmark . }
    \enspace #1
  }

\msg_new:nnn {polyglossia} {latin / ineffective footnote option}
  {
    The~option~"ecclesiasticfootnotes"~is~ineffective~\msg_line_context:
    \c_space_tl as~Latin~is~not~the~main~language.
  }

\cs_new:Npn \polyglossia_latin_apply_footnote_option:
  {
    \str_if_eq:VnTF \xpg@main@language {latin}
      {
        \cs_if_exist:NT \@makefntext
          {
            \iflatin@ecclesiasticfootnotes
              \let \@makefntext \polyglossia_latin_variant_footnote:n
            \else
              \let \@makefntext \polyglossia_latin_original_footnote:n
            \fi
          }
      }
      {
        \iflatin@ecclesiasticfootnotes
          \msg_warning:nn {polyglossia} {latin / ineffective footnote option}
        \fi
      }
  }

\define@boolkey {latin} [latin@] {ecclesiasticfootnotes} [true]
  {
    \token_if_eq_meaning:NNTF \@onlypreamble \@notprerr
      {
        % within the document
        \polyglossia_latin_apply_footnote_option:
      }
      {
        % within the preamble
        % The application of the option has to be postponed as the main
        % language may be undefined when the option is called.
        \AtBeginDocument { \polyglossia_latin_apply_footnote_option: }
      }
  }


%%%%% Language variants: classic, medieval, modern, and ecclesiastic

\str_new:N \l_polyglossia_latin_variant_str

\msg_new:nnn {polyglossia} {latin / language variant}
  {
    Activating~Latin~language~variant~"#1"~\msg_line_context:.
  }

\msg_new:nnn {polyglossia} {latin / illegal language variant}
  {
    The~Latin~language~variant~"#1"~is~undefined~\msg_line_context:.
  }

\cs_new:Npn \polyglossia_latin_classic_settings:
  {
    \bool_set_false:N \l_polyglossia_latin_use_j_bool
    \bool_set_false:N \l_polyglossia_latin_use_v_bool
    \bool_set_false:N \l_polyglossia_latin_use_digraphs_bool
    \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
    \bool_set_false:N \l_polyglossia_latin_punctuation_spacing_bool
    \str_set:Nn \l_polyglossia_latin_variant_str {classic}
    \SetLanguageKeys {latin} { babelname = classiclatin, bcp47 = la-x-classic }
    \polyglossia_latin_set_patterns:n {classiclatin}
  }

\cs_new:Npn \polyglossia_latin_medieval_settings:
  {
    \bool_set_false:N \l_polyglossia_latin_use_j_bool
    \bool_set_false:N \l_polyglossia_latin_use_v_bool
    \bool_set_true:N \l_polyglossia_latin_use_digraphs_bool
    \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
    \bool_set_false:N \l_polyglossia_latin_punctuation_spacing_bool
    \str_set:Nn \l_polyglossia_latin_variant_str {medieval}
    \SetLanguageKeys {latin} { babelname = medievallatin, bcp47 = la-x-medieval }
    \polyglossia_latin_use_modern_patterns:
  }

\cs_new:Npn \polyglossia_latin_modern_settings:
  {
    \bool_set_false:N \l_polyglossia_latin_use_j_bool
    \bool_set_true:N \l_polyglossia_latin_use_v_bool
    \bool_set_false:N \l_polyglossia_latin_use_digraphs_bool
    \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
    \bool_set_false:N \l_polyglossia_latin_punctuation_spacing_bool
    \str_set:Nn \l_polyglossia_latin_variant_str {modern}
    \SetLanguageKeys {latin} { babelname = latin, bcp47 = la }
    \polyglossia_latin_use_modern_patterns:
  }

\cs_new:Npn \polyglossia_latin_ecclesiastic_settings:
  {
    \bool_set_false:N \l_polyglossia_latin_use_j_bool
    \bool_set_true:N \l_polyglossia_latin_use_v_bool
    \bool_set_true:N \l_polyglossia_latin_use_digraphs_bool
    \bool_set_false:N \l_polyglossia_latin_capitalize_month_bool
    \bool_set_true:N \l_polyglossia_latin_punctuation_spacing_bool
    \str_set:Nn \l_polyglossia_latin_variant_str {ecclesiastic}
    \SetLanguageKeys {latin} { babelname = ecclesiasticlatin, bcp47 = la-x-ecclesia }
    \polyglossia_latin_use_modern_patterns:
  }

\define@key{latin}{variant}
  {
    \str_case:nnF {#1}
      {
        {classic}
        {
          \msg_info:nnn {polyglossia} {latin / language variant} {classic}
          \polyglossia_latin_classic_settings:
        }
        {medieval}
        {
          \msg_info:nnn {polyglossia} {latin / language variant} {medieval}
          \polyglossia_latin_medieval_settings:
        }
        {modern}
        {
          \msg_info:nnn {polyglossia} {latin / language variant} {modern}
          \polyglossia_latin_modern_settings:
        }
        {ecclesiastic}
        {
          \msg_info:nnn {polyglossia} {latin / language variant} {ecclesiastic}
          \polyglossia_latin_ecclesiastic_settings:
        }
      }
      {
        \msg_warning:nnn {polyglossia} {latin / illegal language variant} {#1}
      }
  }


%%%%% Boolean options concerning spelling

\define@boolkey{latin}[latin@]{usej}[true]
  {
    \iflatin@usej
      \bool_set_true:N \l_polyglossia_latin_use_j_bool
    \else
      \bool_set_false:N \l_polyglossia_latin_use_j_bool
    \fi
  }

\define@boolkey{latin}[latin@]{capitalizemonth}[true]
  {
    \iflatin@capitalizemonth
      \bool_set_true:N \l_polyglossia_latin_capitalize_month_bool
    \else
      \bool_set_false:N \l_polyglossia_latin_capitalize_month_bool
    \fi
  }


%%%%% Hyphenation variants: classic, liturgical, and modern

\msg_new:nnn {polyglossia} {latin / hyphenation variant}
  {
    Activating~hyphenation~patterns~for~#1~Latin~\msg_line_context:.
  }

\msg_new:nnn {polyglossia} {latin / illegal hyphenation variant}
  {
    The~Latin~hyphenation~variant~"#1"~is~undefined~\msg_line_context:.
  }

\define@key {latin} {hyphenation}
  {
    \str_case:nnTF {#1}
      {
        {classic}    { \polyglossia_latin_set_patterns:n {classiclatin} }
        {liturgical} { \polyglossia_latin_set_patterns:n {liturgicallatin} }
        {modern}     { \polyglossia_latin_use_modern_patterns: }
      }
      {
        \msg_info:nnn {polyglossia} {latin / hyphenation variant} {#1}
      }
      {
        \msg_warning:nnn {polyglossia} {latin / illegal hyphenation variant} {#1}
      }
  }


%%%%% Latin captions and date

\def \captionslatin
  {
    \def \prefacename
      {
        \bool_if:NTF \l_polyglossia_latin_use_digraphs_bool {Præfatio} {Praefatio}
      }
    \def \refname {Conspectus~librorum}
    \def \abstractname {Summarium}
    \def \bibname {Conspectus~librorum}
    \def \chaptername {Caput}
    \def \appendixname {Additamentum}
    \def \contentsname {Index}
    \def \listfigurename {Conspectus~descriptionum}
    \def \listtablename {Conspectus~tabularum}
    \def \indexname {Index~rerum~notabilium}
    \def \figurename {Descriptio}
    \def \tablename {Tabula}
    \def \partname {Pars}
    \def \enclname {Additur}
    \def \ccname {Exemplar}
    \def \headtoname {\ignorespaces}
    \def \pagename {charta}
    \def \seename {cfr.}
    \def \alsoname {cfr.}
    \def \proofname {Demonstratio}
    \def \glossaryname {Glossarium}
  }

\cs_new:Npn \polyglossia_latin_month_name:
  {
    \str_set:Nx \l_tmpa_str
      {
        \int_case:nn { \month }
          {
            {1} { \bool_if:NTF \l_polyglossia_latin_use_j_bool {januarii} {ianuarii} }
            {2} {februarii}
            {3} {martii}
            {4} {aprilis}
            {5} { \bool_if:NTF \l_polyglossia_latin_use_j_bool {maji} {maii} }
            {6} { \bool_if:NTF \l_polyglossia_latin_use_j_bool {junii} {iunii} }
            {7} { \bool_if:NTF \l_polyglossia_latin_use_j_bool {julii} {iulii} }
            {8} {augusti}
            {9} {septembris}
            {10} {octobris}
            {11} { \bool_if:NTF \l_polyglossia_latin_use_v_bool {novembris} {nouembris} }
            {12} {decembris}
          }
      }
    \bool_if:NTF \l_polyglossia_latin_capitalize_month_bool
      {
        \tl_mixed_case:n { \l_tmpa_str }
      }
      {
        \str_use:N \l_tmpa_str
      }
  }

\def \datelatin
  {
    \def \today
      {
        \int_to_Roman:n { \day }
        \c_space_tl
        \polyglossia_latin_month_name:
        \c_space_tl
        \int_to_Roman:n { \year }
      }
  }


%%%%% Latin shorthands

\define@boolkey{latin}[latin@]{babelshorthands}[true]
  {
  }

\define@boolkey{latin}[latin@]{prosodicshorthands}[true]
  {
  }

% Register default options
\xpg@initialize@gloss@options{latin}{variant=modern,hyphenation=modern,babelshorthands=false,
                                     prosodicshorthands=false,ecclesiasticfootnotes=false,
                                     usej=false,capitalizemonth=true}

\ifsystem@babelshorthands
  \setkeys{latin}{babelshorthands=true}
\else
  \setkeys{latin}{babelshorthands=false}
\fi

\ExplSyntaxOff % babelsh.def does not support expl3 syntax
\ifcsundef{initiate@active@char}{\input{babelsh.def}}{}
\ExplSyntaxOn

\initiate@active@char {"}
\initiate@active@char {'}
\initiate@active@char {^}
\initiate@active@char {=}

\shorthandoff {"}
\shorthandoff {'}
\shorthandoff {^}
\shorthandoff {=}

% The active = character may cause problems with key=value interfaces.
% We have to make sure here that no problems can occur outside a Latin
% prosodic shorthand environment.
% The active ' character may cause problems with the unicode-math package
% (in case Latin is used as a secondary language, see #394). We have to
% turn it off if Latin is not the main language.

\protected@write \@auxout { } { \shorthandoff {=} } % for the aux file

\AtBeginDocument
  {
    \str_if_eq:VnTF \xpg@main@language {latin}
      {
        \iflatin@prosodicshorthands
        \else
          \shorthandoff {=}
        \fi
      }
      {
        % The following command should not be called if the main language
        % defines a = shorthand. However, there are no languages besides
        % Latin defining such a shorthand in polyglossia.
        \shorthandoff {=}
        % The following command should not be called if the main language
        % defines a ' shorthand. However, there are no languages besides
        % Latin defining such a shorthand in polyglossia.
        \shorthandoff {'}
      }
  }

\cs_new:Npn \polyglossia_latin_shorthands:
  {
    \def \language@group {latin}
    \bbl@activate {"}
    \declare@shorthand {latin} {"}
      {
        \mode_if_math:TF
          {
            \token_to_str:N "
          }
          {
            \polyglossia_latin_apply_quotemark:N
          }
      }
    % The ' shorthand is normally turned off to avoid problems with the unicode-math
    % package. We have to turn it on here.
    \shorthandon {'}
    \bbl@activate {'}
    \declare@shorthand {latin} {'}
      {
        \mode_if_math:TF
          {
            \active@math@prime % defined in "latex.ltx"
            % This definition is differing from the primes of the unicode-math package.
            % TO DO: Make sure that the appearance of primes is the same as with the
            % unicode-math package if this package is loaded.
          }
          {
            \polyglossia_latin_put_acute:N
          }
      }
  }

\cs_new:Npn \polyglossia_latin_prosodic_shorthands:
  {
    \def \language@group {latin}
    % The '=' shorthand is normally turned off to avoid problems with key=value
    % interfaces. We turn it on here to enable prosodic shorthands.
    \shorthandon {=}
    \bbl@activate {=}
    \declare@shorthand {latin} {=}
      {
        \mode_if_math:TF
          {
            \token_to_str:N =
          }
          {
            \polyglossia_latin_put_macron:N
          }
      }
    \bbl@activate {^}
    \declare@shorthand {latin} {^}
      {
        \mode_if_math:TF
          {
            \token_to_str:N ^
          }
          {
            \polyglossia_latin_put_breve:N
          }
      }
  }

\cs_new:Npn \polyglossia_latin_apply_quotemark:N #1
  {
    \str_case:nnF {#1}
      {
        {A} { \polyglossia_latin_digraph_shorthand:Nnn E { Æ }
                {
                  \polyglossia_latin_digraph_shorthand:Nnn e { Æ }
                    {
                      \polyglossia_latin_allow_hyphens: A
                    }
                }
            }
        {a} { \polyglossia_latin_digraph_shorthand:Nnn e { æ }
                {
                  \polyglossia_latin_allow_hyphens: a
                }
            }
        {O} { \polyglossia_latin_digraph_shorthand:Nnn E { Œ }
                {
                  \polyglossia_latin_digraph_shorthand:Nnn e { Œ }
                    {
                      \polyglossia_latin_allow_hyphens: O
                    }
                }
            }
        {o} { \polyglossia_latin_digraph_shorthand:Nnn e { œ }
                {
                  \polyglossia_latin_allow_hyphens: o
                }
            }
        {|} { \polyglossia_latin_allow_hyphens: }
        {<} { « }
        {>} { » }
      }
      {
        \token_if_letter:NTF #1 { \polyglossia_latin_allow_hyphens: #1 }
          {
            \token_if_eq_meaning:NNTF #1 \AE { \polyglossia_latin_allow_hyphens: #1 }
              {
                \token_if_eq_meaning:NNTF #1 \ae { \polyglossia_latin_allow_hyphens: #1 }
                  {
                    \token_if_eq_meaning:NNTF #1 \OE { \polyglossia_latin_allow_hyphens: #1 }
                      {
                        \token_if_eq_meaning:NNTF #1 \oe { \polyglossia_latin_allow_hyphens: #1 }
                          {
                            \token_to_str:N "
                            #1
                          }
                      }
                  }
              }
          }
      }
  }

\cs_new:Npn \polyglossia_latin_put_acute:N #1
  {
    \str_case:nnF {#1}
      {
        {A} { \polyglossia_latin_digraph_shorthand:Nnn E { Ǽ }
                {
                  \polyglossia_latin_digraph_shorthand:Nnn e { Ǽ } { Á }
                }
            }
        {a} { \polyglossia_latin_digraph_shorthand:Nnn e { ǽ } { á } }
        {E} { É }
        {e} { é }
        {I} { Í }
        {i} { í }
        {O} { \polyglossia_latin_digraph_shorthand:Nnn E { \'Œ }
                {
                  \polyglossia_latin_digraph_shorthand:Nnn e { \'Œ } { Ó }
                }
            }
        {o} { \polyglossia_latin_digraph_shorthand:Nnn e { \'œ } { ó } }
        {U} { Ú }
        {u} { ú }
        {V} { \' V } % V may be a vowel, but lowercase v is never used as a vowel.
        {Y} { Ý }
        {y} { ý }
        {Æ} { Ǽ }
        {æ} { ǽ }
        {Œ} { \'Œ }
        {œ} { \'œ }
      }
      {
        \token_if_eq_meaning:NNTF #1 \AE { Ǽ }
          {
            \token_if_eq_meaning:NNTF #1 \ae { ǽ }
              {
                \token_if_eq_meaning:NNTF #1 \OE { \'Œ }
                  {
                    \token_if_eq_meaning:NNTF #1 \oe { \'œ }
                      {
                        \token_to_str:N '
                        #1
                      }
                  }
              }
          }
      }
  }

\cs_new:Npn \polyglossia_latin_put_macron:N #1
  {
    \str_case:nnF {#1}
      {
        {A} { \polyglossia_latin_diphthong_macron:NNn AE
                {
                  \polyglossia_latin_diphthong_macron:NNn Ae
                    {
                      \polyglossia_latin_diphthong_macron:NNn AU
                        {
                          \polyglossia_latin_diphthong_macron:NNn Au { Ā }
                        }
                    }
                }
            }
        {a} { \polyglossia_latin_diphthong_macron:NNn ae
                {
                  \polyglossia_latin_diphthong_macron:NNn au { ā }
                }
            }
        {E} { \polyglossia_latin_diphthong_macron:NNn EU
                {
                  \polyglossia_latin_diphthong_macron:NNn Eu { Ē }
                }
            }
        {e} { \polyglossia_latin_diphthong_macron:NNn eu { ē } }
        {I} { Ī }
        {i} { ī }
        {O} { \polyglossia_latin_diphthong_macron:NNn OE
                {
                  \polyglossia_latin_diphthong_macron:NNn Oe { Ō }
                }
            }
        {o} { \polyglossia_latin_diphthong_macron:NNn oe { ō } }
        {U} { Ū }
        {u} { ū }
        {V} { \= V } % V may be a vowel, but lowercase v is never used as a vowel.
        {Y} { Ȳ }
        {y} { ȳ }
      }
      {
        \token_to_str:N =
        #1
      }
  }

\cs_new:Npn \polyglossia_latin_put_breve:N #1
  {
    \str_case:nnF {#1}
      {
        {A} { Ă }
        {a} { ă }
        {E} { Ĕ }
        {e} { ĕ }
        {I} { Ĭ }
        {i} { ĭ }
        {O} { Ŏ }
        {o} { ŏ }
        {U} { Ŭ }
        {u} { ŭ }
        {V} { \u{V} } % V may be a vowel, but lowercase v is never used as a vowel.
        {Y} { \u{Y} }
        {y} { \u{y} }
      }
      {
        \token_to_str:N ^
        #1
      }
  }


\cs_new:Npn \polyglossia_latin_allow_hyphens:
  {
    \bbl@allowhyphens
    \discretionary {-} {} {}
    \bbl@allowhyphens
  }

\cs_new:Npn \polyglossia_latin_digraph_shorthand:Nnn #1#2#3
% #1: second letter of digraph (E or e)
% #2: digraph character
% #3: non-digraph code
  {
    \bool_if:NTF \l_polyglossia_latin_use_digraphs_bool
      {
        \peek_meaning_remove:NTF #1 {#2} {#3}
      }
      {
        #3
      }
  }

\cs_new:Npn \polyglossia_latin_diphthong_macron:NNn #1#2#3
% #1: first character of diphthong
% #2: second character of diphthong
% #3: non-diphthong code
  {
    \peek_meaning:NTF #2 { #1 \char "35E \relax } {#3} % U+35E: combining double macron
  }

\cs_new:Npn \polyglossia_latin_no_shorthands:
  {
    \bbl@deactivate {"}
    \bbl@deactivate {'}
    \bbl@deactivate {=}
    \bbl@deactivate {^}
    % The active '=' character may cause problems with key=value interfaces.
    % We have to make sure here that no problems can occur outside a Latin
    % prosodic shorthand environment.
    \shorthandoff {=}
  }


%%%%% Further settings

\let \xpgla@savedvalues \empty

\AtEndPreamble
  {
    \edef \xpgla@savedvalues
      {
        \clubpenalty = \the \clubpenalty \space
        \@clubpenalty = \the \@clubpenalty \space
        \widowpenalty = \the \widowpenalty \space
        \finalhyphendemerits = \the \finalhyphendemerits
      }
  }

\def \noextras@latin
  {
    \iflatin@babelshorthands
      \polyglossia_latin_no_shorthands:
    \fi
    \xpgla@savedvalues
    \polyglossia_latin_no_punctuation_spacing:
    \polyglossia_latin_modern_character_codes:
  }

\cs_new:Npn \polyglossia_latin_inline_extras:
  {
    \bool_if:NF \l_polyglossia_latin_use_v_bool
      {
        \polyglossia_latin_classical_character_codes:
      }
    \bool_if:NT \l_polyglossia_latin_punctuation_spacing_bool
      {
        \polyglossia_latin_punctuation_spacing:
      }
    \iflatin@babelshorthands
      \polyglossia_latin_shorthands:
    \fi
    \iflatin@prosodicshorthands
      \polyglossia_latin_prosodic_shorthands:
    \fi
  }

\def \blockextras@latin
  {
    % The following four values were overtaken from the Italian language module.
    % It is unclear why they were chosen.
    \clubpenalty = 3000
    \@clubpenalty = 3000
    \widowpenalty = 3000
    \finalhyphendemerits = 50000000
    \polyglossia_latin_inline_extras:
  }

\def \inlineextras@latin
  {
    \polyglossia_latin_inline_extras:
  }


%% Default settings

\polyglossia_latin_modern_settings:

\ExplSyntaxOff

%%   Copyright (C) Claudio Beccari 2013-2016
%%   Copyright (C) Élie Roux 2016-2019
%%   Copyright (C) Keno Wehr 2019-2020
%%
%%   Permission is hereby granted, free of charge, to any person obtaining
%%   a copy of this software and associated documentation files
%%   (the "Software"), to deal in the Software without restriction, including
%%   without limitation the rights to use, copy, modify, merge, publish,
%%   distribute, sublicense, and/or sell copies of the Software, and to permit
%%   persons to whom the Software is furnished to do so, subject to the following
%%   conditions:
%%
%%   The above copyright notice and this permission notice shall be included in
%%   all copies or substantial portions of the Software.
%%
%%   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%%   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%%   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
%%   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%%   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%%   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
%%   IN THE SOFTWARE.
%%
%% End of file `gloss-latin.ldf'.
%    \end{macrocode}
% \iffalse
%</gloss-latin.ldf>
%<*gloss-latinclassic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latinclassic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latinclassic.ldf}[polyglossia: module for classic latin]

% We provide this as a babel alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-latinclassic.ldf>
%<*gloss-latinecclesiastic.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latinecclesiastic.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latinecclesiastic.ldf}[polyglossia: module for ecclesiastic latin]

% We provide this as a babel alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-latinecclesiastic.ldf>
%<*gloss-latinmedieval.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latinmedieval.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latinmedieval.ldf}[polyglossia: module for medieval latin]

% We provide this as a babel alias

\xpg@load@master@language{latin}

%    \end{macrocode}
% \iffalse
%</gloss-latinmedieval.ldf>
%<*gloss-latvian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-latvian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-latvian.ldf}[polyglossia: module for latvian]
\PolyglossiaSetup{latvian}{
  bcp47=lv,
  hyphennames={latvian},
  hyphenmins={2,2},
  langtag=LVI,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{latvian}{lv}

\def\captionslatvian{%
   \def\prefacename{Priekšvārds}%
   \def\refname{Literatūras saraksts}%
   \def\abstractname{Anotācija}%
   \def\bibname{Literatūra}%
   \def\chaptername{Nodaļa}%
   \def\appendixname{Pielikums}%
   \def\contentsname{Saturs}%
   \def\listfigurename{Attēlu saraksts}%
   \def\listtablename{Tabulu saraksts}%
   \def\indexname{Index}%
   \def\figurename{Att.}%
   \def\tablename{Tabula}%
   \def\partname{Daļa}%
   \def\enclname{encl}%
   \def\ccname{cc}%
   \def\headtoname{To}%
   \def\pagename{lpp.}%
   \def\seename{sk.}%
   \def\alsoname{sk. arī}%
   \def\proofname{Pierādījums}%
   }
\def\datelatvian{%
   \def\today{%
      \number\year.\thinspace gada%
      \space\number\day.\thinspace%
      \ifcase\month\or%
      janvārī\or februārī\or martā\or%
      aprīlī\or maijā\or jūnijā\or%
      jūlijā\or augustā\or septembrī\or%
      oktobrī\or novembrī\or decembrī\fi}}

%    \end{macrocode}
% \iffalse
%</gloss-latvian.ldf>
%<*gloss-lithuanian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lithuanian.ldf}
%    \begin{macrocode}
% Translated by Paulius Sladkevičius <komsas@gmail.com>

\ProvidesFile{gloss-lithuanian.ldf}[polyglossia: module for lithuanian]
\PolyglossiaSetup{lithuanian}{
  bcp47=lt,
  hyphennames={lithuanian},
  hyphenmins={2,2},
  langtag=LTH,
  indentfirst=true, % TODO Dokumentų rengimo taisyklių, patvirtintų Lietuvos vyriausiojo archyvaro 2011 m. liepos 4 d. įsakymu Nr. V-117, 29.1 punktą
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{lithuanian}{lt}

\def\captionslithuanian{%
   \def\prefacename{Pratarmė}%
   \def\refname{Literatūra}%
   \def\abstractname{Santrauka}%
   \def\bibname{Literatūra}%
   \def\chaptername{Skyrius}% TODO letter case
   \def\appendixname{Priedas}%
   \def\contentsname{Turinys}%
   \def\listfigurename{Iliustracijų sąrašas}%
   \def\listtablename{Lentelių sąrašas}%
   \def\indexname{Rodyklė}%
   \def\figurename{pav.}%
   \def\tablename{lentelė}% TODO any special reason for \protect in babel?
   \def\partname{Dalis}%
   \def\enclname{Įdėta}%
   \def\ccname{Kopijos}%
   \def\headtoname{Kam}% TODO empty in babel?
   \def\pagename{puslapis}%
   \def\seename{žiūrėk}%
   \def\alsoname{taip pat}% TODO some other variants are considered in babel?
   \def\proofname{Įrodymas}%
   \def\glossaryname{Terminų žodynas}% TODO some other variants are considered in babel?
}

\def\datelithuanian{%
   \def\lithuanianmonth{\ifcase\month\or
      sausio\or
      vasario\or
      kovo\or
      balandžio\or
      gegužės\or
      birželio\or
      liepos\or
      rugpjūčio\or
      rugsėjo\or
      spalio\or
      lapkričio\or
      gruodžio\fi}%
   \def\today{\number\year~m.~\lithuanianmonth~\number\day~d.}%
}

\def\blockextras@lithuanian{%
  \let\fnum@figure@orig\fnum@figure
  \def\fnum@figure{\thefigure\nobreakspace\figurename}%
  \let\fnum@table@orig\fnum@table
  \def\fnum@table{\thetable\nobreakspace\tablename}%
}

\def\noextras@lithuanian{%
  \let\fnum@figure\fnum@figure@orig
  \let\fnum@table\fnum@table@orig
}

%    \end{macrocode}
% \iffalse
%</gloss-lithuanian.ldf>
%<*gloss-lo.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lo.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lo.ldf}[polyglossia: module for lo (lao)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{lao}

%    \end{macrocode}
% \iffalse
%</gloss-lo.ldf>
%<*gloss-lowersorbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lowersorbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lowersorbian.ldf}[polyglossia: module for lower sorbian]

% We provide this as a babel alias

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-lowersorbian.ldf>
%<*gloss-lsorbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lsorbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lsorbian.ldf}[polyglossia: module for lower sorbian]

% We only provide this gloss for babel compatibility. Since lsorbian is 
% a sorbian variety, we use 'sorbian' with variant 'lower' now.

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-lsorbian.ldf>
%<*gloss-lt.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lt.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lt.ldf}[polyglossia: module for lt (lithuanian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{lithuanian}

%    \end{macrocode}
% \iffalse
%</gloss-lt.ldf>
%<*gloss-lv.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-lv.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-lv.ldf}[polyglossia: module for lv (latvian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{latvian}

%    \end{macrocode}
% \iffalse
%</gloss-lv.ldf>
%<*gloss-macedonian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-macedonian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-macedonian.ldf}[polyglossia: module for macedonian]
\PolyglossiaSetup{macedonian}{
  bcp47=mk,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=MKD,
  hyphennames={macedonian},
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup
}

% BCP-47 compliant aliases
\setlanguagealias*{macedonian}{mk}

\def\macedonian@Alph#1{%
   \ifcase#1\or
   А\or Б\or В\or Г\or Д\or Ѓ\or Е\or
   Ж\or З\or Ѕ\or И\or Ј\or К\or Л\or 
   Љ\or М\or Н\or Њ\or О\or П\or Р\or
   С\or Т\or Ќ\or У\or Ф\or Х\or Ц\or
   Ч\or Џ\or Ш\else
   \xpg@ill@value{#1}{macedonian@Alph}\fi}%

\def\macedonian@alph#1{%
   \ifcase#1\or
   а\or б\or в\or г\or д\or ѓ\or е\or
   ж\or з\or ѕ\or и\or ј\or к\or л\or
   љ\or м\or н\or њ\or о\or п\or р\or
   с\or т\or ќ\or у\or ф\or х\or ц\or
   ч\or џ\or ш\else
   \xpg@ill@value{#1}{macedonian@alph}\fi}%

\def\macedonian@numbers{%
   \let\@Alph\macedonian@Alph%
   \let\@alph\macedonian@alph%
 }

\def\nomacedonian@numbers{%
   \let\@Alph\latin@Alph%
   \let\@alph\latin@alph%
}

\def\captionsmacedonian{%
   \def\refname{Литература}%
   \def\abstractname{Апстракт}%
   \def\bibname{Библиографија}%
   \def\prefacename{Предговор}%
   \def\chaptername{Глава}%
   \def\appendixname{Прилог}%
   \def\contentsname{Содржина}%
   \def\listfigurename{Листа на слики}%
   \def\listtablename{Листа на табели}%
   \def\indexname{Индекс}%
   \def\figurename{Слика}%
   \def\tablename{Табела}%
   %\def\thepart{}%
   \def\partname{Поглавје}%
   \def\pagename{стр.}%
   \def\seename{види}%
   \def\alsoname{види исто така}%
   \def\enclname{Прилог}%
   %\def\ccname{cc}%
   %\def\headtoname{}%
   \def\proofname{Доказ}%
   \def\glossaryname{Терминолошки речник}%
   }
\def\datemacedonian{%
   \def\today{\number\day~\ifcase\month\or
       јануари\or
       февруари\or
       март\or
       април\or
       мај\or
       јуни\or
       јули\or
       август\or
       септември\or
       октомври\or
       ноември\or
       декември\fi%
       \ \number\year~г.}%
    \def\month@Roman{\expandafter\@Roman\month}%
    \def\todayRoman{\number\day.\,\month@Roman.\,\number\year~г.}%
    }

%    \end{macrocode}
% \iffalse
%</gloss-macedonian.ldf>
%<*gloss-magyar.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-magyar.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-magyar.ldf}[polyglossia: module for magyar]

% We only provide this gloss for babel compatibility.

\xpg@load@master@language{hungarian}

%    \end{macrocode}
% \iffalse
%</gloss-magyar.ldf>
%<*gloss-malay.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-malay.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-malay.ldf}[polyglossia: module for malay]

\RequirePackage{hijrical}

\PolyglossiaSetup{malay}{%
  bcp47=id,
  language=Malay,
  langtag=MLY,
  hyphennames={malay,melayu,bahasam,bahasai,indonesian,indon,bahasa},
  hyphenmins={2,2},
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=malaysian]{malay}{zsm}
\setlanguagealias*[variant=indonesian]{malay}{id}

% Babel aliases
\setlanguagealias[variant=indonesian]{malay}{bahasai}
\setlanguagealias[variant=malaysian]{malay}{bahasa}

% Backwards compat. alias
\setlanguagealias[variant=malaysian]{malay}{bahasam}

\providebool{malay@melayu}
\malay@melayufalse
\def\malay@variant{malay}
\define@choicekey*+{malay}{variant}[\xpg@val\xpg@nr]{indonesian,malaysian}[malaysian]{%
   \ifcase\xpg@nr\relax
      % indonesian:
      \def\malay@variant{indonesian}%
      \malay@melayufalse
   \or
      % malaysian:
      \def\malay@variant{malay}%
      \malay@melayutrue
   \fi
   \ifmalay@melayu
      \SetLanguageKeys{malay}{language=Malay,langtag=MLY,babelname=bahasam,bcp47=zsm}%
      \xpg@fontsetup@latin{malay}%
      % Check if \l@malay is defined. If not, try to set it to some variety
      % (specific order as in the csv list below), or null language if everything fails
      \xpg@ifdefined{malay}{}{%
        \def\do##1{%
            \xpg@ifdefined{##1}%
              {\csletcs{l@malay}{l@##1}\listbreak}%
              {}%
        }%
        \docsvlist{melayu,bahasam,bahasai,indonesian,indon,bahasa}
        \xpg@ifdefined{malay}{}{%
                 \xpg@warning{No hyphenation patterns for Malay (Malaysian) found\MessageBreak
                              I will use the 'null' language instead}%
                 \adddialect\l@malay0%
        }%
      }%
   \else
      \SetLanguageKeys{malay}{language=Indonesian,langtag=IND,babelname=bahasa,bcp47=id}%
      \xpg@fontsetup@latin{malay}%
      % Check if \l@indonesian is defined. If not, try to set it to some variety
      % (specific order as in the csv list below), or null language if everything fails
      \xpg@ifdefined{indonesian}{}{%
        \def\do##1{%
           \xpg@ifdefined{##1}%
              {\csletcs{l@indonesian}{l@##1}\listbreak}%
              {}%
        }%
        \docsvlist{indon,bahasai,bahasam,malay,melayu,bahasa}
        \xpg@ifdefined{indonesian}{}{%
                 \xpg@warning{No hyphenation patterns for Malay (Indonesian) found\MessageBreak
                              I will use the 'null' language instead}%
                 \adddialect\l@indonesian0
        }%
      }%
   \fi
   \xpg@info{Option: malay, variant=\xpg@val}%
}{\xpg@warning{Unknown malay variant `#1'}}

% Register default options
\xpg@initialize@gloss@options{malay}{variant=malaysian}


\def\malay@language{%
   \polyglossia@setup@language@patterns{\malay@variant}%
}%


\def\captionsmalay@indonesian{%
   \def\refname{Pustaka}%
   \def\abstractname{Ringkasan}%
   \def\bibname{Bibliografi}%
   \def\prefacename{Pendahuluan}%
   \def\chaptername{Bab}%
   \def\appendixname{Lampiran}%
   \def\contentsname{Daftar Isi}%
   \def\listfigurename{Daftar Gambar}%
   \def\listtablename{Daftar Tabel}%
   \def\indexname{Indeks}%
   \def\figurename{Gambar}%
   \def\tablename{Tabel}%
   %\def\thepart{}%
   \def\partname{Bagian}%
   \def\pagename{Halaman}%
   \def\seename{lihat}%
   \def\alsoname{lihat juga}%
   \def\enclname{Lampiran}%
   \def\ccname{cc}%
   \def\headtoname{Kepada}%
   \def\proofname{Bukti}%
   \def\glossaryname{Daftar Istilah}%
}

\def\captionsmalay@malay{%
   \def\refname{Rujukan}%
   \def\abstractname{Abstrak}%
   \def\bibname{Bibliografi}%
   \def\prefacename{Pendahuluan}%
   \def\chaptername{Bab}%
   \def\appendixname{Lampiran}%
   \def\contentsname{Kandungan}%
   \def\listfigurename{Senarai Rajah}%
   \def\listtablename{Senarai Jadual}%
   \def\indexname{Indeks}%
   \def\figurename{Rajah}%
   \def\tablename{Jadual}%
   \def\thepart{}%
   \def\partname{Bahagian}%
   \def\pagename{Halaman}%
   \def\seename{lihat}%
   \def\alsoname{lihat juga}%
   \def\enclname{Lampiran}%
   \def\ccname{salinan kpd}%
   \def\headtoname{Kepada}%
   \def\proofname{Bukti}%
   \def\glossaryname{Senarai Istilah}%
}

\def\captionsmalay{%
  \csname captionsmalay@\malay@variant\endcsname%
}

\def\datemalay@indonesian{%
   \def\today{\number\day~\ifcase\month\or
    Januari\or Pebruari\or Maret\or April\or Mei\or Juni\or
    Juli\or Agustus\or September\or Oktober\or Nopember\or Desember\fi
    \space \number\year}}

\def\datemalay@malay{%
   \def\bahasam@day{%
      \ifcase\day\or%
        1hb\or 2hb\or 3hb\or 4hb\or 5hb\or%
        6hb\or 7hb\or 8hb\or 9hb\or 10hb\or%
        11hb\or 12hb\or 13hb\or 14hb\or 15hb\or%
        16hb\or 17hb\or 18hb\or 19hb\or 20hb\or%
        21hb\or 22hb\or 23hb\or 24hb\or 25hb\or%
        26hb\or 27hb\or 28hb\or 29hb\or 30hb\or%
        31hb\fi}%
   \def\today{\bahasam@day~\ifcase\month\or
    Januari\or Februari\or Mac\or April\or Mei\or Jun\or
    Julai\or Ogos\or September\or Oktober\or November\or Disember\fi
    \space \number\year}}

\def\datemalay{%
  \csname datemalay@\malay@variant\endcsname%
}

% Hijri calendar localizations
\def\hijrimonthmalay@indonesian#1{%
  \ifcase#1%
  \or Muharram\or Safar\or Rabiul awal\or Rabiul akhir\or Jumadil awal\or Jumadil akhir\or Rajab%
  \or Sya'ban\or Ramadhan\or Syawal\or Dzulkaidah\or Dzulhijjah\fi%
}

\def\hijrimonthmalay@malay#1{%
  \ifcase#1%
  \or Muharram\or Safar\or Rabiulawal\or Rabiulakhir\or Jamadilawal\or Jamadilakhir\or Rejab%
  \or Syaaban\or Ramadan\or Syawal\or Zulkaedah\or Zulhijah\fi%
}

\def\hijrimonthmalay{%
  \csname hijrimonthmalay@\malay@variant\endcsname%
}

%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{malay}{%
  \number\value{Hijriday}\space\hijrimonthmalay{\value{Hijrimonth}}\space\number\value{Hijriyear}}

%    \end{macrocode}
% \iffalse
%</gloss-malay.ldf>
%<*gloss-malayalam.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-malayalam.ldf}
%    \begin{macrocode}
﻿\ProvidesFile{gloss-malayalam.ldf}[polyglossia: module for malayalam]

% Translations provided by Kevin & Siji, 01-11-2009

\PolyglossiaSetup{malayalam}{
  bcp47=ml,
  script=Malayalam,
  scripttag=mlym,
  langtag=MAL, %FIXME there is also MLR for "Malayalam Reformed"
  hyphennames={malayalam},
  hyphenmins={2,2}, %FIXME
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{malayalam}{ml}

\def\captionsmalayalam{%
     \def\abstractname{സാരാംശം}%
     \def\appendixname{ശിഷ്ടം}%
     \def\bibname{}% (?)
     \def\ccname{}%
     \def\chaptername{അദ്ധ്യായം}%
     \def\contentsname{ഉള്ളടക്കം}%
     \def\enclname{}%
     \def\figurename{ചിത്രം}% रेखाचित्र
     \def\headpagename{}%
     \def\headtoname{}%
     \def\indexname{സൂചിക}%
     \def\listfigurename{ചിത്രസൂചിക}%
     \def\listtablename{പട്ടികകളുടെ സൂചിക}%
     \def\pagename{}%
     \def\partname{ഭാഗം}%
     \def\prefacename{}% 
     \def\refname{}%
     \def\tablename{പട്ടിക}%
     \def\seename{കാണുക}%
     \def\alsoname{ഇതും കാണുക}%
     \def\alsoseename{ഇതും കാണുക}%
}
\def\datemalayalam{%
   \def\today{\number\year\space\ifcase\month\or
     ജനുവരി\or
     ഫിബ്രുവരി\or
     മാർച്ച്\or
     ഏപ്രിൽ\or
     മെയ്\or
     ജൂൺ\or
     ജൂലായ്\or
     ആഗസ്ത്\or
     സെപ്തംബർ\or
     ഒക്ടോബർ\or
     നവംബർ\or
     ഡിസംബർ\fi
     \space\number\day}%
}

%    \end{macrocode}
% \iffalse
%</gloss-malayalam.ldf>
%<*gloss-marathi.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-marathi.ldf}
%    \begin{macrocode}
% Translations provided by Abhijit Navale <abhi_navale@live.in>
% Ordinals (1-100) added by Niranjan Tambe <niranjanvikastambe@gmail.com> on 14th December, 2019
% TODO implement Hindu calendar (not used in day-to-day practice)

\ProvidesFile{gloss-marathi.ldf}[polyglossia: module for marathi]

\RequirePackage{devanagaridigits}

\PolyglossiaSetup{marathi}{
  bcp47=mr,
  script=Devanagari,
  scripttag=deva,
  langtag=MAR,
  hyphennames={marathi},
  hyphenmins={2,2},%CHECK
  fontsetup=true,
  localnumeral=marathinumerals
  %TODO nouppercase=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{marathi}{mr}

\newif\ifmarathi@devanagari@numerals
\marathi@devanagari@numeralstrue

\define@choicekey*+{marathi}{numerals}[\xpg@val\xpg@nr]{Western,Devanagari}[Devanagari]{%
   \ifcase\xpg@nr\relax
      % Western:
      \marathi@devanagari@numeralsfalse%
   \or
      % Devanagari:
      \marathi@devanagari@numeralstrue%
   \fi
   \xpg@info{Option: Marathi, numerals=\xpg@val}%
}{\xpg@warning{Unknown Marathi numerals value `#1'}}

% Register default options
\xpg@initialize@gloss@options{marathi}{numerals=Devanagari}

\newcommand{\marathinumerals}[2]{\marathinumber{#2}}

\def\marathinumber#1{%
  \ifmarathi@devanagari@numerals
    \devanagaridigits{\number#1}%
  \else
    \number#1%
  \fi%
}

\def\captionsmarathi{%
   \def\refname{संदर्भ}%
   \def\abstractname{सारांश}%
   \def\bibname{संदर्भसूची}%
   \def\prefacename{प्रस्तावना}%
   \def\chaptername{प्रकरण}%
   \def\appendixname{परिशिष्ट}%
   \def\contentsname{अनुक्रमणिका}%
   \def\listfigurename{आकृत्यांची सूची}%
   \def\listtablename{कोष्टकसूची}%
   \def\indexname{सूची}%
   \def\figurename{आकृती}%
   \def\tablename{कोष्टक}%
   \def\partname{खंड}%
   \def\pagename{पृष्ठ}%
   \def\seename{पाहा}%
   \def\alsoname{हेदेखील पाहा}%
   \def\enclname{समाविष्ट}%
   \def\ccname{प्रत}%
   \def\headtoname{प्रति}%
   \def\proofname{सिद्धता}%
   \def\glossaryname{संज्ञांची सूची}%
   \def\authorsand{आणि}%
}

\def\datemarathi{%
   \def\marathimonth{%
     \ifcase\month\or
                जानेवारी\or
                फेब्रुवारी\or
                मार्च\or
                एप्रिल\or
                मे\or
                जून\or
                जुलै\or
               ऑगस्ट\or
               सप्टेंबर\or
               ऑक्टोबर\or
               नोव्हेंबर\or
               डिसेंबर%
     \fi%
   }%
   \def\today{%
     \marathinumber\day\space\marathimonth\space\marathinumber\year%
   }%
}

\def\devanagari@akshar#1{\ifcase#1\or अ\or आ\or इ\or ई\or उ\or ऊ\or ऋ\or ऌ\or ए\or ॲ\or ऐ\or ओ\or ऑ\or औ\or अं\or अः\else\@ctrerr\fi}

\def\devanagari@alph#1{%
    \ifcase#1\or क\or ख\or ग\or घ\or ङ\or च\or छ\or ज\or झ\or ञ\or ट\or ठ\or ड\or ढ\or ण\or त\or थ\or द%
       \or ध\or न\or प\or फ\or ब\or भ\or म\or य\or र\or ल\or व\or श\or ष\or स\or ह\or ळ\or क्ष \or ज्ञ \else\@ctrerr%
    \fi%
}

\def\devanagari@letter#1{%
  \ifcase#1\or एक\or दोन\or तीन\or चार\or पाच\or सहा\or सात\or आठ\or नऊ\or दहा\or अकरा\or बारा\or तेरा\or चौदा%
    \or पंधरा\or सोळा\or सतरा\or अठरा\or एकोणीस\or वीस\or एकवीस\or बावीस\or तेवीस\or चोवीस\or पंचवीस\or सव्वीस\or सत्तावीस\or अठ्ठावीस%
    \or एकोणतीस\or तीस\or एकतीस\or बत्तीस\or तेहतीस \or चौतीस \or पस्तीस \or छत्तीस \or सदतीस \or अडतीस \or एकोणचाळीस \or चाळीस %
    \or एकेचाळीस \or बेचाळीस \or त्रेचाळीस \or चव्वेचाळीस \or पंचेचाळीस \or शेहेचाळीस \or सत्तेचाळीस \or अठ्ठेचाळीस \or एकोणपन्नास \or पन्नास %
    \or एकावन्न \or बावन्न \or त्रेपन्न \or चौपन्न \or पंचावन्न \or छप्पन्न\or सत्तावन्न \or अठ्ठावन्न \or एकोणसाठ \or साठ \or एकसष्ट \or बासष्ट \or त्रेसष्ट %
    \or चौसष्ट \or पासष्ट \or सहासष्ट \or सदुष्ट \or अडुसष्ट \or एकोणसत्तर\or सत्तर \or एकाहत्तर \or बाहत्तर \or त्र्याहत्तर \or चौऱ्याहत्तर \or पंचाहत्तर %
    \or शाहत्तर \or सत्त्याहत्तर \or अठ्ठ्याहत्तर \or एकोणऐंशी \or ऐंशी\or एक्याऐंशी \or ब्याऐंशी \or त्र्याऐंशी \or चौऱ्याऐंशी \or पंच्याऐंशी \or श्याऐंशी \or सत्त्याऐंशी %
    \or अठ्ठ्याऐंशी \or एकोणनव्वद \or नव्वद \or एक्याण्णव\or ब्याण्णव \or त्र्याण्णव \or चौऱ्याण्णव \or पंचाण्णव \or शहाण्णव \or सत्त्याण्णव \or अठ्याण्णव %
    \or नव्याण्णव \or शंभर\else\@ctrerr%
  \fi%
}

\let\xpg@save@roman\@roman
\let\xpg@save@Roman\@Roman

\def\marathi@numbers{%
  \let\@alph\devanagari@akshar
  \let\@Alph\devanagari@letter
  \let\@roman\devanagari@alph
  \let\@Roman\devanagari@letter
}

\def\nomarathi@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
  \let\@roman\xpg@save@roman
  \let\@Roman\xpg@save@Roman
}

%    \end{macrocode}
% \iffalse
%</gloss-marathi.ldf>
%<*gloss-mk.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-mk.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-mk.ldf}[polyglossia: module for mk (macedonian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{macedonian}

%    \end{macrocode}
% \iffalse
%</gloss-mk.ldf>
%<*gloss-ml.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ml.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ml.ldf}[polyglossia: module for ml (malayalam)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{malayalam}

%    \end{macrocode}
% \iffalse
%</gloss-ml.ldf>
%<*gloss-mn.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-mn.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-mn.ldf}[polyglossia: module for mn (mongolian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{mongolian}

%    \end{macrocode}
% \iffalse
%</gloss-mn.ldf>
%<*gloss-mongolian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-mongolian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-mongolian.ldf}[polyglossia: module for mongolian]

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{mongolian}{
  bcp47=mn,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=MNG,
  hyphennames={mongolian},
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup,
  localnumeral=mongoliannumerals,
  Localnumeral=Mongoliannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{mongolian}{mn}

% This file is derived from mongolian-babel. which
% provides support for Mongolian (Khalkha variety)
% with Cyrillic script
% TODO: Implement script=mongolian and maybe other
%       variants of Mongolian

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals
\define@choicekey*+{mongolian}{numerals}[\xpg@val\xpg@nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
   \ifcase\xpg@nr\relax
      % arabic:
      \cyrillic@numeralsfalse%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-trad:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-alph:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralstrue%
   \fi
   \xpg@info{Option: Mongolian, numerals=\xpg@val}%
}{\xpg@warning{Unknown Mongolian numerals value `#1'}}

\define@boolkey{mongolian}[mongolian@]{babelshorthands}[true]{}

% Register default options
\xpg@initialize@gloss@options{mongolian}{babelshorthands=false,numerals=arabic}

\ifsystem@babelshorthands
  \setkeys{mongolian}{babelshorthands=true}
\else
  \setkeys{mongolian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\mongolian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{mongolian}%
  \declare@shorthand{mongolian}{"`}{„}%
  \declare@shorthand{mongolian}{"'}{“}%
  \declare@shorthand{mongolian}{"<}{«}%
  \declare@shorthand{mongolian}{">}{»}%
  \declare@shorthand{mongolian}{""}{\hskip\z@skip}%
  \declare@shorthand{mongolian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{mongolian}{"=}{\nobreak-\hskip\z@skip}%
  \declare@shorthand{mongolian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
  \declare@shorthand{mongolian}{"-}{%
     \def\mongolian@sh@tmp{%
       \if\mongolian@sh@next-\expandafter\mongolian@sh@emdash%
       \else\expandafter\mongolian@sh@hyphen\fi%
     }%
     \futurelet\mongolian@sh@next\mongolian@sh@tmp%
  }%
  \def\mongolian@sh@hyphen{%
    \nobreak\-\bbl@allowhyphens}%
  \def\mongolian@sh@emdash##1##2{\cdash-##1##2}%
  \def\cdash##1##2##3{\def\tempx@{##3}%
  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
   \ifx\tempx@\tempa@\@Acdash\else
    \ifx\tempx@\tempb@\@Bcdash\else
     \ifx\tempx@\tempc@\@Ccdash\else
      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
    \cyrdash\hskip.2em\ignorespaces}%
  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z@skip\ignorespaces}%
  \def\@Ccdash{\leavevmode
   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
  \ifx\cyrdash\undefined
    \def\cyrdash{\hbox to.8em{\textendash\hss\textendash}}%
  \fi
  \declare@shorthand{mongolian}{",}{\nobreak\hskip.2em\ignorespaces}%
}

\def\nomongolian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

% Taken from babel-mongolian
\def\captionsmongolian{%
   \def\prefacename{Өмнөх үг}%
   \def\refname{Ашигласан ном}%
   \def\abstractname{Удиртгал}%
   \def\bibname{Номзүй}%
   \def\chaptername{Бүлэг}%
   \def\appendixname{Хавсралт}%
   \ifcsundef{thechapter}%
     {\def\contentsname{Агуулга}}%
     {\def\contentsname{Гарчиг}}%
   \def\listfigurename{Зургийн жагсаалт}%
   \def\listtablename{Хүснэгтийн жагсаалт}%
   \def\indexname{Товъёг}%
   \def\authorname{Нэрийн хэлхээ}%
   \def\figurename{Зураг}%
   \def\tablename{Хүснэгт}%
   \def\partname{Хэсэг}%
   \def\enclname{Ишлэл}%
   \def\ccname{э.с.}%
   \def\headtoname{}%
   \def\pagename{тал}%
   \def\seename{талд үз}%
   \def\alsoname{мөн талд үз}%
   \def\proofname{Баталгаа}%
}

\def\datemongolian{%
  \def\today{\number\year~оны \ifcase\month\or
  1-р\or 2-р\or 3-р\or 4-р\or 5-р\or 6-р\or
  7-р\or 8-р\or 9-р\or 10-р\or 11-р\or 12-р\fi
  ~сарын \number\day}}

\newcommand{\mongoliannumerals}[2]{\mongoliannumber{#2}}
\newcommand{\Mongoliannumerals}[2]{\Mongoliannumber{#2}}

\def\mongoliannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \mongolian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Mongoliannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \mongolian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\mongoliannumeral=\mongoliannumber
\let\Mongoliannumeral=\Mongoliannumber

\def\Asbuk#1{\expandafter\mongolian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\mongolian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}

% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\mongolian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{mongolian@asbuk@Alph}\fi%
}

\def\mongolian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{mongolian@asbuk@alph}\fi%
}

\def\mongolian@numbers{%
   \let\latin@alph\@alph
   \let\latin@Alph\@Alph
   \ifcyrillic@numerals%
     \def\mongolian@alph##1{\expandafter\mongoliannumeral\expandafter{\the##1}}%
     \def\mongolian@Alph##1{\expandafter\Mongoliannumeral\expandafter{\the##1}}%
      \let\@alph\mongolian@alph%
      \let\@Alph\mongolian@Alph%
   \fi
}

\def\nomongolian@numbers{%
   \let\@alph\latin@alph%
   \let\@Alph\latin@Alph%
}

\def\noextras@mongolian{%
   \ifcyrillic@numerals\nomongolian@numbers\fi%
   \ifmongolian@babelshorthands\nomongolian@shorthands\fi%
}

\def\blockextras@mongolian{%
   \ifcyrillic@numerals\mongolian@numbers\fi%
   \ifmongolian@babelshorthands\mongolian@shorthands\fi%
}

\def\inlineextras@mongolian{%
   \ifmongolian@babelshorthands\mongolian@shorthands\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-mongolian.ldf>
%<*gloss-mr.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-mr.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-mr.ldf}[polyglossia: module for mr (marathi)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{marathi}

%    \end{macrocode}
% \iffalse
%</gloss-mr.ldf>
%<*gloss-naustrian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-naustrian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-naustrian.ldf}[polyglossia: module for austrian german (current spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-naustrian.ldf>
%<*gloss-nb.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-nb.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-nb.ldf}[polyglossia: module for nb (norwegian)]

% We provide this as a bcp47-compliant alias

\xpg@load@master@language{norwegian}

%    \end{macrocode}
% \iffalse
%</gloss-nb.ldf>
%<*gloss-newzealand.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-newzealand.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-newzealand.ldf}[polyglossia: module for newzealand english]

% We provide this as a babel alias

\xpg@load@master@language{english}

%    \end{macrocode}
% \iffalse
%</gloss-newzealand.ldf>
%<*gloss-ngerman.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ngerman.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ngerman.ldf}[polyglossia: module for german (current spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-ngerman.ldf>
%<*gloss-nko.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-nko.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-nko.ldf}[Polyglossia: module for N’Ko v0.1 2013/05/19]
\PolyglossiaSetup{nko}{%
  bcp47=nko,
  script=N'ko,
  scripttag=nko~,
  langtag=NKO,
  fontsetup=true,
  hyphennames={nohyphenation},
  direction=RL,
  localnumeral=nkonumerals
}

\RequirePackage{nkonumbers}%

\newcommand{\nkonumerals}[2]{\nkonumber{#2}}

\def\captionsnko{%
  \def\prefacename{ߢߍߛߓߍ}%
  \def\refname{ߞߐߡߊߛߙߋ}%
  \def\abstractname{ߓߊߕߐߡߐ߲}%
  \def\bibname{ߟߍߙߊߥߙߍߟߐ߲߲}%
  \def\chaptername{ߛߌ߰ߘߊ}%
  \def\appendixname{ߘߋ߬ߙߋ}%
  \def\contentsname{ߞߣߐߘߐ}%
  \def\listfigurename{ߢߊ ߟߎ߬ ߛߙߍߘߍ}%
  \def\listtablename{ߦߌ߬ߘߊ߬ߥߟߊ ߟߎ߬ ߛߙߍߘߍ}%
  \def\indexname{ߛߙߍߘߍ}%
  \def\figurename{ߢߊ}%
  \def\tablename{ߦߌ߬ߘߊ߬ߥߟߊ}%
  \def\partname{ߛߌ߰ߘߊ߬ߙߋ߲}%
  \def\enclname{ߝߍ߬ߕߊ}%
  \def\ccname{ߓߊ ߘߏ߫ ߘߌ߫}%
  \def\headtoname{ߞߊߕߙߍ߬}%
  \def\pagename{ߞߐߜߍ}%
  \def\seename{ߡߊߝߟߍ߫}%
  \def\alsoname{ߝߟߍߡߊߛߊ߬ߦߌ߬}%
  \def\proofname{ߦߌ߬ߘߊ߬ߞߏ}%
  \def\glossaryname{ߞߘߐߝߐߟߊ߲}%
}%

% In n'ko, this is an example of date :
% ߂߀߁߃ ߞߏ߲ߞߏߜߍ ߕߟߋ߬ ߁߈ (RTL)
% ( 18 February 2013 )
% The word "ߕߟߋ߬" is mandatory between month name and day number.
% Replace "ߕߟߋ߬" by "ߕߋ߬ߟߋ߫" if and only if day = 2 or day = 3 or day = 9 
% or (day >= 20 and day <= 29).

\newcommand*\nkodayprefix[1]{%
  \ifnum\numexpr#1=2 ߕߋ߬ߟߋ߫\else%
     \ifnum\numexpr#1=3 ߕߋ߬ߟߋ߫\else%
        \ifnum\numexpr#1=9 ߕߋ߬ߟߋ߫\else%
           \ifnum\numexpr#1>19\ifnum\numexpr#1<30 ߕߋ߬ߟߋ߫\else ߕߟߋ߬\fi\else ߕߟߋ߬\fi%
        \fi%
     \fi%
  \fi%
}

\newcommand*\nkoday[1]{%
  % If day = 1, put above "߁", NKO_COMBINING_SHORT_RISING_TONE
  \ifnum\numexpr#1=1 ߁߭\else%
    \nkonumber{#1}
  \fi
}

\def\datenko{%
  \def\today{%
    \nkonumber{\year}\space
    \ifcase\month
    \or ߓߌ߲ߠߊߥߎߟߋ߲%
    \or ߞߏ߲ߞߏߜߍ%
    \or ߕߙߊߓߊ%
    \or ߞߏ߲ߞߏߘߌ߬ߓߌ%
    \or ߘߓߊ߬ߕߊ%
    \or ߥߊ߬ߛߌߥߊ߬ߙߊ%
    \or ߞߊ߬ߙߌߝߐ߭%
    \or ߘߓߊ߬ߓߌߟߊ%
    \or ߕߎߟߊߝߌ߲%
    \or ߞߏ߲ߓߌߕߌ߮%
    \or ߣߍߣߍߓߊ%
    \or ߞߏ߬ߟߌ߲߬ߞߏߟߌ߲\fi
    \space\nkodayprefix{\number\day}
    \space\nkoday{\day}
  }%
}%

%    \end{macrocode}
% \iffalse
%</gloss-nko.ldf>
%<*gloss-norsk.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-norsk.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-norsk.ldf}[polyglossia: module for norwegian (bokmal)]

% We only provide this gloss for babel compatibility. Since norsk is 
% actually norwegian bokmal, we use 'norwegian' with variant 'bokmal' now.

\xpg@load@master@language{norwegian}

%    \end{macrocode}
% \iffalse
%</gloss-norsk.ldf>
%<*gloss-norwegian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-norwegian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-norwegian.ldf}[polyglossia: module for norwegian]
\PolyglossiaSetup{norwegian}{
  bcp47=nn,
  hyphennames={nynorsk},
  langtag=NYN,
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup=false,
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=bokmal]{norwegian}{nb}
\setlanguagealias*[variant=nynorsk]{norwegian}{nn} 
% Babel and backwards compat. aliases
\setlanguagealias[variant=bokmal]{norwegian}{norsk}
\setlanguagealias[variant=nynorsk]{norwegian}{nynorsk}

\def\norwegian@variant{nynorsk}
\define@choicekey*+{norwegian}{variant}[\xpg@val\xpg@nr]{nynorsk,bokmal}[nynorsk]{%
   \ifcase\xpg@nr\relax
      % nynorsk:
      \def\norwegian@variant{nynorsk}%
      \SetLanguageKeys{norwegian}{langtag=NYN,babelname=nynorsk,bcp47=nn}%
      \xpg@fontsetup@latin{norwegian}%
   \or
      % bokmal:
      \def\norwegian@variant{norsk}%
      \SetLanguageKeys{norwegian}{langtag=NOR,babelname=norsk,bcp47=nb}%
      \xpg@fontsetup@latin{norwegian}%
   \fi
   \xpg@info{Option: norwegian, variant=\xpg@val}%
}{\xpg@warning{Unknown norwegian variant `#1'}}


% Register default options
\xpg@initialize@gloss@options{norwegian}{variant=nynorsk}


\def\norwegian@language{%
   \polyglossia@setup@language@patterns{\norwegian@variant}%
}%

\def\captionsnorwegian@nynorsk{%
   \def\refname{Referansar}%
   \def\abstractname{Sammendrag}%
   \def\bibname{Litteratur}%
   \def\prefacename{Forord}%
   \def\chaptername{Kapittel}%
   \def\appendixname{Tillegg}%
   \def\contentsname{Innhald}%
   \def\listfigurename{Figurar}%
   \def\listtablename{Tabellar}%
   \def\indexname{Register}%
   \def\figurename{Figur}%
   \def\tablename{Tabell}%
   %\def\thepart{}% <<<
   \def\partname{Del}%
   \def\pagename{Side}%
   \def\seename{Sjå}%
   \def\alsoname{Sjå òg}%
   \def\enclname{Vedlegg}%
   \def\ccname{Kopi til}%
   \def\headtoname{Til}%
   \def\proofname{Bevis}%
   \def\glossaryname{Ordliste}%
}

\def\captionsnorwegian@norsk{%
   \def\refname{Referanser}%
   \def\abstractname{Sammendrag}%
   \def\bibname{Bibliografi}%
   \def\prefacename{Forord}%
   \def\chaptername{Kapittel}%
   \def\appendixname{Tillegg}%
   \def\contentsname{Innhold}%
   \def\listfigurename{Figurer}%
   \def\listtablename{Tabeller}%
   \def\indexname{Register}%
   \def\figurename{Figur}%
   \def\tablename{Tabell}%
   %\def\thepart{}% <<<
   \def\partname{Del}%
   \def\pagename{Side}%
   \def\seename{Se}%
   \def\alsoname{Se også}%
   \def\enclname{Vedlegg}%
   \def\ccname{Kopi sendt}%
   \def\headtoname{Til}%
   \def\proofname{Bevis}%
   \def\glossaryname{Ordliste}%
}

\def\captionsnorwegian{%
  \csname captionsnorwegian@\norwegian@variant\endcsname%
}

\def\datenorwegian@nynorsk{%   
   \def\today{\number\day.~\ifcase\month\or
    januar\or februar\or mars\or april\or mai\or juni\or
    juli\or august\or september\or oktober\or november\or desember
    \fi\space\number\year}%
}

\def\datenorwegian@norsk{%   
   \def\today{\number\day.~\ifcase\month\or
    januar\or februar\or mars\or april\or mai\or juni\or
    juli\or august\or september\or oktober\or november\or
    desember\fi\space\number\year}%
}

\def\datenorwegian{%
  \csname datenorwegian@\norwegian@variant\endcsname%
}

%    \end{macrocode}
% \iffalse
%</gloss-norwegian.ldf>
%<*gloss-nswissgerman.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-nswissgerman.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-nswissgerman.ldf}[polyglossia: module for swiss german (current spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-nswissgerman.ldf>
%<*gloss-nynorsk.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-nynorsk.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-nynorsk.ldf}[polyglossia: module for norwegian (Nynorsk)]

% We only provide this gloss for babel compatibility. Since nynorsk is 
% a norwegian variety, we use 'norwegian' with variant 'nynorsk' now.

\xpg@load@master@language{norwegian}

%    \end{macrocode}
% \iffalse
%</gloss-nynorsk.ldf>
%<*gloss-occitan.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-occitan.ldf}
%    \begin{macrocode}
%%
%% This is file `gloss-occitan.ldf',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% gloss-occitan.dtx  (with options: `ldf')
%%   ------------------------------------------------------------------
%%   The gloss-occitan module for polyglossia
%%   Copyright (C) 2016 Cédric Valmary
%%   All rights reserved
%% 
%%   Licence information appended
%% 
%%   Created by Cédric Valmary: cvalmary at yahoo dot fr
%%   of Tot en òc <http://www.totenoc.eu/>
%% 
\ProvidesFile{gloss-occitan.ldf}[2016/02/04 v0.3 polyglossia:
     module for Occitan]
\PolyglossiaSetup{occitan}{
  bcp47=oc,
  hyphennames={occitan},
  langtag=OCI,
  hyphenmins={2,2},
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{occitan}{oc}

\define@boolkey{occitan}[occitan@]{babelshorthands}[true]{}

\ifsystem@babelshorthands
  \setkeys{occitan}{babelshorthands=true}
\else
  \setkeys{occitan}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\occitan@shorthands{%
  \bbl@activate{"}%
  \def\language@group{occitan}%
  \declare@shorthand{occitan}{"}{%
    \relax\ifmmode
      \def\xpgoc@next{''}%
    \else
      \def\xpgoc@next{\futurelet\xpgoc@temp\xpgoc@cwm}%
    \fi
  \xpgoc@next}%
}
\def\xpgoc@@cwm{\nobreak\discretionary{-}{}{}\nobreak\hskip\z@skip}
\def\xpgoc@ponchinterior{%
      \nobreak\discretionary{-}{}{\mbox{$\cdot$}}\nobreak\hskip\z@skip}
\def\xpgoc@cwm{\let\xpgoc@@next\relax
  \ifcat\noexpand\xpgoc@temp a%
                         \def\xpgoc@@next{\xpgoc@@cwm}%
  \else
    \if\noexpand\xpgoc@temp \string|%
      \def\xpgoc@@next##1{\xpgoc@@cwm}%
    \else
      \if\noexpand\xpgoc@temp \string<%
        \def\xpgoc@@next##1{«\ignorespaces}%
      \else
        \if\noexpand\xpgoc@temp \string>%
          \def\xpgoc@@next##1{\unskip»}%
        \else
          \if\noexpand\xpgoc@temp\string/%
            \def\xpgoc@@next##1{\slash}%
          \else
            \if\noexpand\xpgoc@temp\string.%
              \def\xpgoc@@next##1{\xpgoc@ponchinterior}%
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
  \xpgoc@@next}
\def\nooccitan@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}
\def\captionsoccitan{%
   \def\refname{Referéncias}%
   \def\abstractname{Resumit}%
   \def\bibname{Bibliografia}%
   \def\prefacename{Prefaci}%
   \def\chaptername{Capítol}%
   \def\appendixname{Annèx}%
   \def\contentsname{Ensenhador}%
   \def\listfigurename{Taula de las figuras}%
   \def\listtablename{Taula dels tablèus}%
   \def\indexname{Indèx}%
   \def\figurename{Figura}%
   \def\tablename{Tablèu}%
   %\def\thepart{}%
   \def\partname{Partida}%
   \def\pagename{Pagina}%
   \def\seename{vejatz}%
   \def\alsoname{vejatz tanben}%
   \def\enclname{Pèça junta}%
   \def\ccname{còpia a}%
   \def\headtoname{A}%
   \def\proofname{Demostracion}%
   \def\glossaryname{Glossari}%
}
\def\dateoccitan{%
   \def\occitanmonth{\ifcase\month\or
      de~genièr\or
      de~febrièr\or
      de~març\or
      d'abril\or
      de~mai\or
      de~junh\or
      de~julhet\or
      d'agost\or
      de~setembre\or
      d'octobre\or
      de~novembre\or
      de~decembre\fi
   }%
   \def\occitanday{\ifcase\day\or
      1èr\else% primièr
      \number\day\fi% all other numbers
   }%
   \def\today{\occitanday\space \occitanmonth\space de~\number\year}%
}
\let\xpgoc@savedvalues\empty
\AtEndPreamble{% the user or the class might define different values
  \edef\xpgoc@savedvalues{%
    \clubpenalty=\the\clubpenalty\space
    \@clubpenalty=\the\@clubpenalty\space
    \widowpenalty=\the\widowpenalty\space
    \finalhyphendemerits=\the\finalhyphendemerits}
}
\def\noextras@occitan{%
   \lccode\string"2019=\z@%
   \ifoccitan@babelshorthands\nooccitan@shorthands\fi%
   \xpgoc@savedvalues%
}
\def\blockextras@occitan{%
   \lccode\string"2019=\string"2019%
   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000%
   \finalhyphendemerits=50000000%
   \ifoccitan@babelshorthands\occitan@shorthands\fi%
}

\def\inlineextras@occitan{%
   \lccode\string"2019=\string"2019%
   \ifoccitan@babelshorthands\occitan@shorthands\fi%
}
%% Distributable under the LaTeX Project Public License,
%% version 1.3c or higher (your choice). The latest version of
%% this license is at: http://www.latex-project.org/lppl.txt
%% 
%% This work is "author-maintained"
%% The maintainer is Cédric Valmary
%% 
%%
%% End of file `gloss-occitan.ldf'.
%    \end{macrocode}
% \iffalse
%</gloss-occitan.ldf>
%<*gloss-persian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-persian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-persian.ldf}[polyglossia: module for persian]

\RequireBidi
\RequirePackage{arabicnumbers}
\RequirePackage{farsical}
\RequirePackage{hijrical}
\PolyglossiaSetup{persian}{
  bcp47=fa,
  babelname=farsi,
  script=Arabic,
  direction=RL,
  scripttag=arab,
  langtag=FAR,
  hyphennames={nohyphenation},
  fontsetup=true,
  localnumeral=farsinumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{persian}{fa}

% Babel and backwards compat. alias
\setlanguagealias{persian}{farsi}

\newif\if@western@numerals
\def\tmp@western{western}
\define@key{persian}{numerals}[eastern]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@western\@western@numeralstrue\else%
    \@western@numeralsfalse%
  \fi}

%this is needed for \abjad in arabicnumbers.sty
\def\tmp@true{true}
\define@key{persian}{abjadjimnotail}[true]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@true\abjad@jim@notailtrue%
  \else
    \abjad@jim@notailfalse
  \fi}

% NOT YET USED
\define@key{persian}{locale}[default]{%
  \def\@persian@locale{#1}}

%TODO add option for CALENDAR

% Register default options
\xpg@initialize@gloss@options{persian}{locale=default,numerals=eastern,abjadjimnotail=false}

\def\farsigregmonth#1{\ifcase#1%
  \or ژانویه\or فوریه\or مارس\or آوریل\or مه\or ژوئن\or ژوئیه\or اوت\or سپتامبر\or اکتبر\or نوامبر\or دسامبر\fi}
\def\farsimonth#1{\ifcase#1%
  \or کانون ثانی\or شباط\or اذار%%or ادار
    \or نیسان\or ایار\or حزیران\or تموز\or آب\or ایلول\or تشرین اول\or تشرین ثانی\or کانون اول\fi}

%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{persian}{\@ensure@RTL{%
\farsinumber{\value{Hijriday}}\space\HijriMonthArabic{\value{Hijrimonth}}\space\farsinumber{\value{Hijriyear}}}}

\def\captionspersian{%
\def\prefacename{\@ensure@RTL{پیشگفتار}}%
\def\refname{\@ensure@RTL{مراجع}}%
\def\abstractname{\@ensure@RTL{چکیده}}%
\def\bibname{\@ensure@RTL{کتاب‌نامه}}%
\def\chaptername{\@ensure@RTL{فصل}}%
\def\appendixname{\@ensure@RTL{پیوست}}%
\def\contentsname{\@ensure@RTL{فهرست مطالب}}%
\def\listfigurename{\@ensure@RTL{لیست تصاویر}}%
\def\listtablename{\@ensure@RTL{لیست جداول}}%
\def\indexname{\@ensure@RTL{نمایه}}%
\def\figurename{\@ensure@RTL{شكل}}%
\def\tablename{\@ensure@RTL{جدول}}%
\def\partname{\@ensure@RTL{بخش}}%
\def\enclname{\@ensure@RTL{پیوست}}%
\def\ccname{\@ensure@RTL{رونوشت}}%
\def\headtoname{\@ensure@RTL{به}}%
\def\pagename{\@ensure@RTL{صفحة}}%
\def\seename{\@ensure@RTL{ببینید}}%
\def\alsoname{\@ensure@RTL{نیز ببینید}}%
\def\proofname{\@ensure@RTL{برهان}}%
\def\glossaryname{\@ensure@RTL{دانش‌نامه}}%
}
\def\datepersian{%
   \def\today{\@ensure@RTL{\farsinumber\day\space\farsigregmonth{\month}\space\farsinumber\year}}%
}

\newcommand{\farsinumerals}[2]{\farsinumber{#2}}

\def\farsinumber#1{%
  \if@western@numerals
    \number#1%
  \else
    \xpg@if@char@available{06F0}%
          {\farsidigits{\number#1}}%
          {\arabicdigits{\number#1}}%
  \fi
}

%\def\farsinum#1{\expandafter\farsinumber\csname c@#1\endcsname}
%\def\farsibracenum#1{(\expandafter\farsinumber\csname c@#1\endcsname)}
%\def\farsiornatebracenum#1{\char"FD3E\expandafter\farsinumber\csname c@#1\endcsname\char"FD3F}
%\def\farsialph#1{\expandafter\@farsialph\csname c@#1\endcsname}

\def\persian@numbers{%
   \let\@alph\abjad%
   \let\@Alph\abjad%
}

\def\nopersian@numbers{%
  \let\@alph\@latinalph%
  \let\@Alph\@latinAlph%
}

\def\persian@globalnumbers{%
   \let\@arabic\farsinumber%
   \renewcommand\thefootnote{\localnumeral*{footnote}}%
   \renewcommand\theequation{\localnumeral*{equation}}%
}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\nopersian@globalnumbers{
   \let\@arabic\xpg@save@arabic%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@persian{%
   \def\MakeUppercase##1{##1}%
}

\def\noextras@persian{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase
}
%    \end{macrocode}
% \iffalse
%</gloss-persian.ldf>
%<*gloss-piedmontese.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-piedmontese.ldf}
%    \begin{macrocode}
% !TEX encoding = UTF-8 Unicode
\ProvidesFile{gloss-piedmontese.ldf}[2013/02/12 v1.0 polyglossia: module for piedmontese]
\makeatletter
\PolyglossiaSetup{piedmontese}{
  bcp47=pms,
  hyphennames={piedmontese},
  hyphenmins={2,2},
  langtag=PMS,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{piedmontese}{pms}

\define@boolkey{piedmontese}[piedmontese@]{babelshorthands}[true]{}

\ifsystem@babelshorthands
  \setkeys{piedmontese}{babelshorthands=true}
\else
  \setkeys{piedmontese}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\piedmontese@shorthands{%
  \bbl@activate{"}%
  \def\language@group{piedmontese}%
  \declare@shorthand{piedmontese}{"}{%
    \relax\ifmmode
      \def\xpgpms@next{''}%
    \else
      \def\xpgpms@next{\futurelet\xpgpms@temp\xpgpms@cwm}%
    \fi
  \xpgpms@next}%
}

\def\xpgpms@@cwm{\nobreak\discretionary{-}{}{}\nobreak\hskip\z@skip}
\def\xpgpms@cwm{\let\xpgpms@@next\relax
\ifcat\noexpand\xpgpms@temp a%
    \def\xpgpms@@next{\pms@@cwm}%
\else
    \ifx\xpgpms@temp/%
        \def\xpgpms@@next{\bbl@allowhyphens/\bbl@allowhyphens\@gobble}%
    \else
        \ifx\xpgpms@temp-%
           \def\xpgpms@@next{\bbl@allowhyphens-\bbl@allowhyphens\@gobble}%
        \else
            \ifx\xpgpms@temp"%
                \def\xpgpms@@next{``\expandafter\@gobble\string}%
            \fi
        \fi
    \fi
\xpgpms@@next}

\def\nopiedmontese@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}
\@namedef{captions\CurrentOption}{%
    \def\prefacename{Prefassion}%
    \def\refname{Riferiment}%
    \def\abstractname{Somari}%
    \def\bibname{Bibliografìa}%
    \def\chaptername{Capìtol}%
    \def\appendixname{Gionta}%
    \def\contentsname{Tàula}%
    \def\listfigurename{Lista dle figure}%
    \def\listtablename{Lista dle tabele}%
    \def\indexname{Tàula analìtica}%
    \def\figurename{Figura}%
    \def\tablename{Tabela}%
    \def\partname{Part}%
    \def\enclname{Gionta/e}%
    \def\ccname{Con còpia a}%
    \def\headtoname{Për}%
    \def\pagename{Pàgina}%
    \def\seename{vëd}%
    \def\alsoname{vëd anche}%
    \def\proofname{Dimostrassion}%
    \def\glossaryname{Glossari}%
}
\@namedef{date\CurrentOption}{%
    \def\today{\number\day\space\ifcase\month\or
      ëd gené\or ëd fevré\or ëd mars\or d'avril\or ëd maj\or ëd giugn\or
      ëd luj\or d'agost\or dë stèmber\or d'otóber\or ëd novèmber\or dë dzèmber%
      \fi\space dal\space\number\year}}
      
\AtEndPreamble{% 
  \edef\xpgpms@savedvalues{%
    \clubpenalty=\the\clubpenalty\space
    \@clubpenalty=\the\@clubpenalty\space
    \widowpenalty=\the\widowpenalty\space
    \finalhyphendemerits=\the\finalhyphendemerits}
}


\def\noextras@piedmontese{%
   \lccode\string"2019=\z@%
   \ifpiedmontese@babelshorthands\nopiedmontese@shorthands\fi%
   \xpgpms@savedvalues%
}

\def\blockextras@piedmontese{%
   \lccode\string"2019=\string"2019%
   \clubpenalty=3000 \@clubpenalty=3000 \widowpenalty=3000%
   \finalhyphendemerits=50000000%
   \ifpiedmontese@babelshorthands\piedmontese@shorthands\fi%
}

\def\inlineextras@piedmontese{%
   \lccode\string"2019=\string"2019%
   \ifpiedmontese@babelshorthands\piedmontese@shorthands\fi%
}
%%% CHANGES END %%%
%    \end{macrocode}
% \iffalse
%</gloss-piedmontese.ldf>
%<*gloss-polish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-polish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-polish.ldf}[polyglossia: module for polish]
\PolyglossiaSetup{polish}{
  bcp47=pl,
  hyphennames={polish},
  hyphenmins={2,2},
  langtag=PLK,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{polish}{pl}

\def\captionspolish{%
  \def\prefacename{Przedmowa}%
  \def\refname{Literatura}%
  \def\abstractname{Streszczenie}%
  \def\bibname{Bibliografia}%
  \def\chaptername{Rozdział}%
  \def\appendixname{Dodatek}%
  \def\contentsname{Spis treści}%
  \def\listfigurename{Spis rysunków}%
  \def\listtablename{Spis tabel}%
  \def\indexname{Indeks}%
  \def\figurename{Rysunek}%
  \def\tablename{Tabela}%
  \def\partname{Część}%
  \def\enclname{Załącznik}%
  \def\ccname{Kopie:}%
  \def\headtoname{Do}%
  \def\pagename{Strona}%
  \def\seename{Zobacz}%
  \def\alsoname{Zobacz też}%
  \def\proofname{Dowód}%
  \def\glossaryname{Glossary}% <-- Needs translation
  }

\def\datepolish{%
  \def\today{\number\day\space\ifcase\month\or
      stycznia\or lutego\or marca\or kwietnia\or maja\or czerwca\or
      lipca\or sierpnia\or września\or października\or
      listopada\or grudnia\fi\space
      \number\year}%
  }

%    \end{macrocode}
% \iffalse
%</gloss-polish.ldf>
%<*gloss-polutonikogreek.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-polutonikogreek.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-polutonikogreek.ldf}[polyglossia: module for polytonic greek]

% We provide this as a babel alias

\xpg@load@master@language{greek}

%    \end{macrocode}
% \iffalse
%</gloss-polutonikogreek.ldf>
%<*gloss-portuges.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-portuges.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-portuges.ldf}[polyglossia: module for portuguese]

% We only provide this gloss for backwards compatibility. The name
% 'portuges' was selected in accordance with babel (which probably
% introduced it in 8.3 filename times). Since polyglossia uses full
% English language names, we use 'portuguese' now.

\xpg@load@master@language{portuguese}
     
%    \end{macrocode}
% \iffalse
%</gloss-portuges.ldf>
%<*gloss-portuguese.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-portuguese.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-portuguese.ldf}[polyglossia: module for portuguese]

\PolyglossiaSetup{portuguese}{
  bcp47=pt-PT,
  babelname=portuges,
  hyphennames={portuges,portuguese},
  hyphenmins={2,3},
  langtag=PTG,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=portuguese]{portuguese}{pt-PT}
\setlanguagealias*[variant=brazilian]{portuguese}{pt-BR}
\setlanguagealias*{portuguese}{pt}

% Babel aliases
\setlanguagealias[variant=portuguese]{portuguese}{portuges}
\setlanguagealias[variant=brazilian]{portuguese}{brazil}

\def\portuguese@variant{portuges}
\define@choicekey*+{portuguese}{variant}[\xpg@val\xpg@nr]{portuguese,brazilian}[portuguese]{%
   \ifcase\xpg@nr\relax
      % portuguese:
      \def\portuguese@variant{portuges}%
      \SetLanguageKeys{portuguese}{babelname=portuges,bcp47=pt-PT}%
   \or
      % brazilian:
      \def\portuguese@variant{brazil}%
      \SetLanguageKeys{portuguese}{babelname=brazil,bcp47=pt-BR}%
      % There are no specific brazil patterns
      \adddialect\l@brazil\l@portuges\relax%
   \fi
   \xpg@info{Option: portuguese, variant=\xpg@val}%
}{\xpg@warning{Unknown portuguese variant `#1'}}


% Register default options
\xpg@initialize@gloss@options{portuguese}{variant=portuguese}


\def\portuguese@language{%
   \polyglossia@setup@language@patterns{\portuguese@variant}%
}%

\def\captionsportuguese@portuges{%
  \def\refname{Referências}%
  \def\abstractname{Resumo}%
  \def\bibname{Bibliografia}%
  \def\prefacename{Prefácio}%
  \def\chaptername{Capítulo}%
  \def\appendixname{Apêndice}%
  \def\contentsname{Conteúdo}%
  \def\listfigurename{Lista de Figuras}%
  \def\listtablename{Lista de Tabelas}%
  \def\indexname{Índice}%
  \def\figurename{Figura}%
  \def\tablename{Tabela}%
  \def\partname{Parte}%
  \def\pagename{Página}%
  \def\seename{ver}%
  \def\alsoname{ver também}%
  \def\enclname{Anexo}%
  \def\ccname{Com cópia a}%
  \def\headtoname{Para}%
  \def\proofname{Demonstração}%
  \def\glossaryname{Glossário}%
}

\def\captionsportuguese@brazil{%
   \def\refname{Referências}%
   \def\abstractname{Resumo}%
   \def\bibname{Referências Bibliográficas}%
   \def\prefacename{Prefácio}%
   \def\chaptername{Capítulo}%
   \def\appendixname{Apêndice}%
   \def\contentsname{Sumário}%
   \def\listfigurename{Lista de Figuras}%
   \def\listtablename{Lista de Tabelas}%
   \def\indexname{Índice Remissivo}%
   \def\figurename{Figura}%
   \def\tablename{Tabela}%
   \def\partname{Parte}%
   \def\pagename{Página}%
   \def\seename{veja}%
   \def\alsoname{veja também}%
   \def\enclname{Anexo}%
   \def\ccname{Cópia para}%
   \def\headtoname{Para}%
   \def\proofname{Demonstração}%
   \def\glossaryname{Glossário}%
}

\def\captionsportuguese{%
  \csname captionsportuguese@\portuguese@variant\endcsname%
}

\def\dateportuguese@portuges{%   
  \def\today{\number\day\space de\space\ifcase\month\or
    Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or
    Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi
    \space de\space\number\year}%
}


\def\dateportuguese@brazil{%   
   \def\today{\number\day\space de\space\ifcase\month\or
      janeiro\or fevereiro\or março\or abril\or maio\or junho\or
      julho\or agosto\or setembro\or outubro\or novembro\or dezembro%
      \fi\space de\space\number\year}%
}

\def\dateportuguese{%
  \csname dateportuguese@\portuguese@variant\endcsname%
}
     
%    \end{macrocode}
% \iffalse
%</gloss-portuguese.ldf>
%<*gloss-romanian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-romanian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-romanian.ldf}[polyglossia: module for romanian]

\PolyglossiaSetup{romanian}{
  bcp47=ro,
  hyphennames={romanian},
  hyphenmins={2,2},
  langtag=ROM,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{romanian}{ro}

\def\captionsromanian{%
   \def\refname{Bibliografie}%
   \def\abstractname{Rezumat}%
   \def\bibname{Bibliografie}%
   \def\prefacename{Prefață}%
   \def\chaptername{Capitolul}%
   \def\appendixname{Anexa}%
   \def\contentsname{Cuprins}%
   \def\listfigurename{Listă de figuri}%
   \def\listtablename{Listă de tabele}%
   \def\indexname{Glosar}%
   \def\figurename{Figura}%
   \def\tablename{Tabela}%
   %\def\thepart{}%
   \def\partname{Partea}%
   \def\pagename{Pagina}%
   \def\seename{Vezi}%
   \def\alsoname{Vezi de asemenea}%
   \def\enclname{Anexă}%
   \def\ccname{Copie}%
   \def\headtoname{Pentru}%
   \def\proofname{Demonstrație}%
   \def\glossaryname{Glosar}%
   }

\def\dateromanian{%
  \def\today{\number\day~\ifcase\month\or
    ianuarie\or februarie\or martie\or aprilie\or mai\or
    iunie\or iulie\or august\or septembrie\or octombrie\or
    noiembrie\or decembrie\fi
    \space \number\year}%
  }

%    \end{macrocode}
% \iffalse
%</gloss-romanian.ldf>
%<*gloss-romansh.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-romansh.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-romansh.ldf}[polyglossia: module for romansh]
\makeatletter
\PolyglossiaSetup{romansh}{%
  bcp47=rm,
  hyphennames={romansh},
  hyphenmins={2,2},
  langtag=RMS,
  indentfirst=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{romansh}{rm}

\def\captionsromansh{%
  \def\prefacename{Prefaziun}%
  \def\refname{Bibliografia}%
  \def\abstractname{Recapitulaziun}%
  \def\bibname{Index bibliografic}%
  \def\chaptername{Chapitel}%
  \def\appendixname{Appendix}%
  \def\contentsname{Tavla dal cuntegn}%
  \def\listfigurename{Tavla da las figuras}%
  \def\listtablename{Tavla da las tabellas}%
  \def\indexname{Register da materias}%       Index?
  \def\figurename{Figura}%
  \def\tablename{Tabella}%
  \def\partname{Part}%
  \def\enclname{Agiunta(s)}%
  \def\ccname{Copia a}%
  \def\headtoname{A}%
  \def\pagename{pagina}%  
  \def\seename{vesair }%
  \def\alsoname{vesair era}%
  \def\proofname{Demonstraziun}%
  \def\glossaryname{Glossari}%
  }
  
\def\dateromansh{%
  \def\today{\ifcase\day\or1.\else ils~\number\day\fi~da~%
    \ifcase\month\or
    schaner\or favrer\or mars\or avrigl\or matg\or zercladur\or
    fanadur\or avust\or settember\or october\or november\or
    december\fi\space \number\year}}
\makeatother
%    \end{macrocode}
% \iffalse
%</gloss-romansh.ldf>
%<*gloss-russian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-russian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-russian.ldf}[polyglossia: module for russian]

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{russian}{
  bcp47=ru,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=RUS,
  hyphennames={russian},
  hyphenmins={2,2},
  frenchspacing=true,
  indentfirst=true,
  fontsetup,
  localnumeral=russiannumerals,
  Localnumeral=Russiannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{russian}{ru}
\setlanguagealias*[spelling=modern]{russian}{ru-luna1918}
\setlanguagealias*[spelling=old]{russian}{ru-petr1708}

\newif\if@russian@modern
\define@key{russian}{spelling}[modern]{%
  \ifstrequal{#1}{old}%
    {\@russian@modernfalse\SetLanguageKeys{russian}{bcp47=ru-petr1708}}%
    {\@russian@moderntrue\SetLanguageKeys{russian}{bcp47=ru}}%
}

\def\captionsrussian{%
   \if@russian@modern\captionsrussian@modern\else\captionsrussian@old\fi%
}%

\def\daterussian{%
   \if@russian@modern\daterussian@modern\else\daterussian@old\fi%
}%

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals
\define@choicekey*+{russian}{numerals}[\xpg@val\xpg@nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
   \ifcase\xpg@nr\relax
      % arabic:
      \cyrillic@numeralsfalse%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-trad:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-alph:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralstrue%
   \fi
   \xpg@info{Option: Russian, numerals=\xpg@val}%
}{\xpg@warning{Unknown Russian numerals value `#1'}}

\define@boolkey{russian}[russian@]{indentfirst}[true]{%
  \ifrussian@indentfirst
      \SetLanguageKeys{russian}{indentfirst=true}%
  \else
      \SetLanguageKeys{russian}{indentfirst=false}%
  \fi%
}

\define@boolkey{russian}[russian@]{babelshorthands}[true]{}

% Force punctuation after heading number
\define@boolkey{russian}[russian@]{forceheadingpunctuation}[true]{}

% Define some math functions
\define@boolkey{russian}[russian@]{mathfunctions}[true]{}

% Register default options
\xpg@initialize@gloss@options{russian}{babelshorthands=false,
                                       spelling=modern,
                                       numerals=arabic,
                                       indentfirst=true,
                                       forceheadingpunctuation=true,
                                       mathfunctions=true}


\ifsystem@babelshorthands
  \setkeys{russian}{babelshorthands=true}
\else
  \setkeys{russian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\russian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{russian}%
%  \declare@shorthand{russian}{"`}{„}%
%  \declare@shorthand{russian}{"'}{“}%
%  \declare@shorthand{russian}{"<}{«}%
%  \declare@shorthand{russian}{">}{»}%
  \declare@shorthand{russian}{""}{\hskip\z@skip}%
  \declare@shorthand{russian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{russian}{"=}{\nobreak-\hskip\z@skip}%
  \declare@shorthand{russian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
  \declare@shorthand{russian}{"-}{%
    \def\russian@sh@tmp{%
      \if\russian@sh@next-\expandafter\russian@sh@emdash%
      \else\expandafter\russian@sh@hyphen\fi%
    }%
    \futurelet\russian@sh@next\russian@sh@tmp}%
  \def\russian@sh@hyphen{%
    \nobreak\-\bbl@allowhyphens}%
  \def\russian@sh@emdash##1##2{\cdash-##1##2}%
  \def\cdash##1##2##3{\def\tempx@{##3}%
  \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
   \ifx\tempx@\tempa@\@Acdash\else
    \ifx\tempx@\tempb@\@Bcdash\else
     \ifx\tempx@\tempc@\@Ccdash\else
      \errmessage{Wrong usage of cdash}\fi\fi\fi}%
  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
    \cyrdash\hskip.2em\ignorespaces}%
  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
   \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z@skip\ignorespaces}%
  \def\@Ccdash{\leavevmode
   \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
  \ifx\cyrdash\undefined
    \def\cyrdash{\hbox to.8em{\textendash\hss\textendash}}%
  \fi
  \declare@shorthand{russian}{",}{\nobreak\hskip.2em\ignorespaces}%
}

\def\norussian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}


\def\captionsrussian@modern{%
   \def\prefacename{Предисловие}%
   \def\refname{Список литературы}%
   \def\abstractname{Аннотация}%
   \def\bibname{Литература}%
   \def\chaptername{Глава}%
   \def\appendixname{Приложение}%
   \ifcsundef{thechapter}%
     {\def\contentsname{Содержание}}%
     {\def\contentsname{Оглавление}}%
   \def\listfigurename{Список иллюстраций}%
   \def\listtablename{Список таблиц}%
   \def\indexname{Предметный указатель}%
   \def\authorname{Именной указатель}%
   \def\figurename{Рис.}%
   \def\tablename{Таблица}%
   \def\partname{Часть}%
   \def\enclname{вкл.}%
   \def\ccname{исх.}%
   \def\headtoname{вх.}%
   \def\pagename{с.}%
   \def\seename{см.}%
   \def\alsoname{см.~также}%
   \def\proofname{Доказательство}%
}
\def\daterussian@modern{%
      \def\today{\number\day%
      \space\ifcase\month\or%
      января\or
      февраля\or
      марта\or
      апреля\or
      мая\or
      июня\or
      июля\or
      августа\or
      сентября\or
      октября\or
      ноября\or
      декабря\fi%
      \space \number\year\space г.}%
}
     
\def\captionsrussian@old{%
   \def\prefacename{Предисловіе}%
   \def\refname{Примѣчанія}%
   \def\abstractname{Аннотація}%
   \def\bibname{Библіографія}%
   \def\chaptername{Глава}%
   \def\appendixname{Приложеніе}%
   \ifcsundef{thechapter}%
     {\def\contentsname{Содержаніе}}%
     {\def\contentsname{Оглавленіе}}%
   \def\listfigurename{Списокъ иллюстрацій}%
   \def\listtablename{Списокъ таблицъ}%
   \def\indexname{Предмѣтный указатель}%
   \def\authorname{Именной указатель}%
   \def\figurename{Рис.}%
   \def\tablename{Таблица}%
   \def\partname{Часть}%
   \def\enclname{вкл.}%
   \def\ccname{исх.}%
   \def\headtoname{вх.}%
   \def\pagename{с.}%
   \def\seename{см.}%
   \def\alsoname{см.~также}%
   \def\proofname{Доказательство}%
}

\def\daterussian@old{%
      \def\today{\number\day%
      \space\ifcase\month\or%
      января\or
      февраля\or
      марта\or
      апреля\or
      мая\or
      іюня\or
      іюля\or
      августа\or
      сентября\or
      октября\or
      ноября\or
      декабря\fi%
      \space \number\year\space г.}%
}

% Russian needs trailing dots in all headings
\def\xpg@save@autodot{}
\ifdef{\KOMAScript}{%
    \providecommand*\autodot{}%
    \let\xpg@save@autodot\autodot%
}

\def\russian@capsformat{%
  \ifrussian@forceheadingpunctuation%
   \ifdef{\KOMAScript}{%
      \renewcommand*\autodot{.}%
   }{%
      % The following is based on some ideas from ruscor.sty
      \def\@seccntformat##1{\csname pre##1\endcsname%
         \csname the##1\endcsname%
         \csname post##1\endcsname}%
       \def\@aftersepkern{\hspace{0.5em}}%
       \def\postchapter{.\@aftersepkern}%
       \def\postsection{.\@aftersepkern}%
       \def\postsubsection{.\@aftersepkern}%
       \def\postsubsubsection{.\@aftersepkern}%
       \def\postparagraph{.\@aftersepkern}%
       \def\postsubparagraph{.\@aftersepkern}%
       \def\prechapter{}%
       \def\presection{}%
       \def\presubsection{}%
       \def\presubsubsection{}%
       \def\preparagraph{}%
       \def\presubparagraph{}%
    }%
  \fi%
}

\def\norussian@capsformat{%
  \ifrussian@forceheadingpunctuation%
    \ifdef{\KOMAScript}{%
       \let\autodot\xpg@save@autodot%
    }{%
       \def\@seccntformat##1{\csname the##1\endcsname\quad}% = LaTeX kernel
    }%
  \fi%
}

\newcommand{\russiannumerals}[2]{\russiannumber{#2}}
\newcommand{\Russiannumerals}[2]{\Russiannumber{#2}}

\def\russiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \russian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Russiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \russian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\russiannumeral=\russiannumber
\let\Russiannumeral=\Russiannumber

\def\Asbuk#1{\expandafter\russian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\russian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}


% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\russian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{russian@asbuk@Alph}\fi%
}

\def\russian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{russian@asbuk@alph}\fi%
}

\def\russian@numbers{%
   \let\latin@alph\@alph
   \let\latin@Alph\@Alph
   \ifcyrillic@numerals%
     \def\russian@alph##1{\expandafter\russiannumeral\expandafter{\the##1}}%
     \def\russian@Alph##1{\expandafter\Russiannumeral\expandafter{\the##1}}%
     \let\@alph\russian@alph%
     \let\@Alph\russian@Alph%
   \fi
}

\def\norussian@numbers{%
   \let\@alph\latin@alph%
   \let\@Alph\latin@Alph%
}

\def\noextras@russian{%
   \norussian@capsformat%
   \ifcyrillic@numerals\norussian@numbers\fi%
   \ifrussian@babelshorthands\norussian@shorthands\fi%
}

\def\blockextras@russian{%
   \russian@capsformat%
   \ifcyrillic@numerals\russian@numbers\fi%
   \ifrussian@babelshorthands\russian@shorthands\fi%
}

\def\inlineextras@russian{%
   \ifrussian@babelshorthands\russian@shorthands\fi%
}

%%% These lines taken from russianb.ldf, part of babel package.
\AtBeginDocument{%
\ifrussian@mathfunctions%
  \def\sh    {\mathop{\operator@font sh}\nolimits}
  \def\ch    {\mathop{\operator@font ch}\nolimits}
  \def\tg    {\mathop{\operator@font tg}\nolimits}
  \def\arctg {\mathop{\operator@font arctg}\nolimits}
  \def\arcctg{\mathop{\operator@font arcctg}\nolimits}
  \def\th    {\mathop{\operator@font th}\nolimits}
  \def\ctg   {\mathop{\operator@font ctg}\nolimits}
  \def\cth   {\mathop{\operator@font cth}\nolimits}
  \def\cosec {\mathop{\operator@font cosec}\nolimits}
  \def\Prob  {\mathop{\kern\z@\mathsf{P}}\nolimits}
  \def\Variance{\mathop{\kern\z@\mathsf{D}}\nolimits}
  \def\nod   {\mathop{\mathrm{н.о.д.}}\nolimits}
  \def\nok   {\mathop{\mathrm{н.о.к.}}\nolimits}
  \def\NOD   {\mathop{\mathrm{НОД}}\nolimits}
  \def\NOK   {\mathop{\mathrm{НОК}}\nolimits}
  \def\Proj  {\mathop{\mathrm{Пр}}\nolimits}
  %\DeclareRobustCommand{\No}{№}
\fi
}

%    \end{macrocode}
% \iffalse
%</gloss-russian.ldf>
%<*gloss-sami.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-sami.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-sami.ldf}[polyglossia: module for sami]

\PolyglossiaSetup{sami}{
  bcp47=se,
  babelname=samin,
  hyphennames={samin},
  hyphenmins={2,2},
  language={Northern Sami},
  langtag=NSM,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{sami}{se}

% Babel and backwards compat. alias
\setlanguagealias{sami}{samin}
%\setlanguagealias[variant=northern]{sami}{samin}

% TODO: Add other Sami varieties
\def\sami@variant{northern}
%\define@choicekey*+{sami}{variant}[\xpg@val\xpg@nr]{northern}[nothern]{%
%   \ifcase\xpg@nr\relax
%      % northern:
%      \def\sami@variant{samin}%
%      \SetLanguageKeys{sami}{language=Northern Sami,langtag=NSM}%
%      \xpg@fontsetup@latin{sami}%
%   \or
%      % other:
%      \def\sami@variant{}%
%      \SetLanguageKeys{sami}{language= Sami,langtag=}%
%      \xpg@fontsetup@latin{sami}%
%   \fi
%   \xpg@info{Option: sami, variant=\xpg@val}%
%}{\xpg@warning{Unknown sami variant `#1'}}


%\def\sami@language{%
%   \polyglossia@setup@language@patterns{\sami@variant}%
%}%

\def\captionssami@northern{%
   \def\refname{Čujuhusat}%
   \def\abstractname{Čoahkkáigeassu}%
   \def\bibname{Girjjálašvuohta}%
   \def\prefacename{Ovdasátni}%
   \def\chaptername{Kapihttal}%
   \def\appendixname{Čuovus}%
   \def\contentsname{Sisdoallu}%
   \def\listfigurename{Govvosat}%
   \def\listtablename{Tabeallat}%
   \def\indexname{Registtar}%
   \def\figurename{Govus}%
   \def\tablename{Tabealla}%
   \def\thepart{}%
   \def\partname{Oassi}%
   \def\pagename{Siidu}%
   \def\seename{geahča}%
   \def\alsoname{geahča maiddái}%
   \def\enclname{Mielddus}%
   \def\ccname{Kopia sáddejuvvon}%
   \def\headtoname{Vuostáiváldi}%
   \def\proofname{Duođaštus}%
   \def\glossaryname{Sátnelistu}%
}

\def\captionssami{%
  \csname captionssami@\sami@variant\endcsname%
}

\def\datesami@northern{%
  \def\today{\ifcase\month\or
    ođđajagemánu\or
    guovvamánu\or
    njukčamánu\or
    cuoŋománu\or
    miessemánu\or
    geassemánu\or
    suoidnemánu\or
    borgemánu\or
    čakčamánu\or
    golggotmánu\or
    skábmamánu\or
    juovlamánu\fi
    \space\number\day.~b.\space\number\year}%
}

\def\datesami{%
  \csname datesami@\sami@variant\endcsname%
}

%    \end{macrocode}
% \iffalse
%</gloss-sami.ldf>
%<*gloss-samin.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-samin.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-samin.ldf}[polyglossia: module for samin]

% We only provide this gloss for babel compatibility. Since samin is 
% a sami variety, we use 'sami' with variant 'northern' now.

\xpg@load@master@language{sami}

%    \end{macrocode}
% \iffalse
%</gloss-samin.ldf>
%<*gloss-sanskrit.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-sanskrit.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-sanskrit.ldf}[polyglossia: module for sanskrit]

\RequirePackage{devanagaridigits}

\PolyglossiaSetup{sanskrit}{
  bcp47=sa-Deva,
  langtag=SAN,
  hyphennames={sanskrit,prakrit},
  hyphenmins={1,3},
  frenchspacing=true,
  fontsetup=false, % will be done below
  localnumeral=sanskritnumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{sanskrit}{sa}
\setlanguagealias*[script=Devanagari]{sanskrit}{sa-Deva}
\setlanguagealias*[script=Malayalam]{sanskrit}{sa-Mlym}
\setlanguagealias*[script=Telugu]{sanskrit}{sa-Telu}
\setlanguagealias*[script=Bengali]{sanskrit}{sa-Beng}
\setlanguagealias*[script=Kannada]{sanskrit}{sa-Knda}
\setlanguagealias*[script=Gujarati]{sanskrit}{sa-Gujr}
\setlanguagealias*[script=Latin]{sanskrit}{sa-Latn}

\define@key{sanskrit}{Script}[Devanagari]{%
  \ifcsdef{fontsetup@sanskrit@#1}%
    {\csname fontsetup@sanskrit@#1\endcsname}%
    {\xpg@error{`#1' is not a valid script for Sanskrit}%
  }%
}

\define@key{sanskrit}{script}[Devanagari]{\setkeys{sanskrit}{Script=#1}}

\def\fontsetup@sanskrit@Devanagari{%
  \SetLanguageKeys{sanskrit}{scripttag=deva,script=Devanagari,bcp47=sa-Deva}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Gujarati{%
  \SetLanguageKeys{sanskrit}{scripttag=gujr,script=Gujarati,bcp47=sa-Gujr}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Malayalam{%
  \SetLanguageKeys{sanskrit}{scripttag=mlym,script=Malayalam,bcp47=sa-Mlym}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Bengali{%
  \SetLanguageKeys{sanskrit}{scripttag=beng,script=Bengali,bcp47=sa-Beng}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Kannada{%
  \SetLanguageKeys{sanskrit}{scripttag=knda,script=Kannada,bcp47=sa-Knda}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Telugu{%
  \SetLanguageKeys{sanskrit}{scripttag=telu,script=Telugu,bcp47=sa-Relu}
  \xpg@fontsetup@nonlatin{sanskrit}}
\def\fontsetup@sanskrit@Latin{%
  \SetLanguageKeys{sanskrit}{scripttag=latn,script=Latin,bcp47=sa-Latn}
  \xpg@fontsetup@latin{sanskrit}}


\newif\ifsanskrit@devanagari@numerals
\sanskrit@devanagari@numeralstrue
\define@choicekey*+{sanskrit}{numerals}[\xpg@val\xpg@nr]{Devanagari,Western}[Devanagari]{%
   \ifcase\xpg@nr\relax
      % Devanagari:
      \sanskrit@devanagari@numeralstrue%
   \or
      % Western:
      \sanskrit@devanagari@numeralsfalse%
   \fi
   \xpg@info{Option: Sanskrit, numerals=\xpg@val}%
}{\xpg@warning{Unknown Sanskrit numeral `#1'}}


% Register default options
\xpg@initialize@gloss@options{sanskrit}{script=Devanagari,numerals=Devanagari}


\newcommand{\sanskritnumerals}[2]{\sanskritnumber{#2}}

\def\sanskritnumber#1{%
  \ifsanskrit@devanagari@numerals
    \devanagaridigits{\number#1}%
  \else
    \number#1%
  \fi%
}

\ifluatex
  \directlua{require('polyglossia-sanskrit')}%
\else
  \newXeTeXintercharclass\sanskrit@questionexclamation % ! ? ‼ ⁇ ⁈ ⁉ ‽
  \newXeTeXintercharclass\sanskrit@punctthin % : ; danda double_danda
\fi

\def\sanskrit@punctthinspace{{\unskip\thinspace}}

\def\sanskrit@punctuation{%
  \ifluatex
    \directlua{polyglossia.activate_sanskrit_punct()}%
  \else
    \XeTeXinterchartokenstate=1%
    \XeTeXcharclass `\! \sanskrit@questionexclamation
    \XeTeXcharclass `\? \sanskrit@questionexclamation
    \XeTeXcharclass `\‼ \sanskrit@questionexclamation
    \XeTeXcharclass `\⁇ \sanskrit@questionexclamation
    \XeTeXcharclass `\⁈ \sanskrit@questionexclamation
    \XeTeXcharclass `\⁉ \sanskrit@questionexclamation
    \XeTeXcharclass `\‽ \sanskrit@questionexclamation % interrobang, U+203D
    \XeTeXcharclass `\: \sanskrit@punctthin
    \XeTeXcharclass `\; \sanskrit@punctthin
    \XeTeXcharclass `\। \sanskrit@punctthin % danda, U+0964
    \XeTeXcharclass `\॥ \sanskrit@punctthin % double danda, U+0965
    \XeTeXinterchartoks \z@ \sanskrit@questionexclamation = \sanskrit@punctthinspace
    \XeTeXinterchartoks \z@ \sanskrit@punctthin = \sanskrit@punctthinspace
    \XeTeXinterchartoks \sanskrit@questionexclamation \sanskrit@punctthin = \sanskrit@punctthinspace
  \fi
}

\def\nosanskrit@punctuation{%
  \ifluatex
    \directlua{polyglossia.deactivate_sanskrit_punct()}%
  \else
    \XeTeXcharclass `\! \z@
    \XeTeXcharclass `\? \z@
    \XeTeXcharclass `\‼ \z@
    \XeTeXcharclass `\⁇ \z@
    \XeTeXcharclass `\⁈ \z@
    \XeTeXcharclass `\⁉ \z@
    \XeTeXcharclass `\‽ \z@
    \XeTeXcharclass `\: \z@
    \XeTeXcharclass `\; \z@
    \XeTeXcharclass `\। \z@
    \XeTeXcharclass `\॥ \z@
    \XeTeXinterchartokenstate=0%
  \fi
}

\def\noextras@sanskrit{%
  \nosanskrit@punctuation%
}

\def\blockextras@sanskrit{%
  \sanskrit@punctuation%
}

%    \end{macrocode}
% \iffalse
%</gloss-sanskrit.ldf>
%<*gloss-scottish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-scottish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-scottish.ldf}[polyglossia: module for scottish]

% We only provide this gloss for babel compatibility. Since scottish is 
% a gaelic variety, we use 'gaelic' with variant 'scottish' now.

\xpg@load@master@language{gaelic}

%    \end{macrocode}
% \iffalse
%</gloss-scottish.ldf>
%<*gloss-serbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-serbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-serbian.ldf}[polyglossia: module for serbian]
%TODO split into gloss-serbiancyr.ldf and gloss-serbianlat.ldf
%% load these automatically from polyglossia.sty according to the script option ??
%% same thing for all languages that have a "script" key !
%% BETTER APPROACH: see gloss-sanskrit!

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{serbian}{
  bcp47=sr-Latn,
  langtag=SRB,
  hyphennames={serbian},
  hyphenmins={2,2},
  indentfirst=true,
  fontsetup=false,
  localnumeral=serbiannumerals,
  Localnumeral=Serbiannumerals,
  babelname=serbian
  %TODO localalph
}

% BCP-47 compliant aliases
\setlanguagealias*{serbian}{sr}
\setlanguagealias*[script=Cyrillic]{serbian}{sr-Cyrl}
\setlanguagealias*[script=Latin]{serbian}{sr-Latn}

% Babel aliases
\setlanguagealias[script=Cyrillic]{serbian}{serbianc}

\newif\if@serbian@cyr
\define@choicekey*+{serbian}{Script}[\xpg@val\xpg@nr]{cyrillic,latin}[cyrillic]{%
   \ifcase\xpg@nr\relax
      % cyrillic:
      \@serbian@cyrtrue
      \SetLanguageKeys{serbian}{scripttag=cyrl,script=Cyrillic,babelname=serbianc,bcp47=sr-Cyrl}
      \xpg@fontsetup@nonlatin{serbian}%
   \or
      % latin:
      \@serbian@cyrfalse
      \SetLanguageKeys{serbian}{scripttag=latn,script=Latin,babelname=serbian,bcp47=sr-Latn}
      \xpg@fontsetup@latin{serbian}%
      %TODO \def\serbian@language{\language=\l@serbianlat}%
      % or should we use Croatian patterns as a fallback for the time being???
   \fi
   \xpg@info{Option: Serbian, script=\xpg@val}%
}{\xpg@warning{Unknown Serbian script `#1'}}

\define@key{serbian}{script}[Cyrillic]{\setkeys{serbian}{Script=#1}}

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals
\define@choicekey*+{serbian}{numerals}[\xpg@val\xpg@nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
   \ifcase\xpg@nr\relax
      % arabic:
      \cyrillic@numeralsfalse%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-trad:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-alph:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralstrue%
   \fi
   \xpg@info{Option: Serbian, numerals=\xpg@val}%
}{\xpg@warning{Unknown Serbian numerals value `#1'}}

\setkeys{serbian}{Script,numerals}

% Register default options
\xpg@initialize@gloss@options{serbian}{script=Cyrillic,numerals=arabic}

\def\captionsserbian{%
   \if@serbian@cyr\captionsserbian@cyr\else\captionsserbian@lat\fi
}

\def\dateserbian{%
   \if@serbian@cyr\dateserbian@cyr\else\dateserbian@lat\fi
}

\def\captionsserbian@lat{%
   \def\refname{Bibliografija}%
   \def\abstractname{Sažetak}%
   \def\bibname{Literatura}%
   \def\prefacename{Predgovor}%
   \def\chaptername{Glava}%
   \def\appendixname{Dodatak}%
   \def\contentsname{Sadržaj}%
   \def\listfigurename{Spisak slika}%
   \def\listtablename{Spisak tabela}%
   \def\indexname{Registar}%
   \def\figurename{Slika}%
   \def\tablename{Tabela}%
   \def\partname{Deo}%
   \renewcommand\thepart{\ifcase\value{part}\or Prvi\or Drugi\or
      Treći\or Čevrti\or Peti\or Šesti\or Sedmi\or Osmi\or
      Deveti\or Deseti\or Jedanaesti\or Dvanaesti\or Trinaesti\or
      Četrnaesti\or Petnaesti\or Šesnaesti\or Sedamnaesti\or
      Osamnaesti\or Devetnaesti\or Dvadeseti\fi}%
   \def\pagename{Strana}%
   \def\seename{Vidi}%
   \def\alsoname{Vidi takođe}%
   \def\enclname{Prilozi}%
   \def\ccname{Kopije}%
   \def\headtoname{Prima}%
   \def\proofname{Dokaz}%
   \def\glossaryname{Rečnik nepoznatih reči}%
}

\def\dateserbian@lat{%
   \def\today{\number\day .~\ifcase\month\or
    januar\or februar\or mart\or april\or maj\or
    jun\or jul\or avgust\or septembar\or oktobar\or novembar\or
    decembar\fi \space \number\year.}%
}

\def\captionsserbian@cyr{%
   \def\refname{Библиографија}%
   \def\abstractname{Сажетак}%
   \def\bibname{Литература}%
   \def\prefacename{Предговор}%
   \def\chaptername{Глава}%
   \def\appendixname{Додатак}%
   \def\contentsname{Садржај}%
   \def\listfigurename{Списак слика}%
   \def\listtablename{Списак табела}%
   \def\indexname{Регистар}%
   \def\figurename{Слика}%
   \def\tablename{Табела}%
   \def\partname{Део}%
   \renewcommand\thepart{\ifcase\value{part}\or Први\or Други\or Трећи\or
   Четврти\or Пети\or Шести\or Седми\or Осми\or Девети\or Десети\or
   Једанаести\or Дванаести\or Тринаести\or Четрнаести\or Петнаести\or
   Шеснаести\or Седамнаести\or Осамнаести\or Деветнаести\or Двадесети\fi}%
   \def\pagename{Страна}%
   \def\seename{Види}%
   \def\alsoname{Види такође}%
   \def\enclname{Прилози}%
   \def\ccname{Копије}%
   \def\headtoname{Прима}%
   \def\proofname{Доказ}%
   \def\glossaryname{Речник непознатих речи}%
}

\def\dateserbian@cyr{%
   \def\today{\number\day .~\ifcase\month\or
    јануар\or фебруар\or март\or април\or мај\or
    јун\or јул\or август\or септембар\or октобар\or новембар\or
    децембар\fi \space \number\year.}%
}


\newcommand{\serbiannumerals}[2]{\serbiannumber{#2}}
\newcommand{\Serbiannumerals}[2]{\Serbiannumber{#2}}

\def\serbiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \serbian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Serbiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \serbian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\serbiannumeral=\serbiannumber
\let\Serbiannumeral=\Serbiannumber

\def\serbian@numbers{%
   \let\latin@alph\@alph
   \let\latin@Alph\@Alph
   \ifcyrillic@numerals
     \def\serbian@alph##1{\expandafter\serbiannumeral\expandafter{\the##1}}%
     \def\serbian@Alph##1{\expandafter\Serbiannumeral\expandafter{\the##1}}%
      \let\@alph\serbian@alph%
      \let\@Alph\serbian@Alph%
   \fi
}

\def\noserbian@numbers{%
   \let\@alph\latin@alph
   \let\@Alph\latin@Alph
}

\def\blockextras@serbian{%
   \ifcyrillic@numerals\serbian@numbers\fi
}
 
\def\noextras@serbian{%
   \ifcyrillic@numerals\noserbian@numbers\fi
}

\def\Asbuk#1{\expandafter\serbian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\serbian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}

% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\serbian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{serbian@asbuk@Alph}\fi%
}

\def\serbian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{serbian@asbuk@alph}\fi%
}

 
%    \end{macrocode}
% \iffalse
%</gloss-serbian.ldf>
%<*gloss-serbianc.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-serbianc.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-serbianc.ldf}[polyglossia: module for serbian (cyrillic)]

% We provide this as a babel alias

\xpg@load@master@language{serbian}

%    \end{macrocode}
% \iffalse
%</gloss-serbianc.ldf>
%<*gloss-slovak.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-slovak.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-slovak.ldf}[polyglossia: module for slovak]

\PolyglossiaSetup{slovak}{
  bcp47=sk,
  hyphennames={slovak},
  hyphenmins={2,2},
  langtag=SKY,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{slovak}{sk}

\ifluatex
  \RequirePackage{luavlna}
\fi

\define@boolkey{slovak}[slovak@]{babelshorthands}[true]{}

\define@boolkey{slovak}[slovak@]{splithyphens}[true]{}

\define@boolkey{slovak}[slovak@]{vlna}[true]{}

% Register default options
\xpg@initialize@gloss@options{slovak}{babelshorthands=false,splithyphens=true,vlna=true}

\ifsystem@babelshorthands
  \setkeys{slovak}{babelshorthands=true}
\else
  \setkeys{slovak}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\slovak@@splhyphen#1{%
  \ifnum\hyphenchar \font>0%
    \kern\z@\discretionary{-}{\char\hyphenchar\the\font}{#1}%
    \nobreak\hskip\z@%
  \else%
    #1%
  \fi%
}

\def\slovak@splhyphen{%
  \slovak@@splhyphen{-}%
}

\def\slovak@shorthands{%
  \bbl@activate{"}%
  \def\language@group{slovak}%
  \declare@shorthand{slovak}{"=}{\slovak@splhyphen}%
  \declare@shorthand{slovak}{""}{\hskip\z@skip}%
  \declare@shorthand{slovak}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{slovak}{"-}{\nobreak\-\bbl@allowhyphens}%
  \declare@shorthand{slovak}{"|}{%
      \textormath{\penalty\@M\discretionary{-}{}{\kern.03em}%
      \bbl@allowhyphens}{}%
  }%
  \declare@shorthand{slovak}{"/}{\textormath
    {\bbl@allowhyphens\discretionary{/}{}{/}\bbl@allowhyphens}{}}%
  \declare@shorthand{slovak}{"`}{„}%
  \declare@shorthand{slovak}{"'}{“}%
  \declare@shorthand{slovak}{"<}{«}%
  \declare@shorthand{slovak}{">}{»}%
}

\def\noslovak@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\ifxetex
  % splithyphens
  \newXeTeXintercharclass\slovak@hyphen % -
  % vlna
  \newXeTeXintercharclass\slovak@openpunctuation
  \newXeTeXintercharclass\slovak@nonsyllabicpreposition
  \ifdefined\e@alloc@intercharclass@top
    \chardef\slovak@boundary=\e@alloc@intercharclass@top
  \else
    \ifdefined\XeTeXinterwordspaceshaping
      \chardef\slovak@boundary=4095 %
      \def\newXeTeXintercharclass{%
        \e@alloc\XeTeXcharclass\chardef
              \xe@alloc@intercharclass\m@ne\@ucharclass@boundary}%
    \else
      \chardef\slovak@boundary=255
    \fi
  \fi
\fi

\def\slovak@hyphens{%
    \ifluatex
      \AfterPreamble{\enablesplithyphens{slovak}}%
    \else
      \XeTeXinterchartokenstate=1
      \XeTeXcharclass `\- \slovak@hyphen
      \XeTeXinterchartoks \z@ \slovak@hyphen = {\slovak@@splhyphen}% "-" -> "\slovak@@splhyphen-"
      % necessary if used together with vlna:
      \XeTeXinterchartoks \slovak@nonsyllabicpreposition \slovak@hyphen = {\slovak@@splhyphen}% "-" -> "\slovak@@splhyphen-"
    \fi%
}

\def\noslovak@hyphens{%
    \ifluatex
      \AfterPreamble{\disablesplithyphens{slovak}}%
    \else
      \XeTeXcharclass `\- \z@
    \fi%
}

% Add nonbreakable space after single-letter word to
% prevent them to land at the end of a line
% vlna code taken and adapted from xevlna.sty
\ifxetex
    \def\slovak@nointerchartoks{\let\slovak@interchartoks\slovak@PreCSpreposition}%
    \def\slovak@PreCSpreposition{%
       \def\next{}%
       \ifnum\catcode`\ =10 % nothing will be done in verbatim
       \ifmmode % nothing in math
       \else
          \let\slovak@interchartoks\slovak@nointerchartoks
          \let\next\slovak@ExamineCSpreposition
       \fi\fi
       \next%
    }%
    \def\slovak@ExamineCSpreposition #1{#1\futurelet\next\slovak@ProcessCSpreposition}%
    \def\slovak@ProcessCSpreposition{\ifx\next\slovak@XeTeXspace\nobreak\fi}%
    \futurelet\slovak@XeTeXspace{ }\slovak@nointerchartoks
\fi

\def\slovak@vlna{%
    \ifluatex
       \preventsingleon
    \else
        % Code taken and adapted from xevlna.sty
        \XeTeXinterchartokenstate=1
        \XeTeXcharclass `\( \slovak@openpunctuation
        \XeTeXcharclass `\[ \slovak@openpunctuation
        \XeTeXcharclass `\„ \slovak@openpunctuation
        \XeTeXcharclass `\» \slovak@openpunctuation
        \XeTeXcharclass `\K \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\k \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\S \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\s \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\V \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\v \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\Z \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\z \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\O \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\o \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\U \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\u \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\A \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\a \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\I \slovak@nonsyllabicpreposition
        \XeTeXcharclass `\i \slovak@nonsyllabicpreposition
        \XeTeXinterchartoks \slovak@boundary \slovak@nonsyllabicpreposition {\slovak@interchartoks}%
        \XeTeXinterchartoks \slovak@openpunctuation \slovak@nonsyllabicpreposition {\slovak@interchartoks}%
    \fi
}

\def\noslovak@vlna{%
    \ifluatex
        \preventsingleoff
    \else
        \XeTeXcharclass`\(\z@
        \XeTeXcharclass`\[\z@
        \XeTeXcharclass`\„\z@
        \XeTeXcharclass`\»\z@
        \XeTeXcharclass`\K\z@
        \XeTeXcharclass`\k\z@
        \XeTeXcharclass`\S\z@
        \XeTeXcharclass`\s\z@
        \XeTeXcharclass`\V\z@
        \XeTeXcharclass`\v\z@
        \XeTeXcharclass`\Z\z@
        \XeTeXcharclass`\z\z@
        \XeTeXcharclass`\O\z@
        \XeTeXcharclass`\o\z@
        \XeTeXcharclass`\U\z@
        \XeTeXcharclass`\u\z@
        \XeTeXcharclass`\A\z@
        \XeTeXcharclass`\a\z@
        \XeTeXcharclass`\I\z@
        \XeTeXcharclass`\i\z@
    \fi
}


\def\captionsslovak{%
   \def\refname{Referencie}%
   \def\abstractname{Abstrakt}%
   \def\bibname{Literatúra}%
   \def\prefacename{Úvod}%
   \def\chaptername{Kapitola}%
   \def\appendixname{Dodatok}%
   \def\contentsname{Obsah}%
   \def\listfigurename{Zoznam obrázkov}%
   \def\listtablename{Zoznam tabuliek}%
   \def\indexname{Index}%
   \def\figurename{Obrázok}%
   \def\tablename{Tabuľka}%
   %\def\thepart{}%
   \def\partname{Časť}%
   \def\pagename{Strana}%
   \def\seename{viď}%
   \def\alsoname{viď tiež}%
   \def\enclname{Prílohy}%
   \def\ccname{cc.}%
   \def\headtoname{Pre}% was komu
   \def\proofname{Dôkaz}%
   \def\glossaryname{Slovník}%
}

\def\dateslovak{%   
  \def\today{\number\day.~\ifcase\month\or
    januára\or februára\or marca\or apríla\or mája\or
    júna\or júla\or augusta\or septembra\or októbra\or
    novembra\or decembra\fi
    \space \number\year}%
}

\def\noextras@slovak{%
  \ifslovak@babelshorthands\noslovak@shorthands\fi%
  \noslovak@hyphens%
  \noslovak@vlna%
  \ifxetex\XeTeXinterchartokenstate=0\fi%
}

\def\blockextras@slovak{%
  \ifslovak@babelshorthands\slovak@shorthands\fi%
  \ifslovak@vlna\slovak@vlna\else\noslovak@vlna\fi%
  \ifslovak@splithyphens\slovak@hyphens\else\noslovak@hyphens\fi%
}

\def\inlineextras@slovak{%
  \ifslovak@babelshorthands\slovak@shorthands\fi%
  \ifslovak@vlna\slovak@vlna\else\noslovak@vlna\fi%
  \ifslovak@splithyphens\slovak@hyphens\else\noslovak@hyphens\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-slovak.ldf>
%<*gloss-slovene.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-slovene.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-slovene.ldf}[polyglossia: module for slovenian]

% We provide this as a babel alias

\xpg@load@master@language{slovenian}

%    \end{macrocode}
% \iffalse
%</gloss-slovene.ldf>
%<*gloss-slovenian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-slovenian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-slovenian.ldf}[polyglossia: module for slovenian]

\PolyglossiaSetup{slovenian}{
  bcp47=sl,
  hyphennames={slovenian,slovene},
  babelname=slovene,
  hyphenmins={2,2},
  langtag=SLV,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{slovenian}{sl}

% Babel aliases
\setlanguagealias{slovenian}{slovene}

\define@boolkey{slovenian}[slovenian@]{localalph}[true]{}

% Register default options
\xpg@initialize@gloss@options{slovenian}{localalph=false}


\def\captionsslovenian{%
   \def\refname{Literatura}%
   \def\abstractname{Povzetek}%
   \def\bibname{Literatura}%
   \def\prefacename{Predgovor}%
   \def\chaptername{Poglavje}%
   \def\appendixname{Dodatek}%
   \def\contentsname{Kazalo}%
   \def\listfigurename{Slike}%
   \def\listtablename{Tabele}%
   \def\indexname{Stvarno kazalo}%
   \def\figurename{Slika}%
   \def\tablename{Tabela}%
   %\def\thepart{}%
   \def\partname{Del}%
   \def\pagename{Stran}%
   \def\seename{glej}%
   \def\alsoname{glej tudi}%
   \def\enclname{Priloge}%
   \def\ccname{Kopije}%
   \def\headtoname{Prejme}%
   \def\proofname{Dokaz}%
   \def\glossaryname{Slovar}%
}

\def\dateslovenian{%   
  \def\today{\number\day.~\ifcase\month\or
    januar\or februar\or marec\or april\or maj\or junij\or
    julij\or avgust\or september\or oktober\or november\or december\fi
    \space \number\year}%
}

\def\slovenian@alph#1{%
  \ifcase#1\or a\or b\or c\or č\or d\or e\or f\or g\or h\or i\or j\or k\or l\or
  m\or n\or o\or p\or r\or s\or š\or t\or u\or v\or z\or ž\else#1\fi
}
\def\slovenian@Alph#1{%
  \ifcase#1\or A\or B\or C\or Č\or D\or E\or F\or G\or H\or I\or J\or K\or L\or
  M\or N\or O\or P\or R\or S\or Š\or T\or U\or V\or Z\or Ž\else#1\fi
}

\def\abeceda#1{\expandafter\slovenian@alph\csname c@#1\endcsname}
\def\Abeceda#1{\expandafter\slovenian@Alph\csname c@#1\endcsname}

\def\extras@slovenian{%
  \ifslovenian@localalph\let\alph\abeceda\let\Alph\Abeceda\fi%
}

\def\blockextras@slovenian{\extras@slovenian}

\def\inlineextras@slovenian{\extras@slovenian}

\def\noextras@slovenian{\let\alph\latinalph\let\Alph\latinAlph}

%    \end{macrocode}
% \iffalse
%</gloss-slovenian.ldf>
%<*gloss-sorbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-sorbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-sorbian.ldf}[polyglossia: module for sorbian]

\PolyglossiaSetup{sorbian}{
  bcp47=hsb,
  language=Upper Sorbian,
  babelname=uppersorbian,
  hyphennames={usorbian,uppersorbian},
  langtag=USB,
  hyphenmins={2,2},
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*[variant=upper]{sorbian}{hsb}
\setlanguagealias*[variant=lower]{sorbian}{dsb} 
% Backwards compat. aliases
\setlanguagealias[variant=lower]{sorbian}{lsorbian}
\setlanguagealias[variant=upper]{sorbian}{usorbian}

% Babel aliases
\setlanguagealias[variant=lower]{sorbian}{lowersorbian}
\setlanguagealias[variant=upper]{sorbian}{uppersorbian}

\def\sorbian@variant{usorbian}
\define@choicekey*+{sorbian}{variant}[\xpg@val\xpg@nr]{upper,lower}[upper]{%
   \ifcase\xpg@nr\relax
      % upper:
      \def\sorbian@variant{usorbian}%
      \SetLanguageKeys{sorbian}{language=Upper Sorbian,langtag=USB,babelname=uppersorbian,bcp47=hsb}%
      \xpg@fontsetup@latin{sorbian}%
      % Check if \l@usorbian is defined. If not, try to set it to some variety
      % (specific order as in the csv list below), or null language if everything fails
      \xpg@ifdefined{usorbian}{}{%
        \def\do##1{%
            \xpg@ifdefined{##1}%
              {\csletcs{l@usorbian}{l@##1}\listbreak}%
              {}%
        }%
        \docsvlist{uppersorbian}
        \xpg@ifdefined{usorbian}{}{%
                 \xpg@warning{No hyphenation patterns for Upper Sorbian found\MessageBreak
                              I will use the 'null' language instead}%
                 \adddialect\l@usorbian0%
        }
      }%
   \or
      % lower:
      \def\sorbian@variant{lsorbian}%
      \SetLanguageKeys{sorbian}{language=Lower Sorbian,langtag=LSB,babelname=lowersorbian,bcp47=dsb}%
      \xpg@fontsetup@latin{sorbian}%
      % Check if \l@lsorbian is defined. If not, try to set it to some variety
      % (specific order as in the csv list below), or null language if everything fails
      \xpg@ifdefined{lsorbian}{}{%
        \def\do##1{%
           \xpg@ifdefined{##1}%
              {\csletcs{l@lsorbian}{l@##1}\listbreak}%
              {}%
        }%
        \docsvlist{lowersorbian,Lsorbian,usorbian,uppersorbian}
        \xpg@ifdefined{lsorbian}{}{%
                 \xpg@warning{No hyphenation patterns for Lower Sorbian found\MessageBreak
                              I will use the 'null' language instead}%
                 \adddialect\l@lsorbian0%
        }
     }%
   \fi
   \xpg@info{Option: sorbian, variant=\xpg@val}%
}{\xpg@warning{Unknown sorbian variant `#1'}}


\define@boolkey{sorbian}[sorbian@]{olddate}[true]{}

% Register default options
\xpg@initialize@gloss@options{sorbian}{variant=upper,olddate=false}


\def\sorbian@language{%
   \polyglossia@setup@language@patterns{\sorbian@variant}%
}%


\def\captionssorbian@lsorbian{%
   \def\refname{Referency}%
   \def\abstractname{Abstrakt}%
   \def\bibname{Literatura}%
   \def\prefacename{Zawod}%
   \def\chaptername{Kapitl}%
   \def\appendixname{Dodawki}%
   \def\contentsname{Wopśimjeśe}%
   \def\listfigurename{Zapis wobrazow}%
   \def\listtablename{Zapis tabulkow}%
   \def\indexname{Indeks}%
   \def\figurename{Wobraz}%
   \def\tablename{Tabulka}%
   %\def\thepart{}%
   \def\partname{Źěl}%
   \def\pagename{Strona}%
   \def\seename{gl.}%
   \def\alsoname{gl.~teke}%
   \def\enclname{Pśiłoga}%
   \def\ccname{CC}%
   \def\headtoname{Komu}%
   \def\proofname{Proof}%
   \def\glossaryname{Glossary}%
}

\def\captionssorbian@usorbian{%
   \def\refname{Referency}%
   \def\abstractname{Abstrakt}%
   \def\bibname{Literatura}%
   \def\prefacename{Zawod}%
   \def\chaptername{Kapitl}%
   \def\appendixname{Dodawki}%
   \def\contentsname{Wobsah}%
   \def\listfigurename{Zapis wobrazow}%
   \def\listtablename{Zapis tabulkow}%
   \def\indexname{Indeks}%
   \def\figurename{Wobraz}%
   \def\tablename{Tabulka}%
   %\def\thepart{}%
   \def\partname{Dźěl}%
   \def\pagename{Strona}%
   \def\seename{hl.}%
   \def\alsoname{hl.~tež}%
   \def\enclname{Přłoha}%
   \def\ccname{CC}%
   \def\headtoname{Komu}%
   \def\proofname{Proof}% <-- needs translation
   \def\glossaryname{Glossary}% <-- needs translation
}%

\def\captionssorbian{%
  \csname captionssorbian@\sorbian@variant\endcsname%
}

\def\datesorbian@lsorbian{%
    \def\oldtoday{%
      \number\day.~\ifcase\month\or
      wjelikego rožka\or małego rožka\or nalětnika\or
      jatšownika\or rožownika\or smažnika\or pražnika\or
      žnjeńca\or požnjeńca\or winowca\or nazymnika\or 
      godownika\fi\space \number\year}%
    \def\today{%
      \ifsorbian@olddate
        \oldtoday%
      \else
        \number\day.~\ifcase\month\or
        januara\or februara\or měrca\or apryla\or maja\or
        junija\or julija\or awgusta\or septembra\or oktobra\or
        nowembra\or decembra\fi
        \space \number\year%
      \fi
   }%
}

\def\datesorbian@usorbian{%
  \def\oldtoday{\number\day.~\ifcase\month\or
    wulkeho róžka\or małeho róžka\or nalětnika\or
    jutrownika\or róžownika\or  smažnika\or pražnika\or
    žnjenca\or požnjenca\or winowca\or nazymnika\or
    hodownika\fi \space \number\year}%
  \def\today{%
    \ifsorbian@olddate
      \oldtoday%
    \else
      \number\day.~\ifcase\month\or
      januara\or februara\or měrca\or apryla\or meje\or junija\or
      julija\or awgusta\or septembra\or oktobra\or
      nowembra\or decembra\fi
      \space \number\year%
    \fi
  }%
}

\def\datesorbian{%
  \csname datesorbian@\sorbian@variant\endcsname%
}

%    \end{macrocode}
% \iffalse
%</gloss-sorbian.ldf>
%<*gloss-spanish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-spanish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-spanish.ldf}[polyglossia: module for spanish]

\PolyglossiaSetup{spanish}{
  bcp47=es-ES,
  hyphennames={spanish},
  hyphenmins={2,2},
  totalhyphenmin=5,
  langtag=ESP,
  frenchspacing=true,
  indentfirst=true,
  fontsetup=true,
  babelname=spanish
}

% BCP-47 compliant aliases
\setlanguagealias*{spanish}{es}
\setlanguagealias*[variant=mexican]{spanish}{es-MX}
\setlanguagealias*[variant=spanish]{spanish}{es-ES}

% Babel aliases
\setlanguagealias[variant=mexican]{spanish}{spanishmx}

\newif\if@spanish@mexico
\@spanish@mexicofalse
\define@choicekey*+{spanish}{variant}[\xpg@val\xpg@nr]{spanish,mexican}[spanish]{%
   \ifcase\xpg@nr\relax
      % spanish:
      \@spanish@mexicofalse%
      \SetLanguageKeys{spanish}{babelname=spanish,bcp47=es-ES}%
   \or
      % mexican:
      \@spanish@mexicotrue%
      \SetLanguageKeys{spanish}{babelname=spanishmx,bcp47=es-MX}%
   \fi
   \xpg@info{Option: spanish, variant=\xpg@val}%
}{\xpg@warning{Unknown spanish variant `#1'}}

% Localized math operators à la babel
\newif\ifspanish@accentedoperators
\newif\ifspanish@spacedoperators
\newif\ifspanish@locoperators

\define@choicekey*+{spanish}{spanishoperators}[\xpg@val\xpg@nr]{all,accented,spaced,none}[all]{%
   \ifcase\xpg@nr\relax
      % all:
      \spanish@locoperatorstrue%
      \spanish@accentedoperatorstrue%
      \spanish@spacedoperatorstrue%
   \or
      % accented:
      \spanish@locoperatorsfalse%
      \spanish@accentedoperatorstrue%
      \spanish@spacedoperatorsfalse%
   \or
      % spaced:
      \spanish@locoperatorsfalse%
      \spanish@accentedoperatorsfalse%
      \spanish@spacedoperatorstrue%
   \or
      % none:
      \spanish@locoperatorsfalse%
      \spanish@accentedoperatorsfalse%
      \spanish@spacedoperatorsfalse%
   \fi
   \xpg@info{Option: Spanish, spanishoperators=\xpg@val}%
}{\xpg@warning{Unknown spanishoperators value `#1'}}


% Register default options
\xpg@initialize@gloss@options{spanish}{variant=spanish,spanishoperators=none}

\let\xpg@save@lim\lim
\let\xpg@save@limsup\limsup
\let\xpg@save@liminf\liminf
\let\xpg@save@max\max
\let\xpg@save@min\min
\let\xpg@save@inf\inf
\let\xpg@save@bmod\bmod
\let\xpg@save@pmod\pmod

\def\spanish@accentedoperators{%
  \DeclareRobustCommand\lim{\mathop{\operator@font lím}}%
  \DeclareRobustCommand\limsup{\mathop{\operator@font lím\,sup}}%
  \DeclareRobustCommand\liminf{\mathop{\operator@font lím\,inf}}%
  \DeclareRobustCommand\max{\mathop{\operator@font máx}}%
  \DeclareRobustCommand\min{\mathop{\operator@font mín}}%
  \DeclareRobustCommand\inf{\mathop{\operator@font ínf}}%
  \DeclareRobustCommand\bmod{%
    \nonscript\mskip-\medmuskip\mkern5mu%
    \mathbin{\operator@font mód}\penalty900\mkern5mu%
    \nonscript\mskip-\medmuskip}%
  \@ifundefined{@amsmath@err}%
    {\DeclareRobustCommand\pmod[1]{%
       \allowbreak\mkern18mu({\operator@font mód}\,\,##1)}}%
    {\let\xpg@save@mod\mod
     \DeclareRobustCommand\mod[1]{\allowbreak\if@display\mkern18mu
        \else\mkern12mu\fi{\operator@font mód}\,\,##1}%
     \DeclareRobustCommand\pmod[1]{\pod{{\operator@font mód}%
        \mkern6mu##1}}}%
}

\def\nospanish@accentedoperators{%
  \let\lim\xpg@save@lim%
  \let\limsup\xpg@save@limsup%
  \let\liminf\xpg@save@liminf%
  \let\max\xpg@save@max%
  \let\min\xpg@save@min%
  \let\inf\xpg@save@inf%
  \let\bmod\xpg@save@bmod%
  \let\pmod\xpg@save@pmod%
  \@ifundefined{@amsmath@err}{}{\let\mod\xpg@save@mod}%
}

\let\xpg@save@arccos\arccos
\let\xpg@save@arcsin\arcsin
\let\xpg@save@arctan\arctan
\let\arcsen\arcsin
\let\arctg\arctan


\def\spanish@spacedoperators{%
  \DeclareRobustCommand\arccos{\mathop{\operator@font arc\,cos}\nolimits}%
  \DeclareRobustCommand\arcsin{\mathop{\operator@font arc\,sen}\nolimits}%
  \DeclareRobustCommand\arctan{\mathop{\operator@font arc\,tg}\nolimits}%
}

\def\nospanish@spacedoperators{%
  \let\arccos\xpg@save@arccos%
  \let\arcsen\arcsin%
  \let\arctg\arctan%
}


\let\xpg@save@sin\sin
\let\xpg@save@tan\tan
\let\xpg@save@sinh\sinh
\let\xpg@save@tanh\tanh
\let\sen\sin
\let\tg\tan
\let\senh\sinh
\let\tgh\tanh

\def\spanish@locoperators{%
  \DeclareRobustCommand\sin{\mathop{\operator@font sen}\nolimits}%
  \DeclareRobustCommand\tan{\mathop{\operator@font tg}\nolimits}%
  \DeclareRobustCommand\sinh{\mathop{\operator@font senh}\nolimits}%
  \DeclareRobustCommand\tanh{\mathop{\operator@font tgh}\nolimits}%
}

\def\nospanish@locoperators{%
  \let\sen\xpg@save@sin%
  \let\tg\xpg@save@tan%
  \let\sinh\xpg@save@sinh%
  \let\tanh\xpg@save@tanh%
  \let\sen\relax%
  \let\tg\relax%
  \let\senh\relax%
  \let\tgh\relax%
}

\newcommand*\spanishoperator[2][]{%
  \ifx#1\\\\
    \protected@csxdef{#2}{\mathop{\operator@font #2}\nolimits}%
  \else
    \protected@csxdef{#2}{\mathop{\operator@font #1}\nolimits}%
  \fi
}

\def\captionsspanish{%
  \def\prefacename{Prefacio}%
  \def\refname{Referencias}%
  \def\abstractname{Resumen}%
  \def\bibname{Bibliografía}%
  \def\chaptername{Capítulo}%
  \def\appendixname{Apéndice}%
  \def\contentsname{Índice general}%
  \def\listfigurename{Índice de figuras}%
  \def\listtablename{Índice de cuadros}%
  \def\indexname{Índice alfabético}%
  \def\figurename{Figura}%
  \def\tablename{Cuadro}%
  \def\partname{Parte}%
  \def\enclname{Adjunto(s)}%
  \def\ccname{Copia a}%
  \def\headtoname{A}%
  \def\pagename{Página}%
  \def\seename{véase}%
  \def\alsoname{véase también}%
  \def\proofname{Prueba}%
  \def\glossaryname{Glosario}%
  \if@spanish@mexico
    \captionsspanish@mexico%
  \fi%
}

\def\captionsspanish@mexico{%
  \def\tablename{Tabla}%
}

\def\datespanish{%
  \def\today{\number\day~de~\ifcase\month\or
    enero\or febrero\or marzo\or abril\or mayo\or junio\or
    julio\or agosto\or septiembre\or octubre\or noviembre\or
    diciembre\fi\space de~\number\year}%
}

\def\noextras@spanish{%
  \nospanish@accentedoperators%
  \nospanish@spacedoperators%
  \nospanish@locoperators%
}

\def\blockextras@spanish{%
  \ifspanish@accentedoperators\spanish@accentedoperators\fi%
  \ifspanish@spacedoperators\spanish@spacedoperators\fi%
  \ifspanish@locoperators\spanish@locoperators\fi%
}

\def\inlineextras@spanish{%
  \ifspanish@accentedoperators\spanish@accentedoperators\fi%
  \ifspanish@spacedoperators\spanish@spacedoperators\fi%
  \ifspanish@locoperators\spanish@locoperators\fi%
}

%    \end{macrocode}
% \iffalse
%</gloss-spanish.ldf>
%<*gloss-spanishmx.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-spanishmx.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-spanishmx.ldf}[polyglossia: module for mexican spanish]

% We provide this as a babel alias

\xpg@load@master@language{spanish}

%    \end{macrocode}
% \iffalse
%</gloss-spanishmx.ldf>
%<*gloss-swedish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-swedish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-swedish.ldf}[polyglossia: module for swedish]

\PolyglossiaSetup{swedish}{
  bcp47=sv,
  hyphennames={swedish},
  hyphenmins={2,2},
  langtag=SVE,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{swedish}{sv}

\def\captionsswedish{%
  \def\refname{Referenser}%
  \def\abstractname{Sammanfattning}%
  \def\bibname{Litteraturförteckning}%
  \def\prefacename{Förord}%
  \def\chaptername{Kapitel}%
  \def\appendixname{Bilaga}%
  \def\contentsname{Innehåll}%
  \def\listfigurename{Figurer}%
  \def\listtablename{Tabeller}%
  \def\indexname{Sakregister}%
  \def\figurename{Figur}%
  \def\tablename{Tabell}%
  %\def\thepart{}%
  \def\partname{Del}%
  \def\pagename{Sida}%
  \def\seename{se}%
  \def\alsoname{se även}%
  \def\enclname{Bil.}%
  \def\ccname{Kopia för kännedom}%
  \def\headtoname{Till}%
  \def\proofname{Bevis}%
  \def\glossaryname{Ordlista}%
  }

\def\dateswedish{%   
  \def\today{%
    \number\day~\ifcase\month\or
    januari\or februari\or mars\or april\or maj\or juni\or
    juli\or augusti\or september\or oktober\or november\or
    december\fi
    \space\number\year}%
    \def\datesymd{%
      \def\today{\number\year-\two@digits\month-\two@digits\day}}%
    \def\datesdmy{%
     \def\today{\number\day/\number\month\space\number\year}}%
    }

%    \end{macrocode}
% \iffalse
%</gloss-swedish.ldf>
%<*gloss-swissgerman.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-swissgerman.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-swissgerman.ldf}[polyglossia: module for swiss german (old spelling)]

% We provide this as a babel alias

\xpg@load@master@language{german}

%    \end{macrocode}
% \iffalse
%</gloss-swissgerman.ldf>
%<*gloss-syriac.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-syriac.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-syriac.ldf}[polyglossia: module for syriac]

\RequireBidi
\RequirePackage{arabicnumbers}

\PolyglossiaSetup{syriac}{
  bcp47=syr,
  script=Syriac,
  scripttag=syrc,
  langtag=SYR,
  direction=RL,
  hyphennames={syriac,nohyphenation},
  fontsetup=true,
  localnumeral=syriacnumerals
  %TODO localalph
}

% BCP-47 compliant aliases
\setlanguagealias*{syriac}{syr}

\def\syriacnumber#1{\@syriacnumber{#1}}%

\newif\if@eastern@numerals
\def\tmp@eastern{eastern}
\def\tmp@abjad{abjad}
\define@key{syriac}{numerals}[western]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@abjad
	  \let\syriacnumber\abjadsyriac
	\else
	  \ifx\@tmpa\tmp@eastern
      \@eastern@numeralstrue
	  \else
      \@eastern@numeralsfalse
 	  \fi
  \fi}

% Register default options
\xpg@initialize@gloss@options{syriac}{numerals=western}
	
%\define@key{polyglossia}{syriaclocale}[default]{%
%	\def\@syriac@locale{#1}}
%
%\def\captionssyriac{%
%\def\prefacename{\@ensure@RTL{}}% 
%\def\refname{\@ensure@RTL{}}
%\def\abstractname{\@ensure@RTL{}}%
%\def\bibname{\@ensure@RTL{}}%
%\def\chaptername{\@ensure@RTL{}}%
%\def\appendixname{\@ensure@RTL{}}%
%\def\contentsname{\@ensure@RTL{}}
%\def\listfigurename{\@ensure@RTL{}}%
%\def\listtablename{\@ensure@RTL{}}%
%\def\indexname{\@ensure@RTL{}}%
%\def\figurename{\@ensure@RTL{}}%
%\def\tablename{\@ensure@RTL{}}%
%\def\partname{\@ensure@RTL{}}%
%\def\enclname{\@ensure@RTL{}}%
%\def\ccname{\@ensure@RTL{}}%
%\def\headtoname{\@ensure@RTL{}}%
%\def\pagename{\@ensure@RTL{}}%
%\def\seename{\@ensure@RTL{}}%
%\def\alsoname{\@ensure@RTL{}}%
%\def\proofname{\@ensure@RTL{}}%
%\def\glossaryname{\@ensure@RTL{}}%
%}

\def\datesyriac{%
  \def\syriac@month##1{\ifcase##1%
  \or ܟܢܘܢ ܐܚܪܝ\or ܫܒܛ\or ܐܕܪ\or ܢܝܣܢ\or ܐܝܪ\or ܚܙܝܪܢ\or ܬܡܘܙ\or ܐܒ\or ܐܝܠܘܠ% ܐܠܘܠ
   \or ܬܫܪܝܢ ܩܕܡ% ܬܫܪܝܢ ܩܕܝܡ
   \or ܬܫܪܝܢ ܐܚܪܝ\or ܟܢܘܢ ܩܕܡ% ܟܢܘܢ ܩܕܝܡ
   \fi}%
   \def\today{\@ensure@RTL{\syriacnumber\day{\space}%
    \syriac@month{\month}{\space}\syriacnumber\year}}%
}

\def\syriac@zero{}

\def\abjadsyriac#1{%
\ifnum#1>9999\xpg@ill@value{#1}{abjadsyriac}%
\else%
  \ifnum#1<\z@\space\xpg@ill@value{#1}{abjadsyriac}%
  \else%
    \ifnum#1<10\expandafter\abj@syr@num@i\number#1%
    \else%
      \ifnum#1<100\expandafter\abj@syr@num@ii\number#1%
      \else%
        \ifnum#1<1000\expandafter\abj@syr@num@iii\number#1%
	\else%
          \expandafter\abj@syr@num@iv\number#1%
	\fi%
      \fi%
    \fi%
  \fi%
\fi%
}
\def\abj@syr@num@i#1{%
  \ifcase#1\or\char"0710\or\char"0712\or\char"0713\or\char"0715%
 \or\char"0717\or\char"0718\or\char"0719\or\char"071A\or\char"071B\fi
  \ifnum#1=\z@\syriac@zero\fi}
\def\abj@syr@num@ii#1{%
  \ifcase#1\or\char"071D\or\char"071F\or\char"0720\or\char"0721\or\char"0722%
          \or\char"0723\or\char"0725\or\char"0726\or\char"0728\fi
  \ifnum#1=\z@\fi\abj@syr@num@i}
\def\abj@syr@num@iii#1{%
  \ifcase#1\or\char"0729\or\char"072A\or\char"072B\or\char"072C%
  \or\char"0722\char"0307\or\char"0723\char"0307\or\char"0725\char"0307%
  \or\char"0726\char"0307\or\char"0728\char"0307\fi
  \ifnum#1=\z@\fi\abj@syr@num@ii}
\def\abj@syr@num@iv#1{%
  \ifcase#1\or\char"0710\char"0748\or\char"0712\char"0748%
  \or\char"0713\char"0748\or\char"0715\char"0748%
  \or\char"0717\char"0748\or\char"0718\char"0748%
  \or\char"0719\char"0748\or\char"071A\char"0748\or\char"071B\char"0748\fi
  \ifnum#1=\z@\fi\abj@syr@num@iii}

\def\@syriacnumber#1{%
   \if@eastern@numerals
      %%% we test for the presence of one of ١٢٣٤٥٦٧٨٩٠ in the Syriac font, 
      %%% else we try \arabicfont if defined (and give a warning), 
      %%% else we fall back to the Western numerals.
      \xpg@if@char@available{0661}%
          {\protect\arabicdigits{\number#1}}%
          {\arabicdigits{\number#1}
           \ifcsdef{arabicfont}%
	     {\protect\arabicdigits{\number#1}%
	      \xpg@warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs:
                           I am using \string\arabicfont instead}}%
	     {\number#1%%% <---changed from \RL{\protect\reset@font\protect\number#1}%
	      \xpg@warning{You have specified the option numerals=eastern for Syriac, but the Syriac font does not contain the appropriate glyphs:
                           since \string\arabicfont is not defined, we'll use Western numerals instead}}%
          }%
   \else
     %%\RL{\protect\reset@font\number#1}%
     \number#1%
   \fi%
}

\def\syriac@numbers{%
   \let\@alph\abjadsyriac%
   \let\@Alph\abjadsyriac%
}

\def\nosyriac@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}

\newcommand{\syriacnumerals}[2]{\syriacnumber{#2}}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\syriac@globalnumbers{%
  \let\@arabic\syriacnumber%
  \renewcommand\thefootnote{\localnumeral*{footnote}}%
}

\def\nosyriac@globalnumbers{%
  \let\@arabic\xpg@save@arabic%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@syriac{%
   \def\MakeUppercase##1{##1}%
}

\def\noextras@syriac{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-syriac.ldf>
%<*gloss-tamil.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-tamil.ldf}
%    \begin{macrocode}
﻿\ProvidesFile{gloss-tamil.ldf}[polyglossia: module for tamil]

% Translations provided by Kevin & Siji, 01-11-2009

\PolyglossiaSetup{tamil}{
  bcp47=ta,
  script=Tamil,
  scripttag=taml,
  langtag=TAM,
  hyphennames={tamil},
  hyphenmins={2,2}, %FIXME?
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{tamil}{ta}

\def\captionstamil{%
     \def\abstractname{சாராம்சம்}%
     \def\appendixname{பிற்சேர்க்கை}%பின்னிணைப்பு
     %\def\bibname{}%
     %\def\ccname{}%
     \def\chaptername{அத்தியாயம்}%
     \def\contentsname{உள்ளே}%
     %\def\enclname{}%
     \def\figurename{படம்}%
     %\def\headpagename{}%
     %\def\headtoname{}%
     \def\indexname{சுட்டி}%பொருளடக்க அட்டவணை
     \def\listfigurename{படங்களின் பட்டியல்}%
     \def\listtablename{அட்டவணை பட்டியல்}%
     %\def\pagename{}%
     \def\partname{பகுதி}%
     %\def\prefacename{}% 
     %\def\refname{}%
     \def\tablename{அட்டவணை}%
     \def\seename{பார்க்க}%
     %\def\alsoname{}%
     %\def\alsoseename{}%
}
\def\datetamil{%
   \def\today{\number\year\space\ifcase\month\or
     ஜனவரி\or
     பிப்ரவரி\or
     மார்ச்\or
    ஏப்ரல்\or
     மே\or
     ஜூன்\or
     ஜூலை\or
    ஆகஸ்ட்\or
     செப்டம்பர்\or
     அக்டோபர்\or
     நவம்பர்\or
     டிசம்பர்\fi
     \space\number\day}%
}

%    \end{macrocode}
% \iffalse
%</gloss-tamil.ldf>
%<*gloss-telugu.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-telugu.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-telugu.ldf}[polyglossia: module for telugu]

% Translations provided by Anmol Sharma <unmole.in@gmail.com>

\PolyglossiaSetup{telugu}{
  bcp47=te,
  script=Telugu,
  scripttag=telu,
  langtag=TEL,
  hyphennames={telugu},
  hyphenmins={2,2}, %FIXME
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{telugu}{te}

\def\captionstelugu{%
   \def\refname{ఆధారాలు}%
   \def\abstractname{సారాంశం}%
   \def\bibname{గ్రంథాల జాబితా}%
   \def\prefacename{ముందుమాట}%
   \def\chaptername{అధ్యాయము}%
   \def\appendixname{అదనంగా}%
   \def\contentsname{విషయాలు}%
   \def\listfigurename{ఆకృతుల జాబితా}%
   \def\listtablename{పట్టికల జాబితా}%
   \def\indexname{విషయ సూచిక}%
   \def\figurename{ఆకృతి}%
   \def\tablename{పట్టిక}%
   %\def\thepart{}%
   \def\partname{భాగం}%
   \def\pagename{పేజి}%
   \def\seename{చూడండి}%
   \def\alsoname{కూడా చూడండి}%
   \def\enclname{ఎంక్లోజర్*}%
   \def\ccname{సిసి}%
   \def\headtoname{కి}%
   \def\proofname{రుజువు}%
   \def\glossaryname{నిఘంటువు}%
}

\def\datetelugu{%
   \def\telugu@month{%
      \ifcase\month\or
         జనవరి\or
         ఫిబ్రవరి\or
         మార్చ్\or
         ఏప్రిల్\or
         మే\or
         జూన్\or
         జూలై\or
         ఆగస్ట్\or
         సెప్టెంబర్\or
         అక్తోబెర్\or
         నవంబర్\or
         డిసంబర్\fi}%
   \def\today{\telugu@month\space\number\day,\space\number\year}%
}

%    \end{macrocode}
% \iffalse
%</gloss-telugu.ldf>
%<*gloss-thai.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-thai.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-thai.ldf}[polyglossia: module for thai]
%% This is partly based on thai-latex for Babel:
%%%% Copyright (C) 1999 - 2006
%%%%           by Surapant Meknavin,
%%%%              Theppitak Karoonboonyanan (thep at linux.thai.net),
%%%%              Chanop Silpa-Anan (chanop at debian.org),
%%%%              Poonlap Veerathanabutr (poonlap at linux.thai.net)
%%%%              Thai Linux Working Group
%%%%              http://linux.thai.net/
%%%%
\PolyglossiaSetup{thai}{
  bcp47=th,
  script=Thai,
  scripttag=thai,
  langtag=THA,
  hyphennames={nohyphenation},
  fontsetup=true,
  localnumeral=thainumerals
  %TODO localalph={xxx@alph,xxx@Alph}
  %TODO localdigits=thainumber
}

% BCP-47 compliant aliases
\setlanguagealias*{thai}{th}

\newif\if@thai@numerals
\def\tmp@thai{thai}
\define@key{thai}{numerals}[arabic]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@thai\@thai@numeralstrue\else
	  \@thai@numeralsfalse\fi
}

% Register default options
\xpg@initialize@gloss@options{thai}{numerals=arabic}

\def\captionsthai{%
   \def\refname{หนังสืออ้างอิง}%
   \def\abstractname{บทคัดย่อ}%
   \def\bibname{บรรณานุกรม}%
   \def\prefacename{คำนำ}%
   \def\chaptername{บทที่}%
   \def\appendixname{ภาคผนวก}%
   \def\contentsname{สารบัญ}%
   \def\listfigurename{สารบัญรูป}%
   \def\listtablename{สารบัญตาราง}%
   \def\indexname{ดรรชนี}%
   \def\figurename{รูปที่}%
   \def\tablename{ตารางที่}%
   %\def\thepart{}%
   \def\partname{ภาค}%
   \def\pagename{หน้า}%
   \def\seename{ดู}%
   \def\alsoname{ดูเพิ่มเติม}%
   \def\enclname{สิ่งที่แนบมาด้วย}%
   \def\ccname{สำเนาถึง}%
   \def\headtoname{เรียน}%
   \def\proofname{พิสูจน์}%
   %\def\glossaryname{}%
}
\def\datethai{%   
   \def\thai@month{%
     \ifcase\month\or
       มกราคม\or กุมภาพันธ์\or มีนาคม\or เมษายน%
      \or พฤษภาคม\or มิถุนายน\or กรกฎาคม\or สิงหาคม%
      \or กันยายน\or ตุลาคม\or พฤศจิกายน\or ธันวาคม\fi}%
   \newcount\thai@year%
   \thai@year=\year%
   \advance\thai@year by 543%
   \def\today{\thainumber\day \space \thai@month\space พ.ศ.~\thainumber\thai@year}%
}

%NB: thai-latex had "plus 0.6pt", but .4em appears to give better results
% FIXME to avoid name clashes, rename \wbr to \wordbreak or \thaiworkbreak ?
\def\wbr{\hskip0pt plus .4em\relax} %%OR \char"200B = ZWSP ? Does not work
%\catcode"200b=\active
%\def^^200b{\hskip 0pt plus .4em}

\def\thaidigits#1{\expandafter\@thai@digits #1@}
\def\@thai@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1๐\else\ifx1#1๑\else\ifx2#1๒\else\ifx3#1๓\else\ifx4#1๔\else\ifx5#1๕\else\ifx6#1๖\else\ifx7#1๗\else\ifx8#1๘\else\ifx9#1๙\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@thai@digits
  \fi
}

\newcommand{\thainumerals}[2]{\thainumber{#2}}

\def\thainumber#1{%
  \if@thai@numerals
    \thaidigits{\number#1}%
    %%{\protect\addfontfeature{Mapping=thaidigits}\protect\number#1}
  \else
    \number#1%
    %%{\protect\reset@font\number#1}
  \fi}

\def\@thaialph#1{%
  \ifcase#1\or ก\or ข\or ค\or ง\or จ\or ฉ\or ช\or ซ\or ฌ\or ญ\or ฎ\or
   ฏ\or ฐ\or ฑ\or ฒ\or ณ\or ด\or ต\or ถ\or ท\or ธ\or น\or บ\or ป\or ผ\or
   ฝ\or พ\or ฟ\or ภ\or ม\or ย\or ร\or ล\or ว\or ศ\or ษ\or ส\or ห\or ฬ\or อ\or
   ฮ\else\xpg@ill@value{#1}{@thaialph}\fi}
\def\thaiAlph#1{\expandafter\@thaiAlph\csname c@#1\endcsname}
\def\@thaiAlph#1{%
  \ifcase#1\or ก\or ข\or ฃ\or ค\or ฅ\or ฆ\or ง\or จ\or ฉ\or ช\or ซ\or
   ฌ\or ญ\or ฎ\or ฏ\or ฐ\or ฑ\or ฒ\or ณ\or ด\or ต\or ถ\or ท\or ธ\or น\or
    บ\or ป\or ผ\or ฝ\or พ\or ฟ\or ภ\or ม\or ย\or ร\or ฤ\or ล\or ฦ\or ว\or
     ศ\or ษ\or ส\or ห\or ฬ\or อ\or ฮ\else\xpg@ill@value{#1}{@thaialph}\fi}
     
\def\thai@numbers{%
   \if@thai@numerals
     \let\@alph\@thaialph%
     \let\@Alph\@thaiAlph%
   \fi
}
\def\nothai@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}

\def\thai@globalnumbers{%
   \let\orig@arabic\@arabic%
   \let\@arabic\thainumber%
   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
}
\def\nothai@globalnumbers{%
   \let\@arabic\orig@arabic%
}

\def\blockextras@thai{%
%%TODO \XeTeXlinebreaklocales "th"% uses ICU to find line breaks on the basis of a dictionary lookup-- make this optional? (in case a user might prefer a preprocessor
   \let\orig@baselinestrech\baselinestretch%
   \renewcommand{\baselinestretch}{1.2}%
}
\def\noblockextras@thai{%
%%TODO \XeTeXlinebreaklocales "en"%
   \let\baselinestrech\orig@baselinestretch%
}

%    \end{macrocode}
% \iffalse
%</gloss-thai.ldf>
%<*gloss-tibetan.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-tibetan.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-tibetan.ldf}[polyglossia: module for tibetan]
%% Copyright 2013 Elie Roux
%% Under the CC0 license <http://creativecommons.org/publicdomain/zero/1.0/>
%%
%% A good font to make tests is \newfontfamily\tibetanfont{Tibetan Machine Uni}
%%

\PolyglossiaSetup{tibetan}{
  bcp47=bo,
  script=Tibetan,
  scripttag=tibt,
  langtag=TIB,
  hyphennames={nohyphenation},
  fontsetup=true,
  localnumeral=tibetannumerals
  %TODO localalph={xxx@alph,xxx@Alph}
}

% BCP-47 compliant aliases
\setlanguagealias*{tibetan}{bo}

\newif\if@tibetan@numerals
\def\tmp@tibetan{tibetan}
\define@key{tibetan}{numerals}[tibetan]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@tibetan\@tibetan@numeralstrue\else
	  \@tibetan@numeralsfalse\fi
}

\ifluatex
  \newluatexattribute\xpg@tibteol %
  \directlua{polyglossia.load_tibt_eol()}%
\fi

\def\tibetan@eol{%
  \ifluatex %
    \xpg@tibteol=1\relax %
    \directlua{polyglossia.activate_tibt_eol()}%
  \else %
    \XeTeXlinebreaklocale "bo"%
    \XeTeXlinebreakskip=0pt plus 0.1em% doesn't do much, but doesn't harm I guess...
  \fi %
}

\def\notibetan@eol{%
  \ifluatex %
    \xpg@tibteol=0\relax %
    %\directlua{polyglossia.activate_tibt_eol()}%
  \else %
    \XeTeXlinebreaklocale "en"% en? really?
    \XeTeXlinebreakskip=0pt plus 0pt%
  \fi %
}

% Register default options
\xpg@initialize@gloss@options{tibetan}{numerals=tibetan}

% some are known, but very few
% a few come from "Standardizing Tibetan Terms of Information Technology"
% from the China Tibetology Research Center
\def\captionstibetan{%
   %\def\refname{}%
   \def\abstractname{གནད་བསྡུས།}%
   \def\bibname{དཔེ་ཆའི་ཐོ་གཞུང་།}% or dpe deb kyi re'u mig?
   \def\prefacename{དཔེ་དེབ་ཀྱི་གླེང་བརྗོད།}% or gleng brjod 'god pa or ngo sprod?
   \def\chaptername{ལེའུ་}%
   \def\appendixname{ཞར་བྱུང་།}%
   \def\contentsname{དཀར་ཆག།}%
   %\def\listfigurename{}%
   %\def\listtablename{}%
   \def\indexname{གསུལ་བྱང་།}%
   \def\figurename{པར་རིས་}% or dpe ris?
   \def\tablename{རེའུ་མིག་}%
   %\def\thepart{}%
   \def\partname{ཆ་ཤས་}%
   \def\pagename{ཤོག་}%
   %\def\seename{}%
   %\def\alsoname{}%
   %\def\enclname{}%
   \def\ccname{འདྲ་བཤུས་ལེན་མཁན་}%
   %\def\headtoname{}%
   \def\proofname{བདེན་དཔང་།}% not sure about this one...
   \def\glossaryname{མིང་ཚིག་རེའུ་མིག།}%
}
\def\datetibetan{%   
   \def\tibetan@month{%
     \ifcase\month\or
       ཟླ་དང་པོ\or ཟླ་གཉིས་པ\or ཟླ་གསུམ་པ%
      \or ཟླ་བཞི་པ\or ཟླ་ལྔ་པ\or ཟླ་དྲུག་པ\or ཟླ་བདུན་པ%
      \or ཟླ་བརྒྱད་པ\or ཟླ་དགུ་པ\or ཟླ་བཆུ་པ\or ཟླ་བཆུ་གཅིག་པ\or ཟླ་བཆུ་གཉིས་པ\fi}%      
   \def\tibetan@daynum{%
     \ifcase\day\or དང་པོ\or གཉིས་པ\or གསུམ་པ \or བཞི་པ\or ལྔ་པ\or དྲུག་པ\or བདུན་པ\or བརྒྱད་པ\or དགུ་པ\or བཆུ་པ%
 \or བཆུ་གཅིག་པ\or བཆུ་གཉིས་པ\or བཆུ་གསུམ་པ\or བཆུ་བཞི་པ\or བཆུ་ལྔ་པ\or བཆུ་དྲུག་པ\or བཆུ་བདུན་པ\or བཆུ་བརྒྱད་པ\or བཆུ་དགུ་པ\or ཉི་ཤུ་པ%
 
 \or ཉི་ཤུ་རྩ་གཅིག་པ\or ཉི་ཤུ་རྩ་གཉིས་པ\or ཉི་ཤུ་རྩ་གསུམ་པ\or ཉི་ཤུ་རྩ་བཞི་པ\or ཉི་ཤུ་རྩ་ལྔ་པ\or ཉི་ཤུ་རྩ་དྲུག་པ\or ཉི་ཤུ་རྩ་བདུན་པ\or ཉི་ཤུ་རྩ་བརྒྱད་པ\or ཉི་ཤུ་རྩ་དགུ་པ\or སུམ་ཆུ་པ%
 \or སུམ་ཆུ་སོ་གཅིག་པ\fi}%      
   % As we use gregorian calendar, it's better to stick with spyi lo
   %\newcount\tibetan@year%
   %\tibetan@year=\year%
   %\advance\tibetan@year by 127% this is bod rgyal lo, the most common, but there are others...
   % I'm not sure the / character is in most tibetan fonts
   %\def\today{\tibetannumber\day /\tibetannumber\day /\tibetannumber\year}%
   \def\today{\tibetannumber\day །\tibetannumber\month །\tibetannumber\year}%
   % this is more litterate, but longer
   %\def\today{སྤྱི་ལོ་\tibetannumber\year ་སྤྱི་\tibetan@month{}་ད་རེས་\tibetan@daynum{}།}%  
}

\def\tibetandigits#1{\expandafter\@tibetan@digits #1@}
\def\@tibetan@digits#1{%
  \ifx @#1% then terminate
  \else
    \ifx0#1༠\else\ifx1#1༡\else\ifx2#1༢\else\ifx3#1༣\else\ifx4#1༤\else\ifx5#1༥\else\ifx6#1༦\else\ifx7#1༧\else\ifx8#1༨\else\ifx9#1༩\else#1\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
    \expandafter\@tibetan@digits
  \fi
}

\def\tibetannumber#1{%
  \if@tibetan@numerals
    \tibetandigits{\number#1}%
    %%{\protect\addfontfeature{Mapping=tibetandigits}\protect\number#1}
  \else
    \number#1%
    %%{\protect\reset@font\number#1}
  \fi}

\def\@tibetanalph#1{%
  \ifcase#1\or ཀ\or ཁ\or ག\or ང\or ཅ\or ཆ\or ཇ\or ཉ\or ཏ\or ཐ\or ད\or ན\or པ\or 
  ཕ\or བ\or མ\or ཙ\or ཚ\or ཛ\or ཝ\or ཞ\or ཟ\or འ\or ཡ\or ར\or ལ\or ཤ\or ས\or ཧ\or ཨ
 \else\xpg@ill@value{#1}{@tibetanalph}\fi}
\def\tibetanAlph#1{\expandafter\@tibetanAlph\csname c@#1\endcsname}
\def\@tibetanAlph#1{%
  \ifcase#1\or ཀ\or ཁ\or ག\or ང\or ཅ\or ཆ\or ཇ\or ཉ\or ཏ\or ཐ\or ད\or ན\or པ\or 
  ཕ\or བ\or མ\or ཙ\or ཚ\or ཛ\or ཝ\or ཞ\or ཟ\or འ\or ཡ\or ར\or ལ\or ཤ\or ས\or ཧ\or ཨ
 \else\xpg@ill@value{#1}{@tibetanalph}\fi}

\newcommand{\tibetanumerals}[2]{\tibetannumber{#2}}

\def\tibetan@numbers{%
   \if@tibetan@numerals
     \let\@alph\@tibetanalph%
     \let\@Alph\@tibetanAlph%
   \fi
}
\def\notibetan@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}

\def\tibetan@globalnumbers{%
   \let\xpg@orig@arabic\@arabic%
   \let\@arabic\tibetannumber%
   \renewcommand{\thefootnote}{\localnumeral*{footnote}}%
}

\def\notibetan@globalnumbers{%
   \let\@arabic\xpg@orig@arabic%
}

\def\noextras@tibetan{%
   \notibetan@eol%
   \ifcsname xpg@orig@baselinestretch\endcsname\renewcommand{\baselinestretch}{\xpg@orig@baselinestretch}\fi %
   }

\def\inlineextras@tibetan{%
   \xdef\xpg@orig@baselinestretch{\ifcsname baselinestretch\endcsname \baselinestretch \else 1\fi}%
   \renewcommand{\baselinestretch}{1.2}%
   \tibetan@eol%
   }

\def\blockextras@tibetan{%
   \xdef\xpg@orig@baselinestretch{\ifcsname baselinestretch\endcsname \baselinestretch \else 1\fi}%
   \renewcommand{\baselinestretch}{1.2}%
   \tibetan@eol%
}

%    \end{macrocode}
% \iffalse
%</gloss-tibetan.ldf>
%<*gloss-turkish.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-turkish.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-turkish.ldf}[polyglossia: module for turkish]
\RequirePackage{hijrical}
\PolyglossiaSetup{turkish}{
  bcp47=tr,
  hyphennames={turkish},
  hyphenmins={2,2},
  langtag=TRK,
  frenchspacing=true,
  fontsetup=true
  }

% TODO Add \ifluatex branch everywhere
\ifxetex
\newXeTeXintercharclass\turkish@punctthin % ! :
\newXeTeXintercharclass\turkish@punctthick % =
\fi

\def\turkish@punctthinspace{{\ifdim\lastskip>\z@\unskip\penalty\@M\thinspace\fi}}
\def\turkish@punctthickspace{{\unskip\nobreakspace}}

\def\turkish@punctuation{%
   \ifxetex
   \XeTeXinterchartokenstate=1%
   \XeTeXcharclass `\! \turkish@punctthin
   \XeTeXcharclass `\: \turkish@punctthin
   \XeTeXcharclass `\= \turkish@punctthick
   \XeTeXinterchartoks \z@ \turkish@punctthin = \turkish@punctthinspace
   \XeTeXinterchartoks \z@ \turkish@punctthick = \turkish@punctthickspace
   \fi
}

% BCP-47 compliant aliases
\setlanguagealias*{turkish}{tr}

\def\noturkish@punctuation{%
   \ifxetex
   \XeTeXcharclass `\! \z@
   \XeTeXcharclass `\: \z@
   \XeTeXcharclass `\= \z@
   \XeTeXinterchartokenstate=0%
   \fi
}

\def\turkish@casing{%
  \lccode`\I=`\ı
  \uccode`\i=`\İ
}

\def\noturkish@casing{%
  \lccode`\I=`\i
  \uccode`\i=`\I
}

\def\captionsturkish{%
  \def\prefacename{Önsöz}%
  \def\refname{Kaynaklar}%
  \def\abstractname{Özet}%
  \def\bibname{Kaynakça}%
  \def\chaptername{Bölüm}%
  \def\appendixname{Ek}%
  \def\contentsname{İçindekiler}%
  \def\listfigurename{Şekil Listesi}%
  \def\listtablename{Tablo Listesi}%
  \def\indexname{Dizin}%
  \def\figurename{Şekil}%
  \def\tablename{Tablo}%
  \def\partname{Kısım}%
  \def\enclname{İlişik}%
  \def\ccname{Diğer Alıcılar}%
  \def\headtoname{Alıcı}%
  \def\pagename{Sayfa}%
  \def\subjectname{İlgili}%
  \def\seename{bkz.}%
  \def\alsoname{ayrıca bkz.}%
  \def\proofname{Kanıt}%
  \def\glossaryname{Lügatçe}%
   }
\def\dateturkish{%
   \def\today{\number\day~\ifcase\month\or
    Ocak\or Şubat\or Mart\or Nisan\or Mayıs\or Haziran\or
    Temmuz\or Ağustos\or Eylül\or Ekim\or Kasım\or
    Aralık\fi
    \space\number\year}%
}
\def\hijrimonthturkish#1{\ifcase#1%
\or Muharrem\or Safer\or Rebiülevvel\or Rebiülahir\or Cemaziyelevvel\or Cemaziyelahir\or Recep\or Şaban\or Ramazan\or Şevval\or Zilkade\or Zilhicce\fi}
%%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{turkish}{%
\number\value{Hijriday}\space\hijrimonthturkish{\value{Hijrimonth}}\space\number\value{Hijriyear}}

\def\noextras@turkish{%
   \noturkish@punctuation%
   \noturkish@casing%
}

\def\blockextras@turkish{%
   \turkish@punctuation%
   \turkish@casing%
}

\def\inlineextras@turkish{%
   \turkish@punctuation%
   \turkish@casing%
}

%    \end{macrocode}
% \iffalse
%</gloss-turkish.ldf>
%<*gloss-turkmen.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-turkmen.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-turkmen.ldf}[polyglossia: module for turkmen]
%% Translations provided by Nazar Annagurban <nazartm at gmail dot com>
\PolyglossiaSetup{turkmen}{
  bcp47=tk,
  hyphennames={turkmen},
  hyphenmins={2,2},
  langtag=TKM,
  frenchspacing=false,
  fontsetup=true
}

% BCP-47 compliant aliases
\setlanguagealias*{turkmen}{tk}

\def\captionsturkmen{%
  \def\prefacename{Sözbaşy}%
  \def\refname{Çeşmeler}%
  \def\abstractname{Gysgaça manysy}%
  \def\bibname{Çeşmeler}%
  \def\chaptername{Bap}%
  \def\appendixname{Goşmaça}%
  \def\contentsname{Mazmuny}%
  \def\listfigurename{Suratlaryň sanawy}%
  \def\listtablename{Tablisalaryň sanawy}%
  \def\indexname{Indeks}%
  \def\figurename{Surat}%
  \def\tablename{Tablisa}%
  \def\partname{Bölüm}%
  \def\enclname{Goşmaça}%
  \def\ccname{Iberilenler}%
  \def\headtoname{Kime}%
  \def\pagename{Sahypa}%
  \def\subjectname{Tema}%
  \def\seename{ser.}%
  \def\alsoname{şuňa-da ser.}%
  \def\proofname{Delil}%
  \def\glossaryname{Sözlük}%
}
\def\dateturkmen{%
   \def\today{\number\day~\ifcase\month\or
    Ýanwar\or Fewral\or Mart\or Aprel\or Maý\or Iýun\or
    Iýul\or Awgust\or Sentýabr\or Oktýabr\or Noýabr\or
    Dekabr\fi
    \space\number\year}%
}
%    \end{macrocode}
% \iffalse
%</gloss-turkmen.ldf>
%<*gloss-ug.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ug.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ug.ldf}[polyglossia: module for ug (Uyghur)]
% BCP 47 tag for Uyghur

\xpg@load@master@language{uyghur}

%    \end{macrocode}
% \iffalse
%</gloss-ug.ldf>
%<*gloss-ukrainian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-ukrainian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-ukrainian.ldf}[polyglossia: module for ukrainian]
% Strings taken from Babel
% and revised by Roman Kyrylych

\RequirePackage{xpg-cyrillicnumbers}

\PolyglossiaSetup{ukrainian}{%
  bcp47=uk,
  script=Cyrillic,
  scripttag=cyrl,
  langtag=UKR,
  hyphennames={ukrainian},
  hyphenmins={2,2},
  frenchspacing=true,
  fontsetup=true,
  localnumeral=ukrainiannumerals,
  Localnumeral=Ukrainiannumerals
}

% BCP-47 compliant aliases
\setlanguagealias*{ukrainian}{uk}

\newif\ifcyrillic@numerals
\newif\ifcyrillic@asbuk@numerals
\define@choicekey*+{ukrainian}{numerals}[\xpg@val\xpg@nr]{arabic,cyrillic,cyrillic-trad,cyrillic-alph}[arabic]{%
   \ifcase\xpg@nr\relax
      % arabic:
      \cyrillic@numeralsfalse%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-trad:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralsfalse%
   \or
      % cyrillic-alph:
      \cyrillic@numeralstrue%
      \cyrillic@asbuk@numeralstrue%
   \fi
   \xpg@info{Option: Ukrainian, numerals=\xpg@val}%
}{\xpg@warning{Unknown Ukrainian numerals value `#1'}}


% Define some math functions
\define@boolkey{ukrainian}[ukrainian@]{mathfunctions}[true]{}

% Register default options
\xpg@initialize@gloss@options{ukrainian}{numerals=arabic,mathfunctions=true}

\define@boolkey{ukrainian}[ukrainian@]{babelshorthands}[true]{}

\ifsystem@babelshorthands
  \setkeys{ukrainian}{babelshorthands=true}
\else
  \setkeys{ukrainian}{babelshorthands=false}
\fi

\ifcsundef{initiate@active@char}{%
  \input{babelsh.def}%
  \initiate@active@char{"}%
  \shorthandoff{"}%
}{}

\def\ukrainian@shorthands{%
  \bbl@activate{"}%
  \def\language@group{ukrainian}%
%  \declare@shorthand{ukrainian}{"`}{„}%
%  \declare@shorthand{ukrainian}{"'}{“}%
%  \declare@shorthand{ukrainian}{"<}{«}%
%  \declare@shorthand{ukrainian}{">}{»}%
  \declare@shorthand{ukrainian}{""}{\hskip\z@skip}%
  \declare@shorthand{ukrainian}{"~}{\textormath{\leavevmode\hbox{-}}{-}}%
  \declare@shorthand{ukrainian}{"=}{\nobreak-\hskip\z@skip}%
  \declare@shorthand{ukrainian}{"|}{\textormath{\nobreak\discretionary{-}{}{\kern.03em}\allowhyphens}{}}%
  \declare@shorthand{ukrainian}{"-}{%
  \def\ukrainian@sh@tmp{%
    \if\ukrainian@sh@next-\expandafter\ukrainian@sh@emdash
    \else\expandafter\ukrainian@sh@hyphen\fi
  }%
  \futurelet\ukrainian@sh@next\ukrainian@sh@tmp}%
  \def\ukrainian@sh@hyphen{%
  \nobreak\-\bbl@allowhyphens}%
  \def\ukrainian@sh@emdash##1##2{\cdash-##1##2}%
  \def\cdash##1##2##3{%
    \def\tempx@{##3}%
    \def\tempa@{-}\def\tempb@{~}\def\tempc@{*}%
    \ifx\tempx@\tempa@\@Acdash\else
    \ifx\tempx@\tempb@\@Bcdash\else
    \ifx\tempx@\tempc@\@Ccdash\else
    \errmessage{Wrong usage of cdash}\fi\fi\fi%
  }%
  \def\@Acdash{\ifdim\lastskip>\z@\unskip\nobreak\hskip.2em\fi
  \cyrdash\hskip.2em\ignorespaces}%
  \def\@Bcdash{\leavevmode\ifdim\lastskip>\z@\unskip\fi
  \nobreak\cyrdash\penalty\exhyphenpenalty\hskip\z@skip\ignorespaces}%
  \def\@Ccdash{\leavevmode
  \nobreak\cyrdash\nobreak\hskip.35em\ignorespaces}%
  \ifx\cyrdash\undefined
    \def\cyrdash{\hbox to.8em{\textendash\hss\textendash}}%
  \fi
  \declare@shorthand{ukrainian}{",}{\nobreak\hskip.2em\ignorespaces}%
}

\def\noukrainian@shorthands{%
  \@ifundefined{initiate@active@char}{}{\bbl@deactivate{"}}%
}

\def\captionsukrainian{%
   \def\refname{Література}%
   \def\abstractname{Анотація}%
   \def\bibname{Бібліоґрафія}%
   \def\prefacename{Вступ}%
   \def\chaptername{Розділ}%
   \def\appendixname{Додаток}%
   \def\contentsname{Зміст}%
   \def\listfigurename{Перелік ілюстрацій}%
   \def\listtablename{Перелік таблиць}%
   \def\indexname{Покажчик}%
   \def\authorname{Іменний покажчик}% babel has "Їменний покажчик"
   \def\figurename{Рис.}%
   \def\tablename{Табл.}%
   %\def\thepart{}%
   \def\partname{Частина}%
   \def\pagename{с.}%
   \def\seename{див.}%
   \def\alsoname{див.\ також}%
   \def\enclname{вкладка}%
   \def\ccname{копія}%
   \def\headtoname{До}%
   \def\proofname{Доведення}%
   \def\glossaryname{Словник термінів}%
}

\def\dateukrainian{%
   \def\today{\number\day~\ifcase\month\or
    січня\or
    лютого\or
    березня\or
    квітня\or
    травня\or
    червня\or
    липня\or
    серпня\or
    вересня\or
    жовтня\or
    листопада\or
    грудня\fi%
    \space\number\year~р.}%
}

% The following is based on some ideas from ruscor.sty
\def\ukrainian@capsformat{%
  \def\@seccntformat##1{\csname pre##1\endcsname%
  \csname the##1\endcsname%
  \csname post##1\endcsname}%
  \def\@aftersepkern{\hspace{0.5em}}%
  \def\postchapter{.\@aftersepkern}%
  \def\postsection{.\@aftersepkern}%
  \def\postsubsection{.\@aftersepkern}%
  \def\postsubsubsection{.\@aftersepkern}%
  \def\postparagraph{.\@aftersepkern}%
  \def\postsubparagraph{.\@aftersepkern}%
  \def\prechapter{}%
  \def\presection{}%
  \def\presubsection{}%
  \def\presubsubsection{}%
  \def\preparagraph{}%
  \def\presubparagraph{}%
}

\newcommand{\ukrainiannumerals}[2]{\ukrainiannumber{#2}}
\newcommand{\Ukrainiannumerals}[2]{\Ukrainiannumber{#2}}

\def\ukrainiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \ukrainian@asbuk@alph{#1}%
    \else
      \cyr@alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\def\Ukrainiannumber#1{%
  \ifcyrillic@numerals
    \ifcyrillic@asbuk@numerals
      \ukrainian@asbuk@Alph{#1}%
    \else
      \cyr@Alph{#1}%
    \fi
  \else
    \number#1%
  \fi%
}

\let\ukrainiannumeral=\ukrainiannumber
\let\Ukrainiannumeral=\Ukrainiannumber

\def\Asbuk#1{\expandafter\ukranian@asbuk@Alph\csname c@#1\endcsname}
\def\asbuk#1{\expandafter\ukranian@asbuk@alph\csname c@#1\endcsname}

\def\AsbukTrad#1{\expandafter\cyr@Alph\csname c@#1\endcsname}
\def\asbukTrad#1{\expandafter\cyr@alph\csname c@#1\endcsname}

% This is a poor man's cyrillic alphanumeric. It just uses the alphabet and
% thus ends at 30.
\def\ukrainian@asbuk@Alph#1{\ifcase#1\or
   А\or Б\or В\or Г\or Д\or Е\or Ж\or
   З\or И\or К\or Л\or М\or Н\or О\or
   П\or Р\or С\or Т\or У\or Ф\or Х\or
   Ц\or Ч\or Ш\or Щ\or Э\or Ю\or Я%
   \else\xpg@ill@value{#1}{ukrainian@asbuk@Alph}\fi%
}

\def\ukrainian@asbuk@alph#1{\ifcase#1\or
   а\or б\or в\or г\or д\or е\or ж\or
   з\or и\or к\or л\or м\or н\or о\or
   п\or р\or с\or т\or у\or ф\or х\or
   ц\or ч\or ш\or щ\or э\or ю\or я%
   \else\xpg@ill@value{#1}{ukrainian@asbuk@alph}\fi%
}

\def\ukrainian@numbers{%
  \ifcyrillic@numerals
     \def\ukrainian@alph##1{\expandafter\ukrainiannumeral\expandafter{\the##1}}%
     \def\ukrainian@Alph##1{\expandafter\Ukrainiannumeral\expandafter{\the##1}}%
     \let\@Alph\ukrainian@Alph%
     \let\@alph\ukrainian@alph%
  \fi
}

\def\noukrainian@numbers{%
   \let\@Alph\latin@Alph%
   \let\@alph\latin@alph%
}

\def\noextras@ukrainian{%
  \def\@seccntformat##1{\csname the##1\endcsname\quad}% = LaTeX kernel
  \ifcyrillic@numerals\noukrainian@numbers\fi
  \ifukrainian@babelshorthands\noukrainian@shorthands\fi%
}

\def\blockextras@ukrainian{%
  \ukrainian@capsformat%
  \ifcyrillic@numerals\ukrainian@numbers\fi%
  \ifukrainian@babelshorthands\ukrainian@shorthands\fi%
}

\def\inlineextras@ukrainian{%
  \ifukrainian@babelshorthands\ukrainian@shorthands\fi%
}

%%% stuff from Babel
\AtBeginDocument{%
\ifukrainian@mathfunctions%
  \def\sh{\mathop{\operator@font sh}\nolimits}
  \def\ch{\mathop{\operator@font ch}\nolimits}
  \def\tg{\mathop{\operator@font tg}\nolimits}
  \def\arctg{\mathop{\operator@font arctg}\nolimits}
  \def\arcctg{\mathop{\operator@font arcctg}\nolimits}
  \def\ctg{\mathop{\operator@font ctg}\nolimits}
  \def\cth{\mathop{\operator@font cth}\nolimits}
  \def\cosec{\mathop{\operator@font cosec}\nolimits}
  \def\Prob{\mathop{\kern\z@\mathsf{P}}\nolimits}
  \def\Variance{\mathop{\kern\z@\mathsf{D}}\nolimits}
  \def\nsd{\mathop{\mathrm{н.с.д.}}\nolimits}
  \def\nsk{\mathop{\mathrm{н.с.к.}}\nolimits}
  \def\NSD{\mathop{\mathrm{НСД}}\nolimits}
  \def\NSK{\mathop{\mathrm{НСК}}\nolimits}
  \def\nod{\mathop{\mathrm{н.о.д.}}\nolimits}
  \def\nok{\mathop{\mathrm{н.о.к.}}\nolimits}
  \def\NOD{\mathop{\mathrm{НОД}}\nolimits}
  \def\NOK{\mathop{\mathrm{НОК}}\nolimits}
  \def\Proj{\mathop{\mathrm{пр}}\nolimits}
\fi
}

%    \end{macrocode}
% \iffalse
%</gloss-ukrainian.ldf>
%<*gloss-uppersorbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-uppersorbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-uppersorbian.ldf}[polyglossia: module for upper sorbian]

% We provide this as a babel alias

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-uppersorbian.ldf>
%<*gloss-urdu.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-urdu.ldf}
%    \begin{macrocode}
%%% Adapted from a file contributed by Kamal Abdali
\ProvidesFile{gloss-urdu.ldf}[polyglossia: module for Urdu]

\RequireBidi
\RequirePackage{arabicnumbers}
\RequirePackage{hijrical}

\PolyglossiaSetup{urdu}{
  bcp47=ur,
  script=Arabic,
  direction=RL,
  scripttag=arab,
  langtag=URD,
  hyphennames={urdu,nohyphenation},
  fontsetup=true,
  localnumeral=urdunumerals
  %TODO localalph={abjad,abjad}
}

% BCP-47 compliant aliases
\setlanguagealias*{urdu}{ur}

\newif\if@western@numerals
\def\tmp@western{western}
\define@key{urdu}{numerals}[eastern]{%
	\def\@tmpa{#1}%
	\ifx\@tmpa\tmp@western\@western@numeralstrue%
	  \else\@western@numeralsfalse%
	\fi}

%% TODO USE boolkey instead !!!
%this is needed for \abjad in arabicnumbers.sty
\def\tmp@true{true}
\define@key{urdu}{abjadjimnotail}[true]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@true\abjad@jim@notailtrue%
  \else
    \abjad@jim@notailfalse
  \fi}

\newif\if@hijrical
\def\tmp@hijri{hijri}
\define@key{urdu}{calendar}[gregorian]{%
  \def\@tmpa{#1}%
  \ifx\@tmpa\tmp@hijri\@hijricaltrue%
    \else\@hijricalfalse%
  \fi}

\define@key{urdu}{hijricorrection}[0]{%
  \gdef\@hijri@correction{#1}}%

% This should set the defaults
\setkeys{urdu}{calendar,numerals,hijricorrection}

\def\urdugregmonth#1{\ifcase#1%
  \or جنوری\or فروری\or مارچ\or اپریل\or مئی\or جون\or جولائی\or اگست\or  ستمبر\or اکتوبر\or نومبر\or دسمبر\fi}

\def\urduhijrimonth#1{\ifcase#1%
 \or محرّم\or صفر\or ربیع الاوّل\or ربیع الثّانی\or جمادی الاوّل\or جمادی الثّانی\or رجب\or شعبان\or  رمضان\or شوّال\or ذیقعدہ\or ذی الحجّہ\fi}

%\Hijritoday is now locale-aware and will format the date with this macro:
\DefineFormatHijriDate{urdu}{\@ensure@RTL{%
  \urdunumber{\value{Hijriday}}؍\space\urduhijrimonth{\value{Hijrimonth}}\space\urdunumber{\value{Hijriyear}}}}

\def\captionsurdu{%
  \def\refname{\@ensure@RTL{حوالہ جات}}%
  \def\abstractname{\@ensure@RTL{ملخّص}}%
  \def\bibname{\@ensure@RTL{کتابیات}}%
  \def\prefacename{\@ensure@RTL{دیباچہ}}%
  \def\chaptername{\@ensure@RTL{باب}}%
  \def\appendixname{\@ensure@RTL{ضمیمہ}}%
  \def\contentsname{\@ensure@RTL{فہرست عنوانات}}%
  \def\listfigurename{\@ensure@RTL{فہرست اشکال}}%
  \def\listtablename{\@ensure@RTL{فہرست جداول}}%
  \def\indexname{\@ensure@RTL{اشاریہ}}%
  \def\figurename{\@ensure@RTL{شكل}}%
  \def\tablename{\@ensure@RTL{جدول}}%
  %\def\thepart{}%
  \def\partname{\@ensure@RTL{حصّہ}}%
  \def\pagename{\@ensure@RTL{صفحہ}}%
  \def\seename{\@ensure@RTL{ملاحظہ ہو}}%
  \def\alsoname{\@ensure@RTL{ایضاً}}%
  \def\enclname{\@ensure@RTL{منسلک}}%
  \def\ccname{\@ensure@RTL{نقل}}%
  \def\headtoname{\@ensure@RTL{بملاحظہ}}%
  \def\proofname{\@ensure@RTL{ثبوت}}%
  \def\glossaryname{\@ensure@RTL{لغت}}%
  \def\sectionname{\@ensure@RTL{فصل}}%
}

\def\dateurdu{%
  \def\today{%
    \if@hijrical
     \Hijritoday[\@hijri@correction]%
    \else
      \@ensure@RTL{\urdunumber\day؍\space\urdugregmonth{\month}%
         \space\urdunumber\year}%
    \fi}%
}

\def\urdunumber#1{%
  \if@western@numerals
    \number#1%
  \else
    %%FIXME use farsidigits instead???
    \protect\arabicdigits{\number#1}%
  \fi}

\def\urdu@numbers{%
  \let\@alph\abjad%
  \let\@Alph\abjad%
}

\def\nourdu@numbers{%
  \let\@alph\latin@alph%
  \let\@Alph\latin@Alph%
}

\newcommand{\urdunumerals}[2]{\urdunumber{#2}}

% Store original definition
\let\xpg@save@arabic\@arabic

\def\urdu@globalnumbers{%
  \let\@arabic\urdunumber%
  % For some reason \thefootnote needs to be set separately:
  \renewcommand\thefootnote{\localnumeral*{footnote}}%
}

\def\nourdu@globalnumbers{
  \let\@arabic\xpg@save@arabic%
}

% Save original \MakeUppercase definition
\let\xpg@save@MakeUppercase\MakeUppercase

\def\blockextras@urdu{%
  \def\MakeUppercase##1{##1}%
}

\def\noextras@urdu{%
   % restore original \MakeUppercase definition
   \let\MakeUppercase\xpg@save@MakeUppercase%
}

%    \end{macrocode}
% \iffalse
%</gloss-urdu.ldf>
%<*gloss-usorbian.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-usorbian.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-usorbian.ldf}[polyglossia: module for upper sorbian]

% We only provide this gloss for babel compatibility. Since usorbian is 
% a sorbian variety, we use 'sorbian' with variant 'upper' now.

\xpg@load@master@language{sorbian}

%    \end{macrocode}
% \iffalse
%</gloss-usorbian.ldf>
%<*gloss-uyghur.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-uyghur.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-uyghur.ldf}[polyglossia: module for Uyghur]
%% Translations provided by Osman Tursun (Github Account: neouyghur)

\PolyglossiaSetup{uyghur}{
  bcp47=ug,
  script=Arabic,
  direction=RL,
  scripttag=arab,
  langtag=UYG,
  hyphennames={nohyphenation}،
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{uyghur}{ug}

\def\captionsuyghur{%
  \def\refname{\@ensure@RTL{پايدىلانما}}%
  \def\abstractname{\@ensure@RTL{ئابستراكت}}%
  \def\bibname{\@ensure@RTL{پايدىلانما}}%
  \def\prefacename{\@ensure@RTL{كىرىش سۆز}}%
  \def\chaptername{\@ensure@RTL{باب}}%
  \def\appendixname{\@ensure@RTL{قوشۇمچە}}%
  \def\contentsname{\@ensure@RTL{مۇندەرىجە}}%
  \def\listfigurename{\@ensure@RTL{رەسىملەر}}%
  \def\listtablename{\@ensure@RTL{جەدۋەللەر}}%
  \def\indexname{\@ensure@RTL{ئىندېكىس}}%
  \def\figurename{\@ensure@RTL{رەسىم}}%
  \def\tablename{\@ensure@RTL{جەدۋەل}}%
  %\def\thepart{}%
  \def\partname{\@ensure@RTL{قىسىم}}%
  \def\pagename{\@ensure@RTL{بەت}}%
  \def\seename{\@ensure@RTL{قاراڭ}}%
  \def\alsoname{\@ensure@RTL{ئايرىم قاراڭ}}%
  \def\enclname{\@ensure@RTL{قوشۇمچە ھۆججەت}}%
  \def\ccname{\@ensure@RTL{باشقا تاپشۇرۇۋالغۇچى}}%
  \def\headtoname{\@ensure@RTL{تاپشۇرۇۋالغۇچى}}%
  \def\proofname{\@ensure@RTL{ئىسپات}}%
  \def\glossaryname{\@ensure@RTL{لۇغەت}}%
  %\def\sectionname{\@ensure@RTL{}}%
  \def\subjectname{\@ensure@RTL{تېما}}%
}

\def\dateuyghur{%
   \def\today{\number\day~\ifcase\month\or
    يانۋار\or فېۋرال\or مارت\or ئاپرېل\or ماي\or ئىيۇن\or
    ئىيۇل\or ئاۋغۇست\or سېنتەبىر\or ئۆكتەبىر\or نويابىر\or
    دېكابىر\fi
    \space\number\year}%
}

%    \end{macrocode}
% \iffalse
%</gloss-uyghur.ldf>
%<*gloss-vietnamese.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-vietnamese.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-vietnamese.ldf}[polyglossia: module for vietnamese]
%% Strings contributed by Daniel Owens < dhowens . pmbx . net >

\PolyglossiaSetup{vietnamese}{
  bcp47=vi,
  hyphennames={nohyphenation},
  hyphenmins={2,2},
  langtag=VIT,
  frenchspacing=true,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{vietnamese}{vi}

\def\captionsvietnamese{%
  \def\refname{Tài liệu}%
  \def\abstractname{Tóm tắt nội dung}%
  \def\bibname{Tài liệu tham khảo}%
  \def\prefacename{Lời nói đầu}%
  \def\chaptername{Chương}%
  \def\appendixname{Phụ lục}%
  \def\contentsname{Mục lục}%
  \def\listfigurename{Danh sách hình vẽ}%
  \def\listtablename{Danh sách bảng}%
  \def\indexname{Chỉ mục}%
  \def\figurename{Hình}%
  \def\tablename{Bảng}%
  \def\partname{Phần}%
  \def\pagename{Trang}%
  \def\seename{Xem}%
  \def\alsoname{Xem thêm}%
  \def\enclname{Kèm theo}%
  \def\ccname{Cùng gửi}%
  \def\headtoname{Gửi}%
  \def\proofname{Chứng minh}%
  \def\glossaryname{Từ điển chú giải}%
  }

\def\datevietnamese{%
  \def\today{%
    Ngày \number\day\space
    tháng \number\month\space
    năm \number\year}%
  }

%    \end{macrocode}
% \iffalse
%</gloss-vietnamese.ldf>
%<*gloss-welsh.ldf>
% \fi
% \clearpage
% 
% \subsection{gloss-welsh.ldf}
%    \begin{macrocode}
\ProvidesFile{gloss-welsh.ldf}[polyglossia: module for welsh]

\PolyglossiaSetup{welsh}{
  bcp47=cy,
  hyphennames={welsh},
  hyphenmins={2,3},
  langtag=WEL,
  fontsetup=true,
}

% BCP-47 compliant aliases
\setlanguagealias*{welsh}{cy}

\providebool{welsh@formaldate}

\define@choicekey*+{welsh}{date}[\xpg@val\xpg@nr]{long,short}[short]{%
   \ifcase\xpg@nr\relax
      % long:
      \welsh@formaldatetrue
   \or
      % accented:
      \welsh@formaldatefalse
   \fi
   \xpg@info{Option: Welsh, date=\xpg@val}%
}{\xpg@warning{Unknown date value `#1'}}

% Register default options
\xpg@initialize@gloss@options{welsh}{date=short}

\def\captionswelsh{%
  \def\refname{Cyfeiriadau}%
  \def\abstractname{Crynodeb}%
  \def\bibname{Llyfryddiaeth}%
  \def\prefacename{Rhagair}%
  \def\chaptername{Pennod}%
  \def\appendixname{Atodiad}%
  \def\contentsname{Cynnwys}%
  \def\listfigurename{Rhestr Ddarluniau}%
  \def\listtablename{Rhestr Dablau}%
  \def\indexname{Mynegai}%
  \def\figurename{Darlun}%
  \def\tablename{Taflen}%
  %\def\thepart{}%
  \def\partname{Rhan}%
  \def\pagename{tudalen}%
  \def\seename{gweler}%
  \def\alsoname{gweler hefyd}%
  \def\enclname{amgaeëdig}%
  \def\ccname{copïau}%
  \def\headtoname{At}% ‘at’ on letters meaning ‘to (a person)’;
                     % ‘to (a place)’ is ‘i’ in Welsh
  \def\proofname{Prawf}%
  \def\glossaryname{Rhestr termau}%
  }

\newif\ifwelsh@first
\def\welsh@article#1{\welsh@firsttrue y\expandafter\welsh@article@do#1}
\def\welsh@article@do#1{\ifwelsh@first\welsh@isvowel#1\ifwelsh@vowel r\space\welsh@vowelfalse\else\space\fi#1\welsh@firstfalse\fi}
\newif\ifwelsh@vowel
\def\welsh@isvowel#1{\show#1\ifx#1a\welsh@voweltrue\else\ifx#1u\welsh@voweltrue\else\ifx#1w\welsh@voweltrue\fi\fi\fi}% FIXME Add the other vowels, just for good measure

\def\welsh@ordinal@long#1{%
  \ifcase#1\or cyntaf\or ail\or trydydd\or pedwerydd\or
  pumed\or chweched\or seithfed\or wythfed\or nawfed\or degfed\or unfed ar ddeg\or deuddegfed\or trydydd ar ddeg\or pedwerydd ar ddeg\or pymthegfed\or unfed ar bymtheg\or ail ar bymtheg\or deunawfed\or pedwerydd ar bymtheg\or ugeinfed\else\expandafter\welsh@ordinalplusxx@long#1\fi}

\def\welsh@ordinalplusxx@long#1{%
  \let\dday=#1\advance\dday by -20\relax\welsh@ordinal@long\dday\space ar hugain%
}

\def\datewelsh{%   
  \def\today{\ifwelsh@formaldate\formaltoday\else\standardtoday\fi}
  \def\standardtoday{%
    \ifcase\day\or 1af\or 2ail\or 3ydd\or 4ydd\or 5ed\or 6ed%
    \or 7fed\or 8fed\or 9fed\or 10fed\or 11eg\or 12fed\or 13eg\or
    14eg\or 15fed\or 16eg\or 17eg\or 18fed\or 19eg\or
    20fed\else\number\day ain\fi\space\ifcase\month\or
    Ionawr\or Chwefror\or Mawrth\or Ebrill\or
    Mai\or Mehefin\or Gorffennaf\or Awst\or
    Medi\or Hydref\or Tachwedd\or Rhagfyr\fi%
    \space\number\year}%
  \def\formaltoday{%
    \expandafter\welsh@article\welsh@ordinal@long\day\space o\space\ifcase\month\or
    Ionawr\or Chwefror\or Fawrth\or Ebrill\or Fai\or Fehefin\or Orffenaf\or Awst\or
    Fedi\or Hydref\or Dachwedd\or Ragfyr\fi%
    \space\number\year}%
}

%    \end{macrocode}
% \iffalse
%</gloss-welsh.ldf>
%<*arabicdigits.map>
% \fi
% \clearpage
% 
% \subsection{arabicdigits.map}
%    \begin{macrocode}
; FC ... 
LHSName	"Digits"
RHSName	"ArabicDigits"

pass(Unicode)
U+0030 <> U+0660 ;
U+0031 <> U+0661 ;
U+0032 <> U+0662 ;
U+0033 <> U+0663 ;
U+0034 <> U+0664 ;
U+0035 <> U+0665 ;
U+0036 <> U+0666 ;
U+0037 <> U+0667 ;
U+0038 <> U+0668 ;
U+0039 <> U+0669 ;

%    \end{macrocode}
% \iffalse
%</arabicdigits.map>
%<*bengalidigits.map>
% \fi
% \clearpage
% 
% \subsection{bengalidigits.map}
%    \begin{macrocode}
; FC ... 
LHSName	"Digits"
RHSName	"BengaliDigits"

pass(Unicode)
U+0030 <> U+09E6 ;
U+0031 <> U+09E7 ;
U+0032 <> U+09E8 ;
U+0033 <> U+09E9 ;
U+0034 <> U+09EA ;
U+0035 <> U+09EB ;
U+0036 <> U+09EC ;
U+0037 <> U+09ED ;
U+0038 <> U+09EE ;
U+0039 <> U+09EF ;

%    \end{macrocode}
% \iffalse
%</bengalidigits.map>
%<*devanagaridigits.map>
% \fi
% \clearpage
% 
% \subsection{devanagaridigits.map}
%    \begin{macrocode}
; FC ... 
LHSName	"Digits"
RHSName	"DevanagariDigits"

pass(Unicode)
U+0030 <> U+0966 ;
U+0031 <> U+0967 ;
U+0032 <> U+0968 ;
U+0033 <> U+0969 ;
U+0034 <> U+096A ;
U+0035 <> U+096B ;
U+0036 <> U+096C ;
U+0037 <> U+096D ;
U+0038 <> U+096E ;
U+0039 <> U+096F ;

%    \end{macrocode}
% \iffalse
%</devanagaridigits.map>
%<*farsidigits.map>
% \fi
% \clearpage
% 
% \subsection{farsidigits.map}
%    \begin{macrocode}
; FC ... 
LHSName	"Digits"
RHSName	"FarsiDigits"

pass(Unicode)
U+0030 <> U+06F0 ;
U+0031 <> U+06F1 ;
U+0032 <> U+06F2 ;
U+0033 <> U+06F3 ;
U+0034 <> U+06F4 ;
U+0035 <> U+06F5 ;
U+0036 <> U+06F6 ;
U+0037 <> U+06F7 ;
U+0038 <> U+06F8 ;
U+0039 <> U+06F9 ;

%    \end{macrocode}
% \iffalse
%</farsidigits.map>
%<*thaidigits.map>
% \fi
% \clearpage
% 
% \subsection{thaidigits.map}
%    \begin{macrocode}
; FC ... 
LHSName	"Digits"
RHSName	"ThaiDigits"

pass(Unicode)
U+0030 <> U+0E50 ;
U+0031 <> U+0E51 ;
U+0032 <> U+0E52 ;
U+0033 <> U+0E53 ;
U+0034 <> U+0E54 ;
U+0035 <> U+0E55 ;
U+0036 <> U+0E56 ;
U+0037 <> U+0E57 ;
U+0038 <> U+0E58 ;
U+0039 <> U+0E59 ;

%    \end{macrocode}
% \iffalse
%</thaidigits.map>
%<*polyglossia-french.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-french.lua}
%    \begin{macrocode}
require('polyglossia-punct')

local function set_left_space(lang, char, kern, rubber)
    polyglossia.add_left_spaced_character(lang, char, kern, "space", rubber)
end

local function set_right_space(lang, char, kern, rubber)
    polyglossia.add_right_spaced_character(lang, char, kern, "space", rubber)
end

local function activate_french_punct(thincolonspace, autospaceguillemets)
    -- We need different language tags here to make switching of options possible
    -- within a paragraph.
    local lang = "french"
    if thincolonspace then
        lang = lang.."-thincolon"
    end
    if autospaceguillemets then
        lang = lang.."-autospace"
    end

    polyglossia.activate_punct(lang)
    polyglossia.clear_spaced_characters(lang)

    if thincolonspace then
        set_left_space(lang, ':', 0.5)
    else
        set_left_space(lang, ':', 1, true) -- stretchable and shrinkable space
    end

    set_left_space(lang, '!', 0.5)
    set_left_space(lang, '?', 0.5)
    set_left_space(lang, ';', 0.5)
    set_left_space(lang, '‼', 0.5)
    set_left_space(lang, '⁇', 0.5)
    set_left_space(lang, '⁈', 0.5)
    set_left_space(lang, '⁉', 0.5)
    set_left_space(lang, '‽', 0.5) -- U+203D (interrobang)

    if autospaceguillemets then
        set_left_space(lang, '»', 0.5)
        set_left_space(lang, '›', 0.5)
        set_right_space(lang, '«', 0.5)
        set_right_space(lang, '‹', 0.5)
    end
end

local function deactivate_french_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_french_punct   = activate_french_punct
polyglossia.deactivate_french_punct = deactivate_french_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-french.lua>
%<*polyglossia-korean.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-korean.lua}
%    \begin{macrocode}
--
-- polyglossia-korean.lua
--

local glyph_id = node.id"glyph"
local hbox_id  = node.id"hlist"
local vbox_id  = node.id"vlist"
local glue_id  = node.id"glue"
local penalty_id = node.id"penalty"
local disc_id  = node.id"disc"

--
-- attr_korean: variant = plain (0), classic (1), modern (2)
--
local attr_korean = luatexbase.attributes["xpg@attr@korean"]
local attr_josa   = luatexbase.attributes["xpg@attr@autojosa"]

--
-- characters after which linebreak is not allowed
--
local nobr_after = {
    [0x28] = 1, -- ( LEFT PARENTHESIS
    [0x3C] = 1, -- < LESS-THAN SIGN
    [0x5B] = 1, -- [ LEFT SQUARE BRACKET
    [0x60] = 1, -- ` GRAVE ACCENT
    [0x7B] = 1, -- { LEFT CURLY BRACKET
    [0xAB] = 1, -- « LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
    [0x2018] = 1, -- ‘ LEFT SINGLE QUOTATION MARK
    [0x201C] = 1, -- “ LEFT DOUBLE QUOTATION MARK
    [0x2329] = 1, -- 〈 LEFT-POINTING ANGLE BRACKET
    [0x3008] = 1, -- 〈 LEFT ANGLE BRACKET
    [0x300A] = 1, -- 《 LEFT DOUBLE ANGLE BRACKET
    [0x300C] = 1, -- 「 LEFT CORNER BRACKET
    [0x300E] = 1, -- 『 LEFT WHITE CORNER BRACKET
    [0x3010] = 1, -- 【 LEFT BLACK LENTICULAR BRACKET
    [0x3014] = 1, -- 〔 LEFT TORTOISE SHELL BRACKET
    [0x3016] = 1, -- 〖 LEFT WHITE LENTICULAR BRACKET
    [0x3018] = 1, -- 〘 LEFT WHITE TORTOISE SHELL BRACKET
    [0x301A] = 1, -- 〚 LEFT WHITE SQUARE BRACKET
    [0x301D] = 1, -- 〝 REVERSED DOUBLE PRIME QUOTATION MARK
    [0xFE17] = 1, -- ︗ PRESENTATION FORM FOR VERTICAL LEFT WHITE LENTICULAR BRACKET
    [0xFE35] = 1, -- ︵ PRESENTATION FORM FOR VERTICAL LEFT PARENTHESIS
    [0xFE37] = 1, -- ︷ PRESENTATION FORM FOR VERTICAL LEFT CURLY BRACKET
    [0xFE39] = 1, -- ︹ PRESENTATION FORM FOR VERTICAL LEFT TORTOISE SHELL BRACKET
    [0xFE3B] = 1, -- ︻ PRESENTATION FORM FOR VERTICAL LEFT BLACK LENTICULAR BRACKET
    [0xFE3D] = 1, -- ︽ PRESENTATION FORM FOR VERTICAL LEFT DOUBLE ANGLE BRACKET
    [0xFE3F] = 1, -- ︿ PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET
    [0xFE41] = 1, -- ﹁ PRESENTATION FORM FOR VERTICAL LEFT CORNER BRACKET
    [0xFE43] = 1, -- ﹃ PRESENTATION FORM FOR VERTICAL LEFT WHITE CORNER BRACKET
    [0xFE47] = 1, -- ﹇ PRESENTATION FORM FOR VERTICAL LEFT SQUARE BRACKET
    [0xFE59] = 1, -- ﹙ SMALL LEFT PARENTHESIS
    [0xFE5B] = 1, -- ﹛ SMALL LEFT CURLY BRACKET
    [0xFE5D] = 1, -- ﹝ SMALL LEFT TORTOISE SHELL BRACKET
    [0xFF08] = 1, -- （ FULLWIDTH LEFT PARENTHESIS
    [0xFF3B] = 1, -- ［ FULLWIDTH LEFT SQUARE BRACKET
    [0xFF5B] = 1, -- ｛ FULLWIDTH LEFT CURLY BRACKET
    [0xFF5F] = 1, -- ｟ FULLWIDTH LEFT WHITE PARENTHESIS
    [0xFF62] = 1, -- ｢ HALFWIDTH LEFT CORNER BRACKET
}

--
-- characters before which linebreak is not allowed
--   (currently, not much differences among the followings)
--   1: normal chars
--   2: hangul jamo vowels and trailing consonants
--   3: kana small letters
--   0: dashes (supress visible spacing)
--
local nobr_before = setmetatable({
    [0x21] = 1, -- ! EXCLAMATION MARK
    [0x22] = 1, -- " QUOTATION MARK
    [0x27] = 1, -- ' APOSTROPHE
    [0x29] = 1, -- ) RIGHT PARENTHESIS
    [0x2C] = 1, -- , COMMA
    [0x2D] = 0, -- - HYPHEN-MINUS
    [0x2E] = 1, -- . FULL STOP
    [0x2F] = 0, -- / SOLIDUS
    [0x3A] = 0, -- : COLON
    [0x3B] = 1, -- ; SEMICOLON
    [0x3E] = 1, -- > GREATER-THAN SIGN
    [0x3F] = 1, -- ? QUESTION MARK
    [0x5C] = 0, -- \ REVERSE SOLIDUS
    [0x5D] = 1, -- ] RIGHT SQUARE BRACKET
    [0x7D] = 1, -- } RIGHT CURLY BRACKET
    [0x7E] = 0, -- ~ TILDE
    [0xB7] = 1, -- · MIDDLE DOT
    [0xBB] = 1, -- » RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
    [0x2013] = 0, -- – EN DASH
    [0x2014] = 0, -- — EM DASH
    [0x2015] = 1, -- ― HORIZONTAL BAR
    [0x2019] = 1, -- ’ RIGHT SINGLE QUOTATION MARK
    [0x201D] = 1, -- ” RIGHT DOUBLE QUOTATION MARK
    [0x2025] = 1, -- ‥ TWO DOT LEADER
    [0x2026] = 1, -- … HORIZONTAL ELLIPSIS
    [0x232A] = 1, -- 〉 RIGHT-POINTING ANGLE BRACKET
    [0x3001] = 1, -- 、 IDEOGRAPHIC COMMA
    [0x3002] = 1, -- 。 IDEOGRAPHIC FULL STOP
    [0x3005] = 1, -- 々 IDEOGRAPHIC ITERATION MARK
    [0x3009] = 1, -- 〉 RIGHT ANGLE BRACKET
    [0x300B] = 1, -- 》 RIGHT DOUBLE ANGLE BRACKET
    [0x300D] = 1, -- 」 RIGHT CORNER BRACKET
    [0x300F] = 1, -- 』 RIGHT WHITE CORNER BRACKET
    [0x3011] = 1, -- 】 RIGHT BLACK LENTICULAR BRACKET
    [0x3015] = 1, -- 〕 RIGHT TORTOISE SHELL BRACKET
    [0x3017] = 1, -- 〗 RIGHT WHITE LENTICULAR BRACKET
    [0x3019] = 1, -- 〙 RIGHT WHITE TORTOISE SHELL BRACKET
    [0x301B] = 1, -- 〛 RIGHT WHITE SQUARE BRACKET
    [0x301C] = 1, -- 〜 WAVE DASH
    [0x301E] = 1, -- 〞 DOUBLE PRIME QUOTATION MARK
    [0x301F] = 1, -- 〟 LOW DOUBLE PRIME QUOTATION MARK
    [0x3035] = 1, -- 〵 VERTICAL KANA REPEAT MARK LOWER HALF
    [0x303B] = 1, -- 〻 VERTICAL IDEOGRAPHIC ITERATION MARK
    [0x303C] = 1, -- 〼 MASU MARK
    [0x3041] = 3, -- ぁ HIRAGANA LETTER SMALL A
    [0x3043] = 3, -- ぃ HIRAGANA LETTER SMALL I
    [0x3045] = 3, -- ぅ HIRAGANA LETTER SMALL U
    [0x3047] = 3, -- ぇ HIRAGANA LETTER SMALL E
    [0x3049] = 3, -- ぉ HIRAGANA LETTER SMALL O
    [0x3063] = 3, -- っ HIRAGANA LETTER SMALL TU
    [0x3083] = 3, -- ゃ HIRAGANA LETTER SMALL YA
    [0x3085] = 3, -- ゅ HIRAGANA LETTER SMALL YU
    [0x3087] = 3, -- ょ HIRAGANA LETTER SMALL YO
    [0x308E] = 3, -- ゎ HIRAGANA LETTER SMALL WA
    [0x3095] = 3, -- ゕ HIRAGANA LETTER SMALL KA
    [0x3096] = 3, -- ゖ HIRAGANA LETTER SMALL KE
    [0x3099] = 1, --  COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
    [0x309A] = 1, --  COMBINING KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
    [0x309B] = 1, -- ゛ KATAKANA-HIRAGANA VOICED SOUND MARK
    [0x309C] = 1, -- ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK
    [0x309D] = 1, -- ゝ HIRAGANA ITERATION MARK
    [0x309E] = 1, -- ゞ HIRAGANA VOICED ITERATION MARK
    [0x30A0] = 1, -- ゠ KATAKANA-HIRAGANA DOUBLE HYPHEN
    [0x30A1] = 3, -- ァ KATAKANA LETTER SMALL A
    [0x30A3] = 3, -- ィ KATAKANA LETTER SMALL I
    [0x30A5] = 3, -- ゥ KATAKANA LETTER SMALL U
    [0x30A7] = 3, -- ェ KATAKANA LETTER SMALL E
    [0x30A9] = 3, -- ォ KATAKANA LETTER SMALL O
    [0x30C3] = 3, -- ッ KATAKANA LETTER SMALL TU
    [0x30E3] = 3, -- ャ KATAKANA LETTER SMALL YA
    [0x30E5] = 3, -- ュ KATAKANA LETTER SMALL YU
    [0x30E7] = 3, -- ョ KATAKANA LETTER SMALL YO
    [0x30EE] = 3, -- ヮ KATAKANA LETTER SMALL WA
    [0x30F5] = 3, -- ヵ KATAKANA LETTER SMALL KA
    [0x30F6] = 3, -- ヶ KATAKANA LETTER SMALL KE
    [0x30FB] = 1, -- ・ KATAKANA MIDDLE DOT
    [0x30FC] = 1, -- ー KATAKANA-HIRAGANA PROLONGED SOUND MARK
    [0x30FD] = 1, -- ヽ KATAKANA ITERATION MARK
    [0x30FE] = 1, -- ヾ KATAKANA VOICED ITERATION MARK
    [0xFE30] = 1, -- ︰ PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
    [0xFE31] = 1, -- ︱ PRESENTATION FORM FOR VERTICAL EM DASH
    [0xFE32] = 1, -- ︲ PRESENTATION FORM FOR VERTICAL EN DASH
    [0xFE36] = 1, -- ︶ PRESENTATION FORM FOR VERTICAL RIGHT PARENTHESIS
    [0xFE38] = 1, -- ︸ PRESENTATION FORM FOR VERTICAL RIGHT CURLY BRACKET
    [0xFE3A] = 1, -- ︺ PRESENTATION FORM FOR VERTICAL RIGHT TORTOISE SHELL BRACKET
    [0xFE3C] = 1, -- ︼ PRESENTATION FORM FOR VERTICAL RIGHT BLACK LENTICULAR BRACKET
    [0xFE3E] = 1, -- ︾ PRESENTATION FORM FOR VERTICAL RIGHT DOUBLE ANGLE BRACKET
    [0xFE40] = 1, -- ﹀ PRESENTATION FORM FOR VERTICAL RIGHT ANGLE BRACKET
    [0xFE42] = 1, -- ﹂ PRESENTATION FORM FOR VERTICAL RIGHT CORNER BRACKET
    [0xFE44] = 1, -- ﹄ PRESENTATION FORM FOR VERTICAL RIGHT WHITE CORNER BRACKET
    [0xFE48] = 1, -- ﹈ PRESENTATION FORM FOR VERTICAL RIGHT SQUARE BRACKET
    [0xFE5A] = 1, -- ﹚ SMALL RIGHT PARENTHESIS
    [0xFE5C] = 1, -- ﹜ SMALL RIGHT CURLY BRACKET
    [0xFE5E] = 1, -- ﹞ SMALL RIGHT TORTOISE SHELL BRACKET
    [0xFF01] = 1, -- ！ FULLWIDTH EXCLAMATION MARK
    [0xFF09] = 1, -- ） FULLWIDTH RIGHT PARENTHESIS
    [0xFF0C] = 1, -- ， FULLWIDTH COMMA
    [0xFF0E] = 1, -- ． FULLWIDTH FULL STOP
    [0xFF1A] = 1, -- ： FULLWIDTH COLON
    [0xFF1B] = 1, -- ； FULLWIDTH SEMICOLON
    [0xFF1F] = 1, -- ？ FULLWIDTH QUESTION MARK
    [0xFF3D] = 1, -- ］ FULLWIDTH RIGHT SQUARE BRACKET
    [0xFF5D] = 1, -- ｝ FULLWIDTH RIGHT CURLY BRACKET
    [0xFF60] = 1, -- ｠ FULLWIDTH RIGHT WHITE PARENTHESIS
    [0xFF61] = 1, -- ｡ HALFWIDTH IDEOGRAPHIC FULL STOP
    [0xFF63] = 1, -- ｣ HALFWIDTH RIGHT CORNER BRACKET
    [0xFF64] = 1, -- ､ HALFWIDTH IDEOGRAPHIC COMMA
    [0xFF65] = 1, -- ･ HALFWIDTH KATAKANA MIDDLE DOT
    [0xFF9E] = 1, -- ﾞ HALFWIDTH KATAKANA VOICED SOUND MARK
    [0xFF9F] = 1, -- ﾟ HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
}, { __index = function(_,c)
        if c >= 0x1160  and c <= 0x11FF  then return 2 end
        if c >= 0xD7B0  and c <= 0xD7FF  then return 2 end
        if c >= 0x302A  and c <= 0x302F  then return 1 end
        if c >= 0x31F0  and c <= 0x31FF  then return 3 end
        if c >= 0xFF67  and c <= 0xFF70  then return 3 end
        if c >= 0xFE00  and c <= 0xFE0F  then return 1 end
        if c >= 0xFE10  and c <= 0xFE19 and not (c == 0xFE17) then return 1 end
        if c >= 0xFE50  and c <= 0xFE58  then return 1 end
        if c >= 0xE0100 and c <= 0xE01EF then return 1 end
    end
})

--
-- whether 'c' is a cjk character
--
local function is_cjk (c)
    return c >= 0xAC00  and c <= 0xD7FF
    or     c >= 0x1100  and c <= 0x11FF
    or     c >= 0xA960  and c <= 0xA97F
    or     c >= 0x2E80  and c <= 0x9FFF
    or     c >= 0xF900  and c <= 0xFAFF
    or     c >= 0xFE10  and c <= 0xFE1F
    or     c >= 0xFE30  and c <= 0xFE6F
    or     c >= 0xFF00  and c <= 0xFFEF
    or     c >= 0x1F100 and c <= 0x1F2FF
    or     c >= 0x20000 and c <= 0x2FA1F
    or     nobr_after[c]  and c > 0x2014
    or     nobr_before[c] and c > 0x2014
end

--
-- classify cjk characters
--   1: openings
--   2: closings
--   3: centered chars
--   4: full stops
--   5: ellipses
--   6: exclamation and question marks
--   0: all others
--
local charclass = setmetatable({
    [0x2018] = 1, [0x201C] = 1, [0x2329] = 1, [0x3008] = 1,
    [0x300A] = 1, [0x300C] = 1, [0x300E] = 1, [0x3010] = 1,
    [0x3014] = 1, [0x3016] = 1, [0x3018] = 1, [0x301A] = 1,
    [0x301D] = 1, [0xFE17] = 1, [0xFE35] = 1, [0xFE37] = 1,
    [0xFE39] = 1, [0xFE3B] = 1, [0xFE3D] = 1, [0xFE3F] = 1,
    [0xFE41] = 1, [0xFE43] = 1, [0xFE47] = 1, [0xFF08] = 1,
    [0xFF3B] = 1, [0xFF5B] = 1, [0xFF5F] = 1, [0xFF62] = 1,
    [0x2019] = 2, [0x201D] = 2, [0x232A] = 2, [0x3001] = 2,
    [0x3009] = 2, [0x300B] = 2, [0x300D] = 2, [0x300F] = 2,
    [0x3011] = 2, [0x3015] = 2, [0x3017] = 2, [0x3019] = 2,
    [0x301B] = 2, [0x301E] = 2, [0x301F] = 2, [0xFE10] = 2,
    [0xFE11] = 2, [0xFE18] = 2, [0xFE36] = 2, [0xFE38] = 2,
    [0xFE3A] = 2, [0xFE3C] = 2, [0xFE3E] = 2, [0xFE40] = 2,
    [0xFE42] = 2, [0xFE44] = 2, [0xFE48] = 2, [0xFF09] = 2,
    [0xFF0C] = 2, [0xFF3D] = 2, [0xFF5D] = 2, [0xFF60] = 2,
    [0xFF63] = 2, [0xFF64] = 2, [0x00B7] = 3, [0x30FB] = 3,
    [0xFF1A] = 3, [0xFF1B] = 3, [0xFF65] = 3, [0x3002] = 4,
    [0xFE12] = 4, [0xFF0E] = 4, [0xFF61] = 4, [0x2015] = 5,
    [0x2025] = 5, [0x2026] = 5, [0xFE19] = 5, [0xFE30] = 5,
    [0xFE31] = 5, [0xFE15] = 6, [0xFE16] = 6, [0xFF01] = 6,
    [0xFF1F] = 6,
}, { __index = function() return 0 end })

--
-- table for spacing between char classes
--   1 stands for 0.5*fontsize when variant=classic
--
local intercharclass = { [0] =
    { [0] = nil,    {1,1},  nil,    {.5,.5} },
    { [0] = nil,    nil,    nil,    {.5,.5} },
    { [0] = {1,1},  {1,1},  nil,    {.5,.5}, nil,    {1,1},  {1,1} },
    { [0] = {.5,.5},{.5,.5},{.5,.5},{1,.5},  {.5,.5},{.5,.5},{.5,.5} },
    { [0] = {1,0},  {1,0},  nil,    {1.5,.5},nil,    {1,0},  {1,0} },
    { [0] = nil,    {1,1},  nil,    {.5,.5} },
    { [0] = {1,1},  {1,1},  nil,    {.5,.5} },
}

--
-- get a new penalty node
--
local function get_new_penalty (p)
    local penalty = node.new("penalty")
    penalty.penalty = p
    return penalty
end

--
-- get a new glue node
--
local function get_new_glue (...)
    local glue = node.new("glue")
    node.setglue(glue, ...)
    return glue
end

--
-- return 0.5*fontsize of given fontid
--   space: true if variant=modern; then 0.5*interword_space
--
local function get_font_size (fid, space)
    local size = font.getparameters(fid)
    if space then
        size = size and size.space or 196608
    else
        size = size and size.quad  or 655360
    end
    return size/2
end

--
-- charclass 1 thru 4 will be packed in \hbox to 0.5em{\hss? curr \hss?}
--   when variant=classic/modern
--
local function glyph_to_box (head, curr, class)
    local g, h = curr
    local size = get_font_size(g.font)
    head, curr = node.remove(head, curr)
    g.next, g.prev = nil, nil
    local hss = get_new_glue(0, 65536, 65536, 2, 2)
    if class == 1 then
        h, hss.next, g.prev = hss, g, hss
    elseif class == 2 or class == 4 then
        h, g.next, hss.prev = g, hss, g
    else
        local hss2 = node.copy(hss)
        h, hss.next, g.prev, g.next, hss2.prev = hss, g, hss, hss2, g
    end
    h = nodes.simple_font_handler(h)
    local box = node.hpack(h, size, "exactly")
    if curr then
        head, curr = node.insert_before(head, curr, box)
    else
        head, curr = node.insert_after(head, node.tail(head), box)
    end
    return head, curr
end

--
-- insert spacing defined as charclass[a][b] between a and b
--   f:    fontid
--   var:  variant = plain, classic, modern
--   cc:   charclass of current char
--   nc:   charclass of next char
--   nobr: linebreak is not allowed
--
local function insert_cjk_penalty_glue (head, curr, f, var, cc, nc, nobr)
    if nobr or cc == 1 or nc > 1 then
        local penalty = get_new_penalty(10000)
        head, curr = node.insert_after(head, curr, penalty)
    end
    local factor = get_font_size(f, var == 2)
    local t = intercharclass[cc][nc]
    local glue = get_new_glue(t[1]*factor, nil, t[2]*factor)
    head, curr = node.insert_after(head, curr, glue)
    return head, curr
end

--
-- insert inter-character spacing in other normal cases
--   f:   fontid
--   var: variant = plain, classic, modern
--   x:   true between cjk and non-cjk (a little more spacing)
--
local function insert_penalty_glue (head, curr, f, var, x)
    if var ~= 1 then
        local penalty = get_new_penalty(50)
        head, curr = node.insert_after(head, curr, penalty)
    end
    local size, glue = get_font_size(f, x and var == 2)
    if x then
        glue = get_new_glue(size/2, size/4, size/8)
    else
        glue = get_new_glue(0, size/10, size/50)
    end
    head, curr = node.insert_after(head, curr, glue)
    return head, curr
end

--
-- main process for linebreak and inter-character spacing
--   lb: true if pre_linebreak_filter
--
local function korean_break (head, lb)
    local curr = head
    while curr do
        if curr.id == glyph_id then
            local var = node.has_attribute(curr, attr_korean)
            if var then
                local c, f = curr.char or 0, curr.font or 0
                local cc, cjkc = charclass[c], is_cjk(c)

                -- compress cjk punctuations when charclass is 1 thru 4
                if var > 0 and cc > 0 and cc < 5 then
                    head, curr = glyph_to_box(head, curr, cc)
                end

                local next = curr.next
                if next and next.id == glyph_id then
                    local n = next.char or 0
                    local nc = charclass[n]
                    local nobr = nobr_before[n] or nobr_after[c]

                    -- insert spacing as of intercharclass
                    if var > 0 and intercharclass[cc][nc] then
                        head, curr = insert_cjk_penalty_glue(head, curr, f, var, cc, nc, nobr)

                    -- or insert spacing when linebreak is allowed
                    elseif not nobr then
                        local cjkn = is_cjk(n)

                        -- if curr or next is cjk char
                        if cjkc or cjkn then

                            -- if between cjk and non-cjk
                            if var > 0 and not (cjkc and cjkn) and nobr_before[c] ~= 0 then
                                head, curr = insert_penalty_glue(head, curr, f, var, true)

                            -- or under pre_linebreak_filter
                            elseif lb then
                                head, curr = insert_penalty_glue(head, curr, f, var)
                            end
                        end
                    end
                end
            end
        end
        curr = curr.next
    end
    return head
end

--
-- process for reordering hangul tone marks (U+302E, U+302F)
--   some hangul fonts (eg. Noto CJK) are so designed that hangul tone marks
--   should be moved to the first position of a syllable.
--   Currently, this functionality is not provided by luaotfload.
--
local function reorder_tm (head)
    local curr, tone = node.slide(head)
    while curr do
        if curr.id == glyph_id and node.has_attribute(curr, attr_korean) then
            local f = font.getfont(curr.font) or font.fonts[curr.font]
            if f and f.hb then -- harfbuzz do the right thing
                tone = nil
            else
                local c, wd = curr.char or 0, curr.width or 0
                if (c == 0x302E or c == 0x302F) and wd > 0 then
                    tone = curr
                elseif tone and not nobr_before[c] then
                    head = node.remove(head, tone)
                    tone.next, tone.prev = nil, nil
                    head, curr = node.insert_before(head, curr, tone)
                    tone = nil
                end
            end
        end
        curr = curr.prev
    end
    return head
end

--
-- automatic josa selection
--
local josa_table = {
    --          consonant ㄹ, vowel,  other consonants
    [0xAC00] = {0xC774,       0xAC00, 0xC774}, -- 가 => 이, 가, 이
    [0xC740] = {0xC740,       0xB294, 0xC740}, -- 은 => 은, 는, 은
    [0xC744] = {0xC744,       0xB97C, 0xC744}, -- 을 => 을, 를, 을
    [0xC640] = {0xACFC,       0xC640, 0xACFC}, -- 와 => 과, 와, 과
    [0xC73C] = {nil,          nil,    0xC73C}, -- 으(로) =>   ,  , 으
    [0xC774] = {0xC774,       nil,    0xC774}, -- 이(라) => 이,  , 이
}

--
-- helper function for number-like characters
--
local function josa_char_num (t, c)
    c = c % 10 + 0x30
    return t[c] or 2
end

--
-- decide josa selection
--
local josa_code = setmetatable({
    [0x30] = 3, [0x31] = 1, [0x33] = 3, [0x36] = 3, [0x37] = 1,
    [0x38] = 1, [0x4C] = 1, [0x4D] = 3, [0x4E] = 3, [0x6C] = 1,
    [0x6D] = 3, [0x6E] = 3, [0xFB02] = 1, [0xFB04] = 1,
},{ __index = function(t,c)
        if c >= 0xAC00 and c <= 0xD7A3 then
            c = (c - 0xAC00) % 28 + 0x11A7
        end
        if c >= 0x11A8 and c <= 0x11FF then
            if c == 0x11AF then return 1 end
            return 3
        end
        if c >= 0xD7CB and c <= 0xD7FB then return 3 end
        if c >= 0x2170 and c <= 0x217F then c = c - 0x10 end
        if c >= 0x2160 and c <= 0x216F then
            if c >= 0x216C then return 3 end
            return josa_char_num(t, c - 0x215F)
        end
        if c >= 0x2460 and c <= 0x2473 then return josa_char_num(t, c - 0x245F) end
        if c >= 0x2474 and c <= 0x2487 then return josa_char_num(t, c - 0x2473) end
        if c >= 0x2488 and c <= 0x249B then return josa_char_num(t, c - 0x2487) end
        if c >= 0x249C and c <= 0x24B5 then return t[c - 0x249C + 0x61] or 2 end
        if c >= 0x24B6 and c <= 0x24CF then return t[c - 0x24B6 + 0x61] or 2 end
        if c >= 0x24D0 and c <= 0x24E9 then return t[c - 0x24D0 + 0x61] or 2 end
        if c >= 0x3131 and c <= 0x318E then
            if c == 0x3139 then return 1 end
            if c >= 0x314F and c <= 0x3163 or c >= 0x3187 then return 2 end
            return 3
        end
        if c >= 0x3260 and c <= 0x327E then c = c - 0x60 end
        if c >= 0x3200 and c <= 0x321E then
            if c == 0x3203 then return 1 end
            if c >= 0x320E then return 2 end
            return 3
        end
        if c >= 0xFF10 and c <= 0xFF19 then return josa_char_num(t, c - 0xFF10) end
        if c >= 0xFF21 and c <= 0xFF3A then return t[c - 0xFF21 + 0x61] or 2 end
        if c >= 0xFF41 and c <= 0xFF5A then return t[c - 0xFF41 + 0x61] or 2 end
        return 2
    end
})

--
-- obtain char that comes just before the josa
--
local function get_prev_char (p)
    while p do
        if p.id == glyph_id then
            local pc = p.char or 0
            if not nobr_after[pc] then
                if not nobr_before[pc] or nobr_before[pc] >= 2 then
                    return pc
                end
            end
        elseif p.id == hbox_id or p.id == vbox_id then
            local pc = get_prev_char(node.slide(p.head))
            if pc then return pc end
        end
        p = p.prev
    end
end

--
-- main process of josa selection
--
local function auto_josa (head)
    local curr, tofree = head, {}
    while curr do
        if curr.id == glyph_id then
            local josa = node.has_attribute(curr, attr_josa)
            if josa then
                local cc = curr.char or 0
                if josa == 0 then
                    josa = josa_code[get_prev_char(curr.prev) or 0x30]
                end
                if cc == 0xC774 then
                    local n = curr.next
                    if n and n.char and n.char >= 0xAC00 and n.char <= 0xD7A3 then
                    else
                        cc = 0xAC00
                    end
                end
                local new = josa_table[cc]
                if new then
                    cc = new[josa]
                    if cc then
                        curr.char = cc
                    else
                        head = node.remove(head, curr)
                        table.insert(tofree, curr)
                    end
                end
                node.unset_attribute(curr, attr_josa)
            end
        end
        curr = curr.next
    end
    for _,v in ipairs(tofree) do node.free(v) end
    return head
end

--
-- now register to luatex callbacks
--   As char value of glyphs can be changed by opentype GSUB process,
--   we have to occupy the first position among callback functions.
--
local prepend_to_callback
if luatexbase.base_add_to_callback then
    prepend_to_callback = function(name, func, desc)
        luatexbase.add_to_callback(name, func, desc, 1)
    end
else
    prepend_to_callback = function(name, func, desc)
        local t = { {func, desc} }
        for _,v in ipairs(luatexbase.callback_descriptions(name)) do
            table.insert(t, {luatexbase.remove_from_callback(name, v)})
        end
        for _,v in ipairs(t) do
            luatexbase.add_to_callback(name, v[1], v[2])
        end
    end
end

prepend_to_callback ("pre_linebreak_filter",
    function(head)
        head = auto_josa(head)
        head = korean_break(head, true)
        head = reorder_tm(head)
        return head
    end,
    "polyglossia.lang_korean")

prepend_to_callback ("hpack_filter",
    function(head)
        head = auto_josa(head)
        head = korean_break(head)
        head = reorder_tm(head)
        return head
    end,
    "polyglossia.lang_korean")

-- vim:ft=lua:tw=0:sw=4:ts=4:expandtab
%    \end{macrocode}
% \iffalse
%</polyglossia-korean.lua>
%<*polyglossia-latin.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-latin.lua}
%    \begin{macrocode}
require('polyglossia-punct')

-- For ecclesiastic Latin (and sometimes for Italian) a very small space is
-- used for the punctuation. The ecclesiastic package uses a space of
-- 0.3\fontdimen2, where \fontdimen2 is a interword space, which is typically
-- between 1/4 and 1/3 of a quad. We choose a half of a \thinspace here.
local hairspace = 0.08333 -- 1/12

local function space_left(char)
    polyglossia.add_left_spaced_character('latin', char, hairspace, 'quad')
end

local function space_right(char)
    polyglossia.add_right_spaced_character('latin', char, hairspace, 'quad')
end

polyglossia.clear_spaced_characters('latin')
space_left('!')
space_left('?')
space_left('‼')
space_left('⁇')
space_left('⁈')
space_left('⁉')
space_left('‽') -- U+203D (interrobang)
space_left(':')
space_left(';')
space_left('»')
space_left('›')
space_right('«')
space_right('‹')

local function activate_latin_punct()
    polyglossia.activate_punct('latin')
end

local function deactivate_latin_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_latin_punct   = activate_latin_punct
polyglossia.deactivate_latin_punct = deactivate_latin_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-latin.lua>
%<*polyglossia-punct.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-punct.lua}
%    \begin{macrocode}
require('polyglossia') -- just in case...

local add_to_callback      = luatexbase.add_to_callback
local remove_from_callback = luatexbase.remove_from_callback
local priority_in_callback = luatexbase.priority_in_callback
local new_attribute        = luatexbase.new_attribute

local node = node

local insert_node_before = node.insert_before
local insert_node_after  = node.insert_after
local remove_node        = node.remove
local has_attribute      = node.has_attribute
local node_copy          = node.copy
local new_node           = node.new
local end_of_math        = node.end_of_math
local getnext            = node.getnext
local getprev            = node.getprev

-- node types according to node.types()
local glue_code    = node.id"glue"
local glyph_code   = node.id"glyph"
local penalty_code = node.id"penalty"
local kern_code    = node.id"kern"
local math_code    = node.id"math"

-- we need some node subtypes
local userkern = 1
local userskip = 0
local removable_skip = {
    [0]  = true, -- userskip
    [13] = true, -- spaceskip
    [14] = true, -- xspaceskip
}

-- we make a new node, so that we can copy it later on
local kern_node = new_node(kern_code)
kern_node.subtype = userkern -- this kern can be removed later on

local function get_kern_node(dim)
    local n = node_copy(kern_node)
    n.kern = dim
    return n
end

local glue_node = new_node(glue_code)
glue_node.subtype = userskip

local function get_glue_node(dim, stretch, shrink)
    local n   = node_copy(glue_node)
    n.width   = dim
    n.stretch = stretch
    n.shrink  = shrink
    return n
end

local penalty_node   = new_node(penalty_code)
penalty_node.penalty = 10000

local function get_penalty_node()
    return node_copy(penalty_node)
end

-- all possible space characters according to section 6.2 of the Unicode Standard
-- https://www.unicode.org/versions/Unicode12.0.0/ch06.pdf
local space_chars = {
    [0x20] = true, -- space
    [0xA0] = true, -- no-break space
    [0x1680] = true, -- ogham space mark
    [0x2000] = true, -- en quad
    [0x2001] = true, -- em quad
    [0x2002] = true, -- en space
    [0x2003] = true, -- em space
    [0x2004] = true, -- three-per-em-space
    [0x2005] = true, -- four-per-em space
    [0x2006] = true, -- six-per-em space
    [0x2007] = true, -- figure space
    [0x2008] = true, -- punctuation space
    [0x2009] = true, -- thin space
    [0x200A] = true, -- hair space
    [0x202F] = true, -- narrow no-break space
    [0x205F] = true, -- medium mathematical space
    [0x3000] = true -- ideographic space
}

-- all left bracket characters, referenced by their Unicode slot
local left_bracket_chars = {
    [0x28] = true, -- left parenthesis
    [0x5B] = true, -- left square bracket
    [0x7B] = true, -- left curly bracket
    [0x27E8] = true -- mathematical left angle bracket
}

-- all right bracket characters, referenced by their Unicode slot
local right_bracket_chars = {
    [0x29] = true,  -- right parenthesis
    [0x5D] = true,  -- right square bracket
    [0x7D] = true,  -- right curly bracket
    [0x27E9] = true -- mathematical right angle bracket
}

-- question and exclamation marks, referenced by their Unicode slot
local question_exclamation_chars = {
    [0x21] = true,   -- exclamation mark !
    [0x3F] = true,   -- question mark ?
    [0x203C] = true, -- double exclamation mark ‼
    [0x203D] = true, -- interrobang ‽
    [0x2047] = true, -- double question mark ⁇
    [0x2048] = true, -- question exclamation mark ⁈
    [0x2049] = true  -- exclamation question mark ⁉
}

-- from nodes-tst.lua, adapted
local function somespace(n)
    if n then
        local id, subtype = n.id, n.subtype
        if id == glue_code then
            -- it is dangerous to remove all the type of glue
            return removable_skip[subtype]
        elseif id == kern_code then
            -- remove only user's kern
            return subtype == userkern
        elseif id == glyph_code then
            return space_chars[n.char]
        end
    end
end

local function someleftbracket(n)
    if n then
        local id = n.id
        if id == glyph_code then
            return left_bracket_chars[n.char]
        end
    end
end

local function somerightbracket(n)
    if n then
        local id = n.id
        if id == glyph_code then
            return right_bracket_chars[n.char]
        end
    end
end

local function question_exclamation_sequence(n1, n2)
    if n1 and n2 then
        local id1 = n1.id
        local id2 = n2.id
        if id1 == glyph_code and id2 == glyph_code then
            return question_exclamation_chars[n1.char] and question_exclamation_chars[n2.char]
        end
    end
end

-- idem
local function somepenalty(n, value)
    if n then
        local id = n.id
        if id == penalty_code then
            if value then
                return n.penalty == value
            else
                return true
            end
        end
    end
end

local punct_attr = new_attribute("polyglossia_punct")

local lang_id      = {}
local lang_counter = 0
local left_space   = {}
local right_space  = {}

local function ensure_lang_id(lang)
    if not lang_id[lang] then
        lang_counter = lang_counter + 1
        lang_id[lang] = lang_counter
    end
    return lang_id[lang]
end

local function clear_spaced_characters(lang)
    local id = ensure_lang_id(lang)
    left_space[id]  = {}
    right_space[id] = {}
end

local function illegal_unit(unit)
    if unit then
        texio.write_nl('Illegal spacing unit "'..unit..'".')
    else
        texio.write_nl('Spacing unit is a nil value.')
    end
end

local function add_left_spaced_character(lang, char, kern, unit, rubber)
-- The parameter kern is a number meant as a fraction of the unit.
-- The unit can be "quad" (1em) or "space" (interword space).
-- The parameter rubber is a Boolean value indicating if the inserted space is
-- stretchable and shrinkable (only relevant if the unit is "space").
    local id = ensure_lang_id(lang)
    if unit == "quad" or unit == "space" then
        left_space[id][char] = {}
        left_space[id][char]["kern"] = kern
        left_space[id][char]["unit"] = unit
        left_space[id][char]["rubber"] = rubber
    else
        illegal_unit(unit)
    end
end

local function add_right_spaced_character(lang, char, kern, unit, rubber)
    local id = ensure_lang_id(lang)
    if unit == "quad" or unit == "space" then
        right_space[id][char] = {}
        right_space[id][char]["kern"] = kern
        right_space[id][char]["unit"] = unit
        right_space[id][char]["rubber"] = rubber
    else
        illegal_unit(unit)
    end
end

-- from typo-spa.lua, adapted
local function process(head)
    local current = head
    while current do
        local id = current.id
        if id == glyph_code then
            local attr = has_attribute(current, punct_attr)
            if attr then
                local char, leftspace, rightspace
                if current.char <= 0x10FFFF then -- greater values may cause problems with utf8.char
                    char = utf8.char(current.char)
                    leftspace  = left_space[attr][char]
                    rightspace = right_space[attr][char]
                end
                if leftspace or rightspace then
                    local fontparameters = fonts.hashes.parameters[current.font]
                    local unit, stretch, shrink, spacing_node
                    if leftspace and fontparameters then
                        local prev = getprev(current)
                        local space_exception = false
                        if prev then
                            -- do not add space after left (opening) bracket and between question/exclamation marks
                            space_exception = someleftbracket(prev) or question_exclamation_sequence(prev, current)
                            -- TODO: there is a question here: do we override a preceding space or not?...
                            while somespace(prev) do
                                head = remove_node(head, prev)
                                prev = getprev(current)
                            end
                            if somepenalty(prev, 10000) then
                                head = remove_node(head, prev)
                            end
                        end
                        if leftspace.unit == "quad" then
                            unit = fontparameters.quad
                            spacing_node = get_kern_node(leftspace.kern*unit)
                        elseif leftspace.unit == "space" then
                            unit = fontparameters.space
                            if leftspace.rubber then
                                stretch = leftspace.kern*fontparameters.space_stretch
                                shrink  = leftspace.kern*fontparameters.space_shrink
                                spacing_node = get_glue_node(leftspace.kern*unit, stretch, shrink)
                                head = insert_node_before(head, current, get_penalty_node())
                            else
                                spacing_node = get_kern_node(leftspace.kern*unit)
                            end
                        end
                        if not space_exception then
                            head = insert_node_before(head, current, spacing_node)
                        end
                    end
                    if rightspace and fontparameters then
                        local next = getnext(current)
                        local space_exception = false
                        if next then
                            -- do not add space before right (closing) bracket
                            space_exception = somerightbracket(next)
                            local nextnext = getnext(next)
                            if somepenalty(next, 10000) and somespace(nextnext) then
                                head, next = remove_node(head, next)
                            end
                            while somespace(next) do
                                head, next = remove_node(head, next)
                            end
                        end
                        if rightspace.unit == "quad" then
                            unit = fontparameters.quad
                            spacing_node = get_kern_node(rightspace.kern*unit)
                        elseif rightspace.unit == "space" then
                            unit = fontparameters.space
                            if rightspace.rubber then
                                stretch = rightspace.kern*fontparameters.space_stretch
                                shrink  = rightspace.kern*fontparameters.space_shrink
                                spacing_node = get_glue_node(rightspace.kern*unit, stretch, shrink)
                                if not space_exception then
                                    head, current = insert_node_after(head, current, get_penalty_node())
                                end
                            else
                                spacing_node = get_kern_node(rightspace.kern*unit)
                            end
                        end
                        if not space_exception then
                            head, current = insert_node_after(head, current, spacing_node)
                        end
                    end
                end
            end
        elseif id == math_code then
            -- warning: this is a feature of luatex > 0.76
            current = end_of_math(current) -- weird, can return nil .. no math end?
        end
        current = getnext(current) -- no error even if current is nil
    end
    return head
end

local function activate(lang)
    local id = ensure_lang_id(lang)
    -- We set the punctuation attribute to a language id here. This is
    -- important to be able to intermix languages with different spacings
    -- in one paragraph.
    tex.setattribute(punct_attr, id)
    for _, callback_name in ipairs{ "pre_linebreak_filter", "hpack_filter" } do
        if not priority_in_callback(callback_name, "polyglossia-punct.process") then
            add_to_callback(callback_name, process, "polyglossia-punct.process", 1)
        end
    end
end

local function deactivate()
    tex.setattribute(punct_attr, -0x7FFFFFFF) -- this value means "unset"
    -- Though it would make compilation slightly faster, it is not possible to
    -- safely uncomment the following lines. Imagine the following case: you
    -- start a paragraph by some spaced punctuation text, then, in the same
    -- paragraph, you change the language to something else, and thus call the
    -- following lines. This means that, at the end of the paragraph, the
    -- function won't be in the callback, so the beginning of the paragraph
    -- won't be processed by it.
    -- if priority_in_callback(callback_name, "polyglossia-punct.process") then
    --     remove_from_callback(callback_name, "polyglossia-punct.process")
    -- end
end

polyglossia.activate_punct             = activate
polyglossia.deactivate_punct           = deactivate
polyglossia.add_left_spaced_character  = add_left_spaced_character
polyglossia.add_right_spaced_character = add_right_spaced_character
polyglossia.clear_spaced_characters    = clear_spaced_characters
%    \end{macrocode}
% \iffalse
%</polyglossia-punct.lua>
%<*polyglossia-sanskrit.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-sanskrit.lua}
%    \begin{macrocode}
require('polyglossia-punct')

-- How do we now, in Lua, what a \thinspace is? In the LaTeX source (latex.ltx)
-- it is defined as:
-- \def\thinspace{\leavevmode@ifvmode\kern .16667em }
-- I see no way of seeing if it has been overriden or not. So we stick to this
-- value.
local thinspace = 0.16667 -- 1/6

local function space_left(char)
    polyglossia.add_left_spaced_character('sanskrit', char, thinspace, 'quad')
end

polyglossia.clear_spaced_characters('sanskrit')
space_left('!')
space_left('?')
space_left('‼')
space_left('⁇')
space_left('⁈')
space_left('⁉')
space_left('‽') -- U+203D (interrobang)
space_left(':')
space_left(';')
space_left('।') -- danda, U+0964
space_left('॥') -- double danda, U+0965

local function activate_sanskrit_punct()
    polyglossia.activate_punct('sanskrit')
end

local function deactivate_sanskrit_punct()
    polyglossia.deactivate_punct()
end

polyglossia.activate_sanskrit_punct   = activate_sanskrit_punct
polyglossia.deactivate_sanskrit_punct = deactivate_sanskrit_punct
%    \end{macrocode}
% \iffalse
%</polyglossia-sanskrit.lua>
%<*polyglossia-tibt.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia-tibt.lua}
%    \begin{macrocode}
require('polyglossia') -- just in case...

local add_to_callback = luatexbase.add_to_callback
local remove_from_callback = luatexbase.remove_from_callback
local priority_in_callback = luatexbase.priority_in_callback

local next, type = next, type

local nodes, fonts, node = nodes, fonts, node

local nodecodes          = nodes.nodecodes --- <= preloaded node.types()

local insert_node_before = node.insert_before
local insert_node_after  = node.insert_after
local remove_node        = nodes.remove
local copy_node          = node.copy
local has_attribute      = node.has_attribute

local end_of_math        = node.end_of_math
if not end_of_math then -- luatex < .76
  local traverse_nodes = node.traverse_id
  local math_code      = nodecodes.math
  local end_of_math = function (n)
    for n in traverse_nodes(math_code, n.next) do
      return n
    end
  end
end

-- node types as of April 2013
local glyph_code         = nodecodes.glyph
local penalty_code       = nodecodes.penalty
local kern_code          = nodecodes.kern

-- we make a new node, so that we can copy it later on
local penalty_node  = node.new(penalty_code)
penalty_node.penalty = 50 -- corresponds to the penalty LaTeX sets at explicit hyphens

local function get_penalty_node()
  return copy_node(penalty_node)
end

local xpgtibtattr = luatexbase.attributes['xpg@tibteol']

local tsheg = unicode.utf8.byte('་')

-- from typo-spa.lua
local function process(head)
    local start = head
    -- head is always begin of par (whatsit), so we have at least two prev nodes
    -- penalty followed by glue
    while start do
        local id = start.id
        if id == glyph_code then 
            local attr = has_attribute(start, xpgtibtattr)
            if attr and attr > 0 then
                if start.char == tsheg then
                    if start.next then
                        insert_node_after(head,start,get_penalty_node())
                    end
                end
            end
        elseif id == math_code then
            -- warning: this is a feature of luatex > 0.76
            start = end_of_math(start) -- weird, can return nil .. no math end?
        end
        if start then
            start = start.next
        end
    end
    return head
end

local callback_name = "pre_linebreak_filter"

local function activate()
  if not priority_in_callback (callback_name, "polyglossia-tibt.process") then
    add_to_callback(callback_name, process, "polyglossia-tibt.process", 1)
  end
end

local function desactivate()
  if priority_in_callback (callback_name, "polyglossia-tibt.process") then
    remove_from_callback(callback_name, "polyglossia-tibt.process")
  end
end

polyglossia.activate_tibt_eol    = activate
polyglossia.desactivate_tibt_eol = desactivate
%    \end{macrocode}
% \iffalse
%</polyglossia-tibt.lua>
%<*polyglossia.lua>
% \fi
% \clearpage
% 
% \subsection{polyglossia.lua}
%    \begin{macrocode}

local module_name = "polyglossia"
local polyglossia_module = {
    name          = module_name,
    version       = 1.3,
    date          = "2013/05/11",
    description   = "Polyglossia",
    author        = "Elie Roux",
    copyright     = "Elie Roux",
    license       = "CC0"
}

luatexbase.provides_module(polyglossia_module)

local log_info = function(message, ...)
    luatexbase.module_info(module_name, message:format(...))
end
local log_warn = function(message, ...)
    luatexbase.module_warning(module_name, message:format(...))
end

polyglossia = polyglossia or {}
local polyglossia = polyglossia

local function select_language(lang, id)
    polyglossia.current_language = lang
end

local function set_default_language(lang, id)
    polyglossia.default_language = lang
end

local byte = utf8.codepoint -- use standard module of lua 5.3

local check_char

if luaotfload and luaotfload.aux and luaotfload.aux.font_has_glyph then
    local font_has_glyph = luaotfload.aux.font_has_glyph
    function check_char(chr)
        local codepoint = tonumber(chr) or byte(chr)
        if font_has_glyph(font.current(), codepoint) then
            tex.sprint('1')
        else
            tex.sprint('0')
        end
    end
else
    function check_char(chr) -- always in current font
        local fontid    = font.current()
        local fontdata  = font.getfont(fontid) or font.fonts[fontid]
        local chardata  = fontdata.characters
        local codepoint = tonumber(chr) or byte(chr)
        if chardata and chardata[codepoint] then
            tex.sprint('1')
        else
            tex.sprint('0')
        end
    end
end

local function load_tibt_eol()
    require('polyglossia-tibt')
end

-- predefined l@nohyphenation or LuaTeX's maximum value for \language
local nohyphid = luatexbase.registernumber'l@nohyphenation' or 16383

-- key `nohyphenation` is for .sty file when possibly undefined l@nohyphenation
local newloader_loaded_languages = { nohyphenation = nohyphid }

local newloader_available_languages = require'language.dat.lua'
-- Suggestion by Dohyun Kim on #129
local t = { }
for k, v in pairs(newloader_available_languages) do
    t[k] = v
    for _, vv in pairs(v.synonyms) do
        t[vv] = v
    end
end
newloader_available_languages = t

-- LaTeX's language register is \count19
local lang_register = 19

-- New hyphenation pattern loader: use language.dat.lua directly and the language identifiers
local function newloader(langentry)
    local loaded_language = newloader_loaded_languages[langentry]
    if loaded_language then
        local langid = lang.id(loaded_language)
        log_info('Language %s already loaded; id is %i', langentry, langid)
        return langid
    else
        local langdata = newloader_available_languages[langentry]
        if langdata then

            local special = langdata.special
            if special then
                -- language0 (USenglish) is already included in the format
                if special == 'language0' then
                    return 0

                -- disabled language should not be used for utf-8 text
                elseif special:find'^disabled:' then
                    log_warn('Hyphenation of language %s %s', langentry, special)
                    return nohyphid
                end
            end

            -- language info will be written into the .log file
            local s = { "Language data for " .. langentry }
            for k, v in pairs(langdata) do
                if type(v) == 'table' then -- for 'synonyms'
                    s[#s+1] = k .. "\t" .. table.concat(v,',')
                else
                    s[#s+1] = k .. "\t" .. tostring(v)
                end
            end
            log_info(table.concat(s,"\n"))

            --
            -- LaTeX's \newlanguage increases language register (count19),
            -- whereas LuaTeX's lang.new() increases its own language id.
            -- So when a user has declared, say, \newlanguage\lang@xyz, then
            -- these two numbers do not match each other. If we do not consider
            -- this possible situation, our newloader() function will
            -- unfortunately overwrite the language \lang@xyz.
            --
            -- Threfore here we will compare LaTeX's \newlanguage number with
            -- LuaTeX's lang.new() id and select the bigger one for our new
            -- language object. Also we will update LaTeX's language register
            -- by this new id, so that another possible \newlanguage should not
            -- overwrite our language object.
            --
            -- get next \newlanguage allocation number
            local langcnt = tex.count[lang_register] + 1
            -- get new lang object
            local langobject = lang.new()
            local langid = lang.id(langobject)
            -- get bigger one between \newlanguage and new lang obj id
            local newlangid = math.max(langcnt, langid)
            -- set language register for possible \newlanguage
            tex.setcount('global', lang_register, newlangid)
            -- get new lang object if needeed
            if langid ~= newlangid then
                langobject = lang.new(newlangid)
            end

            -- load hyphenation patterns and exceptions
            for _,v in ipairs{ 'patterns', 'hyphenation' } do
                local data = langdata[v]
                if data and data ~= '' then
                    -- cope with comma separated list, such as serbian
                    for _,vv in ipairs(data:explode',+') do
                        local filepath = kpse.find_file(vv)
                        if filepath then
                            local fh = io.open(filepath)
                            lang[v](langobject, fh:read'a')
                            fh:close()
                        else
                            log_warn('Hyphenation file %s not found', vv)
                        end
                    end
                end
            end

            newloader_loaded_languages[langentry] = langobject

            log_info('Language %s was not yet loaded; created with id %i',
                     langentry, newlangid)
            return newlangid
        else
            log_warn('Language %s not found in language.dat.lua', langentry)
            return nohyphid
        end
    end
end

polyglossia.select_language = select_language
polyglossia.set_default_language = set_default_language
polyglossia.check_char = check_char
polyglossia.load_tibt_eol = load_tibt_eol
polyglossia.newloader = newloader
polyglossia.newloader_loaded_languages = newloader_loaded_languages
-- global variables:
-- polyglossia.default_language
-- polyglossia.current_language
%    \end{macrocode}
% \iffalse
%</polyglossia.lua>
% \fi
% \clearpage
% \PrintChanges
% \Finale
% 
% \iffalse
%<*examples.tex>
\documentclass[a4paper]{article}
\usepackage[no-math]{fontspec}
\usepackage{xltxtra,url}
\let\XeTeX\undefined
\let\XeLaTeX\undefined
\usepackage{polyglossia}
\usepackage{trace}
\setdefaultlanguage{french}
\setotherlanguage[variant=british,ordinalmonthday=false]{english}
\setotherlanguage[variant=poly]{greek}
\setotherlanguage[numerals=thai]{thai}
\setotherlanguage[locale=mashriq]{arabic}
\setotherlanguage[spelling=new,latesthyphen=true,babelshorthands=true]{german}
\setotherlanguages{latin,russian,turkish,polish,latvian,sanskrit,ukrainian,farsi,syriac,divehi,hebrew,amharic,nko}
\setotherlanguage[calendar=gregorian,numerals=western]{urdu}
\setmainfont{Linux Libertine O}
\defaultfontfeatures{Scale=MatchLowercase}
\setmonofont{Inconsolata}
\newfontfamily\arabicfont[Script=Arabic]{Amiri}
\newfontfamily\syriacfont[Script=Syriac]{Serto Jerusalem}
\newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL}
\newfontfamily\sanskritfont[Script=Devanagari]{Sanskrit 2003}
\newfontfamily\thaifont[Script=Thai]{Norasi}
\newfontfamily\thaanafont[Script=Thaana,WordSpace=2]{FreeSerif}
\newfontfamily\ethiopicfont[Script=Ethiopic]{Abyssinica SIL}
\newfontfamily\nkofont[Renderer=Graphite]{Conakry}
\parskip 1.33\baselineskip
%\newcommand\showhyphmin{\fbox{\the\lefthyphenmin\ \the\righthyphenmin}}
\begin{document}
\hyphenation{Bru-xel-les}
\noindent
\textbf{Le français}\footnote{ From \url{http://fr.wikipedia.org/wiki/Français}} est une langue romane parlée en France, dont elle est originaire (la «langue d'oïl»), ainsi qu'en Afrique francophone, au Canada (principalement au Québec, au Nouveau-Brunswick et en Ontario), en Belgique (en Région wallonne et à Bruxelles), en Suisse, au Liban, en Haïti et dans d'autres régions du monde, soit au total dans 51 pays du monde ayant pour la plupart fait partie des anciens empires coloniaux français et belge. \\
(\today)

\begin{english}
\textbf{English}\footnote{From \url{http://en.wikipedia.org/wiki/English_language}} is a West Germanic language originating in England, and the first language for most people in Australia, Canada, the Commonwealth Caribbean, Ireland, New Zealand, the United Kingdom and the United States of America (also commonly known as the Anglosphere). It is used extensively as a second language and as an official language throughout the world, especially in Commonwealth countries and in many international organisations. \\
(\today)
\end{english}

\begin{german}
\textbf{Die deutsche Sprache}\footnote{ From \url{http://de.wikipedia.org/wiki/Deutsche_Sprache}} (auch das Deutsche) gehört zum westlichen Zweig der germanischen Sprachen und ist eine der meistgesprochenen europäischen Sprachen weltweit, und gilt so als Weltsprache.\\
(\today)
\end{german}

\begin{russian}
\textbf{Русский язык} — один из восточнославянских языков, один из крупнейших языков мира, в том числе самый распространённый из славянских языков и самый распространённый язык Европы, как географически, так и по числу носителей языка как родного (хотя значительная, и географически бо́льшая, часть русского языкового ареала находится в Азии).	\\
(\today)
\end{russian}

\begin{latin}
\textbf{Lingua Latina} est lingua Indoeuropaea. Nomen ductum est de terra in paeninsula Italica quam Latine loquentes incolebant, Vetus Latium appellata sitaque inter flumen Tiberis, Volscam terram, mare Tyrrhenicum, montes Apenninos. 
Quamquam sermone nativo fungi desinit, cumque nostris diebus perpauci Latine loqui possint, lingua mortua appellari solet, multas tamen peperit linguas quae linguae romanicae vocantur, sicut Hispanicam, Francogallicam, Italicam, Lusitanam, Dacoromanicam, Gallaicam, ne omnes afferam. \\
(\today) 
\end{latin}

\begin{greek}
\textbf{Η ελληνική γλώσσα} είναι μία από τις ινδοευρωπαϊκές γλώσσες, για την
οποία έχουμε γραπτά κείμενα από τον 15ο αιώνα π.Χ. μέχρι σήμερα. Αποτελεί το
μοναδικό μέλος ενός κλάδου της ινδοευρωπαϊκής οικογένειας γλωσσών. Ανήκει
επίσης στον βαλκανικό γλωσσικό δεσμό.\\	
(\today) 
\end{greek}


\begin{hebrew}[numerals=hebrew]
\textbf{עברית} היא שפה ממשפחת השפות השמיות, הידועה כשפתו של העם היהודי, ואשר ניב מודרני שלה משמש כשפה הרשמית והעיקרית של מדינת ישראל. \\
(\today\ = \hebrewtoday)
\end{hebrew}

\begin{syriac}[numerals=abjad]
ܠܫܢܐ ܐܪܡܝܐ ܐܘ ܐܪܡܝܬ ܗܘ ܠܫܢ̈ܐ ܥܡ ܬܫܥܝܬܐ ܕ\textrm{3000} ܫܢ̈ܝܐ܂ ܗܘܐ ܠܫܢܐ ܕܡܠܟܘ̈ܬܐ ܘܬܘܕ̈ܝܬܐ܂ ܥܡ ܠܫܢܐ ܥܒܪܝܐ܄ ܗܘܐ ܠܫܢܐ ܕܣܦܪ̈ܐ ܕܕܢܝܐܝܠ ܘܥܙܪܐ ܘܗܘ ܠܫܢܐ ܚܕܢܝܐ ܕܬܠܡܘܕ܂ ܐܪܡܝܐ ܗܘܐ ܠܫܢܐ ܕܝܫܘܥ܂ ܐܕܝܘܡ܄ ܐܪܡܝܐ ܗܘ ܠܫܢܐ ܕܟܠܕ̈ܝܐ܄ ܐܬܘܪ̈ܝܐ܄ ܡܪ̈ܘܢܝܐ܄ ܘܣܘܪ̈ܝܝܐ܀ \\
(\today)
\end{syriac}

\begin{turkish}
\textbf{Türkiye Türkçesi}, Ural-Altay Dilleri içerisinde Türk dil ailesinin Oğuz Grubu'na mensup lehçedir. Anadolu, Kıbrıs, Balkanlar ve Orta Avrupa'da geniş yayılım alanı bulmuş olup, Türkiye Cumhuriyeti, Kuzey Kıbrıs Türk Cumhuriyeti, Güney Kıbrıs Rum Kesimi, Makedonya ve Kosova'nın resmî dilidir. \\
(\today = \Hijritoday)
\end{turkish}

\begin{polish}
\textbf{Język polski (polszczyzna)} należy wraz z językiem czeskim, słowackim, pomorskim (kaszubskim), dolnołużyckim, górnołużyckim oraz wymarłym połabskim do grupy języków zachodniosłowiańskich, stanowiących część rodziny języków indoeuropejskich. Ocenia się, że język polski jest językiem ojczystym około 44 milionów ludzi na świecie (w literaturze naukowej można spotkać szacunki od 40 do 48 milionów), mieszkańców Polski oraz Polaków zamieszkałych za granicą (Polonia).\\
(\today)
\end{polish}

\begin{latvian} 
\textbf{Latviešu valoda} ir dzimtā valoda apmēram 1,5 miljoniem cilvēku, galvenokārt Latvijā, kurā tā ir vienīgā valsts valoda. Lielākās latviešu valodas pratēju kopienas ārzemēs ir Austrālijā, ASV, Zviedrijā, Lielbritānijā, Vācijā, Brazīlijā, Krievijā. Latviešu valoda pieder indoeiropiešu valodu saimes baltu valodu grupai.\\
(\today)
\end{latvian}

\begin{ukrainian}
\textbf{Українська мова} — східнослов'янська мова, входить до однієї підгрупи з білоруською та російською. Подібно до цих мов українську записують кирилицею. Історично білоруська та українська мови походять з давньоруської (давньоукраїнської) — розмовної мови Київської Русі.\\
(\today)
\end{ukrainian}

\begin{sanskrit}
{\Large ससकत} पृथिव्यां प्राचीना समृद्घा वैज्ञानिकी च भाषा मन्यते । विश्ववाङ्‌मयेषु संस्कृतं श्रेष्ठरत्नम् इति न केवलं भारते अपि तु समग्रविश्वे एतद्विषये निर्णयाधिकारिभि: जनै: स्वीकृतम् । महर्षि पाणिनिना विरचिता अष्टाध्यायी इति संस्कृतव्याकरणम्‌ अधुनापि भारते विदेशेषु च भाषाविज्ञानिनां प्रेरणास्‍थानं वर्तते . संस्कृतशब्दा: एव उत्तरं दक्षिणं च भारतं संयोजयन्ति ।
\end{sanskrit}

\begin{Arabic}[]
«اعلم أنّ فنّ التاريخ فنّ عزيز المذهب، جمّ الفوائد، شريف الغاية؛ إذ هو يوقفنا على أحوال الماضين من الأمم في أخلاقهم، و الأنبياء في سيرهم، و الملوك في دولهم و سياستهم؛ حتّى تتمّ فائدة الإقتداء في ذلك لمن يرومه في أحوال الدين و الدنيا.» (ابن خلدون، المقدّمة)\\
(\today\ = \Hijritoday[0])
\end{Arabic}

\begin{farsi}
فارسی یا پارسی، (که دری، فارسی دری، و پارسی دری نیز نامیده می‌شود) زبانی است که
در کشورهای ایران، افغانستان، تاجیکستان و ازبکستان به آن سخن می‌رانند. \\
(\Jalalitoday = \Hijritoday)
\end{farsi}

\pagebreak
\begin{urdu}
اُردو ایک ہندآریائی زبان ہے جس کا تعلّق ہند یوروپی لسانی خاندان کی ہندایرانی شاخ سے ہے۔ بارہویں صدی میں ہندوستان کی مقامی زبانوں اور فارسی، عربی، اور تُرکی زبانوں کے اختلاط سے اردو وجود میں آئی۔ اردو پاکستان کی قومی زبان ہے، اور ہندوستان کی 23 سرکاری زبانوں میں سے ایک ہے۔ جنوبی ایشیا کے باہر خلیجِ فارس کے ممالک، سعودی عرب، برطانیہ، امریکہ، کنیڈا، جرمنی، ناروے، اور آسٹریلیا میں بھی جنوبی ایشیائی مہاجرین کی بڑی تعداد اردو بولتی ہے۔ \\

(\today\ مطابق \Hijritoday[0])
\end{urdu}

\begin{thai}
เป็น\wbr แผนงานเพื่อ\wbr สนับสนุน\wbr การ\wbr ร่วมกัน\wbr สร้าง, การ\wbr ร่วมกันใช้, และ\wbr การ%
ร่วมกัน\wbr พัฒนา\wbr ทรัพยากร\wbr ทาง\wbr ภาษา\wbr ของ\wbr ภาษา\wbr ไทย, บน\wbr เครือข่าย World Wide Web. แผนงานนี้\wbr มี%
จุด\wbr ประสงค์หลั\wbr กอยู่\wbr สอง\wbr ประการคือ เพื่อแก้ปัญหา\wbr กำ\wbr แพง\wbr ทาง\wbr ภาษา, และรักษา%
ไว้เพื่อ\wbr ความค\wbr งอยู่\wbr ของ\wbr ภาษา\wbr และ\wbr วัฒนธรรม\wbr ไทย. \\
(\today)
\end{thai}

\begin{divehi}\small\sloppy
ދިވެހިބަހަކީ ދިވެހިރާއްޖޭގެ ރަސްމީ ބަހެވެ. މި ބަހުން ވާހަކަ ދައްކައި އުޅެނީ ދިވެހިރާއްޖޭގެ އަހުލުވެރިންގެ އިތުރުން ހިންދުސްތާނުގެ މަލިކު ގެ
އަހުލުވެރިންނެވެ. އެބައިމީހުން މި ބަހަށް ކިޔަނީ މަހަލް ބަހެވެ. ބަހާބެހޭ މާހިރުން ދިވެހިބަސް ހިމަނުއްވައިފައިވަނީ އިންޑޯ އާރިޔަން ބަސްތަކުގެ
ތެރޭގަ އެވެ. 
\end{divehi}

%\fontspec[Script=Georgian]{DejaVu Serif}
%ქართული ენა არის საქართველოს სახელმწიფო ენა (აფხაზეთის ავტონომიურ რესპ\-უბლიკაში მის პარალელურად სახელმწიფო ენად აღიარებულია აგრეთვე აფხაზური ენა). ქართულ ენაზე 7 მილიონზე მეტი ადამიანი ლაპარაკობს.
%

\begin{amharic}
\textbf{አማርኛ} የኢትዮጵያ መደበኛ ቋንቋ ነው። ከሴማዊ ቋንቋዎች እንደ ዕብራይስጥ ወይም ዓረብኛ አንዱ ነው። እንዲያውም 27 ሚሊዮን ያህል ተናጋሪዎች እያሉት፣ አማርኛ ከአረብኛ ቀጥሎ ትልቁ ሴማዊ ቋንቋ ነው። የሚጻፈውም በግዕዝ ፊደል ነው። አማርኛ ክዓረብኛና ከዕብራይስጥ ያለው መሰረታዊ ልዩነት አንደላቲን ከግራ ወደ ቀኝ መጻፉ ነው። \\
(\today)
\end{amharic}

\begin{nko}
ߒߞߏ ߦߋ߫ ߛߓߍߟߌߞߊ߲ߞߋ ߟߋ߬ ߘߌ߫ ߝߘߊ߬ߝߌ߲߬ߠߊ߫ ߕߟߋ߬ߓߋ ߘߐ߫ ߡߊ߲߬ߘߋ߲߬ ߡߌߙߌ߲ߘߌ ߞߊ߲ ߞߊߡߊ߬߸ ߊ߬ ߣߴߊ߬ ߡߟߋߞߎߦߊߞߊ߲ ߕߐ߮ ߟߋ߬. ߞߊ߬ߕߎ߲߯ ߸ ߊ߬ ߞߘߐ ߟߋ߬ ߡߊ߲߬ߘߋ߲߫ ߝߘߏ߬ߓߊ߬ߞߊ߲ ߓߏߟߏ߲ ߓߍ߯ ߘߐ߫ ߞߏ߫: ߒ ߞߊ߲߫ ߠߋ߬ ߞߏ߫. ߝߣߊ߫߸ ߊ߬ ߦߋ߫ ߟߊߓߊ߯ߙߟߊ߫ ߟߊ߫ ߖߡߊ߬ߣߊ ߢߌ߲߬ ߠߎ߫ ߟߋ߬ ߘߐ߫ ߓߊߞߍ߭: ߖߌ߬ߣߍ߫، ߜߋ߲ߞߐ߰ߖߌ߬ߘߊ، ߊ߬ ߣߌ߫ ߡߊߟߌ߫.
\\
(\today)
\end{nko}

\end{document}
%</examples.tex>
%<*example-arabic.tex>
\documentclass[a4paper]{book}%
\usepackage[no-math]{fontspec}
\usepackage{xltxtra,url,amsmath}
\setmainfont{Linux Libertine O}
\defaultfontfeatures{Scale=MatchLowercase}
\newfontfamily\arabicfont[Script=Arabic]{Amiri}%
\newfontfamily\arabicfonttt[Script=Arabic,Scale=.75]{DejaVu Sans Mono}
\newfontfamily\farsifont[Script=Arabic,Scale=1.1,WordSpace=2]{IranNastaliq}
\let\XeTeX\undefined
\let\XeLaTeX\undefined
\usepackage[quiet,nolocalmarks]{polyglossia}
\setdefaultlanguage[calendar=gregorian,hijricorrection=1,locale=mashriq]{arabic}
\setotherlanguage[variant=british]{english}
\setotherlanguage{farsi}
\parindent 0pt
\title{اختبار دعم اللغة العربية}
\author{فرانسوا شاريت}
\begin{document}
\pagenumbering{alph}
\maketitle
\tableofcontents
\chapter{تجربة}
\pagenumbering{arabic}
\section{لغات مختلفة}

\textbf{العربية}\footnote{%
من «\LR{\textenglish{\url{http://ar.wikipedia.org/wiki/}}\RL{\ttfamily لغة عربية}}»} 
أكبر لغات المجموعة السامية من حيث عدد المتحدثين، وإحدى أكثر اللغات انتشارا في
العالم، يتحدثها أكثر من ٤٢٢ مليون نسمة، ويتوزع متحدثوها في المنطقة المعروفة
باسم الوطن العربي، بالإضافة إلى العديد من المناطق الأخرى المجاورة كالأحواز وتركيا
وتشاد ومالي والسنغال. وللغة العربية أهمية قصوى لدى أتباع الديانة الإسلامية، فهي
لغة مصدري التشريع الأساسيين في الإسلام: القرآن، والأحاديث النبوية المروية عن النبي
محمد، ولا تتم الصلاة في الإسلام (وعبادات أخرى) إلا بإتقان بعض من كلمات هذه اللغة.
والعربية هي أيضًا لغة طقسية رئيسية لدى عدد من الكنائس المسيحية في العالم العربي،
كما كتبت بها الكثير من أهم الأعمال الدينية والفكرية اليهودية في العصور الوسطى.
وإثر انتشار الإسلام، وتأسيسه دولا، ارتفعت مكانة اللغة العربية، وأصبحت لغة السياسة
والعلم والأدب لقرون طويلة في الأراضي التي حكمها المسلمون، وأثرت العربية، تأثيرا
مباشرا أو غير مباشر على كثير من اللغات الأخرى في العالم الإسلامي، كالتركية
والفارسية والأردية مثلا.

\textlang{farsi}{\bfseries فارسی}\footnote{%
از «\LR{\textenglish{\url{http://fa.wikipedia.org/wiki/}}\RL{\ttfamily فارسي}}»}
\begin{farsi}
یا پارسی، (که دری، فارسی دری، و پارسی دری نیز نامیده می‌شود) زبانی است که
در کشورهای ایران، افغانستان، تاجیکستان و ازبکستان به آن سخن می‌رانند.
(برخی زبان فارسی در تاجیکستان و ازبکستان و چین را فارسی تاجیکی نام
می‌گذارند).  
\end{farsi}

\newpage
\begin{english}
\textbf{English}\footnote{%
	From \url{http://en.wikipedia.org/wiki/English_language}} 
is a West Germanic language originating in England, and the first language for
most people in Australia, Canada, the Commonwealth Caribbean, Ireland, New
Zealand, the United Kingdom and the United States of America (also commonly
known as the Anglosphere). It is used extensively as a second language and as
an official language throughout the world, especially in Commonwealth countries
and in many international organisations.

\textarabic{١ ٢ ٣}

\end{english}
\clearpage

\section{أعمال تأريخية \textenglish{(Calendar operations)}}

%\textenglish{\today} = \LTR{\today} = 
\setfootnoteLR
\today\ = \Hijritoday%\footnote{ 
%	محسوب بـ \textenglish{\textsf{hijrical.sty}}}
\LTRfootnote{ What is this?}
\setfootnoteRL

%\newpage
\subsection{فلان}
\textenglish{This is English: a b c}\marginpar{انكليزي} %FIXME! cf farsitex?

\subsubsection{فلان فلان}
\begin{enumerate}
	\item مثال
	\item مثال
		\begin{enumerate}
			\item مثال
			\item مثال
		\end{enumerate}

	\item مثال	
\end{enumerate}

\begin{table}[h]
	\centering
	\begin{tabular}{cc}
		ا & ب  \\
		ج & د  
	\end{tabular}
	\caption{هذا المثال}
\end{table}

\[
x^\text{مال مال}
\]

\begin{equation}
	x^2 + y^2 = z^2
	\label{test}
\end{equation}
\end{document}
%</example-arabic.tex>
%<*example-thai.tex>
\documentclass[a4paper]{article}
\usepackage[no-math]{fontspec}
\usepackage{xltxtra,url}
\usepackage{polyglossia}
\setdefaultlanguage[numerals=thai]{thai}
\setotherlanguage{english}
\setmainfont{Norasi}
\begin{document}
\begin{center}
	\abstractname
\end{center}
\begin{english}
Some English to begin with.\footnote{ %
	Blabla}
\end{english}
%%% NOTE: The wordbreak (\wbr) commands were inserted by the preprocessor cttex 
%%% (available from http://linux.thai.net/pub/thailinux/cvs/software/cttex/ 
%%% or from http://packages.debian.org/cttex) 
%%% using the command :
%%% $ cttex-utf8 <infile.tex> <outfile.tex>
%%% where cttex-utf8 is the following simple shell script:
%%% #!/bin/bash 
%%% cat $1 | iconv -f UTF-8 -t TIS-620 | cttex -w | sed 's/<WBR>/\\wbr /g' | iconv -f TIS-620 -t UTF8 > $2
%%% (this should also work on MacOSX; windows users need to tweak it into a batch file I guess)

เป็น\wbr แผนงานเพื่อ\wbr สนับสนุน\wbr การ\wbr ร่วมกัน\wbr สร้าง, การ\wbr ร่วมกันใช้, และ\wbr การ%
ร่วมกัน\wbr พัฒนา\wbr ทรัพยากร\wbr ทาง\wbr ภาษา\wbr ของ\wbr ภาษา\wbr ไทย, บน\wbr เครือข่าย World Wide Web. แผนงานนี้\wbr มี%
จุด\wbr ประสงค์หลั\wbr กอยู่\wbr สอง\wbr ประการคือ เพื่อแก้ปัญหา\wbr กำ\wbr แพง\wbr ทาง\wbr ภาษา, และรักษา%
ไว้เพื่อ\wbr ความค\wbr งอยู่\wbr ของ\wbr ภาษา\wbr และ\wbr วัฒนธรรม\wbr ไทย.

เรา\wbr ตระหนัก\wbr ดีถึง\wbr ความ\wbr สำคัญ\wbr ของ\wbr ภาษา ซึ่ง\wbr นอกจาก\wbr จะ\wbr เป็นสื่อ\wbr ระหว่าง\wbr คนกับ\wbr คน\wbr แล้ว ยัง\wbr เป็น%
รูปแทน\wbr ความคิด และ\wbr เป็น\wbr เครื่องมือ\wbr ใน\wbr การใช้\wbr ความคิด\wbr ด้วย. เครือข่าย\wbr คอมพิวเตอร์%
ใน\wbr ปัจจุบัน\wbr ทำให้ข้อมูล\wbr ข่าวสาร\wbr แพร่หลาย\wbr ไป\wbr อย่าง\wbr รวดเร็ว. เครื่องมือที่ใช้\wbr ใน\wbr การแส\wbr ดง\wbr ผล%
และ\wbr การเต\wbr รี\wbr ยมข้อมูล\wbr ข่าวสาร\wbr นั้น จึง\wbr เป็นสิ่ง\wbr จำ\wbr เป็น. ด้วย\wbr เทคโนโลยีที่\wbr ก้าวหน้า\wbr ไป%
อย่าง\wbr รวดเร็ว, การที่\wbr เพียง\wbr จะ\wbr สามารถแส\wbr ดง\wbr ผลได้หรือ\wbr ป้อนข้อมูลได้\wbr เท่านั้น ไม่\wbr เป็นที่%
เพียงพออีก\wbr แล้ว. การแส\wbr ดง\wbr ผลที่\wbr สวย\wbr งาม\wbr ถูก\wbr ต้อง\wbr ตาม\wbr แบบแผน หรือ\wbr การเต\wbr รี\wbr ยมข้อมูลได้\wbr อย่าง%
ถูก\wbr ต้อง และ\wbr รวดเร็วจึง\wbr เป็นสิ่งที่\wbr จำ\wbr เป็นที่\wbr จะ\wbr ต้อง\wbr พัฒนาให้\wbr ทันตาม\wbr การ\wbr เปลี่ยนแปลง\wbr ของ%
เทคโนโลยี.\footnote{ %
	Second footnote}

\today

\begin{english}
This is today: \today
\end{english}

\begin{enumerate}
	\item A
	\item B	
	\begin{enumerate}
		\item a
		\item b	
		\item c	
	\end{enumerate}
	\item C	
\end{enumerate}
\end{document}
%</example-thai.tex>
% \fi
% 
% \typeout{*************************************************************}
% \typeout{*}
% \typeout{* To finish the installation you have to move the following}
% \typeout{* file into a directory searched by TeX:}
% \typeout{*}
% \typeout{* \space\space\space all *.sty, *.lua, *.def and *.ldf files}
% \typeout{*}
% \typeout{* You also need to compile the *.map files with teckit_compile}
% \typeout{* and place the resulting *.tec files under}
% \typeout{* .../fonts/misc/xetex/fontmapping}
% \typeout{*}
% \typeout{*************************************************************}
\endinput
