forked from emacsmirror/auctex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
font-latex.el
2312 lines (2117 loc) · 102 KB
/
font-latex.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; font-latex.el --- LaTeX fontification for Font Lock mode. -*- lexical-binding: t; -*-
;; Copyright (C) 1996-2022 Free Software Foundation, Inc.
;; Authors: Peter S. Galbraith <[email protected]>
;; Simon Marshall <[email protected]>
;; Maintainer: [email protected]
;; Created: 06 July 1996
;; Keywords: tex, wp, faces
;;; This file is not part of GNU Emacs.
;; This package is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This package is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; This package enhances font-lock fontification patterns for LaTeX.
;; font-lock mode is a minor mode that causes your comments to be
;; displayed in one face, strings in another, reserved words in
;; another, and so on.
;;; Code:
(require 'font-lock)
(require 'tex)
(eval-when-compile
(require 'cl-lib))
(defgroup font-latex nil
"Font-latex text highlighting package."
:prefix "font-latex-"
:group 'faces
:group 'tex
:group 'AUCTeX)
(defgroup font-latex-keywords nil
"Keywords for highlighting text in font-latex."
:prefix "font-latex-"
:group 'font-latex)
(defgroup font-latex-highlighting-faces nil
"Faces for highlighting text in font-latex."
:prefix "font-latex-"
:group 'font-latex)
(defvar font-latex-multiline-boundary 5000
"Size of region to search for the start or end of a multiline construct.")
(defvar font-latex-quote-regexp-beg nil
"Regexp used to find quotes.")
(make-variable-buffer-local 'font-latex-quote-regexp-beg)
(defvar font-latex-quote-list '(("``" "''") ("<<" ">>" french) ("«" "»" french))
"List of quote specifiers for quotation fontification.
Each element of the list is either a list consisting of two
strings to be used as opening and closing quotation marks
independently of the value of `font-latex-quotes' or a list with
three elements where the first and second element are strings for
opening and closing quotation marks and the third element being
either the symbol `german' or `french' describing the order of
quotes.
If `font-latex-quotes' specifies a different state, order of the
added quotes will be reversed for fontification. For example if
'(\"\\\"<\" \"\\\">\" french) is given but `font-latex-quotes'
specifies `german', quotes will be used like \">foo\"< for
fontification.")
(defvar font-latex-quotes-control nil
"Internal variable for keeping track if `font-latex-quotes' changed.")
(make-variable-buffer-local 'font-latex-quotes-control)
(defvar font-latex-quotes-internal nil
"Internal variable for tracking outcome of automatic detection.
If automatic detection is not enabled, it is assigned the value
of `font-latex-quotes'.")
(make-variable-buffer-local 'font-latex-quotes-internal)
(defvar font-latex-quotes-fallback 'french
"Fallback value for `font-latex-quotes' if automatic detection fails.")
(defvar font-latex-quote-style-list-french
'("french" "frenchb" "frenchle" "frenchpro" "francais" "canadien"
"acadian" "italian")
"List of styles for which French-style quote matching should be activated.")
(defvar font-latex-quote-style-list-german
'("austrian" "german" "germanb" "naustrian" "ngerman")
"List of styles for which German-style quote matching should be activated.")
(defcustom font-latex-quotes 'auto
"Whether to fontify << French quotes >> or >>German quotes<<.
Also selects \"<quote\"> versus \">quote\"<.
If value `auto' is chosen, an attempt is being made in deriving
the type of quotation mark matching from document settings like
the language option supplied to the babel package.
If nil, quoted content will not be fontified."
:type '(choice (const auto) (const french) (const german) (const nil))
:group 'font-latex)
(put 'font-latex-quotes 'safe-local-variable
(lambda (x) (memq x '(auto french german nil))))
(defun font-latex-add-quotes (quotes)
"Add QUOTES to `font-latex-quote-list'.
QUOTES has to be a list adhering to the format of an element of
`font-latex-quote-list'."
(setq font-latex-quotes-control nil)
(add-to-list (make-local-variable 'font-latex-quote-list) quotes))
(defun font-latex-quotes-set-internal ()
"Set `font-latex-quotes-internal' according to `font-latex-quotes'.
If `font-latex-quotes' is set to `auto', try to derive the
correct value from document properties."
(setq font-latex-quotes-internal
(if (eq font-latex-quotes 'auto)
(or (when (TeX-elt-of-list-member
font-latex-quote-style-list-french TeX-active-styles)
'french)
(when (TeX-elt-of-list-member
font-latex-quote-style-list-german TeX-active-styles)
'german)
font-latex-quotes-fallback)
font-latex-quotes)))
;; Update the value of `font-latex-quotes-internal' when the list of
;; styles changes.
(add-hook 'TeX-update-style-hook #'font-latex-quotes-set-internal)
;; The definitions of the title faces were originally taken from
;; info.el (Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99,
;; 2000, 2001 Free Software Foundation, Inc.) and adapted to the needs
;; of font-latex.el.
(defconst font-latex-sectioning-max 5
"Highest number for font-latex-sectioning-N-face")
(defface font-latex-sectioning-5-face
'((((type tty pc) (class color) (background light))
(:foreground "blue4" :weight bold))
(((type tty pc) (class color) (background dark))
(:foreground "yellow" :weight bold))
(((class color) (background light))
(:weight bold :inherit variable-pitch :foreground "blue4"))
(((class color) (background dark))
(:weight bold :inherit variable-pitch :foreground "yellow"))
(t (:weight bold :inherit variable-pitch)))
"Face for sectioning commands at level 5."
:group 'font-latex-highlighting-faces)
(defcustom font-latex-fontify-sectioning 1.1
"Whether to fontify sectioning macros with varying height or a color face.
If it is a number, use varying height faces. The number is used
for scaling starting from `font-latex-sectioning-5-face'. Typically
values from 1.05 to 1.3 give best results, depending on your font
setup. If it is the symbol `color', use `font-lock-type-face'.
Caveats: Customizing the scaling factor applies to all sectioning
faces unless those face have been saved by customize. Setting
this variable directly does not take effect unless you call
`font-latex-update-sectioning-faces' or restart Emacs.
Switching from `color' to a number or vice versa does not take
effect unless you call \\[font-lock-fontify-buffer] or restart
Emacs."
:type '(choice (number :tag "Scale factor")
(const color))
:initialize #'custom-initialize-default
:set (lambda (symbol value)
(set-default symbol value)
(unless (eq value 'color)
(font-latex-update-sectioning-faces font-latex-sectioning-max value)))
:group 'font-latex)
(defun font-latex-update-sectioning-faces (&optional max height-scale)
"Update sectioning commands faces."
(unless height-scale
(setq height-scale (if (numberp font-latex-fontify-sectioning)
;; Make sure `height-scale' is a floating point
;; number because `set-face-attribute' treats
;; integers differently from floating points.
(float font-latex-fontify-sectioning)
1.1)))
(unless max
(setq max font-latex-sectioning-max))
(dotimes (num max)
(let* (;; reverse for XEmacs:
(num (- max (1+ num)))
(face-name (intern (format "font-latex-sectioning-%s-face" num))))
(unless (get face-name 'saved-face) ; Do not touch customized faces.
(set-face-attribute face-name nil :height height-scale)))))
(defun font-latex-make-sectioning-faces (max &optional height-scale)
"Build the faces used to fontify sectioning commands."
(unless max (setq max font-latex-sectioning-max))
(unless height-scale
(setq height-scale (if (numberp font-latex-fontify-sectioning)
;; Make sure `height-scale' is a floating point
;; number because the integer type is treated
;; differently.
(float font-latex-fontify-sectioning)
1.1)))
(dotimes (num max)
(let* ((num (- max (1+ num)))
(face-name (intern (format "font-latex-sectioning-%s-face" num)))
(f-inherit (intern (format "font-latex-sectioning-%s-face" (1+ num)))))
(eval
`(defface ,face-name
'((t (:height ,height-scale :inherit ,f-inherit)))
(format "Face for sectioning commands at level %s.
Probably you don't want to customize this face directly. Better
change the base face `font-latex-sectioning-5-face' or customize the
variable `font-latex-fontify-sectioning'." ',num)
:group 'font-latex-highlighting-faces)
t))))
(font-latex-make-sectioning-faces font-latex-sectioning-max)
;;; Keywords
(eval-and-compile
(defconst font-latex-built-in-keyword-classes
'(("warning"
("nopagebreak" "pagebreak" "newpage" "clearpage" "cleardoublepage"
"enlargethispage" "nolinebreak" "linebreak" "newline" "-" "\\" "\\*"
"appendix" "displaybreak" "allowdisplaybreaks" "tabularnewline" "include"
"backmatter" "frontmatter" "mainmatter"
"makeatletter" "makeatother" "newblock" "suppressfloats" "endinput")
font-latex-warning-face 1 noarg)
("variable"
(("setlength" "|{\\{") ("settowidth" "|{\\{") ("settoheight" "{{")
("settodepth" "{{") ("setcounter" "{|{\\")
("addtolength" "|{\\{") ("addtocounter" "{|{\\")
("stepcounter" "{") ("refstepcounter" "{")
("counterwithin" "*[{{") ("counterwithout" "*[{{")
("arabic" "{") ("roman" "{") ("Roman" "{") ("alph" "{") ("Alph" "{")
("fnsymbol" "{"))
font-lock-variable-name-face 2 command)
("biblatexnoarg"
("newrefsegment" "mancite" "pno" "ppno" "nopp" "psq" "psqq")
font-lock-variable-name-face 2 noarg)
("biblatex"
(;; 3.2.2 Setting Package Options
("ExecuteBibliographyOptions" "[{")
;; 3.7.1 Resources
("addbibresource" "[{") ("addglobalbib" "[{") ("addsectionbib" "[{")
;; 3.7.2 The Bibliography
("printbibliography" "[") ("bibbysection" "[") ("bibbysegment" "[")
("bibbycategory" "[") ("printbibheading" "[")
;; 3.7.3 Bibliography Lists
("printbiblist" "[{") ("printshorthands" "[")
;; 3.7.4 Bibliography Sections
("newrefsection" "[")
;; 3.7.6 Bibliography Categories
("DeclareBibliographyCategory" "{") ("addtocategory" "{{")
;; 3.7.7 Bibliography Headings and Environments
("defbibenvironment" "{{{{") ("defbibheading" "{[{")
;; 3.7.8 Bibliography Notes
("defbibnote" "{{")
;; 3.7.9 Bibliography Filters and Checks
("defbibfilter" "{{") ("defbibcheck" "{{")
;; 3.7.10 Reference Contexts
("DeclareRefcontext" "{{") ("newrefcontext" "[{")
("assignrefcontextkeyws" "*[{") ("assignrefcontextcats" "*[{")
("assignrefcontextentries" "*[{")
;; 3.7.11 Dynamic Entry Sets
("defbibentryset" "{{")
;; 3.8.1 Standard Commands
("Cite" "[[{")
("parencite" "*[[{") ("Parencite" "[[{")
("footcite" "[[{") ("footcitetext" "[[{")
;; 3.8.2 Style-specific Commands
("textcite" "[[{") ("Textcite" "[[{")
("smartcite" "[[{") ("Smartcite" "[[{")
("supercite" "{")
;; 3.8.3 Qualified Citation Lists
;; For qualified lists, fontify at least 2 mandatory arguments
("cites" "(([[{[[{") ("Cites" "(([[{[[{")
("parencites" "(([[{[[{") ("Parencites" "(([[{[[{")
("footcites" "(([[{[[{") ("footcitetexts" "(([[{[[{")
("smartcites" "(([[{[[{") ("Smartcites" "(([[{[[{")
("textcites" "(([[{[[{") ("Textcites" "(([[{[[{")
("supercites" "(([[{[[{")
;; 3.8.4 Style-independent Commands
("autocite" "*[[{") ("Autocite" "*[[{")
("autocites" "(([[{[[{") ("Autocites" "(([[{[[{")
;; 3.8.5 Text Commands
("citeauthor" "*[[{") ("Citeauthor" "*[[{") ("citetitle" "*[[{")
("citeyear" "*[[{") ("citedate" "*[[{")
("citeurl" "[[{") ("parentext" "{")
("brackettext" "{")
;; 3.8.6 Special Commands
("fullcite" "[[{") ("footfullcite" "[[{")
("volcite" "[{[{") ("Volcite" "[{[{")
("volcites" "(([{[{[{[{") ("Volcites" "(([{[{[{[{")
("pvolcite" "[{[{") ("Pvolcite" "[{[{")
("pvolcites" "(([{[{[{[{") ("Pvolcites" "(([{[{[{[{")
("fvolcite" "[{[{") ("ftvolcite" "[{[{")
("fvolcites" "(([{[{[{[{") ("Fvolcites" "(([{[{[{[{")
("svolcite" "[{[{") ("Svolcite" "[{[{")
("svolcites" "(([{[{[{[{") ("Svolcites" "(([{[{[{[{")
("tvolcite" "[{[{") ("Tvolcite" "[{[{")
("tvolcites" "(([{[{[{[{") ("Tvolcites" "(([{[{[{[{")
("avolcite" "[{[{") ("Avolcite" "[{[{")
("avolcites" "(([{[{[{[{") ("Avolcites" "(([{[{[{[{")
("notecite" "[[{") ("Notecite" "[[{")
("pnotecite" "[[{") ("Pnotecite" "[[{")
("fnotecite" "[[{")
;; 3.8.7 Low-level Commands
("citename" "[[{[{") ("citelist" "[[{[{") ("citefield" "[[{[{")
;; 3.8.8 Miscellaneous Commands
("citereset" "*") ("RN" "{") ("Rn" "{")
;; 3.9 Localization Commands
("DefineBibliographyStrings" "{{") ("DefineBibliographyExtras" "{{")
("UndefineBibliographyExtras" "{{") ("DefineHyphenationExceptions" "{{")
("NewBibliographyString" "{"))
font-lock-constant-face 2 command)
("reference"
(("nocite" "*{") ("cite" "*[[{") ("label" "{") ("pageref" "{")
("vref" "*{") ("eqref" "{") ("ref" "{") ("Ref" "{")
("footref" "{") ("include" "{") ("input" "{")
("bibliography" "{") ("index" "{") ("glossary" "{")
("footnote" "[{") ("footnotemark" "[") ("footnotetext" "[{")
("marginpar" "[{") ("chaptermark" "{") ("sectionmark" "{")
("subsectionmark" "{") ("subsubsectionmark" "{")
("paragraphmark" "{") ("subparagraphmark" "{"))
font-lock-constant-face 2 command)
("function"
(("begin" "{") ("end" "{") ("pagenumbering" "{")
("thispagestyle" "{") ("pagestyle" "{") ("nofiles" "")
("includeonly" "{") ("bibliographystyle" "{") ("documentstyle" "[{")
("documentclass" "[{[") ("newenvironment" "*{[[{{")
("newcommand" "*|{\\[[{") ("newlength" "|{\\")
("newtheorem" "{[{[")
("providecommand" "*|{\\[[{")
("newcounter" "{[") ("renewenvironment" "*{[[{{")
("renewcommand" "*|{\\[[{") ("renewtheorem" "{[{[")
("usepackage" "[{[") ("RequirePackage" "[{[")
("fbox" "{") ("mbox" "{") ("rule" "[{{")
("framebox" "|[([{") ("makebox" "|[([{") ("newsavebox" "|{\\")
("parbox" "[[[{{") ("savebox" "|{\\|[([{") ("sbox" "|{\\{")
("usebox" "|{\\")
("cline" "{") ("extracolsep" "{") ("multicolumn" "{{{")
("linethickness" "{") ("multiput" "(({{") ("put" "({")
("qbezier" "[(((") ("raisebox" "{[[{")
("addvspace" "{") ("vspace" "*{") ("hspace" "*{")
("addcontentsline" "{{{") ("addtocontents" "{{")
("labelformat" "{{") ("linespread" "{")
("AddToHook" "{[{") ("RemoveFromHook" "{[") ("AddToHookNext" "{{")
("ProvidesClass" "{[") ("ProvidesPackage" "{[") ("ProvidesFile" "{[")
;; XXX: Should macros without arguments rather be listed in a
;; separate category with 'noarg instead of 'command handling?
("enspace" "") ("enskip" "") ("quad" "") ("qquad" "") ("nonumber" "")
("bigskip" "") ("medskip" "") ("smallskip" "")
("thinspace" "") ("negthinspace" "")
("thicklines" "") ("thinlines" "")
("noindent" "") ("hline" "") ("ldots" "")
("centering" "") ("raggedright" "") ("raggedleft" "")
("raggedbottom" "") ("flushbottom" "")
("TeX" "") ("LaTeX" "") ("LaTeXe" "")
("normalfont" "") ("normalshape" "")
("tableofcontents" "") ("listoffigures" "") ("listoftables" ""))
font-lock-function-name-face 2 command)
("sectioning-0"
(("part" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-0-face)
2 command)
("sectioning-1"
(("chapter" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-1-face)
2 command)
("sectioning-2"
(("section" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-2-face)
2 command)
("sectioning-3"
(("subsection" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-3-face)
2 command)
("sectioning-4"
(("subsubsection" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-4-face)
2 command)
("sectioning-5"
(("paragraph" "*[{") ("subparagraph" "*[{")
("subsubparagraph" "*[{"))
(if (eq font-latex-fontify-sectioning 'color)
'font-lock-type-face
'font-latex-sectioning-5-face)
2 command)
("slide-title" () font-latex-slide-title-face 2 command)
("textual"
(("item" "[") ("bibitem" "[{") ("title" "{") ("author" "{") ("date" "{")
("thanks" "{") ("address" "{") ("caption" "[{")
("textsuperscript" "{") ("textsubscript" "{") ("verb" "*"))
font-lock-type-face 2 command)
("bold-command"
(("textbf" "{") ("textsc" "{") ("textssc" "{") ("textulc" "{")
("textup" "{") ("textsw" "{") ("boldsymbol" "{") ("pmb" "{")
("mathbf" "{"))
font-latex-bold-face 1 command)
("italic-command"
(("emph" "{") ("textit" "{") ("textsl" "{") ("mathit" "{"))
font-latex-italic-face 1 command)
("math-command"
(("ensuremath" "|{\\"))
font-latex-math-face 1 command)
("type-command"
(("texttt" "{") ("textsf" "{") ("textrm" "{") ("textmd" "{")
("textnormal" "{") ("oldstylenums" "{") ("legacyoldstylenums" "{")
("mathrm" "{") ("mathsf" "{") ("mathtt" "{"))
font-lock-type-face 1 command)
("bold-declaration"
("bf" "bfseries" "sc" "scshape" "sscshape" "ulcshape" "upshape" "swshape")
font-latex-bold-face 1 declaration)
("italic-declaration"
("em" "it" "itshape" "sl" "slshape")
font-latex-italic-face 1 declaration)
("type-declaration"
("tt" "ttfamily" "sf" "sffamily" "rm" "rmfamily" "mdseries"
"tiny" "scriptsize" "footnotesize" "small" "normalsize"
"large" "Large" "LARGE" "huge" "Huge")
font-lock-type-face 1 declaration))
"Built-in keywords and specifications for font locking.
The first element of each item is the name of the keyword class.
The second element is a list of keywords (macros without an
escape character) to highlight or, if the fifth element is the
symbol `command', a list of lists where the first element of each
item is a keyword and the second a string specifying the macro
syntax. It can contain \"*\" if the macro has a starred variant,
\"[\" for an optional argument, \"{\" for a mandatory argument,
and \"\\\" for a macro. A \"|\" means the following two tokens
should be regarded as alternatives.
The third element is the symbol of a face to be used or a Lisp
form returning a face symbol.
The fourth element is the fontification level.
The fifth element is the type of construct to be matched. It can
be one of `noarg' which will match simple macros without
arguments (like \"\\foo\"), `declaration' which will match macros
inside a TeX group (like \"{\\bfseries foo}\"), or `command' which
will match macros of the form \"\\foo[bar]{baz}\"."))
(defcustom font-latex-deactivated-keyword-classes nil
"List of strings for built-in keyword classes to be deactivated.
Valid entries are \"warning\", \"variable\", \"biblatexnoarg\",
\"biblatex\", \"reference\", \"function\" , \"sectioning-0\",
\"sectioning-1\", \"sectioning-2\", \"sectioning-3\",
\"sectioning-4\", \"sectioning-5\", \"slide-title\", \"textual\",
\"bold-command\", \"italic-command\", \"math-command\",
\"type-command\", \"bold-declaration\", \"italic-declaration\",
\"type-declaration\".
You have to restart Emacs for a change of this variable to take effect."
:group 'font-latex-keywords
:type `(set ,@(mapcar
(lambda (spec)
`(const :tag ,(concat
;; Name of the keyword class
(let ((name (split-string (car spec) "-")))
(setcar name (capitalize (car name)))
(mapconcat #'identity name " "))
" keywords in `"
;; Name of the face
(symbol-name
(let ((face (nth 2 spec)))
(if (symbolp face) face (eval face t))))
"'.\n"
;; List of keywords
(with-temp-buffer
(insert " Keywords: "
(mapconcat (lambda (x)
(if (listp x)
(car x)
x))
(nth 1 spec) ", "))
(fill-paragraph nil)
(buffer-string)))
,(car spec)))
font-latex-built-in-keyword-classes)))
(eval-and-compile
(defun font-latex--make-match-defun (prefix name face type)
"Return a function definition for keyword matching.
The variable holding the keywords to match are determined by the
strings PREFIX and NAME. The type of matcher is determined by
the symbol TYPE.
This is a helper function for `font-latex-make-built-in-keywords'
and `font-latex-make-user-keywords' and not intended for general
use."
;; FIXME: Is the cond-clause possible inside of the defun?
;; In an earlier version of font-latex the type could be a list like
;; (command 1). This indicated a macro with one argument. Provide
;; a match function in this case but don't actually support it.
(cond ((or (eq type 'command) (listp type))
`(defun ,(intern (concat prefix name)) (limit)
,(concat "Fontify `" prefix name "' up to LIMIT.
Generated by `font-latex--make-match-defun'.")
(when ,(intern (concat prefix name))
(font-latex-match-command-with-arguments
,(intern (concat prefix name))
(append
(when (boundp ',(intern (concat prefix name
"-keywords-local")))
,(intern (concat prefix name "-keywords-local")))
,(intern (concat prefix name "-keywords")))
;; `face' can be a face symbol, a form returning
;; a face symbol, or a list of face attributes.
,(if (and (listp face) (fboundp (car face)))
face
`',face)
limit))))
((eq type 'declaration)
`(defun ,(intern (concat prefix name)) (limit)
,(concat "Fontify `" prefix name "' up to LIMIT.
Generated by `font-latex--make-match-defun'.")
(when ,(intern (concat prefix name))
(font-latex-match-command-in-braces
,(intern (concat prefix name)) limit))))
((eq type 'noarg)
`(defun ,(intern (concat prefix name)) (limit)
,(concat "Fontify `" prefix name "' up to LIMIT.
Generated by `font-latex--make-match-defun'.")
(when ,(intern (concat prefix name))
(re-search-forward
,(intern (concat prefix name)) limit t))))))
(defun font-latex-keyword-matcher (prefix name face type)
"Return a matcher and highlighter as required by `font-lock-keywords'.
PREFIX and NAME are strings which are concatenated to form the
respective match function. FACE is a face name or a list of face
attributes that will be applied to the respective part of the
match returned by the match function. A lisp form returning a
face name or a list of face attributes is also valid for FACE.
TYPE is the type of construct to be highlighted. Currently the
symbols `command', `declaration' and `noarg' are valid.
This is a helper function for `font-latex-make-built-in-keywords'
and `font-latex-make-user-keywords' and not intended for general
use."
;; Quote a list of face attributes and a face symbol
;; but do not quote a form returning such value.
(unless (and (listp face) (fboundp (car face)))
(setq face `',face))
;; In an earlier version of font-latex the type could be a list like
;; (command 1). This indicated a macro with one argument. Provide
;; a matcher in this case but don't actually support it.
(cond ((or (eq type 'command) (listp type))
`(,(intern (concat prefix name))
(0 (font-latex-matched-face 0) append t)
(1 (font-latex-matched-face 1) append t)
(2 (font-latex-matched-face 2) append t)
(3 (font-latex-matched-face 3) append t)
(4 (font-latex-matched-face 4) append t)
(5 (font-latex-matched-face 5) append t)
(6 (font-latex-matched-face 6) append t)
(7 (font-latex-matched-face 7) append t)
(8 (font-latex-matched-face 8) append t)
(9 (font-latex-matched-face 9) append t)
(10 (font-latex-matched-face 10) append t)
(11 (font-latex-matched-face 11) append t)))
((eq type 'noarg)
`(,(intern (concat prefix name))
(0 ,face)))
((eq type 'declaration)
`(,(intern (concat prefix name))
(0 'font-latex-warning-face t t)
(1 'font-lock-keyword-face append t)
(2 ,face append t))))))
(defmacro font-latex-make-built-in-keywords ()
"Build defuns, defvars and defcustoms for built-in keyword fontification."
(let ((flks '())
(defs '()))
(dolist (item font-latex-built-in-keyword-classes)
(let ((prefix "font-latex-match-")
(name (nth 0 item))
(keywords (nth 1 item))
(face (nth 2 item))
(level (nth 3 item))
(type (nth 4 item)))
;; defvar font-latex-match-*-keywords-local
(push `(defvar-local ,(intern (concat prefix name "-keywords-local"))
',keywords
,(concat "Buffer-local keywords to add to `"
prefix name "-keywords'.\n\n"
(if (eq type 'command)
"\
This must be a list where each element is a list consisting of a
keyword string \(not a regular expression\) omitting the leading
backslash and a format specifier as described in the doc string of
`font-latex-user-keyword-classes'."
"\
This must be a list where each element is a keyword string \(not a
regular expression\) omitting the leading backslash.")
"\n\n\
This is an internal variable which should not be set directly.
Use `font-latex-add-keywords' instead.
Generated by `font-latex-make-built-in-keywords'."))
defs)
;; defvar font-latex-match-*
;; We make this variable buffer local later, but don't use
;; `defvar-local' here because it shouldn't have nil as its
;; default value. Its true default value is set by
;; through font-latex-match-*-make in :set specification of
;; defcustom of font-latex-match-*-keywords below. It's
;; only after that this variable can be buffer local.
(push `(defvar ,(intern (concat prefix name)) nil
,(concat "Regular expression to match " name
" keywords.
Generated by `font-latex-make-built-in-keywords'"))
defs)
;; This defvar (without value) is here just to suppress compiler
;; warnings. Its true definition is done by defcustom following
;; the next defun because its :set function depends on the
;; function defined by that defun.
(push `(defvar ,(intern (concat prefix name "-keywords")))
defs)
;; defun font-latex-match-*-make
(push `(defun ,(intern (concat prefix name "-make")) ()
,(concat "Make or remake the variable `" prefix name "'.
Generated by `font-latex-make-built-in-keywords'.")
(let ((keywords
(append
(unless (member ,name
font-latex-deactivated-keyword-classes)
,(intern (concat prefix name "-keywords-local")))
,(intern (concat prefix name "-keywords"))))
multi-char-macros single-char-macros)
(dolist (elt keywords)
(let ((keyword (if (listp elt) (car elt) elt)))
(if (string-match "^[A-Za-z]" keyword)
(push keyword multi-char-macros)
(push keyword single-char-macros))))
(when (or multi-char-macros single-char-macros)
(setq ,(intern (concat prefix name))
(concat
"\\\\\\("
(when multi-char-macros
(concat
"\\(?:" (regexp-opt multi-char-macros) "\\)\\>"))
(when single-char-macros
(concat
(when multi-char-macros "\\|")
"\\(?:" (regexp-opt single-char-macros) "\\)"))
"\\)")))))
defs)
;; defcustom font-latex-match-*-keywords
(push `(defcustom ,(intern (concat prefix name "-keywords")) nil
,(concat "List of keywords "
(when (eq type 'command) "and formats ")
"for " name " face.\n"
(if (eq type 'command)
"\
Each element has to be a list consisting of the name of a macro
omitting the leading backslash and a format specifier as
described in the doc string of `font-latex-user-keyword-classes'."
"\
Each element has to be the name of a macro as a string, omitting
the leading backslash.")
"\n\n\
Setting this variable directly does not take effect; restart
Emacs.
Generated by `font-latex-make-built-in-keywords'.")
:type '(repeat ,(if (eq type 'command)
'(list (string :tag "Keyword")
(string :tag "Format"))
'(string :tag "Keyword")))
:set (lambda (symbol value)
(set-default symbol value)
(funcall ',(intern (concat prefix name "-make"))))
:group 'font-latex-keywords)
defs)
;; Now that font-latex-match-* has attained proper default
;; value, make it buffer local.
(push `(make-variable-buffer-local ',(intern (concat prefix name)))
defs)
;; defun font-latex-match-*
(push (font-latex--make-match-defun prefix name face type) defs)
;; Add matchers and highlighters to `font-latex-keywords-{1,2}'.
(let ((keywords-entry (font-latex-keyword-matcher
prefix name face type)))
(push (cons level keywords-entry) flks))))
`(progn
,@(nreverse defs)
(defvar font-latex-keywords-1
',(nreverse (delq nil (mapcar (lambda (x) (if (eq 1 (car x)) (cdr x)))
flks)))
"Subdued level highlighting for LaTeX modes.")
(defvar font-latex-keywords-2
',(nreverse (mapcar #'cdr flks))
"High level highlighting for LaTeX modes."))))
(font-latex-make-built-in-keywords)
(defcustom font-latex-user-keyword-classes nil
"List of user-defined keyword classes for font locking.
Every keyword class consists of four parts, a name, a list of
keywords, a face and a specifier for the type of macro to be
highlighted.
When adding new entries, you have to use unique values for the
class names, that is, they must not clash with names of the
built-in keyword classes or other names given by you.
Additionally the names must not contain spaces.
The list of keywords defines which commands and declarations
should be covered by the keyword class. A keyword can either be
a simple command name omitting the leading backslash or a list
consisting of the command name and a string specifying the syntax
of the command. The latter is useful if you want to match LaTeX
macros with arguments (see below). You can specify the occurence
and order of optional (\"[\") and mandatory (\"{\") arguments for
each keyword. For example for \"documentclass\" you'd use \"[{\"
because the macro has one optional followed by one mandatory
argument. Optionally starred macros can be indicated with \"*\".
In case an argument is an unbraced macro, use \"\\\". You can
also specify two alternative arguments by prefixing them with
\"|\". As an example, the specifier for \\newcommand is
\"*|{\\=\\[[{\".
The face argument can either be an existing face or a face
attribute.
There are three alternatives for the class type:
A value of `command' indicates commands with arguments
\(\"\\foo[bar]{baz}\"). The mandatory arguments in curly braces
will get the face you specified.
A value of `declaration' indicates declarations inside of TeX
groups (\"{\\foo bar}\"). The content inside the braces,
excluding the command, will get the face you specified. In case
the braces are missing, the face will be applied to the command
itself.
A value of `noarg' indicates commands without arguments
\(\"\\foo\"). The command itself will get the face you
specified.
Setting this variable directly does not take effect;
restart Emacs."
:group 'font-latex-keywords
:type '(repeat (list (string :tag "Name")
(choice (repeat :tag "Keywords" (string :tag "Keyword"))
(repeat
:tag "Keywords with specs"
(group (string :tag "Keyword")
(string :tag "Format specifier"))))
(choice (face :tag "Face name")
(custom-face-edit :tag "Face attributes"))
(choice :tag "Type"
;; Maps to
;;`font-latex-match-command-with-arguments'
(const :tag "Command with arguments"
command)
;; Maps to
;;`font-latex-match-command-in-braces'
(const :tag "Declaration inside TeX group"
declaration)
;; Maps to `re-search-forward'
(const :tag "Command without arguments"
noarg))))
:set (lambda (symbol value)
(dolist (item value)
(when (string-match " " (car item))
(error "No spaces allowed in name")))
(let (names names-uniq)
(dolist (item (append font-latex-built-in-keyword-classes value))
(setq names (append names (list (car item)))))
(setq names (TeX-sort-strings names))
(setq names-uniq (TeX-delete-duplicate-strings names))
(dotimes (i (safe-length names-uniq))
(unless (string= (nth i names) (nth i names-uniq))
(error "Name %S already exists" (nth i names)))))
(set-default symbol value)
(let ((prefix "font-latex-match-"))
(dolist (elt value)
(unless (boundp (intern (concat prefix (car elt))))
;; defvar font-latex-match-*
(eval `(defvar ,(intern (concat prefix (car elt))) nil
,(concat "Regular expression to match " (car elt)
" keywords.
Generated by `font-latex-user-keyword-classes'"))))
(let ((keywords (nth 1 elt))
single-char-macro-flag)
(setq keywords (if (listp (car keywords))
(mapcar #'car keywords)
keywords))
(catch 'single-char
(dolist (keyword keywords)
(unless (string-match "^[A-Za-z]" keyword)
(setq single-char-macro-flag t)
(throw 'single-char nil))))
(set (intern (concat prefix (car elt)))
(when (> (safe-length keywords) 0)
(concat "\\\\" (let ((max-specpdl-size 1000))
(regexp-opt keywords t))
(unless single-char-macro-flag "\\>")))))))))
(defun font-latex-make-user-keywords ()
"Build defuns and defvars for user keyword fontification."
(let ((keyword-specs font-latex-user-keyword-classes))
(dolist (item keyword-specs)
(let ((prefix "font-latex-match-")
(name (nth 0 item))
(keywords (nth 1 item))
(face (nth 2 item))
(type (nth 3 item)))
;; defvar font-latex-match-*-keywords
(eval `(defvar ,(intern (concat prefix name "-keywords")) ',keywords
,(concat "Font-latex keywords for " name " face.
Generated by `font-latex-make-user-keywords'.")))
;; defun font-latex-match-*
(eval (font-latex--make-match-defun prefix name face type) t)
;; Add the matcher to `font-latex-keywords-2'.
(add-to-list 'font-latex-keywords-2
(font-latex-keyword-matcher prefix name face type) t))))
;; Add the "fixed" matchers and highlighters.
(dolist (item
'(("\\(^\\|[^\\]\\)\\(&+\\)" 2 'font-latex-warning-face)
(font-latex-match-dollar-math 0 'font-latex-math-face keep)
(font-latex-match-quotation
(0 'font-latex-string-face append)
(1 'font-latex-warning-face))
;; Hack to remove the verbatim face from the \ in
;; \end{verbatim} and similar. The same hack is used in
;; tex-mode.el.
("\\(\\\\\\)end"
(1 (get-text-property (match-end 1) 'face) t))))
(add-to-list 'font-latex-keywords-1 item)
(add-to-list 'font-latex-keywords-2 item))
(dolist (item
'((font-latex-match-math-env
(0 'font-latex-warning-face t t)
(1 'font-latex-math-face append t))
(font-latex-match-math-envII
(1 'font-latex-math-face append t))
(font-latex-match-simple-command
(0 'font-latex-sedate-face append))
(font-latex-match-script
(1 (font-latex-script (match-beginning 0)) append))
(font-latex-match-script-chars
(1 (font-latex-script-char (match-beginning 1)) prepend))))
(add-to-list 'font-latex-keywords-2 item t)))
(font-latex-make-user-keywords)
(defun font-latex-add-keywords (keywords class)
"Add KEYWORDS to CLASS.
KEYWORDS is a list of keywords or keywords with syntax specs.
CLASS corresponds to a keyword class and can be one of the
symbols `warning', `variable', `reference', `biblatexnoarg',
`biblatex', `function', `sectioning-0', `sectioning-1',
`sectioning-2', `sectioning-3', `sectioning-4', `sectioning-5',
`slide-title', `textual', `bold-command', `italic-command',
`math-command', `type-command', `bold-declaration',
`italic-declaration' or `type-declaration'.
The keywords will be added to the buffer-local list of keywords
of the respective keyword class and necessary updates of the font
locking machinery will be triggered."
(let* ((class (symbol-name class))
(list (intern (format "font-latex-match-%s-keywords-local" class))))
(dolist (elt keywords)
(add-to-list list elt))
(funcall (intern (format "font-latex-match-%s-make" class)))
;; Trigger refontification.
(when (fboundp 'font-lock-flush)
(font-lock-flush))))
(defvar font-latex-keywords font-latex-keywords-1
"Default expressions to highlight in TeX mode.")
;;; Subscript and superscript
(defcustom font-latex-fontify-script t
"If non-nil, fontify subscript and superscript strings.
By default, super/subscripts are raised/lowered if this variable
is non-nil. This fontification only affects one level of
scripts, for example in x^{y^z}, the y and the z have the same
size and are equally raised over x.
If this variable is set to the symbol `multi-level', then y is
raised above x, and z is raised above y. With many script
levels, the text might become too small to be readable, thus
there is the option `font-latex-fontify-script-max-level'. (The
factors for text shrinking are defined in the faces
`font-latex-superscript-face' and `font-latex-subscript-face' and
the raise/lower factor in `font-latex-script-display'.)
If this variable is set to the symbol `invisible', then the
effect is essentially like `multi-level' but additionally the
script operators ^ and _ are not displayed."
:type '(choice (boolean :tag "Enabled")
(const :tag "Multiple levels" multi-level)
(const :tag "Hide ^ and _" invisible))
:group 'font-latex)
(put 'font-latex-fontify-script 'safe-local-variable
(lambda (val)
(or (booleanp val)
(memq val '(multi-level invisible)))))
(defcustom font-latex-fontify-script-max-level 3
"Maximum scriptification level for which script faces are applied.
The faces `font-latex-superscript-face' and
`font-latex-subscript-face' define custom :height values < 1.0.
Therefore, scripts are displayed with a slightly smaller font
than normal math text. If `font-latex-fontify-script' is
`multi-level' or `invisible', the font size becomes too small to
be readable after a few levels. This option allows to specify
the maximum level after which the size of the script text won't
be shrunken anymore.
For example, see this expression:
\\( x^{y^{z^a_b}} \\)
x has scriptification level 0, y has level 1, z has level 2, and
both a and b have scriptification level 3.
If `font-latex-fontify-script-max-level' was 2, then z, a, and b
would have the same font size. If it was 3 or more, then a and b
were smaller than z just in the same way as z is smaller than y
and y is smaller than x."
:group 'font-latex
:type 'integer)
(defcustom font-latex-script-display '((raise -0.5) . (raise 0.5))
"Display specification for subscript and superscript content.
The car is used for subscript, the cdr is used for superscripts."
:group 'font-latex
:type '(cons (choice (sexp :tag "Subscript form")
(const :tag "No lowering" nil))
(choice (sexp :tag "Superscript form")
(const :tag "No raising" nil))))
;;; Syntactic keywords
(defvar font-latex-syntactic-keywords nil