"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/polyglossia.el" (18 Oct 2020, 14551 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "polyglossia.el": 12.2_vs_12.3.

    1 ;;; polyglossia.el --- AUCTeX style for `polyglossia.sty' version 1.42.0.
    2 
    3 ;; Copyright (C) 2015, 2018 Free Software Foundation, Inc.
    4 
    5 ;; Maintainer: auctex-devel@gnu.org
    6 ;; Author: Mosè Giordano <mose@gnu.org>
    7 ;; Keywords: tex
    8 
    9 ;; This file is part of AUCTeX.
   10 
   11 ;; AUCTeX is free software; you can redistribute it and/or modify it
   12 ;; under the terms of the GNU General Public License as published by
   13 ;; the Free Software Foundation; either version 3, or (at your option)
   14 ;; any later version.
   15 
   16 ;; AUCTeX is distributed in the hope that it will be useful, but
   17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
   18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19 ;; General Public License for more details.
   20 
   21 ;; You should have received a copy of the GNU General Public License
   22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
   23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
   24 ;; 02110-1301, USA.
   25 
   26 ;;; Commentary:
   27 
   28 ;; This file adds support for `polyglossia.sty' version 1.42.0.
   29 
   30 ;;; TODO:
   31 
   32 ;;  -- Create language specific styles with names `gloss-<lang>.el'.  They
   33 ;;     should add `text<lang>' macros, `<lang>' environments (`Arabic' for
   34 ;;     `arabic' language), and the others language-specific commands.
   35 
   36 ;;; Code:
   37 
   38 (require 'tex) ;Indispensable when compiling the call to `TeX-auto-add-type'.
   39 
   40 ;; Silence the compiler:
   41 (declare-function font-latex-add-keywords
   42           "font-latex"
   43           (keywords class))
   44 
   45 (TeX-auto-add-type "polyglossia-lang" "LaTeX")
   46 
   47 ;; Self Parsing -- see (info "(auctex)Hacking the Parser").
   48 (defvar LaTeX-polyglossia-lang-regexp
   49   (concat "\\\\set\\(defaultlanguage\\|mainlanguage\\|otherlanguages?\\)"
   50       "[ \t\n\r]*\\(?:\\[\\(.*\\)\\]\\)?[ \t\n\r]*{\\([A-Za-z, ]+\\)}")
   51   "Matches languages set with polyglossia macros.")
   52 
   53 (defvar LaTeX-polyglossia-setkeys-regexp
   54   (concat "\\\\setkeys"
   55       "[ \t\n\r]*{\\([A-Za-z]+\\)}[ \t\n\r]*{\\([^}]*\\)}")
   56   "Matches polyglossia languages options set using \"\setkeys\".")
   57 
   58 (defvar LaTeX-auto-polyglossia-lang nil
   59   "Temporary for parsing polyglossia languages.")
   60 
   61 (defvar LaTeX-auto-polyglossia-setkeys nil
   62   "Temporary for parsing polyglossia language options.")
   63 
   64 (defun LaTeX-polyglossia-prepare ()
   65   "Clear some polyglossia variables before use."
   66   (setq LaTeX-auto-polyglossia-lang nil
   67     LaTeX-auto-polyglossia-setkeys nil
   68     LaTeX-polyglossia-lang-list nil))
   69 
   70 (defun LaTeX-polyglossia-cleanup ()
   71   "Move languages and their options from
   72 `LaTeX-auto-polyglossia-lang' to `LaTeX-polyglossia-lang-list'."
   73   ;; Example: now the value of `LaTeX-auto-polyglossia-lang' is something like
   74   ;;   '(("danish" "defaultlanguage" "")
   75   ;;     ("arabic" "otherlanguage" "locale=tunisia,numerals=maghrib")
   76   ;;     ("german" "otherlanguage" "spelling=new,script=latin")
   77   ;;     ("icelandic,brazil,sanskrit" "otherlanguages" ""))
   78   ;; We want to end up with a list like
   79   ;;   '(("danish" "defaultlanguage")
   80   ;;     ("arabic" "otherlanguage" "locale=tunisia" "numerals=maghrib")
   81   ;;     ("german" "otherlanguage" "spelling=new" "script=latin")
   82   ;;     ("icelandic" "otherlanguages")
   83   ;;     ("brazil" "otherlanguages")
   84   ;;     ("sanskrit" "otherlanguages" "script=Devanagari"))
   85   ;; with "script=Devanagari" option to "sanskrit" language set using
   86   ;; "\setkeys".
   87   ;; In each element of the alist, the key is the language, the second value is
   88   ;; the polyglossia command which set the language, the rest of values is the
   89   ;; list of options given to the language.
   90   (let (opts otheropts)
   91     (mapc
   92      (lambda (elt)
   93        (mapc
   94     (lambda (language)
   95       ;; `opts' is the string of options for `language', set using
   96       ;; "\setdefaultlanguage" or "\setotherlanguage".
   97       (setq opts (cdr (cdr elt)))
   98       ;; `otheropts' is the string of options for `language' set using
   99       ;; "\setkeys".
  100       (setq otheropts
  101         (car (cdr (assoc language LaTeX-auto-polyglossia-setkeys))))
  102       (add-to-list
  103        'LaTeX-polyglossia-lang-list
  104        (append
  105         (list language) (list (nth 1 elt))
  106         (unless (equal opts '(""))
  107           (LaTeX-listify-package-options (car opts)))
  108         (if otheropts (LaTeX-listify-package-options otheropts))) t))
  109     (LaTeX-listify-package-options (car elt))))
  110      LaTeX-auto-polyglossia-lang)))
  111 
  112 (add-hook 'TeX-auto-prepare-hook #'LaTeX-polyglossia-prepare)
  113 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-polyglossia-cleanup)
  114 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
  115 ;; Run style hooks for every active language.  This *has* to be done after
  116 ;; `TeX-auto-parse'.
  117 (add-hook 'TeX-update-style-hook #'LaTeX-polyglossia-load-languages t)
  118 
  119 (defvar LaTeX-polyglossia-language-list
  120   '("albanian" "amharic" "arabic" "armenian" "asturian" "bahasai" "bahasam"
  121     "basque" "bengali" "brazil" "breton" "bulgarian" "catalan" "coptic"
  122     "croatian" "czech" "danish" "divehi" "dutch" "english" "esperanto"
  123     "estonian" "farsi" "finnish" "french" "friulan" "galician" "german" "greek"
  124     "hebrew" "hindi" "icelandic" "interlingua" "irish" "italian" "kannada"
  125     "khmer" "korean" "lao" "latin" "latvian" "lithuanian" "lsorbian" "magyar"
  126     "malayalam" "marathi" "nko" "norsk" "nynorsk" "occitan" "piedmontese"
  127     "polish" "portuges" "romanian" "romansh" "russian" "samin" "sanskrit"
  128     "scottish" "serbian" "slovak" "slovenian" "spanish" "swedish" "syriac"
  129     "tamil" "telugu" "thai" "tibetan" "turkish" "turkmen" "ukrainian" "urdu"
  130     "usorbian" "vietnamese" "welsh")
  131   "List of languages supported by the polyglossia LaTeX package.")
  132 
  133 (defun LaTeX-polyglossia-active-languages ()
  134   "Return a list of polyglossia languages used in the document.
  135 The last language is the default one."
  136   (let (active-languages default)
  137     (mapc
  138      (lambda (elt)
  139        (setq default (or (string-equal "defaultlanguage" (nth 1 elt))
  140              (string-equal "mainlanguage" (nth 1 elt))))
  141        ;; Append the language to the list if it's the default one.
  142        (add-to-list 'active-languages (car elt) default))
  143      LaTeX-polyglossia-lang-list)
  144     active-languages))
  145 
  146 (defun LaTeX-polyglossia-lang-option-member (language option)
  147   "Return non-nil if OPTION has been given to polyglossia LANGUAGE.
  148 The value is actually the tail of the list of options given to LANGUAGE."
  149   (member option (cdr (cdr (assoc language LaTeX-polyglossia-lang-list)))))
  150 
  151 (defun LaTeX-arg-polyglossia-lang (_optional _default multiple setkeys)
  152   "Prompt for language and its options with completion and insert them
  153 as arguments.
  154 
  155 This function is triggered by \"\setdefaultlanguage\",
  156 \"\setotherlanguage\", \"\setotherlanguages\", and \"\setkeys\"
  157 macros by polyglossia package.
  158 
  159 OPTIONAL and DEFAULT are ignored, if MULTIPLE is non-nil prompt
  160 for multiple languages, if SETKEYS is non-nil insert options as
  161 second mandatory argument."
  162   ;; DEFAULT =  t , MULTIPLE = nil, SETKEYS = nil: "\setdefaultlanguage".
  163   ;; DEFAULT = nil, MULTIPLE = nil, SETKEYS = nil: "\setotherlanguage".
  164   ;; DEFAULT = nil, MULTIPLE =  t , SETKEYS = nil: "\setotherlanguages".
  165   ;; DEFAULT = nil, MULTIPLE = nil, SETKEYS =  t : "\setkeys".
  166 
  167   ;; Note: `DEFAULT' is currently ignored because we don't really have a
  168   ;; mechanism to identify the default polyglossia language.
  169   (let ((language (funcall
  170            (if multiple
  171                'TeX-completing-read-multiple
  172              'completing-read)
  173            (if multiple "Languages: " "Language: ")
  174            (if setkeys
  175                (LaTeX-polyglossia-active-languages)
  176              LaTeX-polyglossia-language-list)))
  177     var  options)
  178     (if multiple
  179     (mapc (lambda (elt) (TeX-run-style-hooks (concat "gloss-" elt)))
  180           language)
  181       (TeX-run-style-hooks (concat "gloss-" language)))
  182     ;; "\setotherlanguages" doesn't take options, don't prompt for them.
  183     (setq options
  184       (if multiple ""
  185         (setq var (intern (format "LaTeX-polyglossia-%s-options-list" language)))
  186         (if (and (boundp var) (symbol-value var))
  187         ;; "\setdefaultlanguage" and "\setotherlanguage" use `options'
  188         ;; as first optional argument; "\setkeys" uses `options' as
  189         ;; second mandatory argument.
  190         (TeX-read-key-val (not setkeys) (symbol-value var))
  191           ;; When `LaTeX-polyglossia-<lang>-options-list' is nil or not
  192           ;; defined, don't prompt for options.
  193           "")))
  194     (unless setkeys
  195       (let ((TeX-arg-opening-brace LaTeX-optop)
  196         (TeX-arg-closing-brace LaTeX-optcl))
  197     (TeX-argument-insert options t)))
  198     (if multiple
  199     (setq language (mapconcat 'identity language ",")))
  200     (TeX-argument-insert language nil)
  201     (if setkeys
  202     (TeX-argument-insert options nil))))
  203 
  204 (defun LaTeX-arg-polyglossiasetup-options (optional)
  205   "Prompt for setup options of polyglossia package.
  206 If OPTIONAL is non-nil, insert the resulting value as an optional
  207 argument, otherwise as a mandatory one."
  208   (TeX-arg-key-val optional
  209            '(("language") ;; TODO: add completion in `fontspec.el', see
  210                   ;; "\newfontlanguage"s in `fontspec-xetex.sty'.
  211              ("hyphennames")
  212              ("script") ;; TODO: add completion in `fontspec.el', see
  213                 ;; "\newfontscript"s in `fontspec-xetex.sty'.
  214              ("direction" ("RL" "LR"))
  215              ("scripttag")
  216              ("langtag")
  217              ("hyphenmins")
  218              ("frenchspacing" ("true" "false"))
  219              ("indentfirst" ("true" "false"))
  220              ("fontsetup" ("true" "false"))
  221              ;; The following options aren't already implemented but are
  222              ;; present in `polyglossia.sty' comments.
  223              ;; ("nouppercase" ("true" "false"))
  224              ;; ("localalph")
  225              ;; ("localnumber")
  226              )))
  227 
  228 (defun LaTeX-polyglossia-load-languages ()
  229   "Load style files of babel active languages."
  230   (mapc (lambda (elt) (TeX-run-style-hooks (concat "gloss-" elt)))
  231     (LaTeX-polyglossia-active-languages)))
  232 
  233 (TeX-add-style-hook
  234  "polyglossia"
  235  (lambda ()
  236    (unless (featurep 'tex-buf)
  237      (require 'tex-buf))
  238    (TeX-check-engine-add-engines 'luatex 'xetex)
  239    (TeX-auto-add-regexp
  240     `(,LaTeX-polyglossia-lang-regexp (3 1 2) LaTeX-auto-polyglossia-lang))
  241    (TeX-auto-add-regexp
  242     `(,LaTeX-polyglossia-setkeys-regexp (1 2) LaTeX-auto-polyglossia-setkeys))
  243    (TeX-run-style-hooks "etoolbox" "makecmds" "xkeyval" "fontspec")
  244    (TeX-add-symbols
  245     '("setdefaultlanguage" (LaTeX-arg-polyglossia-lang  t  nil nil))
  246     '("setmainlanguage"    (LaTeX-arg-polyglossia-lang  t  nil nil))
  247     '("setotherlanguage"   (LaTeX-arg-polyglossia-lang nil nil nil))
  248     '("setotherlanguages"  (LaTeX-arg-polyglossia-lang nil  t  nil))
  249     '("setkeys"            (LaTeX-arg-polyglossia-lang nil nil  t ))
  250     '("PolyglossiaSetup"   (TeX-arg-eval completing-read "Language: "
  251                      (LaTeX-polyglossia-active-languages))
  252       LaTeX-arg-polyglossiasetup-options)
  253     "selectbackgroundlanguage"
  254     '("resetdefaultlanguage" ["argument"] 1)
  255     "normalfontlatin"
  256     "rmfamilylatin"
  257     "sffamilylatin"
  258     "ttfamilylatin"
  259     "selectlanguage"
  260     "foreignlanguage")
  261 
  262    (TeX-declare-expert-macros
  263     "polyglossia"
  264     "PolyglossiaSetup" "selectbackgroundlanguage" "resetdefaultlanguage"
  265     "normalfontlatin" "rmfamilylatin" "sffamilylatin" "ttfamilylatin"
  266     "selectlanguage" "foreignlanguage")
  267 
  268    ;; Fontification
  269    (when (and (featurep 'font-latex)
  270           (eq TeX-install-font-lock 'font-latex-setup))
  271      (font-latex-add-keywords '(("setdefaultlanguage" "[{")
  272                 ("setmainlanguage" "[{")
  273                 ("setotherlanguage" "[{")
  274                 ("setotherlanguages" "{")
  275                 ("setkeys" "{{"))
  276                   'function)))
  277  LaTeX-dialect)
  278 
  279 ;; TODO: move each option variable in its specific `gloss-<lang>.el' file.
  280 (defvar LaTeX-polyglossia-arabic-options-list
  281   '(("calendar" ("gregorian" "islamic"))
  282     ("locale" ("default" "mashriq" "libya" "algeria" "tunisia" "morocco" "mauritania"))
  283     ("numerals" ("mashriq" "maghrib"))
  284     ("abjadjimnotail" ("false" "true")))
  285   "Arabic language options for the polyglossia package.")
  286 
  287 (defvar LaTeX-polyglossia-bengali-options-list
  288   '(("numerals" ("Western" "Devanagari"))
  289     ("changecounternumbering" ("true" "false")))
  290   "Bengali language options for the polyglossia package.")
  291 
  292 (defvar LaTeX-polyglossia-catalan-options-list
  293   '(("babelshorthands" ("true" "false")))
  294   "Catalan language options for the polyglossia package.")
  295 
  296 (defvar LaTeX-polyglossia-dutch-options-list
  297   '(("babelshorthands" ("true" "false")))
  298   "Dutch language options for the polyglossia package.")
  299 
  300 (defvar LaTeX-polyglossia-english-options-list
  301   '(("variant" ("american" "usmax" "british" "australian" "newzealand"))
  302     ("ordinalmonthday" ("true" "false")))
  303   "English language options for the polyglossia package.")
  304 
  305 (defvar LaTeX-polyglossia-farsi-options-list
  306   '(("numerals" ("western" "eastern"))
  307     ;; ("locale") ;; not yet implemented
  308     ;; ("calendar") ;; not yet implemented
  309     )
  310   "Farsi language options for the polyglossia package.")
  311 
  312 (defvar LaTeX-polyglossia-german-options-list
  313   '(("variant" ("german" "austrian" "swiss"))
  314     ("spelling" ("new" "old"))
  315     ("latesthyphen" ("true" "false"))
  316     ("babelshorthands" ("true" "false"))
  317     ("script" ("latin" "fraktur")))
  318   "German language options for the polyglossia package.")
  319 
  320 (defvar LaTeX-polyglossia-greek-options-list
  321   '(("variant" ("monotonic" "polytonic" "ancient"))
  322     ("numerals" ("greek" "arabic"))
  323     ("attic" ("true" "false")))
  324   "Greek language options for the polyglossia package.")
  325 
  326 (defvar LaTeX-polyglossia-hebrew-options-list
  327   '(("numerals" ("hebrew" "arabic"))
  328     ("calendar" ("hebrew" "gregorian")))
  329   "Hebrew language options for the polyglossia package.")
  330 
  331 (defvar LaTeX-polyglossia-hindi-options-list
  332   '(("numerals" ("Western" "Devanagari")))
  333   "Hindi language options for the polyglossia package.")
  334 
  335 (defvar LaTeX-polyglossia-lao-options-list
  336   '(("numerals" ("lao" "arabic")))
  337   "Lao language options for the polyglossia package.")
  338 
  339 (defvar LaTeX-polyglossia-russian-options-list
  340   '(("spelling" ("modern" "old"))
  341     ("babelshorthands" ("true" "false")))
  342   "Russian language options for the polyglossia package.")
  343 
  344 (defvar LaTeX-polyglossia-sanskrit-options-list
  345   '(("Script" ("Devanagari")))
  346   "Sanskrit language options for the polyglossia package.")
  347 
  348 (defvar LaTeX-polyglossia-serbian-options-list
  349   '(("script" ("cyrillic" "latin")))
  350   "Serbian language options for the polyglossia package.")
  351 
  352 (defvar LaTeX-polyglossia-syriac-options-list
  353   '(("numerals" ("western" "eastern" "abjad")))
  354   "Syriac language options for the polyglossia package.")
  355 
  356 (defvar LaTeX-polyglossia-thai-options-list
  357   '(("numerals" ("thai" "arabic")))
  358   "Thai language options for the polyglossia package.")
  359 
  360 (defvar LaTeX-polyglossia-package-options
  361   '("babelshorthands" "localmarks" "nolocalmarks" "quiet")
  362   "Package options for the polyglossia package.")
  363 
  364 ;;; polyglossia.el ends here