### Font Setup for Scripts and Languages Source: https://context7.com/reutenauer/polyglossia/llms.txt Define specific fonts for scripts or languages using \newfontfamily with naming conventions like \⟨script⟩font or \⟨language⟩font. Sans and monospace variants can also be defined. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setmainfont{Linux Libertine O} \defaultfontfeatures{Scale=MatchLowercase} % Language-specific fonts \newfontfamily\arabicfont[Script=Arabic]{Amiri}[ UprightFont = *-Regular, BoldFont = *-Bold, Extension = .ttf, ItalicFont = *-Italic, BoldItalicFont = *-BoldItalic] \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL} \newfontfamily\greekfont[Script=Greek]{GFS Didot} \newfontfamily\thaifont[Script=Thai]{Norasi} \newfontfamily\sanskritfont[Script=Devanagari]{Sanskrit 2003} % Sans and monospace variants for specific scripts \newfontfamily\arabicfontsf[Script=Arabic]{DejaVu Sans} \newfontfamily\arabicfonttt[Script=Arabic,Scale=.75]{DejaVu Sans Mono} \setdefaultlanguage{english} \setotherlanguage{arabic} \setotherlanguage{hebrew} \begin{document} English text in Linux Libertine. \begin{Arabic} النص العربي يظهر بخط أميري. \end{Arabic} \begin{hebrew} טקסט בעברית \end{hebrew} \end{document} ``` -------------------------------- ### Configure Right-to-Left Language Support Source: https://context7.com/reutenauer/polyglossia/llms.txt Demonstrates setting up Arabic with RTL support and using explicit direction commands like \LR and \RL. ```latex \documentclass{book} \usepackage{fontspec} \usepackage{polyglossia} \setmainfont{Linux Libertine O} \newfontfamily\arabicfont[Script=Arabic]{Amiri}[ UprightFont = *-Regular, BoldFont = *-Bold, Extension = .ttf] \setdefaultlanguage[calendar=gregorian,locale=mashriq]{arabic} \setotherlanguage[variant=british]{english} \title{اختبار دعم اللغة العربية} \author{المؤلف} \begin{document} \maketitle \tableofcontents \chapter{المقدمة} هذا نص عربي يُكتب من اليمين إلى اليسار. % Embed LTR English in RTL context \textenglish{This is English text} داخل النص العربي. % Explicit direction commands \LR{Left-to-Right forced text} \begin{english} This entire section is in English, written left-to-right. \textarabic{النص العربي} can be embedded here. \end{english} \end{document} ``` -------------------------------- ### Enable Babel Shorthands Source: https://context7.com/reutenauer/polyglossia/llms.txt Configures keyboard shortcuts for special characters and demonstrates inheriting or disabling shorthands. ```latex \documentclass{article} \usepackage{fontspec} \usepackage[babelshorthands]{polyglossia} % Global activation \setdefaultlanguage{english} \setotherlanguage[babelshorthands=true]{german} % Per-language activation \setotherlanguage[babelshorthands=true]{russian} \begin{document} \begin{german} % German shorthands: "a "o "u "s % → ä ö ü ß "< "> % → « » "` "' % → „ " "- "" % → soft hyphen, compound word break \end{german} % Inherit shorthands from one language to another \inheritbabelshorthands{german}{english} % Use shorthands inline without switching language \usebabelshorthands{german} Now "a produces ä even in English. \usebabelshorthands{none} % Disable shorthands \end{document} ``` -------------------------------- ### Add Secondary Languages Source: https://context7.com/reutenauer/polyglossia/llms.txt Use \setotherlanguage for individual languages or \setotherlanguages to load multiple languages. Options can be specified for individual languages. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english} % Load individual language with options \setotherlanguage[variant=polytonic]{greek} \setotherlanguage[spelling=new,babelshorthands=true]{german} \setotherlanguage[locale=mashriq]{arabic} % Load multiple languages without options \setotherlanguages{french,spanish,italian,russian,latin} \begin{document} English text here. \begin{german} Dies ist deutscher Text mit neuer Rechtschreibung. \end{german} \end{document} ``` -------------------------------- ### Define Language Aliases and Use BCP-47 Tags Source: https://context7.com/reutenauer/polyglossia/llms.txt Demonstrates how to set default and other languages, define custom aliases for languages, and use BCP-47 tags directly for language switching. Useful for managing multilingual documents with specific regional or historical language variants. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage[variant=austrian,spelling=old]{german} \setotherlanguage[variant=british]{english} % Define custom alias \setlanguagealias[variant=austrian]{german}{AT} % Starred version: no \textAT or {AT} environment created % (useful when name conflicts with existing commands) \setlanguagealias*[variant=polytonic]{greek}{grc} \begin{document} % Use custom alias \textAT{Österreichisches Deutsch} % Use BCP-47 tags directly (predefined aliases) \textlang{en-GB}{British English text} \textlang{de-AT-1901}{Österreichisches Deutsch, alte Rechtschreibung} \textlang{el-polyton}{Πολυτονικά ελληνικά} \begin{lang}{fr-CA} Français canadien \end{lang} % Access BCP-47 data Current language tag: \BCPdata{tag} Main language: \BCPdata{main.language} Script: \BCPdata{script} \end{document} ``` -------------------------------- ### Set Main Language with Options Source: https://context7.com/reutenauer/polyglossia/llms.txt Use \setdefaultlanguage or \setmainlanguage to specify the primary document language with optional settings like variant and ordinal month/day formatting. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} % Set main language with options \setdefaultlanguage[variant=british,ordinalmonthday=false]{english} % Alternative: using \setmainlanguage (identical behavior) \setmainlanguage[variant=american]{english} \begin{document} Today's date: \today % Outputs date in British English format \end{document} ``` -------------------------------- ### Language Environments Source: https://context7.com/reutenauer/polyglossia/llms.txt Use language environments for longer passages to switch hyphenation, translate caption strings, and pass language info to auxiliary files. The generic \begin{lang}{...} environment is useful for BCP-47 tags. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage[variant=british]{english} \setotherlanguage[variant=polytonic]{greek} \setotherlanguage{german} \begin{document} \section{Introduction} This is the main English text. \begin{greek}[variant=ancient] μῆνιν ἄειδε θεὰ Πηληϊάδεω Ἀχιλῆος οὐλομένην, ἣ μυρί' Ἀχαιοῖς ἄλγε' ἔθηκε. \end{greek} % Generic lang environment (useful for BCP-47 tags) \begin{lang}{de-AT-1901} Dies ist österreichisches Deutsch mit alter Rechtschreibung. (\today) \end{lang} \begin{german} \section{Deutsche Überschrift} Dieser Text erscheint auf Deutsch. Das Wort ``Section'' wird automatisch zu ``Abschnitt'' übersetzt. (\today) \end{german} \end{document} ``` -------------------------------- ### Perform Conditional Language Checks Source: https://context7.com/reutenauer/polyglossia/llms.txt Illustrates how to check if a language is loaded, if a specific Babel name is active, if a language option is set, and if the current language is the main language. Also shows how to retrieve language identifiers. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage[variant=british]{english} \setotherlanguage[spelling=new]{german} \begin{document} % Check if a language is loaded \iflanguageloaded{german}{German is loaded.}{German not loaded.} % Check if babel name is loaded \ifbabellanguageloaded{ngerman}{New German loaded.}{Not loaded.} % Check current language option value \iflanguageoption{german}{spelling}{new}{New spelling active.}{Old spelling.} % Check if current language is main language \IfMainLanguageTF{english}{ This is the main language. }{ This is a secondary language. } % Get language identifiers Language name: \languagename Main language: \mainlanguagename Babel name: \babelname BCP-47 ID: \languageid{bcp47} \end{document} ``` -------------------------------- ### Implement Non-Gregorian Calendars Source: https://context7.com/reutenauer/polyglossia/llms.txt Uses specific calendar packages to display dates in Hebrew, Islamic, and Persian formats. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \usepackage{hebrewcal} \usepackage{hijrical} \usepackage{farsical} \newfontfamily\arabicfont[Script=Arabic]{Amiri} \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL} \setdefaultlanguage{english} \setotherlanguage[calendar=hebrew]{hebrew} \setotherlanguage[calendar=islamic]{arabic} \setotherlanguage{farsi} \begin{document} Gregorian date: \today \begin{hebrew}[numerals=hebrew] Hebrew date: \hebrewtoday \end{hebrew} \begin{Arabic} % Hijri date with optional correction days Islamic date: \Hijritoday[0] \end{Arabic} \begin{farsi} % Persian/Jalali calendar Persian date: \Jalalitoday \end{farsi} \end{document} ``` -------------------------------- ### Use Local Numerals Source: https://context7.com/reutenauer/polyglossia/llms.txt Converts numbers to local scripts using \localnumeral and language-specific settings. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \newfontfamily\arabicfont[Script=Arabic]{Amiri} \newfontfamily\thaifont[Script=Thai]{Norasi} \newfontfamily\hebrewfont[Script=Hebrew]{Ezra SIL} \setdefaultlanguage{english} \setotherlanguage[numerals=arabic]{arabic} \setotherlanguage[numerals=thai]{thai} \setotherlanguage[numerals=hebrew]{hebrew} \begin{document} % Automatic numeral conversion in language context \begin{Arabic} الرقم ١٢٣٤٥ % Arabic-Indic numerals \end{Arabic} \begin{thai} ๑๒๓๔٥ % Thai numerals \end{thai} % Manual numeral conversion Arabic numerals for 2024: \textarabic{\localnumeral{2024}} % Counter output in local numerals \localnumeral*{page} % Current page number in local numerals \Localnumeral{42} % Uppercase variant where applicable \end{document} ``` -------------------------------- ### Control Hyphenation Patterns Source: https://context7.com/reutenauer/polyglossia/llms.txt Configures hyphenation exceptions, thresholds, and global toggles for specific languages. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage{german} \setotherlanguage{french} % Language-specific hyphenation exceptions \pghyphenation{english}{poly-glos-sia Xe-La-TeX} \pghyphenation[spelling=new]{german}{Recht-schrei-bung} % Set hyphenation thresholds (left min, right min) \setlanghyphenmins{english}{3}{3} \setlanghyphenmins[spelling=old]{german}{4}{4} \begin{document} % Disable/enable hyphenation globally \disablehyphenation This text will not be hyphenated at all. \enablehyphenation Normal hyphenation resumes. % Use hyphenrules environment for pattern-only switching \begin{hyphenrules}[variant=british]{english} Text using British hyphenation patterns only. \end{hyphenrules} \end{document} ``` -------------------------------- ### Inline Language Switching with \textlang Source: https://context7.com/reutenauer/polyglossia/llms.txt Use \textlang{language}{text} or \text⟨lang⟩{text} for short inline text in another language. This switches hyphenation patterns and activates language-specific features. Options can be passed to \textlang. ```latex \documentclass{article} \usepackage{fontspec} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage{french} \setotherlanguage{russian} \setotherlanguage{greek} \begin{document} The French word \textfrench{aujourd'hui} means ``today''. Using \textlang command: \textlang{russian}{Привет мир} means ``Hello world''. % With options \textlang[variant=ancient]{greek}{μῆνιν ἄειδε θεὰ} % Date is also localized Russian date: \textrussian{\today} \end{document} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.