Initial Commit
[packages] / xemacs-packages / auctex / style / fontspec.el
1 ;;; fontspec.el --- AUCTeX style for `fontspec.sty' version 2.3c.
2
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5 ;; Maintainer: auctex-devel@gnu.org
6 ;; Author: Mosè Giordano <giordano.mose@libero.it>
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.3c.
29
30 ;;; Code:
31
32 (defvar LaTeX-fontspec-font-features
33   '(;; More control over font shape selection
34     ("BoldFont")
35     ("ItalicFont")
36     ("BoldItalicFont")
37     ("SlantedFont")
38     ("BoldSlantedFont")
39     ("SmallCapsFont")
40     ;; Different features for different font shapes
41     ("BoldFeatures")
42     ("ItalicFeatures")
43     ("BoldItalicFeatures")
44     ("SlantedFeatures")
45     ("BoldSlantedFeatures")
46     ("SmallCapsFeatures")
47     ;; Different features for different font sizes
48     ("SizeFeatures")
49     ;; Font independent options
50     ("Color")
51     ("Scale" ("MatchLowercase" "MatchUppercase"))
52     ("WordSpace")
53     ("PunctuationSpace")
54     ("HyphenChar")
55     ("OpticalSize")
56     ;; OpenType options
57     ("Ligatures" ("Required"
58                   "NoRequired"
59                   "Common"
60                   "NoCommon"
61                   "Contextual"
62                   "NoContextual"
63                   "Rare"
64                   "Historic"
65                   "TeX"))
66     ("Letters" ("Uppercase"
67                 "SmallCaps"
68                 "PetiteCaps"
69                 "UppercaseSmallCaps"
70                 "UppercasePetiteCaps"
71                 "Unicase"))
72     ("Numbers" ("Lining"
73                 "OldStyle"
74                 "Proportional"
75                 "Monospaced"
76                 "SlashedZero"
77                 "Arabic"))
78     ("Contextuals" ("Swash"
79                     "Alternate"
80                     "WordInitial"
81                     "WordFinal"
82                     "LineFinal"
83                     "Inner"))
84     ("VerticalPosition" ("Superior"
85                          "Inferior"
86                          "Numerator"
87                          "Denominator"
88                          "ScientificInferior"
89                          "Ordinal"))
90     ("Fraction" ("On" "Alternate"))
91     ("StylisticSet")
92     ("CharacterVariants")
93     ("Alternate")
94     ("Style" ("Alternate"
95               "Italic"
96               "Ruby"
97               "Swash"
98               "Historic"
99               "TitlingCaps"
100               "HorizontalKana"
101               "VerticalKana"))
102     ("Diacritics" ("MarkToBase"
103                    "NoMarkToBase"
104                    "MarkToMark"
105                    "NoMarkToMark"
106                    "AboveBase"
107                    "NoAboveBase"
108                    "BelowBase"
109                    "NoBelowBase"))
110     ("Kerning" ("Uppercase" "On" "Off"))
111     ("AutoFakeBold")
112     ("AutoFakeSlant")
113     ("FakeSlant")
114     ("FakeStretch")
115     ("FakeBold")
116     ("Annotation")
117     ("CJKShape" ("Traditional"
118                  "Simplified"
119                  "JIS1978"
120                  "JIS1983"
121                  "JIS1990"
122                  "Expert"
123                  "NLC"))
124     ("CharacterWidth" ("Proportional"
125                        "Full"
126                        "Half"
127                        "Third"
128                        "Quarter"
129                        "AlternateProportional"
130                        "AlternateHalf"))
131     ("Vertical" ("RotatedGlyphs")))
132   "Font features options for macros of the fontspec package.")
133
134 (defvar LaTeX-fontspec-font-list nil
135   "List of the fonts accessible to fontspec.")
136
137 (defun LaTeX-fontspec-arg-font (optional &optional prompt)
138   "Prompt for a font name with completion.
139 If OPTIONAL is non-nil, insert the resulting value as an optional
140 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
141 string.
142
143 Customize `LaTeX-fontspec-arg-font-search' in order to decide how
144 to retrieve the list of fonts."
145   (unless LaTeX-fontspec-font-list
146     (when (if (eq LaTeX-fontspec-arg-font-search 'ask)
147               (not (y-or-n-p "Find font yourself? "))
148             LaTeX-fontspec-arg-font-search)
149       (message "Searching for fonts...")
150       (with-temp-buffer
151         (shell-command "luaotfload-tool --list=basename" t)
152         ;; Search for the font base names and full names, and add them to
153         ;; `LaTeX-fontspec-font-list'.  The list is in the form
154         ;;     <base name><TAB><full name><TAB><version>
155         (while
156             (re-search-forward "^\\([^\n\r\t]*\\)\t\\([^\n\r\t]*\\)\t.*$" nil t)
157           (add-to-list 'LaTeX-fontspec-font-list (match-string-no-properties 1))
158           (add-to-list 'LaTeX-fontspec-font-list
159                        (match-string-no-properties 2))))))
160   (TeX-argument-insert
161    (completing-read
162     (TeX-argument-prompt optional prompt "Font name")
163     (or LaTeX-fontspec-font-list LaTeX-fontspec-font-list-default))
164    optional))
165
166 (TeX-add-style-hook
167  "fontspec"
168  (lambda ()
169    (TeX-run-style-hooks "expl3" "xparse")
170    (TeX-add-symbols
171     ;; Font selection
172     '("fontspec" [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
173       LaTeX-fontspec-arg-font)
174     ;; Default font families
175     '("setmainfont"
176       [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
177       (LaTeX-fontspec-arg-font "Main font name"))
178     '("setsansfont"
179       [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
180       (LaTeX-fontspec-arg-font "Sans font name"))
181     '("setmonofont"
182       [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
183       (LaTeX-fontspec-arg-font "Mono font name"))
184     ;; New commands to select font families
185     '("newfontfamily" TeX-arg-define-macro
186       [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
187       LaTeX-fontspec-arg-font)
188     '("newfontface" TeX-arg-define-macro
189       [TeX-arg-key-val LaTeX-fontspec-font-features "Font features"]
190       LaTeX-fontspec-arg-font)
191     ;; Math(s) fonts
192     '("setmathrm" [ "Font features" ] "Font name")
193     '("setmathsf" [ "Font features" ] "Font name")
194     '("setmathtt" [ "Font features" ] "Font name")
195     '("setboldmathrm" [ "Font features" ] "Font name")
196     ;; Emphasis and nested emphasis
197     "emshape"
198     "eminnershape"
199     ;; Default settings
200     '("defaultfontfeatures" [ LaTeX-fontspec-arg-font ]
201       (TeX-arg-key-val LaTeX-fontspec-font-features "Font features"))
202     ;; Changing the currently selected features
203     '("addfontfeatures"
204       (TeX-arg-key-val LaTeX-fontspec-font-features "Font features"))
205     ;; Defining new scripts and languages
206     '("newfontscript" "Script name" "OpenType tag")
207     '("newfontlanguage" "Language name" "OpenType tag"))
208
209    ;; Fontification
210    (when (and (featurep 'font-latex)
211               (eq TeX-install-font-lock 'font-latex-setup))
212      (font-latex-add-keywords '(("fontspec"    "[{")
213                                 ("setmainfont" "[{")
214                                 ("setsansfont" "[{")
215                                 ("setmonofont" "[{")
216                                 ("newfontfamily" "{[{")
217                                 ("newfontface" "{[{")
218                                 ("setmathrm" "[{")
219                                 ("setmathsf" "[{")
220                                 ("setmathtt" "[{")
221                                 ("setboldmathrm" "[{")
222                                 ("emshape")
223                                 ("eminnershape")
224                                 ("defaultfontfeatures" "[{")
225                                 ("addfontfeature" "{")
226                                 ("newfontscript" "{{")
227                                 ("newfontlanguage" "{{"))
228                               'function)))
229  LaTeX-dialect)
230
231 (defvar LaTeX-fontspec-package-options
232   '("math" "no-math" "config" "no-config" "quiet" "silent")
233   "Package options for the fontspec package.")
234
235 ;;; fontspec.el ends here