"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/fontspec.el" (18 Oct 2020, 14501 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 "fontspec.el": 12.2_vs_12.3.

    1 ;;; fontspec.el --- AUCTeX style for `fontspec.sty' version 2.6a.
    2 
    3 ;; Copyright (C) 2013, 2017, 2018, 2020 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 `fontspec.sty' version 2.6a.  Starting
   29 ;; with `fontspec.sty' v2.4, the order of mandatory font names and
   30 ;; optional font features in related macros has changed, i.e. optional
   31 ;; argument comes after the mandatory one.  This change is now (April
   32 ;; 2017) implemented in this file.  Fontification support retains
   33 ;; backward compatibilty.
   34 
   35 ;;; Code:
   36 
   37 ;; Silence the compiler:
   38 (declare-function font-latex-add-keywords
   39           "font-latex"
   40           (keywords class))
   41 
   42 (declare-function LaTeX-color-definecolor-list "color" ())
   43 (declare-function LaTeX-xcolor-definecolor-list "xcolor" ())
   44 
   45 (defvar LaTeX-fontspec-font-features
   46   '(;; 5 Font selection
   47     ("Extension" (".otf" ".ttf" ".ttc" ".dfont"))
   48     ("Path")
   49     ;; 6.1 More control over font shape selection
   50     ("BoldFont")
   51     ("ItalicFont")
   52     ("BoldItalicFont")
   53     ("SlantedFont")
   54     ("BoldSlantedFont")
   55     ("SmallCapsFont")
   56     ;; 6.2 Specifically choosing the NFSS family
   57     ("NFSSFamily")
   58     ("FontFace")
   59     ;; 11 Different features for different font shapes
   60     ("UprightFeatures")
   61     ("BoldFeatures")
   62     ("ItalicFeatures")
   63     ("BoldItalicFeatures")
   64     ("SlantedFeatures")
   65     ("BoldSlantedFeatures")
   66     ("SmallCapsFeatures")
   67     ;; 13 Different features for different font sizes
   68     ("SizeFeatures")
   69     ;; 14 Font independent options
   70     ("Color")
   71     ("Scale" ("MatchLowercase" "MatchUppercase"))
   72     ("WordSpace")
   73     ("PunctuationSpace")
   74     ("HyphenChar")
   75     ("OpticalSize")
   76     ("AutoFakeBold")
   77     ("AutoFakeSlant")
   78     ("FakeSlant")
   79     ("FakeStretch")
   80     ("FakeBold")
   81     ("LetterSpace")
   82     ;; 16 OpenType options
   83     ("Ligatures" ("Required"      "RequiredOff"
   84           "Common"        "CommonOff"
   85           "Contextual"    "ContextualOff"
   86           "Rare"          "RareOff"
   87           "Discretionary" "DiscretionaryOff"
   88           "Historic"      "HistoricOff"
   89           "TeX"
   90           "ResetAll"))
   91     ("Letters" ("Uppercase"           "UppercaseOff"
   92         "SmallCaps"           "SmallCapsOff"
   93         "PetiteCaps"          "PetiteCapsOff"
   94         "UppercaseSmallCaps"  "UppercaseSmallCapsOff"
   95         "UppercasePetiteCaps" "UppercasePetiteCapsOff"
   96         "Unicase"             "UnicaseOff"
   97         "ResetAll"))
   98     ("Numbers" ("Uppercase"    "UppercaseOff"
   99         "Lowercase"    "LowercaseOff"
  100         "Lining"       "LiningOff"
  101         "OldStyle"     "OldStyleOff"
  102         "Proportional" "ProportionalOff"
  103         "Monospaced"   "MonospacedOff"
  104         "SlashedZero"  "SlashedZeroOff"
  105         "Arabic"       "ArabicOff"
  106         "ResetAll"))
  107     ("Contextuals" ("Swash"       "SwashOff"
  108             "Alternate"   "AlternateOff"
  109             "WordInitial" "WordInitialOff"
  110             "WordFinal"   "WordFinalOff"
  111             "LineFinal"   "LineFinalOff"
  112             "Inner"       "InnerOff"
  113             "ResetAll"))
  114     ("VerticalPosition" ("Superior"           "SuperiorOff"
  115              "Inferior"           "InferiorOff"
  116              "Numerator"          "NumeratorOff"
  117              "Denominator"        "DenominatorOff"
  118              "ScientificInferior" "ScientificInferiorOff"
  119              "Ordinal"            "OrdinalOff"
  120              "ResetAll"))
  121     ("Fraction" ("On" "Off" "Reset" "Alternate" "AlternateOff" "ResetAll"))
  122     ("StylisticSet")
  123     ("CharacterVariant")
  124     ("Alternate" ("Random"))
  125     ("Style" ("Alternate"      "AlternateOff"
  126           "Italic"         "ItalicOff"
  127           "Ruby"           "RubyOff"
  128           "Swash"          "SwashOff"
  129           "Cursive"        "CursiveOff"
  130           "Historic"       "HistoricOff"
  131           "TitlingCaps"    "TitlingCapsOff"
  132           "HorizontalKana" "HorizontalKanaOff"
  133           "VerticalKana"   "VerticalKanaOff"
  134           "ResetAll"))
  135     ("Diacritics" ("MarkToBase" "MarkToBaseOff"
  136            "MarkToMark" "MarkToMarkOff"
  137            "AboveBase"  "AboveBaseOff"
  138            "BelowBase"  "BelowBaseOff"
  139            "ResetAll"))
  140     ("Kerning" ("Uppercase" "UppercaseOff" "On" "Off" "Reset" "ResetAll"))
  141     ("CharacterWidth" ("Proportional"          "ProportionalOff"
  142                "Full"                  "FullOff"
  143                "Half"                  "HalfOff"
  144                "Third"                 "ThirdOff"
  145                "Quarter"               "QuarterOff"
  146                "AlternateProportional" "AlternateProportionalOff"
  147                "AlternateHalf"         "AlternateHalfOff"
  148                "ResetAll"))
  149     ("Annotation")
  150     ("CJKShape" ("Traditional"
  151          "Simplified"
  152          "JIS1978"
  153          "JIS1983"
  154          "JIS1990"
  155          "Expert"
  156          "NLC"))
  157     ("Vertical" ("RotatedGlyphs"         "RotatedGlyphsOff"
  158          "AlternatesForRotation" "AlternatesForRotationOff"
  159          "Alternates"            "AlternatesOff"
  160          "KanaAlternates"        "KanaAlternatesOff"
  161          "Kerning"               "KerningOff"
  162          "AlternateMetrics"      "AlternateMetricsOff"
  163          "HalfMetrics"           "HalfMetricsOff"
  164          "ProportionalMetrics"   "ProportionalMetricsOff"
  165          "ResetAll"))
  166     ;; 25 Going behind fontspec's back: Offer only an excerpt of all
  167     ;; possible tags:
  168     ("RawFeature" ("frac" "lnum" "onum" "pnum" "smcp" "tnum" "zero")))
  169   "Font features options for macros of the fontspec package.")
  170 
  171 (defvar LaTeX-fontspec-font-features-local nil
  172   "Buffer-local font features options for macros of the fontspec package.")
  173 (make-variable-buffer-local 'LaTeX-fontspec-font-features-local)
  174 
  175 (defvar LaTeX-fontspec-font-list nil
  176   "List of the fonts accessible to fontspec.")
  177 
  178 (defun LaTeX-fontspec-arg-font (optional &optional prompt)
  179   "Prompt for a font name with completion.
  180 If OPTIONAL is non-nil, insert the resulting value as an optional
  181 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
  182 string.
  183 
  184 Customize `LaTeX-fontspec-arg-font-search' in order to decide how
  185 to retrieve the list of fonts."
  186   (unless LaTeX-fontspec-font-list
  187     (when (if (eq LaTeX-fontspec-arg-font-search 'ask)
  188           (not (y-or-n-p "Find font yourself? "))
  189         LaTeX-fontspec-arg-font-search)
  190       (message "Searching for fonts...")
  191       (with-temp-buffer
  192     (shell-command "luaotfload-tool --list=basename" t)
  193     ;; Search for the font base names and full names, and add them to
  194     ;; `LaTeX-fontspec-font-list'.  The list is in the form
  195     ;;     <base name><TAB><full name><TAB><version>
  196     (while
  197         (re-search-forward "^\\([^\n\r\t]*\\)\t\\([^\n\r\t]*\\)\t.*$" nil t)
  198       (add-to-list 'LaTeX-fontspec-font-list (match-string-no-properties 1))
  199       (add-to-list 'LaTeX-fontspec-font-list
  200                (match-string-no-properties 2))))
  201       (message "Searching for fonts...done")))
  202   (TeX-argument-insert
  203    (completing-read
  204     (TeX-argument-prompt optional prompt "Font name")
  205     (or LaTeX-fontspec-font-list LaTeX-fontspec-font-list-default))
  206    optional))
  207 
  208 (defun LaTeX-fontspec-update-font-features ()
  209   "Update Color key=values in `LaTeX-fontspec-font-features-local'."
  210   ;; Check if any color defininig package is loaded and update the
  211   ;; key=values for coloring.  Prefer xcolor.sty if both packages are
  212   ;; loaded.
  213   (when (or (member "xcolor" (TeX-style-list))
  214         (member "color" (TeX-style-list)))
  215     (let* ((colorcmd (if (member "xcolor" (TeX-style-list))
  216              #'LaTeX-xcolor-definecolor-list
  217                #'LaTeX-color-definecolor-list))
  218        (tmp (copy-alist LaTeX-fontspec-font-features)))
  219       (setq tmp (assq-delete-all (car (assoc "Color" tmp)) tmp))
  220       (push (list "Color" (mapcar #'car (funcall colorcmd))) tmp)
  221       (setq LaTeX-fontspec-font-features-local
  222         (copy-alist tmp)))))
  223 
  224 ;; Setup for \newfontfamily and \newfontface:
  225 (TeX-auto-add-type "fontspec-newfontcmd" "LaTeX")
  226 
  227 (defvar LaTeX-fontspec-newfontcmd-regexp
  228   '("\\\\newfontfa\\(?:ce\\|mily\\)[ \t\n\r%]*\\\\\\([a-zA-Z]+\\)"
  229     1 LaTeX-auto-fontspec-newfontcmd)
  230   "Matches new macros defined with \\newfontface and \\newfontfamily.")
  231 
  232 (defun LaTeX-fontspec-auto-prepare ()
  233   "Clear `LaTeX-auto-fontspec-newfontcmd' before parsing."
  234   (setq LaTeX-auto-fontspec-newfontcmd nil))
  235 
  236 (defun LaTeX-fontspec-auto-cleanup ()
  237   "Process parsed elements for fontspec package."
  238   (dolist (mac (mapcar #'car (LaTeX-fontspec-newfontcmd-list)))
  239     ;; Add macro to list of known macros
  240     (TeX-add-symbols mac)
  241     ;; Cater for fontification
  242     (when (and (featurep 'font-latex)
  243            (eq TeX-install-font-lock 'font-latex-setup))
  244       (font-latex-add-keywords `((,mac ""))
  245                    'type-declaration)))
  246   ;; Update values of Color key:
  247   (LaTeX-fontspec-update-font-features))
  248 
  249 (add-hook 'TeX-auto-prepare-hook #'LaTeX-fontspec-auto-prepare t)
  250 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-fontspec-auto-cleanup t)
  251 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
  252 
  253 (TeX-add-style-hook
  254  "fontspec"
  255  (lambda ()
  256    (unless (featurep 'tex-buf)
  257      (require 'tex-buf))
  258    (TeX-check-engine-add-engines 'luatex 'xetex)
  259    (TeX-run-style-hooks "expl3" "xparse")
  260 
  261    ;; Add fontspec to the parser.
  262    (TeX-auto-add-regexp LaTeX-fontspec-newfontcmd-regexp)
  263 
  264    ;; Activate the buffer local version of font features:
  265    (setq LaTeX-fontspec-font-features-local
  266      (copy-alist LaTeX-fontspec-font-features))
  267 
  268    (TeX-add-symbols
  269     ;; 4.3 Commands for old-style and lining numbers: \oldstylenums is
  270     ;; already provided by LaTeX, so just add \liningnums here
  271     '("liningnums" "Numbers")
  272 
  273     ;; 4.5 Emphasis and nested emphasis
  274     ;; \emshape seems to be an internal macro
  275     "emshape"
  276     '("emfontdeclare" t)
  277     "emreset"
  278 
  279     ;; 4.6 Strong emphasis
  280     '("strong" t)
  281     '("strongfontdeclare" t)
  282     "strongreset"
  283 
  284     ;; 5 Font selection
  285     '("fontspec"
  286       LaTeX-fontspec-arg-font
  287       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  288 
  289     ;; Default font families
  290     '("setmainfont"
  291       (LaTeX-fontspec-arg-font "Main font name")
  292       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  293     '("setsansfont"
  294       (LaTeX-fontspec-arg-font "Sans font name")
  295       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  296     '("setmonofont"
  297       (LaTeX-fontspec-arg-font "Mono font name")
  298       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  299 
  300     ;; 5.3 Querying whether a font exists
  301     '("IfFontExistsTF" LaTeX-fontspec-arg-font 2)
  302 
  303     ;; 6 commands to select font families
  304     '("newfontfamily" TeX-arg-define-macro
  305       LaTeX-fontspec-arg-font
  306       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  307 
  308     '("newfontface" TeX-arg-define-macro
  309       LaTeX-fontspec-arg-font
  310       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"])
  311 
  312     ;; 6.4 Math(s) fonts
  313     '("setmathrm" "Font name" [ "Font features" ])
  314     '("setmathsf" "Font name" [ "Font features" ])
  315     '("setmathtt" "Font name" [ "Font features" ])
  316     '("setboldmathrm" "Font name" [ "Font features" ])
  317 
  318     ;; 8 Default settings
  319     '("defaultfontfeatures" [ LaTeX-fontspec-arg-font ]
  320       (TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"))
  321     '("defaultfontfeatures+" [ LaTeX-fontspec-arg-font ]
  322       (TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"))
  323 
  324     ;; 10 Working with the currently selected features
  325     '("IfFontFeatureActiveTF"
  326       [TeX-arg-key-val LaTeX-fontspec-font-features-local "Font feature"] 2)
  327 
  328     ;; Changing the currently selected features
  329     '("addfontfeatures"
  330       (TeX-arg-key-val LaTeX-fontspec-font-features-local "Font features"))
  331 
  332     ;; 23 Defining new features
  333     '("newAATfeature"
  334       (TeX-arg-eval completing-read
  335             (TeX-argument-prompt optional nil "Existing feature")
  336             LaTeX-fontspec-font-features-local)
  337       "New option" 2)
  338 
  339     '("newopentypefeature"
  340       (TeX-arg-eval completing-read
  341             (TeX-argument-prompt optional nil "Existing feature")
  342             LaTeX-fontspec-font-features-local)
  343       "New option" t)
  344 
  345     '("newfontfeature" "New feature" t)
  346 
  347     ;; 24 Defining new scripts and languages
  348     '("newfontscript" "Script name" "OpenType tag")
  349     '("newfontlanguage" "Language name" "OpenType tag")
  350 
  351     ;; 26 Renaming existing features & options
  352     '("aliasfontfeature"
  353       (TeX-arg-eval completing-read
  354             (TeX-argument-prompt optional nil "Existing feature")
  355             LaTeX-fontspec-font-features-local)
  356       "New name")
  357 
  358     '("aliasfontfeatureoption"
  359       (TeX-arg-eval
  360        (lambda ()
  361      (let* ((key (completing-read
  362               (TeX-argument-prompt optional nil "Feature")
  363               LaTeX-fontspec-font-features-local))
  364         (val (completing-read
  365               (TeX-argument-prompt optional nil "Existing name")
  366               (cadr (assoc key LaTeX-fontspec-font-features-local)))))
  367        (TeX-argument-insert key optional)
  368        (format "%s" val))))
  369       "New name") )
  370 
  371    (LaTeX-add-environments
  372     ;; 4.6 Strong emphasis
  373     '("strong"))
  374 
  375    ;; Fontification
  376    (when (and (featurep 'font-latex)
  377           (eq TeX-install-font-lock 'font-latex-setup))
  378      (font-latex-add-keywords '(("fontspec"    "[{[")
  379                 ("setmainfont" "[{[")
  380                 ("setsansfont" "[{[")
  381                 ("setmonofont" "[{[")
  382                 ("newfontfamily" "\\[{[")
  383                 ("newfontface"   "\\[{[")
  384                 ("setmathrm" "[{[")
  385                 ("setmathsf" "[{[")
  386                 ("setmathtt" "[{[")
  387                 ("setboldmathrm" "[{[")
  388                 ("defaultfontfeatures" "+[{")
  389                 ("addfontfeature"  "{")
  390                 ("addfontfeatures" "{")
  391                 ("newfontscript"   "{{")
  392                 ("newfontlanguage" "{{")
  393                 ("emfontdeclare"   "{")
  394                 ("strongfontdeclare"  "{")
  395                 ("newAATfeature"      "{{{{")
  396                 ("newopentypefeature" "{{{")
  397                 ("newfontfeature"     "{{")
  398                 ("aliasfontfeature"   "{{")
  399                 ("aliasfontfeatureoption" "{{{"))
  400                   'function)
  401      (font-latex-add-keywords '(("liningnums"    "{"))
  402                   'type-command)
  403      (font-latex-add-keywords '(("strong"    "{"))
  404                   'bold-command)))
  405  LaTeX-dialect)
  406 
  407 (defvar LaTeX-fontspec-package-options
  408   '("tuenc" "euenc" "math" "no-math" "config" "no-config" "quiet" "silent")
  409   "Package options for the fontspec package.")
  410 
  411 ;;; fontspec.el ends here