-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tex.el
10532 lines (9406 loc) · 433 KB
/
tex.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
;;; tex.el --- Support for TeX documents. -*- lexical-binding: t; -*-
;; Copyright (C) 1985-2024 Free Software Foundation, Inc.
;; Maintainer: [email protected]
;; Keywords: tex
;; This file is part of AUCTeX.
;; AUCTeX 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.
;; AUCTeX 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This file provides basic functions used by the AUCTeX modes.
;;; Code:
(when (< emacs-major-version 27)
(error "AUCTeX requires Emacs 27.1 or later"))
(require 'custom)
(require 'auctex)
(require 'cl-lib)
(require 'subr-x)
(require 'texmathp)
;; seq.el is preloaded in Emacs 29, so the next form can be removed
;; once 29 is the minimum required Emacs version
(require 'seq)
;; Require dbus at compile time to get macro definition of
;; `dbus-ignore-errors'.
(eval-when-compile (require 'dbus))
;; Silence the compiler for functions:
(declare-function dbus-get-unique-name "ext:dbusbind.c"
(bus))
(declare-function dbus-ping "ext:dbus"
(bus service &optional timeout))
(declare-function dbus-introspect-get-method "ext:dbus"
(bus service path interface method))
(declare-function dbus-call-method "ext:dbus"
(bus service path interface method &rest args))
(declare-function dbus-register-signal "ext:dbus"
(bus service path interface signal handler &rest args))
(declare-function font-latex-setup "font-latex" nil)
(declare-function LaTeX-environment-list "latex" nil)
(declare-function LaTeX-bibliography-list "latex" nil)
(declare-function LaTeX-completion-label-annotation-function "latex" (label))
(declare-function LaTeX-completion-label-list "latex" nil)
(declare-function LaTeX-section-name "latex" (level))
(declare-function TeX-fold-mode "tex-fold" (&optional arg))
(declare-function comint-exec "ext:comint"
(buffer name command startfile switches))
(declare-function comint-mode "ext:comint" nil)
(declare-function tex--prettify-symbols-compose-p "ext:tex-mode"
(start end match))
(declare-function gnuserv-start "ext:gnuserv"
(&optional leave-dead) t)
;; Silence the compiler for variables:
;; tex.el: Variables defined somewhere in this file:
(defvar TeX-PDF-from-DVI)
(defvar TeX-PDF-mode)
(defvar TeX-PDF-mode-parsed)
(defvar TeX-all-extensions)
(defvar TeX-command-default)
(defvar TeX-default-extension)
(defvar TeX-esc)
(defvar TeX-interactive-mode)
(defvar TeX-macro-global)
(defvar TeX-mode-map)
(defvar TeX-mode-p)
(defvar TeX-output-extension)
(defvar TeX-source-correlate-mode)
(defvar TeX-source-specials-places)
(defvar TeX-source-specials-tex-flags)
(defvar TeX-synctex-tex-flags)
(defvar TeX-current-process-region-p)
(defvar TeX-region)
(defvar TeX-region-orig-buffer)
;; Variables defined in other AUCTeX libraries:
;; latex.el:
(defvar LaTeX-default-verb-delimiter)
(defvar LaTeX-optcl)
(defvar LaTeX-optop)
(defvar LaTeX-largest-level)
;; tex-ispell.el
(defvar TeX-ispell-verb-delimiters)
;; Others:
(defvar tex--prettify-symbols-alist) ; tex-mode.el
(defvar Info-file-list-for-emacs) ; info.el
(defvar ispell-parser) ; ispell.el
(defvar compilation-error-regexp-alist) ; compile.el
(defvar compilation-in-progress) ; compile.el
(defconst TeX-mode-comparison-alist
'((plain-tex-mode . plain-TeX-mode)
(latex-mode . LaTeX-mode)
(doctex-mode . docTeX-mode)
(context-mode . ConTeXt-mode)
(texinfo-mode . Texinfo-mode)
(ams-tex-mode . AmSTeX-mode)
(japanese-plain-tex-mode . japanese-plain-TeX-mode)
(japanese-latex-mode . japanese-LaTeX-mode))
"Comparison table of AUCTeX former and current mode names.
Each entry is of the form (FORMER . CURRENT) where FORMER and
CURRENT are each mode name symbols.")
(defgroup TeX-file nil
"Files used by AUCTeX."
:group 'AUCTeX)
(defgroup TeX-command nil
"Calling external commands from AUCTeX."
:group 'AUCTeX)
(defgroup LaTeX nil
"LaTeX support in AUCTeX."
:tag "LaTeX"
:group 'AUCTeX
:prefix "LaTeX-")
(defgroup TeX-misc nil
"Various AUCTeX settings."
:group 'AUCTeX)
;;; Site Customization
;;
;; The following variables are likely to need to be changed for your
;; site. You should do this with customize.
(defcustom TeX-command "tex"
"Command to run plain TeX."
:group 'TeX-command
:type 'string)
(defcustom TeX-Omega-command "omega"
"Command to run plain TeX on Omega."
:group 'TeX-command
:type '(choice (const :tag "Aleph" "aleph")
(const :tag "Omega" "omega")
(string :tag "Other command")))
(defcustom LaTeX-command "latex"
"Command to run LaTeX."
:group 'TeX-command
:type 'string)
(defcustom LaTeX-Omega-command "lambda"
"Command to run LaTeX on Omega."
:group 'TeX-command
:type '(choice (const :tag "Lamed" "lamed")
(const :tag "Lambda" "lambda")
(string :tag "Other command")))
(defcustom TeX-file-line-error t
"Whether to have TeX produce file:line:error style error messages."
:group 'TeX-command
:type 'boolean)
(defcustom ConTeXt-engine nil
"Engine to use for --engine in the texexec command.
If nil, none is specified."
:group 'TeX-command
:type '(choice (const :tag "Unspecified" nil)
string))
(defcustom ConTeXt-Omega-engine TeX-Omega-command
"Engine to use for --engine in the texexec command in Omega mode.
If nil, none is specified."
:group 'TeX-command
:type '(choice (const :tag "Unspecified" nil)
string))
;; At least in TeXLive 2009 ConTeXt does not support an omega option anymore.
(make-obsolete-variable 'ConTeXt-Omega-engine 'TeX-engine-alist "11.86")
(defcustom TeX-mode-hook nil
"A hook run in TeX mode buffers."
:type 'hook
:group 'TeX-misc)
;; This is the major configuration variable. Most sites will only need to
;; change the second string in each entry, which is the name of a command to
;; send to the shell. If you use other formatters like AMSLaTeX or AMSTeX, you
;; can add those to the list. See `TeX-expand-list' and
;; `TeX-expand-list-builtin' for a description of the % escapes
(defcustom TeX-command-list
'(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t"
TeX-run-TeX nil
(plain-TeX-mode AmSTeX-mode Texinfo-mode) :help "Run plain TeX")
("LaTeX" "%`%l%(mode)%' %T"
TeX-run-TeX nil
(LaTeX-mode docTeX-mode) :help "Run LaTeX")
;; Not part of standard TeX.
("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t" TeX-run-compile nil
(Texinfo-mode) :help "Run Makeinfo with Info output")
("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t" TeX-run-compile nil
(Texinfo-mode) :help "Run Makeinfo with HTML output")
("AmSTeX" "amstex %(PDFout) %`%(extraopts) %S%(mode)%' %(output-dir) %t"
TeX-run-TeX nil (AmSTeX-mode) :help "Run AMSTeX")
;; support for ConTeXt --pg
;; first version of ConTeXt to support nonstopmode: 2003.2.10
("ConTeXt" "%(cntxcom) --once %(extraopts) %(execopts)%t"
TeX-run-TeX nil (ConTeXt-mode) :help "Run ConTeXt once")
("ConTeXt Full" "%(cntxcom) %(extraopts) %(execopts)%t"
TeX-run-TeX nil
(ConTeXt-mode) :help "Run ConTeXt until completion")
("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode
ConTeXt-mode)
:help "Run BibTeX")
("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Run Biber")
;; Not part of standard TeX.
;; It seems that texindex doesn't support "--output-dir" option.
("Texindex" "texindex %s.??" TeX-run-command nil
(Texinfo-mode) :help "Run Texindex")
;; TODO:
;; 1. Supply "--dvipdf" option if `TeX-PDF-mode' and
;; `TeX-PDF-from-DVI' are non-nil.
;; 2. Supply "--build-dir=DIR" option when `TeX-output-dir' is
;; non-nil.
("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command nil
(Texinfo-mode) :help "Run Texi2dvi or Texi2pdf")
("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
("Print" "%p" TeX-run-command t t :help "Print the file")
("Queue" "%q" TeX-run-background nil t :help "View the printer queue"
:visible TeX-queue-command)
("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Generate PostScript file")
("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Convert DVI file to PostScript")
("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Convert DVI file to PDF with dvipdfmx")
("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Convert PostScript file to PDF")
("LaTeXMk" "latexmk %(latexmk-out) %(file-line-error) %(output-dir) \
%`%(extraopts) %S%(mode)%' %t"
TeX-run-format nil (LaTeX-mode docTeX-mode) :help "Run LaTeXMk")
("Glossaries" "makeglossaries %(d-dir) %s" TeX-run-command nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Run makeglossaries to create glossary file")
("Index" "makeindex %(O?idx)" TeX-run-index nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Run makeindex to create index file")
("upMendex" "upmendex %(O?idx)" TeX-run-index t
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Run upmendex to create index file")
("Xindy" "texindy %s" TeX-run-command nil
(plain-TeX-mode LaTeX-mode docTeX-mode AmSTeX-mode Texinfo-mode)
:help "Run xindy to create index file")
("Check" "lacheck %s" TeX-run-compile nil (LaTeX-mode)
:help "Check LaTeX file for correctness")
("ChkTeX" "chktex -v6 %s" TeX-run-compile nil (LaTeX-mode)
:help "Check LaTeX file for common mistakes")
("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t
:help "Spell-check the document")
("Clean" "TeX-clean" TeX-run-function nil t
:help "Delete generated intermediate files")
("Clean All" "(TeX-clean t)" TeX-run-function nil t
:help "Delete generated intermediate and output files")
("Other" "" TeX-run-command t t :help "Run an arbitrary command"))
"List of commands to execute on the current document.
Each element is a list, whose first element is the name of the command
as it will be presented to the user.
The second element is the string handed to the shell after being
expanded. The expansion is done using the information found in
`TeX-expand-list'.
The third element is the function which actually start the process.
Several such hooks have been defined:
`TeX-run-command': Start up the process and show the output in a
separate buffer. Check that there is not two commands running for the
same file. Return the process object.
`TeX-run-format': As `TeX-run-command', but assume the output is created
by a TeX macro package. Return the process object.
`TeX-run-TeX': For TeX output.
`TeX-run-interactive': Run TeX or LaTeX interactively.
`TeX-run-BibTeX': For BibTeX output.
`TeX-run-Biber': For Biber output.
`TeX-run-compile': Use `compile' to run the process.
`TeX-run-shell': Use `shell-command' to run the process.
`TeX-run-discard': Start the process in the background, discarding its
output.
`TeX-run-background': Start the process in the background, show output
in other window.
`TeX-run-silent': Start the process in the background.
`TeX-run-discard-foreground': Start the process in the foreground,
discarding its output.
`TeX-run-function': Execute the Lisp function or function call
specified by the string in the second element. Consequently,
this hook does not start a process.
`TeX-run-discard-or-function': If the command is a Lisp function,
execute it as such, otherwise start the command as a process,
discarding its output.
To create your own hook, define a function taking three arguments: The
name of the command, the command string, and the name of the file to
process. It might be useful to use `TeX-run-command' in order to
create an asynchronous process.
If the fourth element is non-nil, the user will get a chance to
modify the expanded string.
The fifth element indicates in which mode(s) the command should be
present in the Command menu. Use t if it should be active in any
mode. If it should only be present in some modes, specify a list with
the respective mode names.
Any additional elements get just transferred to the respective menu entries."
:group 'TeX-command
:type '(repeat (group :value ("" "" TeX-run-command nil t)
(string :tag "Name")
(string :tag "Command")
(choice :tag "How"
:value TeX-run-command
(function-item TeX-run-command)
(function-item TeX-run-format)
(function-item TeX-run-TeX)
(function-item TeX-run-interactive)
(function-item TeX-run-BibTeX)
(function-item TeX-run-Biber)
(function-item TeX-run-compile)
(function-item TeX-run-shell)
(function-item TeX-run-discard)
(function-item TeX-run-background)
(function-item TeX-run-silent)
(function-item TeX-run-discard-foreground)
(function-item TeX-run-function)
(function-item TeX-run-discard-or-function)
(function :tag "Other"))
(boolean :tag "Prompt")
(choice :tag "Modes"
(const :tag "All" t)
(set (const :tag "Plain TeX" plain-TeX-mode)
(const :tag "LaTeX" LaTeX-mode)
(const :tag "DocTeX" docTeX-mode)
(const :tag "ConTeXt" ConTeXt-mode)
(const :tag "Texinfo" Texinfo-mode)
(const :tag "AmSTeX" AmSTeX-mode)))
(repeat :tag "Menu elements" :inline t sexp)))
:package-version '(auctex . "14.0.7"))
(defcustom TeX-command-output-list
'(
; Add the following line if you want to use htlatex (tex4ht)
; ("\\`htlatex" ("html"))
)
"List of regexps and file extensions.
Each element is a list, whose first element is a regular expression to
match against the name of the command that will be used to process the TeX
file.
The second element is either a string or a list with a string as element.
If it is a string this is the default file extension that will be expected
for output files that are produced by commands that match the first
element. The real file extension will be obtained from the logging output
if possible, defaulting to the given string.
If it is a list, the element of the list will be the fixed extension used
without looking at the logging output.
If this list does not yield an extension, the default is either \"dvi\"
or \"pdf\", depending on the setting of `TeX-PDF-mode'.
Extensions must be given without the \".\"."
:group 'TeX-command
:type '(repeat (group (regexp :tag "Command Regexp")
(choice (string :tag "Default Extension")
(group (string :tag "Fixed Extension"))))))
;; You may want to change the default LaTeX version for your site.
(defcustom LaTeX-version "2e"
"Default LaTeX version. Currently recognized is \"2\" and \"2e\"."
:group 'LaTeX
:type '(radio (const :format "%v\n%h"
:doc "\
The executable `latex' is LaTeX version 2."
"2")
(const :format "%v\n%h"
:doc "\
The executable `latex' is LaTeX version 2e."
"2e")
(string :tag "Other")))
;; Use different compilation commands depending on style.
;; Only works if parsing is enabled.
(defcustom LaTeX-command-style
;; They have all been combined in LaTeX 2e.
'(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %(output-dir) %S%(PDFout)"))
"List of style options and LaTeX commands.
If the first element (a regular expression) matches the name of one of
the style files, any occurrence of the string `%l' in a command in
`TeX-command-list' will be replaced with the second element. The first
match is used, if no match is found the `%l' is replaced with the empty
string."
:group 'TeX-command
:type '(repeat (group :value ("" "")
regexp (string :tag "Style"))))
;; Printing: If you want to print, TeX-print-command must be non-nil
;; (if it is nil, you'll get a complaint when using the print menu).
;; If you want to view the queue, TeX-queue-command needs to be
;; non-nil (if it is nil, it won't get mentioned in the menu). If
;; TeX-printer-list is nil, nothing else gets asked: the menu entries
;; lead directly to the respective commands. If those commands
;; contain %p, the value of TeX-printer-default gets inserted there,
;; no questions asked. Now if TeX-printer-list is non-nil, you'll
;; always get asked which printer you want to use. You can enter a
;; configured printer from TeX-printer-list, or an unknown one. The
;; respective menus will show all configured printers. Since you can
;; enter unknown printers, the printer name _must_ be set with %p in
;; TeX-print-command.
(defcustom TeX-print-command
"{ test -e %d && %(o?)dvips -P%p %r %s; } || lpr -P%p %o"
"Command used to print a file.
First `%p' is expanded to the printer name, then ordinary expansion is
performed as specified in `TeX-expand-list'. If it is nil,
then customization is requested."
:group 'TeX-command
:type '(choice (string :tag "Print command")
(const :tag "No print command customized" nil)))
(defcustom TeX-queue-command "lpq -P%p"
"Command used to show the status of a printer queue.
First `%p' is expanded to the printer name, then ordinary expansion is
performed as specified in `TeX-expand-list'. If this is nil,
the printer has no corresponding command."
:group 'TeX-command
:type '(choice (string :tag "Queue check command")
(const :tag "No such command" nil)))
;; Enter the names of the printers available at your site, or nil if
;; you only have one printer.
(defcustom TeX-printer-list
'(("Default"
;; Print to the (unnamed) default printer. If there is a DVI
;; file print via Dvips. If not, pass the output file (which
;; should then be a Postscript or PDF file) directly to lpr.
"{ test -e %d && %(o?)dvips -f %r %s | lpr; } || lpr %o"
;; Show the queue for the (unnamed) default printer.
"lpq"))
"List of available printers.
The first element of each entry is the printer name.
The second element is the command used to print to this
printer. It defaults to the value of `TeX-print-command' when nil.
The third element is the command used to examine the print queue for
this printer. It defaults to the value of `TeX-queue-command' similarly.
Any occurrence of `%p' in the second or third element is expanded to
the printer name given in the first element, then ordinary expansion
is performed as specified in `TeX-expand-list'.
If this list is empty, only `TeX-print-command' and `TeX-queue-command'
get consulted."
:group 'TeX-command
:type '(repeat (group (string :tag "Name")
(option (group :inline t
:extra-offset -4
(choice :tag "Print"
(const :tag "default")
(string :format "%v"))
(option (choice :tag "Queue"
(const :tag "default")
(string
:format "%v"))))))))
;; The name of the most used printer.
(defcustom TeX-printer-default (or (getenv "PRINTER")
(and TeX-printer-list
(car (car TeX-printer-list)))
"lp")
"Default printer to use with `TeX-command'."
:group 'TeX-command
:type 'string)
(defcustom TeX-print-style '(("^landscape$" "-t landscape"))
"List of style options and print options.
If the first element (a regular expression) matches the name of one of
the style files, any occurrence of the string `%r' in a command in
`TeX-command-list' will be replaced with the second element. The first
match is used, if no match is found the `%r' is replaced with the empty
string."
:group 'TeX-command
:type '(repeat (group regexp (string :tag "Command"))))
(defcustom TeX-command-extra-options ""
"String with the extra options to be given to the TeX processor."
:type 'string)
(make-variable-buffer-local 'TeX-command-extra-options)
(defvar TeX-command-text nil
"Dynamically bound by `TeX-command-expand'.")
(defvar TeX-command-pos nil
"Dynamically bound by `TeX-command-expand'.")
(defvar TeX-expand-pos nil
"Dynamically bound by `TeX-command-expand'.")
(defvar TeX-expand-command nil
"Dynamically bound by `TeX-command-expand'.")
;; This is the list of expansion for the commands in
;; TeX-command-list. Not likely to be changed, but you may e.g. want
;; to handle .ps files.
(defvar TeX-expand-list-builtin
'(("%q" (lambda ()
(TeX-printer-query t)))
("%V" (lambda ()
(TeX-source-correlate-start-server-maybe)
(TeX-view-command-raw)))
("%r" (lambda ()
(TeX-style-check TeX-print-style)))
("%l" (lambda ()
(TeX-style-check LaTeX-command-style)))
("%(PDF)" (lambda ()
(if (and (eq TeX-engine 'default)
(if TeX-PDF-mode
(not (TeX-PDF-from-DVI))
TeX-DVI-via-PDFTeX))
"pdf"
"")))
("%(PDFout)" (lambda ()
(cond ((eq major-mode 'AmSTeX-mode)
(if TeX-PDF-mode
" -output-format=pdf"
" -output-format=dvi"))
((and (eq TeX-engine 'xetex)
(not TeX-PDF-mode))
" -no-pdf")
((and (eq TeX-engine 'luatex)
(not TeX-PDF-mode))
" --output-format=dvi")
((and (eq TeX-engine 'default)
(not TeX-PDF-mode)
TeX-DVI-via-PDFTeX)
" \"\\pdfoutput=0 \"")
(t ""))))
("%(mode)" (lambda ()
(if TeX-interactive-mode
""
" -interaction=nonstopmode")))
("%(file-line-error)"
(lambda () (if TeX-file-line-error " -file-line-error" "")))
("%(o?)" (lambda () (if (eq TeX-engine 'omega) "o" "")))
("%(tex)" (lambda () (eval (nth 2 (TeX-engine-in-engine-alist TeX-engine)))))
("%(latex)" (lambda () (eval (nth 3 (TeX-engine-in-engine-alist TeX-engine)))))
("%(cntxcom)" ConTeXt-expand-command)
("%(execopts)" ConTeXt-expand-options)
("%(extraopts)" (lambda () TeX-command-extra-options))
("%(output-dir)" TeX--output-dir-arg "--output-directory=")
("%(o-dir)" TeX--output-dir-arg "-o ")
("%(d-dir)" TeX--output-dir-arg "-d ")
("%S" TeX-source-correlate-expand-options)
("%dS" TeX-source-specials-view-expand-options)
("%cS" TeX-source-specials-view-expand-client)
("%(outpage)" (lambda ()
;; When `TeX-source-correlate-output-page-function' is nil
;; and we are using synctex, fallback on
;; `TeX-synctex-output-page'.
(and TeX-source-correlate-mode
(null TeX-source-correlate-output-page-function)
(eq (TeX-source-correlate-method-active) 'synctex)
(setq TeX-source-correlate-output-page-function
#'TeX-synctex-output-page))
(or (if TeX-source-correlate-output-page-function
(funcall TeX-source-correlate-output-page-function))
"1")))
;; `TeX-active-master-with-quotes' calls either `TeX-master-file'
;; or `TeX-region-file' returning the master or region file, and
;; adds suitable quotes for use in shell command line.
("%s" TeX-active-master-with-quotes nil t)
("%t" TeX-active-master-with-quotes t t)
("%(s-filename-only)" TeX-active-master-with-quotes nil t nil nil file-name-nondirectory)
("%(t-filename-only)" TeX-active-master-with-quotes t t nil nil file-name-nondirectory)
;; If any TeX codes appear in the interval between %` and %', move
;; all of them after the interval and supplement " \input". The
;; appearance is marked by leaving the bind to `TeX-command-text'
;; with the TeX codes.
;; Rule:
;; 1. %` and %' must appear in pair.
;; 2. %` and %' must not appear more than once in one command
;; line string (including the results of %-expansion).
;; 3. Each TeX codes between %` and %' must be enclosed in
;; double quotes and preceded by a space.
("%`" (lambda nil
(setq TeX-command-pos t TeX-command-text nil)
""))
(" \"\\" (lambda nil
(if (eq TeX-command-pos t)
(setq TeX-command-pos TeX-expand-pos
TeX-expand-pos (+ 3 TeX-expand-pos))
(setq TeX-expand-pos (1+ TeX-expand-pos)))))
("\"" (lambda nil (if (numberp TeX-command-pos)
(setq TeX-command-text
(concat
TeX-command-text
(substring TeX-expand-command
TeX-command-pos
(1+ TeX-expand-pos)))
TeX-expand-command
(concat
(substring TeX-expand-command
0
TeX-command-pos)
(substring TeX-expand-command
(1+ TeX-expand-pos)))
TeX-expand-pos TeX-command-pos
TeX-command-pos t)
(setq TeX-expand-pos (1+ TeX-expand-pos)))))
("%'" (lambda nil
(setq TeX-command-pos nil)
(if (stringp TeX-command-text)
(progn
(setq TeX-expand-pos (+ TeX-expand-pos (length TeX-command-text) 9))
(concat TeX-command-text " \"\\input\""))
"")))
;; The fourth argument of t directs to supply "\detokenize{}" when
;; necessary. See doc string and comment of
;; `TeX-active-master-with-quotes'.
("%T" TeX-active-master-with-quotes t t nil t)
("%n" TeX-current-line)
("%d" TeX-active-master-with-quotes "dvi" t)
("%f" TeX-active-master-with-quotes "ps" t)
("%(O?aux)" TeX-active-master-with-quotes "aux" t)
("%(O?idx)" TeX-active-master-with-quotes "idx" t)
("%(O?pdf)" TeX-active-master-with-quotes "pdf" t)
("%o" (lambda nil (TeX-active-master-with-quotes (TeX-output-extension) t)))
;; for source specials the file name generated for the xdvi
;; command needs to be relative to the master file, just in
;; case the file is in a different subdirectory
("%b" TeX-current-file-name-master-relative)
;; Okular forward PDF search requires absolute path.
("%a" (lambda nil (prin1-to-string (expand-file-name (TeX-buffer-file-name)))))
;; the following is for preview-latex.
("%m" preview-create-subdirectory)
;; LaTeXMk support
("%(latexmk-out)"
(lambda ()
(cond ((eq TeX-engine 'xetex)
" -pdfxe")
((eq TeX-engine 'luatex)
(cond ((and TeX-PDF-mode
(TeX-PDF-from-DVI))
" -dvilua -pdfdvi")
((and (not TeX-PDF-mode)
TeX-DVI-via-PDFTeX)
" -dvilua -ps")
;; This covers the case:
;; (and TeX-PDF-mode (not (TeX-PDF-from-DVI)))
(t
" -pdflua")))
;; This covers everything else since we ignore 'omega:
(t
(cond ((and TeX-PDF-mode
(not (TeX-PDF-from-DVI)))
" -pdf")
((and TeX-PDF-mode
(string= (TeX-PDF-from-DVI) "Dvips"))
" -pdfps")
;; FIXME: This might be inaccurate:
((and TeX-PDF-mode
(string= (TeX-PDF-from-DVI) "Dvipdfmx"))
" -pdfdvi")
((and (not TeX-PDF-mode)
TeX-DVI-via-PDFTeX)
" -pdflatex -dvi -ps")
(t
" -dvi -ps")))))))
"List of built-in expansion strings for TeX command names.
This should not be changed by the user who can use
`TeX-expand-list' variable. The latter variable also contains a
description of the data format.
Programs should not use these variables directly but the function
`TeX-expand-list'.")
(defcustom TeX-expand-list nil
"List of expansion strings for TeX command names defined by the user.
Each entry is a list with two or more elements. The first
element is the string to be expanded. The second element is the
name of a function returning the expanded string when called with
the remaining elements as arguments.
The second element can also be a variable name whose value is
such function.
Built-in expansions provided in `TeX-expand-list-builtin' can be
overwritten by defining expansions strings with the same
expander. Only \"%p\" expander cannot be overwritten.
Programs should not use these variables directly but the function
`TeX-expand-list'."
:group 'TeX-command
:type '(repeat (group (string :tag "Key")
(sexp :tag "Expander")
(repeat :inline t
:tag "Arguments"
(sexp :format "%v")))))
(defun TeX-expand-list ()
"Complete list of expansion strings for TeX command names.
Concatenate `TeX-expand-list' and `TeX-expand-list-builtin' making
sure \"%p\" is the first entry."
(append
;; %p must be the first entry, see `TeX-print-command'.
'(("%p" TeX-printer-query))
TeX-expand-list
TeX-expand-list-builtin))
(defcustom TeX-parse-all-errors t
"Whether to automatically collect all warning and errors after running TeX.
If t, it makes it possible to use `TeX-previous-error' with TeX
commands."
:group 'TeX-command
:type 'boolean)
(defcustom TeX-LaTeX-sentinel-banner-regexp
"^\\(\\*\\* \\)?J?I?p?\\(La\\|Sli\\)TeX\\(2e\\)? \
\\(Version\\|ver\\.\\|<[0-9/-]*\\(?:u[^>]*\\)?>\\)"
"Regexp to identify the banner line in the LaTeX output."
:group 'TeX-output
:type 'regexp)
;;; Portability.
(defmacro TeX--if-macro-fboundp (name then &rest else)
"Execute THEN if macro NAME is bound and ELSE otherwise.
Essentially,
(TeX--if-macro-fboundp name then else...)
is equivalent to
(if (fboundp \\='name) then else...)
but takes care of byte-compilation issues where the byte-code for
the latter could signal an error if it has been compiled with
emacs 24.1 and is then later run by emacs 24.5."
(declare (indent 2) (debug (symbolp form &rest form)))
(if (fboundp name) ;If macro exists at compile-time, just use it.
then
`(if (fboundp ',name) ;Else, check if it exists at run-time.
(eval ',then) ;If it does, then run the then code.
,@else))) ;Otherwise, run the else code.
(require 'easymenu)
;;; Documentation for Info-goto-emacs-command-node and similar
(eval-after-load 'info '(dolist (elt '("TeX" "LaTeX" "ConTeXt" "Texinfo"
"docTeX"))
(add-to-list 'Info-file-list-for-emacs
(cons elt "AUCTeX"))))
(advice-add 'hack-one-local-variable :after #'TeX--call-minor-mode)
(defun TeX--call-minor-mode (var val &rest _)
"Call minor mode function if minor mode variable is found."
;; Instead of checking for each mode explicitly `minor-mode-list'
;; could be used. But this may make the byte compiler pop up.
(when (memq var '(TeX-PDF-mode
TeX-source-correlate-mode TeX-interactive-mode
TeX-fold-mode LaTeX-math-mode))
(funcall var (if (symbol-value val) 1 0))))
(defvar TeX-overlay-priority-step 16
"Numerical difference of priorities between nested overlays.
The step should be big enough to allow setting a priority for new
overlays between two existing ones.")
;; require crm here, because we often do
;;
;; (let ((crm-separator ","))
;; (TeX-completing-read-multiple ...))
;;
;; which results in a void-variable error if crm hasn't been loaded before.
(require 'crm)
;; For GNU Emacs 24.4 or later, based on `completing-read-multiple' of
;; git commit b14abca9476cba2f500b5eda89441d593dd0f12b
;; 2013-01-10 * lisp/emacs-lisp/crm.el: Allow any regexp for separators.
(defun TeX-completing-read-multiple
(prompt table &optional predicate require-match initial-input
hist def inherit-input-method)
"Like `completing-read-multiple' which see.
Retain zero-length substrings but ensure that empty input results
in nil across different emacs versions."
(unwind-protect
(progn
(add-hook 'choose-completion-string-functions
#'crm--choose-completion-string)
(let* ((minibuffer-completion-table #'crm--collection-fn)
(minibuffer-completion-predicate predicate)
;; see completing_read in src/minibuf.c
(minibuffer-completion-confirm
(unless (eq require-match t) require-match))
(crm-completion-table table)
(map (if require-match
crm-local-must-match-map
crm-local-completion-map))
;; If the user enters empty input, `read-from-minibuffer'
;; returns the empty string, not DEF.
(input (read-from-minibuffer
prompt initial-input map
nil hist def inherit-input-method))
result)
(and def (string-equal input "") (setq input def))
(if (equal (setq result (split-string input crm-separator))
'(""))
nil
result)))
(remove-hook 'choose-completion-string-functions
#'crm--choose-completion-string)))
(defun TeX-read-string (prompt &optional initial-input history default-value)
(read-string prompt initial-input history default-value t))
(defun TeX-active-mark ()
(and transient-mark-mode mark-active))
(defun TeX-activate-region ()
(setq deactivate-mark nil)
(activate-mark))
(defun TeX-overlay-prioritize (start end)
"Calculate a priority for an overlay extending from START to END.
The calculated priority is lower than the minimum of priorities
of surrounding overlays and higher than the maximum of enclosed
overlays."
(let (outer-priority inner-priority ov-priority)
(dolist (ov (overlays-in start end))
(when (or (eq (overlay-get ov 'category) 'TeX-fold)
(overlay-get ov 'preview-state))
(setq ov-priority (overlay-get ov 'priority))
(if (>= (overlay-start ov) start)
(setq inner-priority (max ov-priority (or inner-priority
ov-priority)))
(setq outer-priority (min ov-priority (or outer-priority
ov-priority))))))
(cond ((and inner-priority (not outer-priority))
(+ inner-priority TeX-overlay-priority-step))
((and (not inner-priority) outer-priority)
(/ outer-priority 2))
((and inner-priority outer-priority)
(+ (/ (- outer-priority inner-priority) 2) inner-priority))
(t TeX-overlay-priority-step))))
(defun TeX-delete-dups-by-car (alist &optional keep-list)
"Return a list of all elements in ALIST, but each car only once.
Elements of KEEP-LIST are not removed even if duplicate."
;; Copy of `reftex-uniquify-by-car' (written by David Kastrup).
(setq keep-list (TeX-sort-strings keep-list))
(setq alist (sort (copy-sequence alist)
#'TeX-car-string-lessp))
(let ((new alist) elt)
(while (cdr new)
(setq elt (caar new))
(while (and keep-list (string< (car keep-list) elt))
(setq keep-list (cdr keep-list)))
(unless (and keep-list (string= elt (car keep-list)))
(while (string= elt (car (cadr new)))
(setcdr new (cddr new))))
(setq new (cdr new))))
alist)
(defun TeX-delete-duplicate-strings (list)
"Return a list of all strings in LIST, but each only once."
(setq list (TeX-sort-strings list))
(let ((new list) elt)
(while (cdr new)
(setq elt (car new))
(while (string= elt (cadr new))
(setcdr new (cddr new)))
(setq new (cdr new))))
list)
(defun TeX-sort-strings (list)
"Return sorted list of all strings in LIST."
(sort (copy-sequence list) #'string<))
(defun TeX-car-string-lessp (s1 s2)
"Compare the cars of S1 and S2 in lexicographic order.
Return t if first is less than second in lexicographic order."
(string-lessp (car s1) (car s2)))
;;; Buffer
(defgroup TeX-output nil
"Parsing TeX output."
:prefix "TeX-"
:group 'AUCTeX)
(defcustom TeX-display-help t
"Control type of help display when stepping through errors with \\[TeX-next-error].
If t display help buffer. If nil display message about error in
echo area. If `expert' display output buffer with raw processor output."
:group 'TeX-output
:type '(choice (const :tag "Help buffer" t)
(const :tag "Echo area" nil)
(const :tag "Output buffer" expert)))
(defcustom TeX-debug-bad-boxes nil
"Non-nil means also find overfull/underfull box warnings with \\[TeX-next-error]."
:group 'TeX-output
:type 'boolean)
(defcustom TeX-debug-warnings nil
"Non-nil means also find LaTeX or package warnings with \\[TeX-next-error]."
:group 'TeX-output
:type 'boolean)
(defcustom TeX-ignore-warnings nil
"Controls which warnings are to be ignored.
It can be either a regexp matching warnings to be ignored, or a
symbol with the name of a custom function taking as arguments all
the information of the warning listed in `TeX-error-list', except
the last one about whether to ignore the warning.
If you want to use the custom function, see how it is used in the
code of `TeX-warning'."
:group 'TeX-command
:type '(choice (const :tag "Do not ignore anything" nil)
(string :tag "Regexp")
(symbol :tag "Function name")))
(defcustom TeX-suppress-ignored-warnings nil
"Whether to actually show ignored warnings.
Note that `TeX-debug-warnings' always takes the precedence."
:group 'TeX-command
:type 'boolean)
(defun TeX-toggle-debug-bad-boxes ()
"Toggle if the debugger should display \"bad boxes\" too."
(interactive)
(setq TeX-debug-bad-boxes (not TeX-debug-bad-boxes))
(message (concat "TeX-debug-bad-boxes: "
(if TeX-debug-bad-boxes "on" "off"))))
(defun TeX-toggle-debug-warnings ()
"Toggle if the debugger should display warnings too."
(interactive)
(setq TeX-debug-warnings (not TeX-debug-warnings))
(message (concat "TeX-debug-warnings: "
(if TeX-debug-warnings "on" "off"))))
(defun TeX-toggle-suppress-ignored-warnings ()
"Toggle if the debugger should display ignored warnings too.
See `TeX-suppress-ignored-warnings' and `TeX-ignore-warnings' for
more details."
(interactive)
(setq TeX-suppress-ignored-warnings (not TeX-suppress-ignored-warnings))