1 ;;; tex-mode.el --- TeX, LaTeX, and SliTeX mode commands -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1989, 1992, 1994-1999, 2001-2017 Free
4 ;; Software Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
9 ;; Contributions over the years by William F. Schelter, Dick King,
10 ;; Stephen Gildea, Michael Prange, Jacob Gore, and Edward M. Reingold.
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 ;; Pacify the byte-compiler
37 (defvar font-lock-comment-face
)
38 (defvar font-lock-doc-face
)
43 (defgroup tex-file nil
44 "TeX files and directories."
49 "Running external commands from TeX mode."
53 (defgroup tex-view nil
54 "Viewing and printing TeX files."
59 (defcustom tex-shell-file-name nil
60 "If non-nil, the shell file name to run in the subshell used to run TeX."
61 :type
'(choice (const :tag
"None" nil
)
66 (defcustom tex-directory
(purecopy ".")
67 "Directory in which temporary files are written.
68 You can make this `/tmp' if your TEXINPUTS has no relative directories in it
69 and you don't try to apply \\[tex-region] or \\[tex-buffer] when there are
70 `\\input' commands with relative directories."
75 (defcustom tex-first-line-header-regexp nil
76 "Regexp for matching a first line which `tex-region' should include.
77 If this is non-nil, it should be a regular expression string;
78 if it matches the first line of the file,
79 `tex-region' always includes the first line in the TeX run."
80 :type
'(choice (const :tag
"None" nil
)
85 (defcustom tex-main-file nil
86 "The main TeX source file which includes this buffer's file.
87 The command `tex-file' runs TeX on the file specified by `tex-main-file'
88 if the variable is non-nil."
89 :type
'(choice (const :tag
"None" nil
)
94 (defcustom tex-offer-save t
95 "If non-nil, ask about saving modified buffers before \\[tex-file] is run."
100 (defcustom tex-run-command
(purecopy "tex")
101 "Command used to run TeX subjob.
102 TeX Mode sets `tex-command' to this string.
103 See the documentation of that variable."
108 (defcustom latex-run-command
(purecopy "latex")
109 "Command used to run LaTeX subjob.
110 LaTeX Mode sets `tex-command' to this string.
111 See the documentation of that variable."
116 (defcustom slitex-run-command
(purecopy "slitex")
117 "Command used to run SliTeX subjob.
118 SliTeX Mode sets `tex-command' to this string.
119 See the documentation of that variable."
124 (defcustom tex-start-options
(purecopy "")
125 "TeX options to use when starting TeX.
126 These immediately precede the commands in `tex-start-commands'
127 and the input file name, with no separating space and are not shell-quoted.
128 If nil, TeX runs with no options. See the documentation of `tex-command'."
134 (defcustom tex-start-commands
(purecopy "\\nonstopmode\\input")
135 "TeX commands to use when starting TeX.
136 They are shell-quoted and precede the input file name, with a separating space.
137 If nil, no commands are used. See the documentation of `tex-command'."
138 :type
'(radio (const :tag
"Interactive (nil)" nil
)
139 (const :tag
"Nonstop (\"\\nonstopmode\\input\")"
140 "\\nonstopmode\\input")
141 (string :tag
"String at your choice"))
145 (defvar latex-standard-block-names
146 '("abstract" "array" "center" "description"
147 "displaymath" "document" "enumerate" "eqnarray"
148 "eqnarray*" "equation" "figure" "figure*"
149 "flushleft" "flushright" "itemize" "letter"
150 "list" "minipage" "picture" "quotation"
151 "quote" "slide" "sloppypar" "tabbing"
152 "table" "table*" "tabular" "tabular*"
153 "thebibliography" "theindex*" "titlepage" "trivlist"
154 "verbatim" "verbatim*" "verse" "math")
155 "Standard LaTeX block names.")
158 (defcustom latex-block-names nil
159 "User defined LaTeX block names.
160 Combined with `latex-standard-block-names' for minibuffer completion."
161 :type
'(repeat string
)
165 (defcustom tex-bibtex-command
(purecopy "bibtex")
166 "Command used by `tex-bibtex-file' to gather bibliographic data.
167 If this string contains an asterisk (`*'), that is replaced by the file name;
168 otherwise, the file name, preceded by blank, is added at the end."
173 (defcustom tex-dvi-print-command
(purecopy "lpr -d")
174 "Command used by \\[tex-print] to print a .dvi file.
175 If this string contains an asterisk (`*'), that is replaced by the file name;
176 otherwise, the file name, preceded by blank, is added at the end."
181 (defcustom tex-alt-dvi-print-command
(purecopy "lpr -d")
182 "Command used by \\[tex-print] with a prefix arg to print a .dvi file.
183 If this string contains an asterisk (`*'), that is replaced by the file name;
184 otherwise, the file name, preceded by blank, is added at the end.
186 If two printers are not enough of a choice, you can set the variable
187 `tex-alt-dvi-print-command' to an expression that asks what you want;
190 (setq tex-alt-dvi-print-command
191 \\='(format \"lpr -P%s\" (read-string \"Use printer: \")))
193 would tell \\[tex-print] with a prefix argument to ask you which printer to
195 :type
'(choice (string :tag
"Command")
196 (sexp :tag
"Expression"))
200 (defcustom tex-dvi-view-command
202 ((eq window-system
'x
) ,(purecopy "xdvi"))
203 ((eq window-system
'w32
) ,(purecopy "yap"))
204 (t ,(purecopy "dvi2tty * | cat -s")))
205 "Command used by \\[tex-view] to display a `.dvi' file.
206 If it is a string, that specifies the command directly.
207 If this string contains an asterisk (`*'), that is replaced by the file name;
208 otherwise, the file name, preceded by a space, is added at the end.
210 If the value is a form, it is evaluated to get the command to use."
211 :type
'(choice (const nil
) string sexp
)
215 (defcustom tex-show-queue-command
(purecopy "lpq")
216 "Command used by \\[tex-show-print-queue] to show the print queue.
217 Should show the queue(s) that \\[tex-print] puts jobs on."
222 (defcustom tex-default-mode
'latex-mode
223 "Mode to enter for a new file that might be either TeX or LaTeX.
224 This variable is used when it can't be determined whether the file
225 is plain TeX or LaTeX or what because the file contains no commands.
226 Normally set to either `plain-tex-mode' or `latex-mode'."
231 (defcustom tex-open-quote
(purecopy "``")
232 "String inserted by typing \\[tex-insert-quote] to open a quotation."
234 :options
'("``" "\"<" "\"`" "<<" "«")
238 (defcustom tex-close-quote
(purecopy "''")
239 "String inserted by typing \\[tex-insert-quote] to close a quotation."
241 :options
'("''" "\">" "\"'" ">>" "»")
244 (defcustom tex-fontify-script t
245 "If non-nil, fontify subscript and superscript strings."
249 (put 'tex-fontify-script
'safe-local-variable
'booleanp
)
251 (defcustom tex-font-script-display
'(-0.2
0.2)
252 "How much to lower and raise subscript and superscript content.
253 This is a list of two floats. The first is negative and
254 specifies how much subscript is lowered, the second is positive
255 and specifies how much superscript is raised. Heights are
256 measured relative to that of the normal text."
258 :type
'(list (float :tag
"Subscript")
259 (float :tag
"Superscript"))
262 (defvar tex-last-temp-file nil
263 "Latest temporary file generated by \\[tex-region] and \\[tex-buffer].
264 Deleted when the \\[tex-region] or \\[tex-buffer] is next run, or when the
265 tex shell terminates.")
267 (defvar tex-command
"tex"
269 If this string contains an asterisk \(`*'), that is replaced by the file name;
270 otherwise the value of `tex-start-options', the \(shell-quoted)
271 value of `tex-start-commands', and the file name are added at the end
272 with blanks as separators.
274 In TeX, LaTeX, and SliTeX Mode this variable becomes buffer local.")
276 (defvar tex-trailer nil
277 "String appended after the end of a region sent to TeX by \\[tex-region].")
279 (defvar tex-start-of-header nil
280 "Regular expression used by \\[tex-region] to find start of file's header.")
282 (defvar tex-end-of-header nil
283 "Regular expression used by \\[tex-region] to find end of file's header.")
285 (defvar tex-shell-cd-command
"cd"
286 "Command to give to shell running TeX to change directory.
287 The value of `tex-directory' is appended to this, separated by a space.")
289 (defvar tex-zap-file nil
290 "Temporary file name used for text being sent as input to TeX.
291 Should be a simple file name with no extension or directory specification.")
293 (defvar tex-last-buffer-texed nil
294 "Buffer which was last TeXed.")
296 (defvar tex-print-file nil
297 "File name that \\[tex-print] prints.
298 Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
300 (defvar tex-mode-syntax-table
301 (let ((st (make-syntax-table)))
302 (modify-syntax-entry ?%
"<" st
)
303 (modify-syntax-entry ?
\n ">" st
)
304 (modify-syntax-entry ?
\f ">" st
)
305 (modify-syntax-entry ?\C-
@ "w" st
)
306 (modify-syntax-entry ?
' "w" st
)
307 (modify-syntax-entry ?
@ "_" st
)
308 (modify-syntax-entry ?
* "_" st
)
309 (modify-syntax-entry ?
\t " " st
)
310 ;; ~ is printed by TeX as a space, but it's semantics in the syntax
311 ;; of TeX is not `whitespace' (i.e. it's just like \hspace{foo}).
312 (modify-syntax-entry ?~
"." st
)
313 (modify-syntax-entry ?$
"$$" st
)
314 (modify-syntax-entry ?
\\ "/" st
)
315 (modify-syntax-entry ?
\" "." st
)
316 (modify-syntax-entry ?
& "." st
)
317 (modify-syntax-entry ?_
"." st
)
318 (modify-syntax-entry ?^
"." st
)
320 "Syntax table used while in TeX mode.")
326 (defcustom latex-imenu-indent-string
". "
327 "String to add repeated in front of nested sectional units for Imenu.
328 An alternative value is \" . \", if you use a font with a narrow period."
332 (defvar latex-section-alist
333 '(("part" .
0) ("chapter" .
1)
334 ("section" .
2) ("subsection" .
3)
335 ("subsubsection" .
4)
336 ("paragraph" .
5) ("subparagraph" .
6)))
338 (defvar latex-metasection-list
339 '("documentstyle" "documentclass"
340 "begin{document}" "end{document}"
341 "appendix" "frontmatter" "mainmatter" "backmatter"))
343 (defun latex-imenu-create-index ()
344 "Generate an alist for imenu from a LaTeX buffer."
345 (let ((section-regexp
346 (concat "\\\\" (regexp-opt (mapcar #'car latex-section-alist
) t
)
349 (concat "\\\\" (regexp-opt latex-metasection-list t
)))
350 i0 menu case-fold-search
)
352 ;; Find the top-most level in this file but don't allow it to be
353 ;; any deeper than "section" (which is top-level in an article).
354 (goto-char (point-min))
355 (if (search-forward-regexp "\\\\part\\*?[ \t]*{" nil t
)
357 (if (search-forward-regexp "\\\\chapter\\*?[ \t]*{" nil t
)
361 ;; Look for chapters and sections.
362 (goto-char (point-min))
363 (while (search-forward-regexp section-regexp nil t
)
364 (let ((start (match-beginning 0))
366 (i (cdr (assoc (buffer-substring-no-properties
369 latex-section-alist
))))
373 ;; Using sexps allows some use of matching {...} inside
376 (push (cons (concat (apply #'concat
379 latex-imenu-indent-string
))
380 (buffer-substring-no-properties
386 ;; Look for included material.
387 (goto-char (point-min))
388 (while (search-forward-regexp
389 "\\\\\\(include\\|input\\|verbatiminput\\|bibliography\\)\
390 [ \t]*{\\([^}\n]+\\)}"
392 (push (cons (concat "<<" (buffer-substring-no-properties
395 (if (= (char-after (match-beginning 1)) ?b
)
401 ;; Look for \frontmatter, \mainmatter, \backmatter, and \appendix.
402 (goto-char (point-min))
403 (while (search-forward-regexp metasection-regexp nil t
)
404 (push (cons "--" (match-beginning 0)) menu
))
406 ;; Sort in increasing buffer position order.
407 (sort menu
(function (lambda (a b
) (< (cdr a
) (cdr b
))))))))
413 (defvar latex-outline-regexp
415 (regexp-opt (append latex-metasection-list
416 (mapcar #'car latex-section-alist
))
419 (defun latex-outline-level ()
420 (if (looking-at latex-outline-regexp
)
421 (1+ (or (cdr (assoc (match-string 1) latex-section-alist
)) -
1))
424 (defun tex-current-defun-name ()
425 "Return the name of the TeX section/paragraph/chapter at point, or nil."
427 (when (re-search-backward
428 "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)"
430 (goto-char (match-beginning 0))
431 (buffer-substring-no-properties
432 (1+ (point)) ; without initial backslash
433 (line-end-position)))))
436 ;;;; Font-Lock support
439 ;(defvar tex-font-lock-keywords
440 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
441 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
442 ; 2 font-lock-function-name-face)
443 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
444 ; 2 font-lock-constant-face)
445 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
446 ; ;; not be able to display those fonts.
447 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
448 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
449 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
450 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
451 ; ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
452 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
453 ; 2 font-lock-function-name-face)
454 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
455 ; 2 font-lock-constant-face)
456 ; ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
457 ; "\\\\\\([a-zA-Z@]+\\|.\\)"
458 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
459 ; ;; not be able to display those fonts.
460 ; ;; LaTeX2e: \emph{This is emphasized}.
461 ; ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
462 ; ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
463 ; ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
464 ; 3 (if (match-beginning 2) 'bold 'italic) keep)
465 ; ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
466 ; ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
467 ; 3 (if (match-beginning 2) 'bold 'italic) keep))
469 ;; Rewritten with the help of Alexandra Bac <abac@welcome.disi.unige.it>.
470 (defconst tex-font-lock-keywords-1
472 (let* (;; Names of commands whose arg should be fontified as heading, etc.
473 (headings (regexp-opt
474 '("title" "begin" "end" "chapter" "part"
475 "section" "subsection" "subsubsection"
476 "paragraph" "subparagraph" "subsubparagraph"
477 "newcommand" "renewcommand" "providecommand"
478 "newenvironment" "renewenvironment"
479 "newtheorem" "renewtheorem")
481 (variables (regexp-opt
482 '("newcounter" "newcounter*" "setcounter" "addtocounter"
483 "setlength" "addtolength" "settowidth")
485 (includes (regexp-opt
486 '("input" "include" "includeonly" "bibliography"
487 "epsfig" "psfig" "epsf" "nofiles" "usepackage"
488 "documentstyle" "documentclass" "verbatiminput"
489 "includegraphics" "includegraphics*")
491 (verbish (regexp-opt '("url" "nolinkurl" "path") t
))
494 (opt " *\\(\\[[^]]*\\] *\\)*")
495 ;; This would allow highlighting \newcommand\CMD but requires
496 ;; adapting subgroup numbers below.
497 ;; (arg "\\(?:{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)\\|\\\\[a-z*]+\\)"))
498 (inbraces-re (lambda (re)
499 (concat "\\(?:[^{}\\]\\|\\\\.\\|" re
"\\)")))
500 (arg (concat "{\\(" (funcall inbraces-re
"{[^}]*}") "+\\)")))
501 `( ;; Highlight $$math$$ and $math$.
502 ;; This is done at the very beginning so as to interact with the other
503 ;; keywords in the same way as comments and strings.
504 (,(concat "\\$\\$?\\(?:[^$\\{}]\\|\\\\.\\|{"
506 (concat "{" (funcall inbraces-re
"{[^}]*}") "*}"))
510 (,(concat slash headings
"\\*?" opt arg
)
511 ;; If ARG ends up matching too much (if the {} don't match, e.g.)
512 ;; jit-lock will do funny things: when updating the buffer
513 ;; the re-highlighting is only done locally so it will just
514 ;; match the local line, but defer-contextually will
515 ;; match more lines at a time, so ARG will end up matching
516 ;; a lot more, which might suddenly include a comment
517 ;; so you get things highlighted bold when you type them
518 ;; but they get turned back to normal a little while later
519 ;; because "there's already a face there".
520 ;; Using `keep' works around this un-intuitive behavior as well
521 ;; as improves the behavior in the very rare case where you do
522 ;; have a comment in ARG.
523 3 font-lock-function-name-face keep
)
524 (,(concat slash
"\\(?:provide\\|\\(?:re\\)?new\\)command\\** *\\(\\\\[A-Za-z@]+\\)")
525 1 font-lock-function-name-face keep
)
527 (,(concat slash variables
" *" arg
) 2 font-lock-variable-name-face
)
529 (,(concat slash includes opt arg
) 3 font-lock-builtin-face
)
530 ;; Verbatim-like args.
531 (,(concat slash verbish opt arg
) 3 'tex-verbatim
)
532 ;; Definitions. I think.
533 ("^[ \t]*\\\\def *\\\\\\(\\(\\w\\|@\\)+\\)"
534 1 font-lock-function-name-face
))))
535 "Subdued expressions to highlight in TeX modes.")
537 (defun tex-font-lock-append-prop (prop)
538 (unless (memq (get-text-property (match-end 1) 'face
)
539 '(font-lock-comment-face tex-verbatim
))
542 (defconst tex-font-lock-keywords-2
543 (append tex-font-lock-keywords-1
546 ;; Names of commands whose arg should be fontified with fonts.
547 (bold (regexp-opt '("textbf" "textsc" "textup"
550 (italic (regexp-opt '("textit" "textsl" "emph") t
))
551 ;; FIXME: unimplemented yet.
552 ;; (type (regexp-opt '("texttt" "textmd" "textrm" "textsf") t))
554 ;; Names of commands whose arg should be fontified as a citation.
555 (citations (regexp-opt
556 '("label" "ref" "pageref" "vref" "eqref"
557 "cite" "nocite" "index" "glossary" "bibitem"
558 ;; natbib's two variants of \cite:
560 ;; These are text, rather than citations.
561 ;; "caption" "footnote" "footnotemark" "footnotetext"
565 ;; Names of commands that should be fontified.
566 (specials-1 (regexp-opt '("\\" "\\*") t
)) ;; "-"
567 (specials-2 (regexp-opt
568 '("linebreak" "nolinebreak" "pagebreak" "nopagebreak"
569 "newline" "newpage" "clearpage" "cleardoublepage"
570 "displaybreak" "allowdisplaybreaks"
573 (general "\\([a-zA-Z@]+\\**\\|[^ \t\n]\\)")
577 (opt " *\\(\\[[^]]*\\] *\\)*")
578 (args "\\(\\(?:[^{}&\\]+\\|\\\\.\\|{[^}]*}\\)+\\)")
579 (arg "{\\(\\(?:[^{}\\]+\\|\\\\.\\|{[^}]*}\\)+\\)"))
583 (list (concat slash citations opt arg
) 3 'font-lock-constant-face
)
585 ;; Text between `` quotes ''.
586 (cons (concat (regexp-opt `("``" "\"<" "\"`" "<<" "«") t
)
587 "[^'\">{]+" ;a bit pessimistic
588 (regexp-opt `("''" "\">" "\"'" ">>" "»") t
))
589 'font-lock-string-face
)
591 ;; Command names, special and general.
592 (cons (concat slash specials-1
) 'font-lock-warning-face
)
593 (list (concat "\\(" slash specials-2
"\\)\\([^a-zA-Z@]\\|\\'\\)")
594 1 'font-lock-warning-face
)
595 (concat slash general
)
597 ;; Font environments. It seems a bit dubious to use `bold' etc. faces
598 ;; since we might not be able to display those fonts.
599 (list (concat slash bold
" *" arg
) 2
600 '(tex-font-lock-append-prop 'bold
) 'append
)
601 (list (concat slash italic
" *" arg
) 2
602 '(tex-font-lock-append-prop 'italic
) 'append
)
603 ;; (list (concat slash type arg) 2 '(quote bold-italic) 'append)
605 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for tables.
606 (list (concat "\\\\\\(em\\|it\\|sl\\)\\>" args
)
607 2 '(tex-font-lock-append-prop 'italic
) 'append
)
608 ;; This is separate from the previous one because of cases like
609 ;; {\em foo {\bf bar} bla} where both match.
610 (list (concat "\\\\\\(bf\\(series\\)?\\)\\>" args
)
611 3 '(tex-font-lock-append-prop 'bold
) 'append
)))))
612 "Gaudy expressions to highlight in TeX modes.")
614 (defun tex-font-lock-suscript (pos)
615 (unless (or (memq (get-text-property pos
'face
)
616 '(font-lock-constant-face font-lock-builtin-face
617 font-lock-comment-face tex-verbatim
))
618 ;; Check for backslash quoting
621 (while (eq (char-before pos
) ?
\\)
622 (setq pos
(1- pos
) odd
(not odd
)))
624 (if (eq (char-after pos
) ?_
)
625 `(face subscript display
(raise ,(car tex-font-script-display
)))
626 `(face superscript display
(raise ,(cadr tex-font-script-display
))))))
628 (defun tex-font-lock-match-suscript (limit)
629 "Match subscript and superscript patterns up to LIMIT."
630 (when (and tex-fontify-script
631 (re-search-forward "[_^] *\\([^\n\\{}]\\|\
632 \\\\\\([a-zA-Z@]+\\|[^ \t\n]\\)\\|\\({\\)\\)" limit t
))
634 (let ((beg (match-beginning 3))
635 (end (save-restriction
636 (narrow-to-region (point-min) limit
)
637 (condition-case nil
(scan-lists (point) 1 1) (error nil
)))))
638 (store-match-data (if end
639 (list (match-beginning 0) end beg end
)
640 (list beg beg beg beg
)))))
643 (defconst tex-font-lock-keywords-3
644 (append tex-font-lock-keywords-2
645 '((tex-font-lock-match-suscript
646 (1 (tex-font-lock-suscript (match-beginning 0)) append
))))
647 "Experimental expressions to highlight in TeX modes.")
649 (defconst tex-font-lock-keywords tex-font-lock-keywords-1
650 "Default expressions to highlight in TeX modes.")
652 (defvar tex-verbatim-environments
653 '("verbatim" "verbatim*"))
654 (put 'tex-verbatim-environments
'safe-local-variable
655 (lambda (x) (null (delq t
(mapcar #'stringp x
)))))
658 (defconst tex-syntax-propertize-rules
659 (syntax-propertize-precompile-rules
660 ("\\\\verb\\**\\([^a-z@*]\\)"
663 (match-beginning 0) (char-after (match-beginning 1))))))))
665 (defconst latex-syntax-propertize-rules
666 (syntax-propertize-precompile-rules
667 tex-syntax-propertize-rules
668 ("\\\\\\(?:end\\|begin\\) *\\({[^\n{}]*}\\)"
670 (tex-env-mark (match-beginning 0)
671 (match-beginning 1) (match-end 1))))))))
673 (defun tex-env-mark (cmd start end
)
674 (when (= cmd
(line-beginning-position))
675 (let ((arg (buffer-substring-no-properties (1+ start
) (1- end
))))
676 (when (member arg tex-verbatim-environments
)
677 (if (eq ?b
(char-after (1+ cmd
)))
679 (put-text-property (line-end-position)
680 (line-beginning-position 2)
681 'syntax-table
(string-to-syntax "< c"))
682 ;; In the case of an empty verbatim env, the \n after the \begin is
683 ;; the same as the \n before the \end. Lucky for us, the "> c"
684 ;; property associated to the \end will be placed afterwards, so it
685 ;; will override the "< c".
686 (put-text-property (1- cmd
) cmd
687 'syntax-table
(string-to-syntax "> c"))
688 ;; The text between \end{verbatim} and \n is ignored, so we'll treat
690 (put-text-property end
(min (1+ end
) (line-end-position))
691 'syntax-table
(string-to-syntax "<"))))))
692 ;; Mark env args for possible electric pairing.
693 (unless (get-char-property (1+ start
) 'text-clones
) ;Already paired-up.
694 (put-text-property start end
'latex-env-pair t
)))
696 (define-minor-mode latex-electric-env-pair-mode
697 "Toggle Latex Electric Env Pair mode.
698 With a prefix argument ARG, enable the mode if ARG is positive,
699 and disable it otherwise. If called from Lisp, enable it if ARG
702 Latex Electric Env Pair mode is a buffer-local minor mode for use
703 with `latex-mode'. When enabled, typing a \\begin or \\end tag
704 automatically inserts its partner."
706 (if latex-electric-env-pair-mode
707 (add-hook 'before-change-functions
708 #'latex-env-before-change nil
'local
)
709 (remove-hook 'before-change-functions
710 #'latex-env-before-change
'local
)))
712 (defun latex-env-before-change (start end
)
713 (when (get-text-property start
'latex-env-pair
)
715 (with-silent-modifications
716 ;; Remove properties even if don't find a pair.
717 (remove-text-properties
718 (previous-single-property-change (1+ start
) 'latex-env-pair
)
719 (next-single-property-change start
'latex-env-pair
)
721 (unless (or (get-char-property start
'text-clones
)
722 (get-char-property (1+ start
) 'text-clones
)
725 (not (re-search-backward
726 "\\\\\\(?:end\\|begi\\(n\\)\\) *{"
727 (line-beginning-position) t
))))
728 (let ((cmd-start (match-beginning 0))
729 (type (match-end 1)) ;nil for \end, else \begin.
730 (arg-start (1- (match-end 0))))
732 (goto-char (match-end 0))
733 (when (and (looking-at "[^\n{}]*}")
734 (> (match-end 0) end
))
735 (let ((arg-end (match-end 0)))
736 (if (null type
) ;\end
737 (progn (goto-char arg-end
)
738 (latex-forward-sexp -
1)
739 (forward-word-strictly 1))
740 (goto-char cmd-start
)
741 (latex-forward-sexp 1)
742 (let (forward-sexp-function) (backward-sexp)))
744 (regexp-quote (buffer-substring arg-start arg-end
)))
745 (text-clone-create arg-start arg-end
))))))))
747 (error (message "Error in latex-env-before-change: %s" err
)))))
749 (defun tex-font-lock-unfontify-region (beg end
)
750 (font-lock-default-unfontify-region beg end
)
752 (let ((next (next-single-property-change beg
'display nil end
))
753 (prop (get-text-property beg
'display
)))
754 (if (and (eq (car-safe prop
) 'raise
)
755 (member (car-safe (cdr prop
)) tex-font-script-display
)
757 (put-text-property beg next
'display nil
))
760 (defcustom tex-suscript-height-ratio
0.8
761 "Ratio of subscript/superscript height to that of the preceding text.
762 In nested subscript/superscript, this factor is applied repeatedly,
763 subject to the limit set by `tex-suscript-height-minimum'."
768 (defcustom tex-suscript-height-minimum
0.0
769 "Integer or float limiting the minimum size of subscript/superscript text.
770 An integer is an absolute height in units of 1/10 point, a float
771 is a height relative to that of the default font. Zero means no minimum."
772 :type
'(choice (integer :tag
"Integer height in 1/10 point units")
773 (float :tag
"Fraction of default font height"))
777 (defun tex-suscript-height (height)
778 "Return the integer height of subscript/superscript font in 1/10 points.
779 Not smaller than the value set by `tex-suscript-height-minimum'."
780 (ceiling (max (if (integerp tex-suscript-height-minimum
)
781 tex-suscript-height-minimum
782 ;; For bootstrapping.
784 (* tex-suscript-height-minimum
785 (face-attribute 'default
:height
))
787 ;; NB assumes height is integer.
788 (* height tex-suscript-height-ratio
))))
791 '((t :height tex-suscript-height
)) ;; :raise 0.2
792 "Face used for superscripts."
795 '((t :height tex-suscript-height
)) ;; :raise -0.2
796 "Face used for subscripts."
800 '((t :inherit font-lock-string-face
))
801 "Face used to highlight TeX math expressions."
804 (defface tex-verbatim
805 '((t :inherit fixed-pitch-serif
))
806 "Face used to highlight TeX verbatim environments."
809 (defun tex-font-lock-verb (start delim
)
810 "Place syntax table properties on the \\verb construct.
811 START is the position of the \\ and DELIM is the delimiter char."
812 ;; Do nothing if the \verb construct is itself inside a comment or
814 (unless (nth 8 (save-excursion (syntax-ppss start
)))
815 ;; Let's find the end and mark it.
816 (let ((afterdelim (point)))
817 (skip-chars-forward (string ?^ delim
) (line-end-position))
819 ;; "LaTeX Error: \verb ended by end of line."
820 ;; Remove the syntax-table property we've just put on the
821 ;; start-delimiter, so it doesn't spill over subsequent lines.
822 (put-text-property (1- afterdelim
) afterdelim
824 (when (eq (char-syntax (preceding-char)) ?
/)
825 (put-text-property (1- (point)) (point)
826 'syntax-table
(string-to-syntax ".")))
827 (put-text-property (point) (1+ (point))
828 'syntax-table
(string-to-syntax "\""))))))
830 ;; Use string syntax but math face for $...$.
831 (defun tex-font-lock-syntactic-face-function (state)
832 (let ((char (nth 3 state
)))
835 (if (eq 2 (nth 7 state
)) 'tex-verbatim font-lock-comment-face
))
836 ((eq char ?$
) 'tex-math
)
841 (defun tex-define-common-keys (keymap)
842 "Define the keys that we want defined both in TeX mode and in the TeX shell."
843 (define-key keymap
"\C-c\C-k" 'tex-kill-job
)
844 (define-key keymap
"\C-c\C-l" 'tex-recenter-output-buffer
)
845 (define-key keymap
"\C-c\C-q" 'tex-show-print-queue
)
846 (define-key keymap
"\C-c\C-p" 'tex-print
)
847 (define-key keymap
"\C-c\C-v" 'tex-view
)
849 (define-key keymap
[menu-bar tex
] (cons "TeX" (make-sparse-keymap "TeX")))
851 (define-key keymap
[menu-bar tex tex-kill-job
]
852 '(menu-item "Tex Kill" tex-kill-job
:enable
(tex-shell-running)))
853 (define-key keymap
[menu-bar tex tex-recenter-output-buffer
]
854 '(menu-item "Tex Recenter" tex-recenter-output-buffer
855 :enable
(get-buffer "*tex-shell*")))
856 (define-key keymap
[menu-bar tex tex-show-print-queue
]
857 '("Show Print Queue" . tex-show-print-queue
))
858 (define-key keymap
[menu-bar tex tex-alt-print
]
859 '(menu-item "Tex Print (alt printer)" tex-alt-print
860 :enable
(stringp tex-print-file
)))
861 (define-key keymap
[menu-bar tex tex-print
]
862 '(menu-item "Tex Print" tex-print
:enable
(stringp tex-print-file
)))
863 (define-key keymap
[menu-bar tex tex-view
]
864 '(menu-item "Tex View" tex-view
:enable
(stringp tex-print-file
))))
867 (let ((map (make-sparse-keymap)))
868 (set-keymap-parent map text-mode-map
)
869 (tex-define-common-keys map
)
870 (define-key map
"\"" 'tex-insert-quote
)
871 (define-key map
"\n" 'tex-handle-newline
)
872 (define-key map
"\M-\r" 'latex-insert-item
)
873 (define-key map
"\C-c}" 'up-list
)
874 (define-key map
"\C-c{" 'tex-insert-braces
)
875 (define-key map
"\C-c\C-r" 'tex-region
)
876 (define-key map
"\C-c\C-b" 'tex-buffer
)
877 (define-key map
"\C-c\C-f" 'tex-file
)
878 (define-key map
"\C-c\C-c" 'tex-compile
)
879 (define-key map
"\C-c\C-i" 'tex-bibtex-file
)
880 (define-key map
"\C-c\C-o" 'latex-insert-block
)
882 ;; Redundant keybindings, for consistency with SGML mode.
883 (define-key map
"\C-c\C-t" 'latex-insert-block
)
884 (define-key map
"\C-c]" 'latex-close-block
)
885 (define-key map
"\C-c/" 'latex-close-block
)
887 (define-key map
"\C-c\C-e" 'latex-close-block
)
888 (define-key map
"\C-c\C-u" 'tex-goto-last-unclosed-latex-block
)
889 (define-key map
"\C-c\C-m" 'tex-feed-input
)
890 (define-key map
[(control return
)] 'tex-feed-input
)
891 (define-key map
[menu-bar tex tex-bibtex-file
]
892 '("BibTeX File" . tex-bibtex-file
))
893 (define-key map
[menu-bar tex tex-validate-region
]
894 '(menu-item "Validate Region" tex-validate-region
:enable mark-active
))
895 (define-key map
[menu-bar tex tex-validate-buffer
]
896 '("Validate Buffer" . tex-validate-buffer
))
897 (define-key map
[menu-bar tex tex-region
]
898 '(menu-item "TeX Region" tex-region
:enable mark-active
))
899 (define-key map
[menu-bar tex tex-buffer
]
900 '("TeX Buffer" . tex-buffer
))
901 (define-key map
[menu-bar tex tex-file
] '("TeX File" . tex-file
))
903 "Keymap shared by TeX modes.")
905 (defvar latex-mode-map
906 (let ((map (make-sparse-keymap)))
907 (set-keymap-parent map tex-mode-map
)
908 (define-key map
"\C-c\C-s" 'latex-split-block
)
910 "Keymap for `latex-mode'. See also `tex-mode-map'.")
912 (defvar plain-tex-mode-map
913 (let ((map (make-sparse-keymap)))
914 (set-keymap-parent map tex-mode-map
)
916 "Keymap for `plain-tex-mode'. See also `tex-mode-map'.")
918 (defvar tex-shell-map
919 (let ((m (make-sparse-keymap)))
920 (set-keymap-parent m shell-mode-map
)
921 (tex-define-common-keys m
)
923 "Keymap for the TeX shell.
924 Inherits `shell-mode-map' with a few additions.")
926 (defvar tex-face-alist
929 (bold-italic .
"{\\bi ") ; hypothetical
930 (underline .
"\\underline{")
931 (default .
"{\\rm "))
932 "Alist of face and TeX font name for facemenu.")
934 (defvar tex-latex-face-alist
935 `((italic .
"{\\em ")
937 "Alist of face and LaTeX font name for facemenu.")
939 (defun tex-facemenu-add-face-function (face _end
)
940 (or (cdr (assq face tex-face-alist
))
941 (or (and (consp face
)
944 (eq major-mode
'latex-mode
)
945 ;; This actually requires the `color' LaTeX package.
946 (cond ((eq (caar face
) :foreground
)
947 (format "{\\color{%s} " (cadr (car face
))))
948 ((eq (caar face
) :background
)
949 (format "\\colorbox{%s}{" (cadr (car face
))))))
950 (error "Face %s not configured for %s mode" face mode-name
))))
952 ;; This would be a lot simpler if we just used a regexp search,
953 ;; but then it would be too slow.
954 (defun tex-guess-mode ()
955 (let ((mode tex-default-mode
) slash comment
)
957 (goto-char (point-min))
958 (while (and (setq slash
(search-forward "\\" nil t
))
959 (setq comment
(let ((search-end (point)))
962 (search-forward "%" search-end t
))))))
963 (when (and slash
(not comment
))
968 (regexp-opt '("documentstyle" "documentclass"
969 "begin" "subsection" "section"
970 "part" "chapter" "newcommand"
971 "renewcommand" "RequirePackage") 'words
)
972 "\\|NeedsTeXFormat{LaTeX")))
974 "document\\(style\\|class\\)\\(\\[.*\\]\\)?{slides}")
975 ;; SliTeX is almost never used any more nowadays.
976 (tex-executable-exists-p slitex-run-command
))
982 ;; `tex-mode' plays two roles: it's the parent of several sub-modes
983 ;; but it's also the function that chooses between those submodes.
984 ;; To tell the difference between those two cases where the function
985 ;; might be called, we check `delay-mode-hooks'.
986 (define-derived-mode tex-mode text-mode
"generic-TeX"
987 (tex-common-initialization))
988 ;; We now move the function and define it again. This gives a warning
989 ;; in the byte-compiler :-( but it's difficult to avoid because
990 ;; `define-derived-mode' will necessarily define the function once
991 ;; and we need to define it a second time for `autoload' to get the
993 (defalias 'tex-mode-internal
(symbol-function 'tex-mode
))
995 ;; Suppress the byte-compiler warning about multiple definitions.
996 ;; This is a) ugly, and b) cheating, but this was the last
997 ;; remaining warning from byte-compiling all of Emacs...
999 (setq byte-compile-function-environment
1000 (delq (assq 'tex-mode byte-compile-function-environment
)
1001 byte-compile-function-environment
)))
1005 "Major mode for editing files of input for TeX, LaTeX, or SliTeX.
1006 Tries to determine (by looking at the beginning of the file) whether
1007 this file is for plain TeX, LaTeX, or SliTeX and calls `plain-tex-mode',
1008 `latex-mode', or `slitex-mode', respectively. If it cannot be determined,
1009 such as if there are no commands in the file, the value of `tex-default-mode'
1010 says which mode to use."
1012 (if delay-mode-hooks
1013 ;; We're called from one of the children already.
1017 ;; The following three autoloaded aliases appear to conflict with
1018 ;; AUCTeX. However, even though AUCTeX uses the mixed case variants
1019 ;; for all mode relevant variables and hooks, the invocation function
1020 ;; and setting of `major-mode' themselves need to be lowercase for
1021 ;; AUCTeX to provide a fully functional user-level replacement. So
1022 ;; these aliases should remain as they are, in particular since AUCTeX
1023 ;; users are likely to use them.
1026 (defalias 'TeX-mode
'tex-mode
)
1028 (defalias 'plain-TeX-mode
'plain-tex-mode
)
1030 (defalias 'LaTeX-mode
'latex-mode
)
1033 (define-derived-mode plain-tex-mode tex-mode
"TeX"
1034 "Major mode for editing files of input for plain TeX.
1035 Makes $ and } display the characters they match.
1036 Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
1037 and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
1039 Use \\[tex-region] to run TeX on the current region, plus a \"header\"
1040 copied from the top of the file (containing macro definitions, etc.),
1041 running TeX under a special subshell. \\[tex-buffer] does the whole buffer.
1042 \\[tex-file] saves the buffer and then processes the file.
1043 \\[tex-print] prints the .dvi file made by any of these.
1044 \\[tex-view] previews the .dvi file made by any of these.
1045 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
1047 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
1048 mismatched $'s or braces.
1051 \\{plain-tex-mode-map}
1055 Command string used by \\[tex-region] or \\[tex-buffer].
1057 Directory in which to create temporary files for TeX jobs
1058 run by \\[tex-region] or \\[tex-buffer].
1059 tex-dvi-print-command
1060 Command string used by \\[tex-print] to print a .dvi file.
1061 tex-alt-dvi-print-command
1062 Alternative command string used by \\[tex-print] (when given a prefix
1063 argument) to print a .dvi file.
1064 tex-dvi-view-command
1065 Command string used by \\[tex-view] to preview a .dvi file.
1066 tex-show-queue-command
1067 Command string used by \\[tex-show-print-queue] to show the print
1068 queue that \\[tex-print] put your job on.
1070 Entering Plain-tex mode runs the hook `text-mode-hook', then the hook
1071 `tex-mode-hook', and finally the hook `plain-tex-mode-hook'. When the
1072 special subshell is initiated, the hook `tex-shell-hook' is run."
1073 (setq-local tex-command tex-run-command
)
1074 (setq-local tex-start-of-header
"%\\*\\*start of header")
1075 (setq-local tex-end-of-header
"%\\*\\*end of header")
1076 (setq-local tex-trailer
"\\bye\n"))
1079 (define-derived-mode latex-mode tex-mode
"LaTeX"
1080 "Major mode for editing files of input for LaTeX.
1081 Makes $ and } display the characters they match.
1082 Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
1083 and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
1085 Use \\[tex-region] to run LaTeX on the current region, plus the preamble
1086 copied from the top of the file (containing \\documentstyle, etc.),
1087 running LaTeX under a special subshell. \\[tex-buffer] does the whole buffer.
1088 \\[tex-file] saves the buffer and then processes the file.
1089 \\[tex-print] prints the .dvi file made by any of these.
1090 \\[tex-view] previews the .dvi file made by any of these.
1091 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
1093 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
1094 mismatched $'s or braces.
1101 Command string used by \\[tex-region] or \\[tex-buffer].
1103 Directory in which to create temporary files for LaTeX jobs
1104 run by \\[tex-region] or \\[tex-buffer].
1105 tex-dvi-print-command
1106 Command string used by \\[tex-print] to print a .dvi file.
1107 tex-alt-dvi-print-command
1108 Alternative command string used by \\[tex-print] (when given a prefix
1109 argument) to print a .dvi file.
1110 tex-dvi-view-command
1111 Command string used by \\[tex-view] to preview a .dvi file.
1112 tex-show-queue-command
1113 Command string used by \\[tex-show-print-queue] to show the print
1114 queue that \\[tex-print] put your job on.
1116 Entering Latex mode runs the hook `text-mode-hook', then
1117 `tex-mode-hook', and finally `latex-mode-hook'. When the special
1118 subshell is initiated, `tex-shell-hook' is run."
1119 (setq-local tex-command latex-run-command
)
1120 (setq-local tex-start-of-header
"\\\\document\\(style\\|class\\)")
1121 (setq-local tex-end-of-header
"\\\\begin\\s-*{document}")
1122 (setq-local tex-trailer
"\\end{document}\n")
1123 ;; A line containing just $$ is treated as a paragraph separator.
1124 ;; A line starting with $$ starts a paragraph,
1125 ;; but does not separate paragraphs if it has more stuff on it.
1126 (setq paragraph-start
1127 (concat "[ \t]*\\(\\$\\$\\|"
1129 "\\\\" (regexp-opt (append
1130 (mapcar #'car latex-section-alist
)
1131 '("begin" "label" "end"
1132 "item" "bibitem" "newline" "noindent"
1133 "newpage" "footnote" "marginpar"
1134 "parbox" "caption"))
1136 "\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t
)
1138 (setq paragraph-separate
1139 (concat "[\f%]\\|[ \t]*\\($\\|"
1141 "\\\\" (regexp-opt (append
1142 (mapcar #'car latex-section-alist
)
1143 '("begin" "label" "end" ))
1145 "\\>\\|\\\\\\(" (regexp-opt '("item" "bibitem" "newline"
1146 "noindent" "newpage" "footnote"
1147 "marginpar" "parbox" "caption"))
1148 "\\|\\$\\$\\|[a-z]*\\(space\\|skip\\|page[a-z]*\\)"
1149 "\\>\\)[ \t]*\\($\\|%\\)\\)"))
1150 (setq-local imenu-create-index-function
#'latex-imenu-create-index
)
1151 (setq-local tex-face-alist tex-latex-face-alist
)
1152 (add-hook 'fill-nobreak-predicate
#'latex-fill-nobreak-predicate nil t
)
1153 (setq-local indent-line-function
#'latex-indent
)
1154 (setq-local fill-indent-according-to-mode t
)
1155 (add-hook 'completion-at-point-functions
1156 #'latex-complete-data nil
'local
)
1157 (setq-local outline-regexp latex-outline-regexp
)
1158 (setq-local outline-level
#'latex-outline-level
)
1159 (setq-local forward-sexp-function
#'latex-forward-sexp
)
1160 (setq-local skeleton-end-hook nil
))
1163 (define-derived-mode slitex-mode latex-mode
"SliTeX"
1164 "Major mode for editing files of input for SliTeX.
1165 Makes $ and } display the characters they match.
1166 Makes \" insert \\=`\\=` when it seems to be the beginning of a quotation,
1167 and \\='\\=' when it appears to be the end; it inserts \" only after a \\.
1169 Use \\[tex-region] to run SliTeX on the current region, plus the preamble
1170 copied from the top of the file (containing \\documentstyle, etc.),
1171 running SliTeX under a special subshell. \\[tex-buffer] does the whole buffer.
1172 \\[tex-file] saves the buffer and then processes the file.
1173 \\[tex-print] prints the .dvi file made by any of these.
1174 \\[tex-view] previews the .dvi file made by any of these.
1175 \\[tex-bibtex-file] runs bibtex on the file of the current buffer.
1177 Use \\[tex-validate-buffer] to check buffer for paragraphs containing
1178 mismatched $'s or braces.
1185 Command string used by \\[tex-region] or \\[tex-buffer].
1187 Directory in which to create temporary files for SliTeX jobs
1188 run by \\[tex-region] or \\[tex-buffer].
1189 tex-dvi-print-command
1190 Command string used by \\[tex-print] to print a .dvi file.
1191 tex-alt-dvi-print-command
1192 Alternative command string used by \\[tex-print] (when given a prefix
1193 argument) to print a .dvi file.
1194 tex-dvi-view-command
1195 Command string used by \\[tex-view] to preview a .dvi file.
1196 tex-show-queue-command
1197 Command string used by \\[tex-show-print-queue] to show the print
1198 queue that \\[tex-print] put your job on.
1200 Entering SliTeX mode runs the hook `text-mode-hook', then the hook
1201 `tex-mode-hook', then the hook `latex-mode-hook', and finally the hook
1202 `slitex-mode-hook'. When the special subshell is initiated, the hook
1203 `tex-shell-hook' is run."
1204 (setq tex-command slitex-run-command
)
1205 (setq tex-start-of-header
"\\\\documentstyle{slides}\\|\\\\documentclass{slides}"))
1207 (defvar tildify-space-string
)
1208 (defvar tildify-foreach-region-function
)
1209 (declare-function tildify-foreach-ignore-environments
1210 "tildify" (pairs callback _beg end
))
1211 (defvar tex--prettify-symbols-alist
)
1213 (defun tex-common-initialization ()
1214 ;; Regexp isearch should accept newline and formfeed as whitespace.
1215 (setq-local search-whitespace-regexp
"[ \t\r\n\f]+")
1216 ;; Use tilde as hard-space character in tildify package.
1217 (setq-local tildify-space-string
"~")
1218 ;; FIXME: Use the fact that we're parsing the document already
1219 ;; rather than using regex-based filtering.
1220 (setq-local tildify-foreach-region-function
1222 #'tildify-foreach-ignore-environments
1223 `(("\\\\\\\\" .
"") ; do not remove this
1224 (,(eval-when-compile
1225 (concat "\\\\begin{\\("
1226 (regexp-opt '("verbatim" "math" "displaymath"
1227 "equation" "eqnarray" "eqnarray*"))
1229 .
("\\\\end{" 1 "}"))
1230 ("\\\\verb\\*?\\(.\\)" .
(1))
1233 ("\\\\[[]" .
"\\\\[]]")
1234 ("\\\\[a-zA-Z]+\\( +\\|{}\\)[a-zA-Z]*" .
"")
1236 ;; A line containing just $$ is treated as a paragraph separator.
1237 (setq-local paragraph-start
"[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$")
1238 ;; A line starting with $$ starts a paragraph,
1239 ;; but does not separate paragraphs if it has more stuff on it.
1240 (setq-local paragraph-separate
"[ \t]*$\\|[\f\\\\%]\\|[ \t]*\\$\\$[ \t]*$")
1241 (setq-local add-log-current-defun-function
#'tex-current-defun-name
)
1242 (setq-local comment-start
"%")
1243 (setq-local comment-add
1)
1244 (setq-local comment-start-skip
1245 "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(%+ *\\)")
1246 (setq-local parse-sexp-ignore-comments t
)
1247 (setq-local compare-windows-whitespace
'tex-categorize-whitespace
)
1248 (setq-local facemenu-add-face-function
'tex-facemenu-add-face-function
)
1249 (setq-local facemenu-end-add-face
"}")
1250 (setq-local facemenu-remove-face-function t
)
1251 (setq-local font-lock-defaults
1252 '((tex-font-lock-keywords tex-font-lock-keywords-1
1253 tex-font-lock-keywords-2 tex-font-lock-keywords-3
)
1255 ;; Who ever uses that anyway ???
1256 (font-lock-mark-block-function . mark-paragraph
)
1257 (font-lock-syntactic-face-function
1258 . tex-font-lock-syntactic-face-function
)
1259 (font-lock-unfontify-region-function
1260 . tex-font-lock-unfontify-region
)))
1261 (setq-local prettify-symbols-alist tex--prettify-symbols-alist
)
1262 (add-function :override
(local 'prettify-symbols-compose-predicate
)
1263 #'tex--prettify-symbols-compose-p
)
1264 (setq-local syntax-propertize-function
1265 (syntax-propertize-rules latex-syntax-propertize-rules
))
1266 ;; TABs in verbatim environments don't do what you think.
1267 (setq-local indent-tabs-mode nil
)
1268 ;; Other vars that should be buffer-local.
1269 (make-local-variable 'tex-command
)
1270 (make-local-variable 'tex-start-of-header
)
1271 (make-local-variable 'tex-end-of-header
)
1272 (make-local-variable 'tex-trailer
))
1274 (defun tex-categorize-whitespace (backward-limit)
1275 ;; compare-windows-whitespace is set to this.
1276 ;; This is basically a finite-state machine.
1277 ;; Returns a symbol telling how TeX would treat
1278 ;; the whitespace we are looking at: null, space, or par.
1279 (let ((category 'null
)
1281 (skip-chars-backward " \t\n\f" backward-limit
)
1283 (cond ((looking-at "[ \t]+")
1284 (goto-char (match-end 0))
1285 (if (eq category
'null
)
1286 (setq category
'space
)))
1288 (cond ((eq category
'newline
)
1289 (setq category
'par
)
1290 (setq not-finished nil
))
1292 (setq category
'newline
) ;a strictly internal state
1293 (goto-char (match-end 0)))))
1295 (setq category
'par
)
1296 (setq not-finished nil
))
1298 (setq not-finished nil
))))
1299 (skip-chars-forward " \t\n\f")
1300 (if (eq category
'newline
)
1301 'space
;TeX doesn't distinguish
1304 (defun tex-insert-quote (arg)
1305 "Insert the appropriate quote marks for TeX.
1306 Inserts the value of `tex-open-quote' (normally \\=`\\=`) or `tex-close-quote'
1307 \(normally \\='\\=') depending on the context. With prefix argument, always
1308 inserts \" characters."
1310 ;; Discover if we'll be inserting normal double quotes.
1312 (if (or arg
(memq (char-syntax (preceding-char)) '(?
/ ?
\\))
1313 (eq (get-text-property (point) 'face
) 'tex-verbatim
)
1314 (nth 4 (syntax-ppss)) ; non-nil if point is in a TeX comment
1315 ;; Discover if a preceding occurrence of `tex-open-quote'
1316 ;; should be morphed to a normal double quote.
1318 (and (>= (point) (+ (point-min) (length tex-open-quote
)))
1320 (backward-char (length tex-open-quote
))
1321 (when (or (looking-at (regexp-quote tex-open-quote
))
1322 (looking-at (regexp-quote tex-close-quote
)))
1323 (delete-char (length tex-open-quote
))
1324 (when (looking-at (regexp-quote tex-close-quote
))
1325 (delete-char (length tex-close-quote
)))
1327 ;; Insert the normal quote (eventually letting
1328 ;; `electric-pair-mode' do its thing).
1330 (self-insert-command (prefix-numeric-value arg
))
1331 ;; We'll be inserting fancy TeX quotes, but consider and imitate
1332 ;; `electric-pair-mode''s two behaviors: pair-insertion and
1335 (if (and electric-pair-mode
(use-region-p))
1336 (let* ((saved (point-marker)))
1338 (insert (if (> saved
(mark)) tex-open-quote tex-close-quote
))
1340 (insert (if (> saved
(mark)) tex-close-quote tex-open-quote
)))
1341 (if (or (memq (char-syntax (preceding-char)) '(?\
( ?
> ?\s
))
1342 (memq (preceding-char) '(?~ ?
')))
1343 ;; We're in an "opening" context
1345 (if electric-pair-mode
1346 (if (looking-at (regexp-quote tex-close-quote
))
1347 (forward-char (length tex-close-quote
))
1348 (insert tex-open-quote
)
1349 (insert tex-close-quote
)
1350 (backward-char (length tex-close-quote
)))
1351 (insert tex-open-quote
))
1352 ;; We're in a "closing" context.
1354 (if (looking-at (regexp-quote tex-close-quote
))
1355 (forward-char (length tex-close-quote
))
1356 (insert tex-close-quote
))))))
1358 (defun tex-validate-buffer ()
1359 "Check current buffer for paragraphs containing mismatched braces or $s.
1360 Their positions are recorded in the buffer `*Occur*'.
1361 To find a particular invalidity from `*Occur*', switch to that buffer
1362 and type C-c C-c or click with mouse-2
1363 on the line for the invalidity you want to see."
1365 (let ((buffer (current-buffer))
1366 (prevpos (point-min))
1369 (with-output-to-temp-buffer "*Occur*"
1370 (princ "Mismatches:\n")
1371 (with-current-buffer standard-output
1373 ;; This won't actually work...Really, this whole thing should
1374 ;; be rewritten instead of being a hack on top of occur.
1375 (setq occur-revert-arguments
(list nil
0 (list buffer
))))
1377 (goto-char (point-max))
1378 ;; Do a little shimmy to place point at the end of the last
1379 ;; "real" paragraph. Need to avoid validating across an \end,
1380 ;; because that blows up latex-forward-sexp.
1381 (backward-paragraph)
1384 ;; Scan the previous paragraph for invalidities.
1385 (backward-paragraph)
1387 (or (tex-validate-region (point) (save-excursion
1390 (let ((end (line-beginning-position 2))
1393 (setq start
(point))
1394 ;; Keep track of line number as we scan,
1395 ;; in a cumulative fashion.
1397 (setq linenum
(- linenum
1398 (count-lines prevpos
(point))))
1399 (setq linenum
(1+ (count-lines 1 start
))))
1400 (setq prevpos
(point))
1401 ;; Mention this mismatch in *Occur*.
1402 ;; Since we scan from end of buffer to beginning,
1403 ;; add each mismatch at the beginning of *Occur*.
1405 (setq tem
(point-marker))
1406 (set-buffer standard-output
)
1407 (goto-char (point-min))
1408 ;; Skip "Mismatches:" header line.
1410 (setq num-matches
(1+ num-matches
))
1411 (insert-buffer-substring buffer start end
)
1412 (let (text-beg (text-end (point-marker)))
1413 (forward-char (- start end
))
1414 (setq text-beg
(point-marker))
1415 (insert (format "%3d: " linenum
))
1416 (add-text-properties
1417 text-beg
(- text-end
1)
1418 '(mouse-face highlight
1420 "mouse-2: go to this invalidity"))
1421 (put-text-property text-beg
(- text-end
1)
1422 'occur-target tem
))))))))
1423 (with-current-buffer standard-output
1424 (let ((no-matches (zerop num-matches
)))
1427 (if (called-interactively-p 'interactive
)
1428 (message (cond (no-matches "No mismatches found")
1429 ((= num-matches
1) "1 mismatch found")
1430 (t "%d mismatches found"))
1433 (defun tex-validate-region (start end
)
1434 "Check for mismatched braces or $'s in region.
1435 Returns t if no mismatches. Returns nil and moves point to suspect
1436 area if a mismatch is found."
1438 (let ((failure-point nil
) (max-possible-sexps (- end start
)))
1442 (narrow-to-region start end
)
1443 ;; First check that the open and close parens balance in numbers.
1445 (while (and (not (eobp))
1446 (<= 0 (setq max-possible-sexps
1447 (1- max-possible-sexps
))))
1449 ;; Now check that like matches like.
1451 (while (re-search-forward "\\s(" nil t
)
1453 (let ((pos (match-beginning 0)))
1455 (skip-chars-backward "\\\\") ; escaped parens
1457 (or (eq (preceding-char) (cdr (syntax-after pos
)))
1458 (eq (char-after pos
) (cdr (syntax-after (1- (point)))))
1459 (error "Mismatched parentheses"))))))
1461 (skip-syntax-forward " .>")
1462 (setq failure-point
(point)))))
1463 (if failure-point
(goto-char failure-point
))
1464 (not failure-point
)))
1466 (defun tex-handle-newline (inhibit-validation)
1467 "Break a TeX paragraph with two newlines, or continue a comment.
1468 If not in a comment, insert two newlines, breaking a paragraph for TeX,
1469 and check for mismatched braces or $s in the paragraph being terminated
1470 unless prefix arg INHIBIT-VALIDATION is non-nil to inhibit the checking.
1471 Otherwise (in a comment), just insert a single continued comment line."
1473 (if (nth 4 (syntax-ppss)) ; non-nil if point is in a TeX comment
1474 (comment-indent-new-line)
1475 (tex-terminate-paragraph inhibit-validation
)))
1477 (defun tex-terminate-paragraph (inhibit-validation)
1478 "Insert two newlines, breaking a paragraph for TeX.
1479 Check for mismatched braces or $s in paragraph being terminated.
1480 A prefix arg inhibits the checking."
1482 (or inhibit-validation
1484 ;; For the purposes of this, a "paragraph" is a block of text
1485 ;; wherein all the brackets etc are expected to be balanced. It
1486 ;; may start after a blank line (ie a "proper" paragraph), or
1487 ;; a begin{} or end{} block, etc.
1488 (tex-validate-region
1490 (backward-paragraph)
1493 (message "Paragraph being closed appears to contain a mismatch"))
1496 (define-skeleton tex-insert-braces
1497 "Make a pair of braces and be poised to type inside of them."
1501 ;; This function is used as the value of fill-nobreak-predicate
1502 ;; in LaTeX mode. Its job is to prevent line-breaking inside
1503 ;; of a \verb construct.
1504 (defun latex-fill-nobreak-predicate ()
1506 (skip-chars-backward " ")
1507 ;; Don't break after \ since `\ ' has special meaning.
1508 (or (and (not (bobp)) (memq (char-syntax (char-before)) '(?
\\ ?
/)))
1509 (let ((opoint (point))
1512 (while (re-search-forward "\\\\verb\\(.\\)" opoint t
)
1513 (unless (re-search-forward (regexp-quote (match-string 1)) opoint t
)
1517 (defvar latex-block-default
"enumerate")
1519 (defvar latex-block-args-alist
1520 '(("array" nil ?\
{ (skeleton-read "Format: ") ?\
})
1521 ("tabular" nil ?\
{ (skeleton-read "Format: ") ?\
})
1522 ("minipage" nil ?\
{ (skeleton-read "Size: ") ?\
})
1523 ("picture" nil ?\
( (skeleton-read "SizeX,SizeY: ") ?\
))
1524 ;; FIXME: This is right for Prosper, but not for seminar.
1525 ;; ("slide" nil ?\{ (skeleton-read "Title: ") ?\})
1527 "Skeleton element to use for arguments to particular environments.
1528 Every element of the list has the form (NAME . SKEL-ELEM) where NAME is
1529 the name of the environment and SKEL-ELEM is an element to use in
1530 a skeleton (see `skeleton-insert').")
1532 (defvar latex-block-body-alist
1533 '(("enumerate" nil
'(latex-insert-item) > _
)
1534 ("itemize" nil
'(latex-insert-item) > _
)
1535 ("table" nil
"\\caption{" > (skeleton-read "Caption: ") "}" > \n
1536 '(if (and (boundp 'reftex-mode
) reftex-mode
) (reftex-label "table"))
1538 ("figure" nil
> _
\n "\\caption{" > (skeleton-read "Caption: ") "}" > \n
1539 '(if (and (boundp 'reftex-mode
) reftex-mode
) (reftex-label "table"))))
1540 "Skeleton element to use for the body of particular environments.
1541 Every element of the list has the form (NAME . SKEL-ELEM) where NAME is
1542 the name of the environment and SKEL-ELEM is an element to use in
1543 a skeleton (see `skeleton-insert').")
1545 ;; Like tex-insert-braces, but for LaTeX.
1546 (defalias 'tex-latex-block
'latex-insert-block
)
1547 (define-skeleton latex-insert-block
1548 "Create a matching pair of lines \\begin{NAME} and \\end{NAME} at point.
1549 Puts point on a blank line between them."
1550 (let ((choice (completing-read (format "LaTeX block name [%s]: "
1551 latex-block-default
)
1552 (latex-complete-envnames)
1553 nil nil nil nil latex-block-default
)))
1554 (setq latex-block-default choice
)
1555 (unless (or (member choice latex-standard-block-names
)
1556 (member choice latex-block-names
))
1557 ;; Remember new block names for later completion.
1558 (push choice latex-block-names
))
1560 \n "\\begin{" str
"}"
1561 (cdr (assoc str latex-block-args-alist
))
1562 > \n (or (cdr (assoc str latex-block-body-alist
)) '(nil > _
))
1564 "\\end{" str
"}" > \n)
1566 (define-skeleton latex-insert-item
1567 "Insert an \\item macro."
1572 ;;;; LaTeX completion.
1574 (defvar latex-complete-bibtex-cache nil
)
1576 (define-obsolete-function-alias 'latex-string-prefix-p
1577 'string-prefix-p
"24.3")
1579 (defvar bibtex-reference-key
)
1580 (declare-function reftex-get-bibfile-list
"reftex-cite.el" ())
1582 (defun latex-complete-bibtex-keys ()
1583 (when (bound-and-true-p reftex-mode
)
1584 (lambda (key pred action
)
1585 (let ((re (concat "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n]*\\([{(][ \t\n]*\\)"
1586 (regexp-quote key
)))
1587 (files (reftex-get-bibfile-list))
1589 (if (and (eq (car latex-complete-bibtex-cache
)
1590 (reftex-get-bibfile-list))
1591 (string-prefix-p (nth 1 latex-complete-bibtex-cache
)
1594 (setq keys
(nth 2 latex-complete-bibtex-cache
))
1595 (dolist (file files
)
1596 (with-current-buffer (find-file-noselect file
)
1597 (goto-char (point-min))
1598 (while (re-search-forward re nil t
)
1599 (goto-char (match-end 2))
1600 (when (and (not (member-ignore-case (match-string 1)
1601 '("c" "comment" "string")))
1602 (looking-at bibtex-reference-key
))
1603 (push (match-string-no-properties 0) keys
)))))
1605 (setq-local latex-complete-bibtex-cache
(list files key keys
)))
1606 (complete-with-action action keys key pred
)))))
1608 (defun latex-complete-envnames ()
1609 (completion-table-in-turn
1610 (append latex-block-names latex-standard-block-names
)
1611 (completion-table-dynamic
1613 (with-current-buffer (if (and (minibufferp) (minibuffer-selected-window))
1614 (window-buffer (minibuffer-selected-window))
1619 (goto-char (point-min))
1620 (while (re-search-forward (concat "\\\\begin{\\(" str
"[^}\n ]*\\)")
1622 (unless (and (<= (match-beginning 0) pos
)
1623 (>= (match-end 0) pos
))
1624 (push (match-string 1) comps
)))
1627 (defun latex-complete-refkeys ()
1628 (when (boundp 'reftex-docstruct-symbol
)
1629 (symbol-value reftex-docstruct-symbol
)))
1631 (defvar latex-complete-alist
1632 `(("\\`\\\\\\(short\\)?cite\\'" .
,#'latex-complete-bibtex-keys
)
1633 ("\\`\\\\\\(begin\\|end\\)\\'" .
,#'latex-complete-envnames
)
1634 ("\\`\\\\[vf]?ref\\'" .
,#'latex-complete-refkeys
)))
1636 (defun latex-complete-data ()
1637 "Get completion-data at point."
1640 (skip-chars-backward "^ {}\n\t\\\\")
1641 (pcase (char-before)
1642 ((or `nil ?\s ?
\n ?
\t ?\
}) nil
)
1644 ;; TODO: Complete commands.
1647 ;; Complete args to commands.
1651 (skip-chars-backward " \n")
1652 (buffer-substring (point)
1654 (skip-chars-backward "a-zA-Z@*")
1655 (let ((n (skip-chars-backward "\\\\")))
1656 (forward-char (* 2 (/ n
2))))
1659 (_ (progn (goto-char pt
) (skip-chars-backward "^," start
)))
1661 (_ (progn (goto-char pt
) (skip-chars-forward "^, {}\n\t\\\\")))
1665 (let ((f (lambda () t
)))
1666 (dolist (comp latex-complete-alist
)
1667 (if (string-match (car comp
) cmd
)
1668 (setq f
(cdr comp
))))
1673 (list comp-beg comp-end table
))))))))
1676 ;;;; LaTeX syntax navigation
1679 (defmacro tex-search-noncomment
(&rest body
)
1680 "Execute BODY as long as it return non-nil and point is in a comment.
1681 Return the value returned by the last execution of BODY."
1683 (let ((res-sym (make-symbol "result")))
1686 (and (setq ,res-sym
(progn ,@body
))
1687 (save-excursion (skip-chars-backward "^\n%") (not (bolp)))))
1690 (defun tex-last-unended-begin ()
1691 "Leave point at the beginning of the last `\\begin{...}' that is unended."
1693 (while (and (tex-search-noncomment
1694 (re-search-backward "\\\\\\(begin\\|end\\)\\s *{"))
1695 (looking-at "\\\\end"))
1696 (tex-last-unended-begin))
1697 (search-failed (error "Couldn't find unended \\begin"))))
1699 (defun tex-next-unmatched-end ()
1700 "Leave point at the end of the next `\\end' that is unmatched."
1701 (while (and (tex-search-noncomment
1702 (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}"))
1703 (save-excursion (goto-char (match-beginning 0))
1704 (looking-at "\\\\begin")))
1705 (tex-next-unmatched-end)))
1707 (defun tex-next-unmatched-eparen (otype)
1708 "Leave point after the next unmatched escaped closing parenthesis.
1709 The string OTYPE is an opening parenthesis type: `(', `{', or `['."
1711 (let ((ctype (char-to-string (cdr (aref (syntax-table)
1712 (string-to-char otype
))))))
1713 (while (and (tex-search-noncomment
1714 (re-search-forward (format "\\\\[%s%s]" ctype otype
)))
1716 (goto-char (match-beginning 0))
1717 (looking-at (format "\\\\%s" (regexp-quote otype
)))))
1718 (tex-next-unmatched-eparen otype
)))
1719 (wrong-type-argument (error "Unknown opening parenthesis type: %s" otype
))
1720 (search-failed (error "Couldn't find closing escaped paren"))))
1722 (defun tex-last-unended-eparen (ctype)
1723 "Leave point at the start of the last unended escaped opening parenthesis.
1724 The string CTYPE is a closing parenthesis type: `)', `}', or `]'."
1726 (let ((otype (char-to-string (cdr (aref (syntax-table)
1727 (string-to-char ctype
))))))
1728 (while (and (tex-search-noncomment
1729 (re-search-backward (format "\\\\[%s%s]" ctype otype
)))
1730 (looking-at (format "\\\\%s" (regexp-quote ctype
))))
1731 (tex-last-unended-eparen ctype
)))
1732 (wrong-type-argument (error "Unknown opening parenthesis type: %s" ctype
))
1733 (search-failed (error "Couldn't find unended escaped paren"))))
1735 (defun tex-goto-last-unclosed-latex-block ()
1736 "Move point to the last unclosed \\begin{...}.
1737 Mark is left at original location."
1741 (tex-last-unended-begin)
1742 (setq spot
(point)))
1746 (defvar latex-handle-escaped-parens t
)
1748 ;; Don't think this one actually _needs_ (for the purposes of
1749 ;; tex-mode) to handle escaped parens.
1750 ;; Does not handle escaped parens when latex-handle-escaped-parens is nil.
1751 (defun latex-backward-sexp-1 ()
1752 "Like (backward-sexp 1) but aware of multi-char elements and escaped parens."
1754 (forward-sexp-function))
1757 (if latex-handle-escaped-parens
1758 "\\\\\\(begin\\>\\|[[({]\\)"
1761 (list "Containing expression ends prematurely"
1762 (point) (prog1 (point) (goto-char pos
)))))
1763 ((and latex-handle-escaped-parens
1764 (looking-at "\\\\\\([])}]\\)"))
1765 (tex-last-unended-eparen (match-string 1)))
1766 ((eq (char-after) ?
{)
1767 (let ((newpos (point)))
1768 (when (ignore-errors (backward-sexp 1) t
)
1769 (if (or (looking-at "\\\\end\\>")
1770 ;; In case the \\ ends a verbatim section.
1771 (and (looking-at "end\\>") (eq (char-before) ?
\\)))
1772 (tex-last-unended-begin)
1773 (goto-char newpos
))))))))
1775 ;; Note this does not handle things like mismatched brackets inside
1776 ;; begin/end blocks.
1777 ;; Needs to handle escaped parens for tex-validate-*.
1778 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00038.html
1779 ;; Does not handle escaped parens when latex-handle-escaped-parens is nil.
1780 (defun latex-forward-sexp-1 ()
1781 "Like (forward-sexp 1) but aware of multi-char elements and escaped parens."
1783 (forward-sexp-function))
1785 (let ((newpos (point)))
1786 (skip-syntax-backward "/w")
1788 ((looking-at "\\\\end\\>")
1790 (list "Containing expression ends prematurely"
1793 (progn (ignore-errors (forward-sexp 2)) (point))
1795 ((looking-at "\\\\begin\\>")
1796 (goto-char (match-end 0))
1797 (tex-next-unmatched-end))
1798 ;; A better way to handle this, \( .. \) etc, is probably to
1799 ;; temporarily change the syntax of the \ in \( to punctuation.
1800 ((and latex-handle-escaped-parens
1801 (looking-back "\\\\[])}]" (- (point) 2)))
1803 (list "Containing expression ends prematurely"
1804 (- (point) 2) (prog1 (point)
1806 ((and latex-handle-escaped-parens
1807 (looking-back "\\\\\\([({[]\\)" (- (point) 2)))
1808 (tex-next-unmatched-eparen (match-string 1)))
1809 (t (goto-char newpos
))))))
1811 (defun latex-forward-sexp (&optional arg
)
1812 "Like `forward-sexp' but aware of multi-char elements and escaped parens."
1814 (unless arg
(setq arg
1))
1818 (while (and (/= (point) opoint
)
1820 (setq opoint
(point))
1823 (progn (latex-forward-sexp-1) (1- arg
))
1824 (progn (latex-backward-sexp-1) (1+ arg
)))))
1827 (signal (car err
) (cdr err
))))))
1829 (defun latex-syntax-after ()
1830 "Like (char-syntax (char-after)) but aware of multi-char elements."
1831 (if (looking-at "\\\\end\\>") ?\
) (char-syntax (following-char))))
1833 (defun latex-skip-close-parens ()
1834 "Like (skip-syntax-forward \" )\") but aware of multi-char elements."
1835 (let ((forward-sexp-function nil
))
1836 (while (progn (skip-syntax-forward " )")
1837 (looking-at "\\\\end\\>"))
1840 (defun latex-down-list ()
1841 "Like (down-list 1) but aware of multi-char elements."
1842 (forward-comment (point-max))
1843 (let ((forward-sexp-function nil
))
1844 (if (not (looking-at "\\\\begin\\>"))
1848 (while (looking-at "[ \t]*[[{(]")
1849 (with-syntax-table tex-mode-syntax-table
1852 (defalias 'tex-close-latex-block
'latex-close-block
)
1853 (define-skeleton latex-close-block
1854 "Create an \\end{...} to match the last unclosed \\begin{...}."
1856 (tex-last-unended-begin)
1857 (if (not (looking-at "\\\\begin\\(\\s *{[^}\n]*}\\)")) '("{" _
"}")
1859 \n "\\end" str
> \n)
1861 (define-skeleton latex-split-block
1862 "Split the enclosing environment by inserting \\end{..}\\begin{..} at point."
1864 (tex-last-unended-begin)
1865 (if (not (looking-at "\\\\begin\\(\\s *{[^}\n]*}\\)")) '("{" _
"}")
1866 (prog1 (match-string 1)
1867 (goto-char (match-end 1))
1868 (setq v1
(buffer-substring (point)
1870 (while (looking-at "[ \t]*[[{]")
1873 \n "\\end" str
> \n _
\n "\\begin" str v1
> \n)
1875 (defconst tex-discount-args-cmds
1876 '("begin" "end" "input" "special" "cite" "ref" "include" "includeonly"
1877 "documentclass" "usepackage" "label")
1878 "TeX commands whose arguments should not be counted as text.")
1880 (defun tex-count-words (begin end
)
1881 "Count the number of words in the buffer."
1883 (if (and transient-mark-mode mark-active
)
1884 (list (region-beginning) (region-end))
1885 (list (point-min) (point-max))))
1886 ;; TODO: skip comments and math and maybe some environments.
1890 (while (and (< (point) end
) (re-search-forward "\\<" end t
))
1891 (if (not (eq (char-syntax (preceding-char)) ?
/))
1893 ;; Don't count single-char words.
1894 (unless (looking-at ".\\>") (cl-incf count
))
1897 (buffer-substring-no-properties
1898 (point) (progn (when (zerop (skip-chars-forward "a-zA-Z@"))
1901 (when (member cmd tex-discount-args-cmds
)
1902 (skip-chars-forward "*")
1903 (forward-comment (point-max))
1904 (when (looking-at "\\[")
1906 (forward-comment (point-max)))
1907 (if (not (looking-at "{"))
1909 (forward-sexp 1))))))
1910 (message "%s words" count
))))
1914 ;;; Invoking TeX in an inferior shell.
1916 ;; Why use a shell instead of running TeX directly? Because if TeX
1917 ;; gets stuck, the user can switch to the shell window and type at it.
1919 (defvar tex-error-parse-syntax-table
1920 (let ((st (make-syntax-table)))
1921 (modify-syntax-entry ?\
( "()" st
)
1922 (modify-syntax-entry ?\
) ")(" st
)
1923 (modify-syntax-entry ?
\\ "\\" st
)
1924 (modify-syntax-entry ?\
{ "_" st
)
1925 (modify-syntax-entry ?\
} "_" st
)
1926 (modify-syntax-entry ?\
[ "_" st
)
1927 (modify-syntax-entry ?\
] "_" st
)
1928 ;; Single quotations may appear in errors
1929 (modify-syntax-entry ?
\" "_" st
)
1931 "Syntax-table used while parsing TeX error messages.")
1933 (defun tex-old-error-file-name ()
1934 ;; This is unreliable, partly because we don't try very hard, and
1935 ;; partly because TeX's output format is eminently ambiguous and unfriendly
1939 (with-syntax-table tex-error-parse-syntax-table
1941 (backward-up-list 1)
1942 (skip-syntax-forward "(_")
1943 (while (not (let ((try-filename (thing-at-point 'filename
)))
1945 (not (string= "" try-filename
))
1946 (file-readable-p try-filename
))))
1947 (skip-syntax-backward "(_")
1948 (backward-up-list 1)
1949 (skip-syntax-forward "(_"))
1950 (thing-at-point 'filename
)))))
1952 (defconst tex-error-regexp-alist
1953 ;; First alternative handles the newer --file-line-error style:
1954 ;; ./test2.tex:14: Too many }'s.
1956 ;; Second handles the old-style, which spans two lines but doesn't include
1960 ("^l\\.\\([1-9][0-9]*\\) \\(?:\\.\\.\\.\\)?\\(.*\\)$"
1961 tex-old-error-file-name
1 nil nil nil
1962 ;; Since there's no filename to highlight, let's highlight the message.
1963 (2 compilation-error-face
))
1964 ;; A few common warning messages.
1965 ("^\\(?:Und\\|Ov\\)erfull \\\\[hv]box .* at lines? \\(\\([1-9][0-9]*\\)\\(?:--\\([1-9][0-9]*\\)\\)?\\)$"
1966 tex-old-error-file-name
(2 .
3) nil
1 nil
1967 (1 compilation-warning-face
))
1968 ("^(Font) *\\([^ \n].* on input line \\([1-9][0-9]*\\)\\)\\.$"
1969 tex-old-error-file-name
2 nil
1 1
1970 (2 compilation-warning-face
))
1971 ;; Included files get output as (<file> ...).
1972 ;; FIXME: there tend to be a boatload of them at the beginning of the
1973 ;; output which aren't that interesting. Maybe we should filter out
1974 ;; all the file name that start with /usr/share?
1975 ;; ("(\\.?/\\([^() \n]+\\)" 1 nil nil 0)
1978 ;; The utility functions:
1980 (define-derived-mode tex-shell shell-mode
"TeX-Shell"
1981 (setq-local compilation-error-regexp-alist tex-error-regexp-alist
)
1982 (compilation-shell-minor-mode t
))
1985 (defun tex-start-shell ()
1986 (with-current-buffer
1989 (or tex-shell-file-name
(getenv "ESHELL") shell-file-name
)
1991 ;; Specify an interactive shell, to make sure it prompts.
1993 (let ((proc (get-process "tex-shell")))
1994 (set-process-sentinel proc
'tex-shell-sentinel
)
1995 (set-process-query-on-exit-flag proc nil
)
1997 (while (zerop (buffer-size))
2000 (defun tex-feed-input ()
2001 "Send input to the tex shell process.
2002 In the tex buffer this can be used to continue an interactive tex run.
2003 In the tex shell buffer this command behaves like `comint-send-input'."
2005 (set-buffer (tex-shell-buf))
2007 (tex-recenter-output-buffer nil
))
2009 (defun tex-display-shell ()
2010 "Make the TeX shell buffer visible in a window."
2011 (display-buffer (tex-shell-buf))
2012 (tex-recenter-output-buffer nil
))
2014 (defun tex-shell-sentinel (proc _msg
)
2015 (cond ((null (buffer-name (process-buffer proc
)))
2017 (set-process-buffer proc nil
)
2018 (tex-delete-last-temp-files))
2019 ((memq (process-status proc
) '(signal exit
))
2020 (tex-delete-last-temp-files))))
2022 (defun tex-set-buffer-directory (buffer directory
)
2023 "Set BUFFER's default directory to be DIRECTORY."
2024 (setq directory
(file-name-as-directory (expand-file-name directory
)))
2025 (if (not (file-directory-p directory
))
2026 (error "%s is not a directory" directory
)
2027 (with-current-buffer buffer
2028 (setq default-directory directory
))))
2030 (defvar tex-send-command-modified-tick
0)
2031 (make-variable-buffer-local 'tex-send-command-modified-tick
)
2033 (defun tex-shell-proc ()
2034 (or (tex-shell-running) (error "No TeX subprocess")))
2035 (defun tex-shell-buf ()
2036 (process-buffer (tex-shell-proc)))
2037 (defun tex-shell-buf-no-error ()
2038 (let ((proc (tex-shell-running)))
2039 (and proc
(process-buffer proc
))))
2041 (defun tex-send-command (command &optional file background
)
2042 "Send COMMAND to TeX shell process, substituting optional FILE for *.
2043 Do this in background if optional BACKGROUND is t. If COMMAND has no *,
2044 FILE will be appended, preceded by a blank, to COMMAND. If FILE is nil, no
2045 substitution will be made in COMMAND. COMMAND can be any expression that
2046 evaluates to a command string.
2048 Return the process in which TeX is running."
2050 (let* ((cmd (eval command
))
2051 (proc (tex-shell-proc))
2052 (buf (process-buffer proc
))
2053 (star (string-match "\\*" cmd
))
2058 (if (file-name-absolute-p file
)
2059 (setq file
(convert-standard-filename file
)))
2060 (if star
(concat (substring cmd
0 star
)
2061 (shell-quote-argument file
)
2062 (substring cmd
(1+ star
)))
2063 (concat cmd
" " (shell-quote-argument file
))))
2064 (if background
"&" ""))))
2065 ;; Switch to buffer before checking for subproc output in it.
2067 ;; If text is unchanged since previous tex-send-command,
2068 ;; we haven't got any output. So wait for output now.
2069 (if (= (buffer-modified-tick buf
) tex-send-command-modified-tick
)
2070 (accept-process-output proc
))
2071 (goto-char (process-mark proc
))
2074 (setq tex-send-command-modified-tick
(buffer-modified-tick buf
))
2077 (defun tex-delete-last-temp-files (&optional not-all
)
2078 "Delete any junk files from last temp file.
2079 If NOT-ALL is non-nil, save the `.dvi' file."
2080 (if tex-last-temp-file
2081 (let* ((dir (file-name-directory tex-last-temp-file
))
2082 (list (and (file-directory-p dir
)
2083 (file-name-all-completions
2084 (file-name-base tex-last-temp-file
)
2089 ;; If arg is non-nil, don't delete the .dvi file.
2090 (not (string-match "\\.dvi$" (car list
)))
2091 (delete-file (concat dir
(car list
))))
2092 (delete-file (concat dir
(car list
))))
2093 (setq list
(cdr list
))))))
2095 (add-hook 'kill-emacs-hook
'tex-delete-last-temp-files
)
2098 ;; Machinery to guess the command that the user wants to execute.
2101 (defvar tex-compile-history nil
)
2103 (defvar tex-input-files-re
2105 (concat "\\." (regexp-opt '("tex" "texi" "texinfo"
2106 "bbl" "ind" "sty" "cls") t
)
2107 ;; Include files with no dots (for directories).
2108 "\\'\\|\\`[^.]+\\'")))
2110 (defcustom tex-use-reftex t
2111 "If non-nil, use RefTeX's list of files to determine what command to use."
2115 (defvar tex-compile-commands
2116 `(,@(mapcar (lambda (prefix)
2117 `((concat ,prefix tex-command
2118 " " (if (< 0 (length tex-start-commands
))
2119 (shell-quote-argument tex-start-commands
))
2122 '("pdf" "xe" "lua"))
2123 ((concat tex-command
2124 " " (if (< 0 (length tex-start-commands
))
2125 (shell-quote-argument tex-start-commands
))
2128 ("xdvi %r &" "%r.dvi")
2129 ("\\doc-view \"%r.pdf\"" "%r.pdf")
2130 ("xpdf %r.pdf &" "%r.pdf")
2131 ("gv %r.ps &" "%r.ps")
2132 ("yap %r &" "%r.dvi")
2133 ("advi %r &" "%r.dvi")
2134 ("gv %r.pdf &" "%r.pdf")
2135 ("bibtex %r" "%r.aux" "%r.bbl")
2136 ("makeindex %r" "%r.idx" "%r.ind")
2138 ("dvipdfm %r" "%r.dvi" "%r.pdf")
2139 ("dvipdf %r" "%r.dvi" "%r.pdf")
2140 ("dvips -o %r.ps %r" "%r.dvi" "%r.ps")
2141 ("ps2pdf %r.ps" "%r.ps" "%r.pdf")
2142 ("lpr %r.ps" "%r.ps"))
2143 "List of commands for `tex-compile'.
2144 Each element should be of the form (FORMAT IN OUT) where
2145 FORMAT is an expression that evaluates to a string that can contain
2146 - `%r' the main file name without extension.
2147 - `%f' the main file name.
2148 IN can be either a string (with the same % escapes in it) indicating
2149 the name of the input file, or t to indicate that the input is all
2150 the TeX files of the document, or nil if we don't know.
2151 OUT describes the output file and is either a %-escaped string
2152 or nil to indicate that there is no output file.")
2154 (define-obsolete-function-alias 'tex-string-prefix-p
'string-prefix-p
"24.3")
2156 (defun tex-guess-main-file (&optional all
)
2157 "Find a likely `tex-main-file'.
2158 Looks for hints in other buffers in the same directory or in
2159 ALL other buffers. If ALL is `sub' only look at buffers in parent directories
2160 of the current buffer."
2161 (let ((dir default-directory
)
2162 (header-re tex-start-of-header
))
2164 ;; Look for a buffer with `tex-main-file' set.
2165 (dolist (buf (if (consp all
) all
(buffer-list)))
2166 (with-current-buffer buf
2168 ((null all
) (equal dir default-directory
))
2169 ((eq all
'sub
) (string-prefix-p default-directory dir
))
2171 (stringp tex-main-file
))
2172 (throw 'found
(expand-file-name tex-main-file
)))))
2173 ;; Look for a buffer containing the magic `tex-start-of-header'.
2174 (dolist (buf (if (consp all
) all
(buffer-list)))
2175 (with-current-buffer buf
2177 ((null all
) (equal dir default-directory
))
2178 ((eq all
'sub
) (string-prefix-p default-directory dir
))
2181 ;; (or (easy-mmode-derived-mode-p 'latex-mode)
2182 ;; (easy-mmode-derived-mode-p 'plain-tex-mode))
2186 (goto-char (point-min))
2188 header-re
(+ (point) 10000) t
))))
2189 (throw 'found
(expand-file-name buffer-file-name
))))))))
2191 (defun tex-main-file ()
2192 "Return the relative name of the main file."
2193 (let* ((file (or tex-main-file
2194 ;; Compatibility with AUCTeX.
2196 (when (boundp 'TeX-master
)
2197 (cond ((stringp TeX-master
)
2198 (setq-local tex-main-file TeX-master
))
2199 ((and (eq TeX-master t
) buffer-file-name
)
2200 (file-relative-name buffer-file-name
)))))
2201 ;; Try to guess the main file.
2202 (if (not buffer-file-name
)
2203 (error "Buffer is not associated with any file")
2206 (goto-char (point-min))
2207 (re-search-forward tex-start-of-header
2208 (+ (point) 10000) t
))
2209 ;; This is the main file.
2211 ;; This isn't the main file, let's try to find better,
2212 (or (tex-guess-main-file)
2213 (tex-guess-main-file 'sub
)
2214 ;; (tex-guess-main-file t)
2215 buffer-file-name
)))))))
2216 (if (or (file-exists-p file
) (string-match "\\.tex\\'" file
))
2217 file
(concat file
".tex"))))
2219 (defun tex-summarize-command (cmd)
2220 (if (not (stringp cmd
)) ""
2221 (mapconcat #'identity
2222 (mapcar (lambda (s) (car (split-string s
)))
2223 (split-string cmd
"\\s-*\\(?:;\\|&&\\)\\s-*"))
2226 (defun tex-uptodate-p (file)
2227 "Return non-nil if FILE is not uptodate w.r.t the document source files.
2228 FILE is typically the output DVI or PDF file."
2229 ;; We should check all the files included !!!
2231 ;; Clearly, the target must exist.
2232 (file-exists-p file
)
2233 ;; And the last run must not have asked for a rerun.
2234 ;; FIXME: this should check that the last run was done on the same file.
2235 (let ((buf (condition-case nil
(tex-shell-buf) (error nil
))))
2237 (with-current-buffer buf
2239 (goto-char (point-max))
2240 (and (re-search-backward
2241 (concat "(see the transcript file for additional information)"
2242 "\\|^Output written on .*"
2243 (regexp-quote (file-name-nondirectory file
))
2247 ;; Usually page numbers are output as [N], but
2248 ;; I've already seen things like
2249 ;; [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]
2250 (or (re-search-backward "\\[[0-9]+\\({[^}]*}\\)?\\]"
2254 (or (re-search-backward "Rerun" nil t
)
2256 ;; And the input files must not have been changed in the meantime.
2257 (let ((files (if (and tex-use-reftex
2258 (fboundp 'reftex-scanning-info-available-p
)
2259 (reftex-scanning-info-available-p))
2260 (reftex-all-document-files)
2261 (list (file-name-directory (expand-file-name file
)))))
2265 (delq nil
(mapcar (lambda (s) (if (eq (aref s
(1- (length s
))) ?
/)
2266 (substring s
0 (1- (length s
)))))
2267 completion-ignored-extensions
))
2270 (while (and files uptodate
)
2271 (let ((f (pop files
)))
2272 (if (and (file-directory-p f
)
2273 ;; Avoid infinite loops.
2274 (not (file-symlink-p f
)))
2275 (unless (string-match ignored-dirs-re f
)
2277 (ignore-errors ;Not readable or something.
2278 (directory-files f t tex-input-files-re
))
2280 (when (file-newer-than-file-p f file
)
2281 (setq uptodate nil
)))))
2285 (autoload 'format-spec
"format-spec")
2287 (defvar tex-executable-cache nil
)
2288 (defun tex-executable-exists-p (name)
2289 "Like `executable-find' but with a cache."
2290 (let ((f (and (string-match "^\\\\\\([^ \t\n]+\\)" name
)
2291 (intern-soft (concat "tex-cmd-" (match-string 1 name
))))))
2294 (let ((cache (assoc name tex-executable-cache
)))
2295 (if cache
(cdr cache
)
2296 (let ((executable (executable-find name
)))
2297 (push (cons name executable
) tex-executable-cache
)
2300 (defun tex-command-executable (cmd)
2301 (let ((s (if (stringp cmd
) cmd
(eval (car cmd
)))))
2302 (substring s
0 (string-match "[ \t]\\|\\'" s
))))
2304 (defun tex-command-active-p (cmd fspec
)
2305 "Return non-nil if the CMD spec might need to be run."
2306 (let ((in (nth 1 cmd
))
2309 (let ((file (format-spec in fspec
)))
2310 (when (file-exists-p file
)
2312 (file-newer-than-file-p
2313 file
(format-spec out fspec
)))))
2314 (when (and (eq in t
) (stringp out
))
2315 (not (tex-uptodate-p (format-spec out fspec
)))))))
2317 (defcustom tex-cmd-bibtex-args
"--min-crossref=100"
2318 "Extra args to pass to `bibtex' by default."
2323 (defun tex-format-cmd (format fspec
)
2324 "Like `format-spec' but adds user-specified args to the command.
2325 Only applies the FSPEC to the args part of FORMAT."
2326 (if (not (string-match "\\([^ /\\]+\\) " format
))
2327 (format-spec format fspec
)
2328 (let* ((prefix (substring format
0 (match-beginning 0)))
2329 (cmd (match-string 1 format
))
2330 (args (substring format
(match-end 0)))
2331 (sym (intern-soft (format "tex-cmd-%s-args" cmd
)))
2332 (extra-args (and sym
(symbol-value sym
))))
2334 (if extra-args
(concat " " extra-args
))
2335 " " (format-spec args fspec
)))))
2337 (defun tex-compile-default (fspec)
2338 "Guess a default command given the `format-spec' FSPEC."
2339 ;; TODO: Learn to do latex+dvips!
2342 ;; Only consider active commands.
2343 (dolist (cmd tex-compile-commands
)
2344 (when (tex-executable-exists-p (tex-command-executable cmd
))
2345 (if (tex-command-active-p cmd fspec
)
2347 (push (nth 1 cmd
) unchanged-in
))))
2348 ;; If no command seems to be applicable, arbitrarily pick the first one.
2349 (setq cmds
(if cmds
(nreverse cmds
) (list (car tex-compile-commands
))))
2350 ;; Remove those commands whose input was considered stable for
2351 ;; some other command (typically if (t . "%.pdf") is inactive
2352 ;; then we're using pdflatex and the fact that the dvi file
2353 ;; is nonexistent doesn't matter).
2356 (unless (member (nth 1 cmd
) unchanged-in
)
2358 ;; Only remove if there's something left.
2359 (if tmp
(setq cmds
(nreverse tmp
))))
2360 ;; Remove commands whose input is not uptodate either.
2361 (let ((outs (delq nil
(mapcar (lambda (x) (nth 2 x
)) cmds
)))
2364 (unless (member (nth 1 cmd
) outs
)
2366 ;; Only remove if there's something left.
2367 (if tmp
(setq cmds
(nreverse tmp
))))
2368 ;; Select which file we're going to operate on (the latest).
2369 (let ((latest (nth 1 (car cmds
))))
2370 (dolist (cmd (prog1 (cdr cmds
) (setq cmds
(list (car cmds
)))))
2371 (if (equal latest
(nth 1 cmd
))
2373 (unless (eq latest t
) ;Can't beat that!
2374 (if (or (not (stringp latest
))
2376 (and (stringp (nth 1 cmd
))
2377 (file-newer-than-file-p
2378 (format-spec (nth 1 cmd
) fspec
)
2379 (format-spec latest fspec
))))
2380 (setq latest
(nth 1 cmd
) cmds
(list cmd
)))))))
2381 ;; Expand the command spec into the actual text.
2382 (dolist (cmd (prog1 cmds
(setq cmds nil
)))
2383 (push (cons (eval (car cmd
)) (cdr cmd
)) cmds
))
2384 ;; Select the favorite command from the history.
2385 (let ((hist tex-compile-history
)
2388 (setq hist-cmd
(pop hist
))
2389 (setq re
(concat "\\`"
2390 (regexp-quote (tex-command-executable hist-cmd
))
2391 "\\([ \t]\\|\\'\\)"))
2393 ;; If the hist entry uses the same command and applies to a file
2394 ;; of the same type (e.g. `gv %r.pdf' vs `gv %r.ps'), select cmd.
2395 (and (string-match re
(car cmd
))
2396 (or (not (string-match "%[fr]\\([-._[:alnum:]]+\\)" (car cmd
)))
2397 (string-match (regexp-quote (match-string 1 (car cmd
)))
2399 (setq hist nil cmds
(list cmd
)))))
2400 ;; Substitute and return.
2402 (string-match (concat "[' \t\"]" (format-spec "%r" fspec
)
2403 "\\([;&' \t\"]\\|\\'\\)")
2405 ;; The history command was already applied to the same file,
2406 ;; so just reuse it.
2408 (if cmds
(tex-format-cmd (caar cmds
) fspec
))))))
2410 (defun tex-cmd-doc-view (file)
2411 (pop-to-buffer (find-file-noselect file
)))
2413 (defun tex-compile (dir cmd
)
2414 "Run a command CMD on current TeX buffer's file in DIR."
2415 ;; FIXME: Use time-stamps on files to decide the next op.
2417 (let* ((file (tex-main-file))
2419 (prog1 (file-name-directory (expand-file-name file
))
2420 (setq file
(file-name-nondirectory file
))))
2421 (root (file-name-sans-extension file
))
2422 (fspec (list (cons ?r
(shell-quote-argument root
))
2423 (cons ?f
(shell-quote-argument file
))))
2424 (default (tex-compile-default fspec
)))
2425 (list default-directory
2427 (format "Command [%s]: " (tex-summarize-command default
))
2429 (list (tex-format-cmd (eval (car x
)) fspec
)))
2430 tex-compile-commands
)
2431 nil nil nil
'tex-compile-history default
))))
2432 (save-some-buffers (not compilation-ask-about-save
) nil
)
2433 (let ((f (and (string-match "^\\\\\\([^ \t\n]+\\)" cmd
)
2434 (intern-soft (concat "tex-cmd-" (match-string 1 cmd
))))))
2437 (let ((default-directory dir
))
2438 (apply f
(split-string-and-unquote
2439 (substring cmd
(match-end 0)))))
2440 (wrong-number-of-arguments
2441 (error "Wrong number of arguments to %s"
2442 (substring (symbol-name f
) 8))))
2443 (if (tex-shell-running)
2446 (tex-send-tex-command cmd dir
))))
2448 (defun tex-start-tex (command file
&optional dir
)
2449 "Start a TeX run, using COMMAND on FILE."
2450 (let* ((star (string-match "\\*" command
))
2453 (concat (substring command
0 star
)
2454 (shell-quote-argument file
)
2455 (substring command
(1+ star
)))
2458 (if (< 0 (length tex-start-commands
))
2460 (shell-quote-argument tex-start-commands
) " "))
2461 (shell-quote-argument file
)))))
2462 (tex-send-tex-command compile-command dir
)))
2464 (defun tex-send-tex-command (cmd &optional dir
)
2465 (unless (or (equal dir
(let ((buf (tex-shell-buf-no-error)))
2466 (and buf
(with-current-buffer buf
2467 default-directory
))))
2469 (let (shell-dirtrack-verbose)
2470 (tex-send-command tex-shell-cd-command dir
)))
2471 (with-current-buffer (process-buffer (tex-send-command cmd
))
2472 (setq compilation-last-buffer
(current-buffer))
2473 (compilation-forget-errors)
2474 ;; Don't parse previous compilations.
2475 (set-marker compilation-parsing-end
(1- (point-max))))
2477 (setq tex-last-buffer-texed
(current-buffer)))
2481 (defun tex-region (beg end
)
2482 "Run TeX on the current region, via a temporary file.
2483 The file's name comes from the variable `tex-zap-file' and the
2484 variable `tex-directory' says where to put it.
2486 If the buffer has a header, the header is given to TeX before the
2487 region itself. The buffer's header is all lines between the strings
2488 defined by `tex-start-of-header' and `tex-end-of-header' inclusive.
2489 The header must start in the first 100 lines of the buffer.
2491 The value of `tex-trailer' is given to TeX as input after the region.
2493 The value of `tex-command' specifies the command to use to run TeX."
2495 (if (tex-shell-running)
2499 (setq tex-zap-file
(tex-generate-zap-file-name)))
2500 ;; Temp file will be written and TeX will be run in zap-directory.
2501 ;; If the TEXINPUTS file has relative directories or if the region has
2502 ;; \input of files, this must be the same directory as the file for
2503 ;; TeX to access the correct inputs. That's why it's safest if
2504 ;; tex-directory is ".".
2505 (let* ((zap-directory
2506 (file-name-as-directory (expand-file-name tex-directory
)))
2507 (tex-out-file (expand-file-name (concat tex-zap-file
".tex")
2509 (main-file (expand-file-name (tex-main-file)))
2510 (ismain (string-equal main-file
(buffer-file-name)))
2512 ;; Don't delete temp files if we do the same buffer twice in a row.
2513 (or (eq (current-buffer) tex-last-buffer-texed
)
2514 (tex-delete-last-temp-files t
))
2515 (let ((default-directory zap-directory
)) ; why?
2516 ;; We assume the header is fully contained in tex-main-file.
2517 ;; We use f-f-ns so we get prompted about any changes on disk.
2518 (with-current-buffer (find-file-noselect main-file
)
2519 (setq already-output
(tex-region-header tex-out-file
2521 ;; Write out the specified region (but don't repeat anything
2522 ;; already written in the header).
2523 (write-region (if ismain
2524 (max beg already-output
)
2526 end tex-out-file
(not (zerop already-output
)))
2527 ;; Write the trailer, if any.
2528 ;; Precede it with a newline to make sure it
2529 ;; is not hidden in a comment.
2531 (write-region (concat "\n" tex-trailer
) nil
2533 ;; Record the file name to be deleted afterward.
2534 (setq tex-last-temp-file tex-out-file
)
2535 ;; Use a relative file name here because (1) the proper dir
2536 ;; is already current, and (2) the abs file name is sometimes
2537 ;; too long and can make tex crash.
2538 (tex-start-tex tex-command
(concat tex-zap-file
".tex") zap-directory
)
2539 (setq tex-print-file tex-out-file
)))
2541 (defun tex-region-header (file &optional beg
)
2542 "If there is a TeX header in the current buffer, write it to FILE.
2543 Return point at the end of the region so written, or zero. If
2544 the optional buffer position BEG is specified, then the region
2545 written out starts at BEG, if this lies before the start of the header.
2547 If the first line matches `tex-first-line-header-regexp', it is
2548 also written out. The variables `tex-start-of-header' and
2549 `tex-end-of-header' are used to locate the header. Note that the
2550 start of the header is required to be within the first 100 lines."
2554 (goto-char (point-min))
2555 (let ((search-end (save-excursion
2560 ;; Maybe copy first line, such as `\input texinfo', to temp file.
2561 (and tex-first-line-header-regexp
2562 (looking-at tex-first-line-header-regexp
)
2563 (write-region (point)
2564 (progn (forward-line 1)
2565 (setq already-output
(point)))
2567 ;; Write out the header, if there is one, and any of the
2568 ;; specified region which extends before it. But don't repeat
2569 ;; anything already written.
2570 (and tex-start-of-header
2571 (re-search-forward tex-start-of-header search-end t
)
2574 (setq hbeg
(point)) ; mark beginning of header
2575 (when (re-search-forward tex-end-of-header nil t
)
2577 (setq hend
(point)) ; mark end of header
2583 hend file
(not (zerop already-output
)))
2584 (setq already-output hend
))))
2587 (defun tex-buffer ()
2588 "Run TeX on current buffer. See \\[tex-region] for more information.
2589 Does not save the buffer, so it's useful for trying experimental versions.
2590 See \\[tex-file] for an alternative."
2592 (tex-region (point-min) (point-max)))
2595 "Prompt to save all buffers and run TeX (or LaTeX) on current buffer's file.
2596 This function is more useful than \\[tex-buffer] when you need the
2597 `.aux' file of LaTeX to have the correct name."
2599 (when tex-offer-save
2600 (save-some-buffers))
2601 (let* ((source-file (tex-main-file))
2602 (file-dir (file-name-directory (expand-file-name source-file
))))
2603 (if (tex-shell-running)
2606 (tex-start-tex tex-command source-file file-dir
)
2607 (setq tex-print-file
(expand-file-name source-file
))))
2609 (defun tex-generate-zap-file-name ()
2610 "Generate a unique name suitable for use as a file name."
2611 ;; Include the shell process number and host name
2612 ;; in case there are multiple shells (for same or different user).
2613 ;; Dec 1998: There is a report that some versions of xdvi
2614 ;; don't work with file names that start with #.
2616 (process-id (get-buffer-process "*tex-shell*"))
2617 (subst-char-in-string ?. ?-
(system-name))))
2619 ;; This will perhaps be useful for modifying TEXINPUTS.
2620 ;; Expand each file name, separated by colons, in the string S.
2621 (defun tex-expand-files (s)
2622 (let (elts (start 0))
2623 (while (string-match ":" s start
)
2624 (setq elts
(cons (substring s start
(match-beginning 0)) elts
))
2625 (setq start
(match-end 0)))
2627 (setq elts
(cons (substring s start
) elts
)))
2628 (mapconcat (lambda (elt)
2629 (if (= (length elt
) 0) elt
(expand-file-name elt
)))
2630 (nreverse elts
) ":")))
2632 (defun tex-shell-running ()
2633 (let ((proc (get-process "tex-shell")))
2635 (if (and (eq (process-status proc
) 'run
)
2636 (buffer-live-p (process-buffer proc
)))
2637 ;; return the TeX process on success
2639 ;; get rid of the process permanently
2640 ;; this should get rid of the annoying w32 problem with
2641 ;; dead tex-shell buffer and live process
2642 (delete-process proc
)))))
2644 (defun tex-kill-job ()
2645 "Kill the currently running TeX job."
2647 ;; `quit-process' leads to core dumps of the tex process (except if
2648 ;; coredumpsize has limit 0kb as on many environments). One would
2649 ;; like to use (kill-process proc 'lambda), however that construct
2650 ;; does not work on some systems and kills the shell itself.
2651 (let ((proc (get-process "tex-shell")))
2652 (when proc
(quit-process proc t
))))
2654 (defun tex-recenter-output-buffer (linenum)
2655 "Redisplay buffer of TeX job output so that most recent output can be seen.
2656 The last line of the buffer is displayed on
2657 line LINE of the window, or centered if LINE is nil."
2659 (let ((tex-shell (get-buffer "*tex-shell*"))
2661 (if (null tex-shell
)
2662 (message "No TeX output buffer")
2663 (setq window
(display-buffer tex-shell
))
2664 (with-selected-window window
2665 (bury-buffer tex-shell
)
2666 (goto-char (point-max))
2667 (recenter (if linenum
2668 (prefix-numeric-value linenum
)
2669 (/ (window-height) 2)))))))
2671 (defcustom tex-print-file-extension
".dvi"
2672 "The TeX-compiled file extension for viewing and printing.
2673 If you use pdflatex instead of latex, set this to \".pdf\" and modify
2674 `tex-dvi-view-command' and `tex-dvi-print-command' appropriately."
2679 (defun tex-print (&optional alt
)
2680 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
2681 Runs the shell command defined by `tex-dvi-print-command'. If prefix argument
2682 is provided, use the alternative command, `tex-alt-dvi-print-command'."
2684 (let ((print-file-name-dvi (tex-append tex-print-file
2685 tex-print-file-extension
))
2687 (if (and (not (equal (current-buffer) tex-last-buffer-texed
))
2689 ;; Check that this buffer's printed file is up to date.
2690 (file-newer-than-file-p
2691 (setq test-name
(tex-append (buffer-file-name)
2692 tex-print-file-extension
))
2693 (buffer-file-name)))
2694 (setq print-file-name-dvi test-name
))
2695 (if (not (file-exists-p print-file-name-dvi
))
2696 (error "No appropriate `.dvi' file could be found")
2697 (if (tex-shell-running)
2701 (if alt tex-alt-dvi-print-command tex-dvi-print-command
)
2705 (defun tex-alt-print ()
2706 "Print the .dvi file made by \\[tex-region], \\[tex-buffer] or \\[tex-file].
2707 Runs the shell command defined by `tex-alt-dvi-print-command'."
2712 "Preview the last `.dvi' file made by running TeX under Emacs.
2713 This means, made using \\[tex-region], \\[tex-buffer] or \\[tex-file].
2714 The variable `tex-dvi-view-command' specifies the shell command for preview.
2715 You must set that variable yourself before using this command,
2716 because there is no standard value that would generally work."
2718 (or tex-dvi-view-command
2719 (error "You must set `tex-dvi-view-command'"))
2720 ;; Restart the TeX shell if necessary.
2721 (or (tex-shell-running)
2723 (let ((tex-dvi-print-command (eval tex-dvi-view-command
)))
2726 (defun tex-append (file-name suffix
)
2727 "Append to FILENAME the suffix SUFFIX, using same algorithm TeX uses.
2728 Pascal-based TeX scans for the first period, C TeX uses the last.
2729 No period is retained immediately before SUFFIX,
2730 so normally SUFFIX starts with one."
2731 (if (stringp file-name
)
2732 (let ((file (file-name-nondirectory file-name
))
2734 ;; Try splitting on last period.
2735 ;; The first-period split can get fooled when two files
2736 ;; named a.tex and a.b.tex are both tex'd;
2737 ;; the last-period split must be right if it matches at all.
2739 (concat (file-name-directory file-name
)
2741 (string-match "\\.[^.]*$" file
))
2743 (if (or (file-exists-p trial-name
)
2744 (file-exists-p (concat trial-name
".aux"))) ;for BibTeX files
2746 ;; Not found, so split on first period.
2747 (concat (file-name-directory file-name
)
2749 (string-match "\\." file
))
2753 (defun tex-show-print-queue ()
2754 "Show the print queue that \\[tex-print] put your job on.
2755 Runs the shell command defined by `tex-show-queue-command'."
2757 (if (tex-shell-running)
2760 (tex-send-command tex-show-queue-command
)
2761 (tex-display-shell))
2763 (defun tex-bibtex-file ()
2764 "Run BibTeX on the current buffer's file."
2766 (if (tex-shell-running)
2769 (let* (shell-dirtrack-verbose
2770 (source-file (expand-file-name (tex-main-file)))
2772 (tex-append (file-name-nondirectory source-file
) ""))
2773 (file-dir (file-name-directory source-file
)))
2774 (tex-send-command tex-shell-cd-command file-dir
)
2775 (tex-send-command tex-bibtex-command tex-out-file
))
2776 (tex-display-shell))
2779 ;;;; LaTeX indentation
2782 (defvar tex-indent-allhanging t
)
2783 (defvar tex-indent-arg
4)
2784 (defvar tex-indent-basic
2)
2785 (defvar tex-indent-item tex-indent-basic
)
2786 (defvar tex-indent-item-re
"\\\\\\(bib\\)?item\\>")
2787 (defvar latex-noindent-environments
'("document"))
2788 (put 'latex-noindent-environments
'safe-local-variable
2789 (lambda (x) (null (delq t
(mapcar #'stringp x
)))))
2791 (defvar tex-latex-indent-syntax-table
2792 (let ((st (make-syntax-table tex-mode-syntax-table
)))
2793 (modify-syntax-entry ?$
"." st
)
2794 (modify-syntax-entry ?\
( "." st
)
2795 (modify-syntax-entry ?\
) "." st
)
2797 "Syntax table used while computing indentation.")
2799 (defun latex-indent (&optional _arg
)
2800 (if (and (eq (get-text-property (if (and (eobp) (bolp))
2801 (max (point-min) (1- (point)))
2802 (line-beginning-position))
2806 (with-syntax-table tex-latex-indent-syntax-table
2807 ;; TODO: Rather than ignore $, we should try to be more clever about it.
2811 (latex-find-indent))))
2812 (if (< indent
0) (setq indent
0))
2813 (if (<= (current-column) (current-indentation))
2814 (indent-line-to indent
)
2815 (save-excursion (indent-line-to indent
)))))))
2817 (defcustom latex-indent-within-escaped-parens nil
2818 "Non-nil means add extra indent to text within escaped parens.
2819 When this is non-nil, text within matching pairs of escaped
2820 parens is indented at the column following the open paren. The
2821 default value does not add any extra indent thus providing the
2822 behavior of Emacs 22 and earlier."
2827 (defun latex-find-indent (&optional virtual
)
2828 "Find the proper indentation of text after point.
2829 VIRTUAL if non-nil indicates that we're only trying to find the indentation
2830 in order to determine the indentation of something else.
2831 There might be text before point."
2832 (let ((latex-handle-escaped-parens latex-indent-within-escaped-parens
))
2834 (skip-chars-forward " \t")
2836 ;; Stick the first line at column 0.
2837 (and (= (point-min) (line-beginning-position)) 0)
2838 ;; Trust the current indentation, if such info is applicable.
2839 (and virtual
(save-excursion (skip-chars-backward " \t&") (bolp))
2841 ;; Stick verbatim environments to the left margin.
2842 (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)")
2843 (member (match-string 2) tex-verbatim-environments
)
2845 ;; Put leading close-paren where the matching open paren would be.
2847 (and (or (eq (latex-syntax-after) ?\
))
2848 ;; Try to handle escaped close parens but keep
2849 ;; original position if it doesn't work out.
2850 (and latex-handle-escaped-parens
2851 (setq escaped
(looking-at "\\\\\\([])}]\\)"))))
2855 (goto-char (match-beginning 1)))
2856 (latex-skip-close-parens)
2857 (latex-backward-sexp-1)
2858 (latex-find-indent 'virtual
)))))
2859 ;; Default (maybe an argument)
2861 ;; Outdent \item if necessary.
2862 (indent (if (looking-at tex-indent-item-re
) (- tex-indent-item
) 0))
2864 ;; Find the previous point which determines our current indentation.
2867 (latex-backward-sexp-1)
2868 (while (> (current-column) (current-indentation))
2869 (latex-backward-sexp-1)))
2871 (setq up-list-pos
(nth 2 err
))))
2873 ((= (point-min) pos
) 0) ; We're really just indenting the first line.
2874 ((integerp up-list-pos
)
2875 ;; Have to indent relative to the open-paren.
2876 (goto-char up-list-pos
)
2877 (if (and (not tex-indent-allhanging
)
2879 ;; Make sure we're an argument to a macro and
2880 ;; that the macro is at the beginning of a line.
2883 (while (eq (char-syntax (char-after)) ?\
()
2885 (and (eq (char-syntax (char-after)) ?
/)
2886 (progn (skip-chars-backward " \t&")
2889 (> pos
(progn (latex-down-list)
2890 (forward-comment (point-max))
2892 ;; Align with the first element after the open-paren.
2894 ;; We're the first element after a hanging brace.
2895 (goto-char up-list-pos
)
2896 (+ (if (and (looking-at "\\\\begin *{\\([^\n}]+\\)")
2897 (member (match-string 1)
2898 latex-noindent-environments
))
2900 indent
(latex-find-indent 'virtual
))))
2901 ;; We're now at the "beginning" of a line.
2902 ((not (and (not virtual
) (eq (char-after) ?
\\)))
2903 ;; Nothing particular here: just keep the same indentation.
2904 (+ indent
(current-column)))
2905 ;; We're now looking at a macro call.
2906 ((looking-at tex-indent-item-re
)
2907 ;; Indenting relative to an item, have to re-add the outdenting.
2908 (+ indent
(current-column) tex-indent-item
))
2910 (let ((col (current-column)))
2911 (if (or (not (eq (char-syntax (or (char-after pos
) ?\s
)) ?\
())
2912 ;; Can't be an arg if there's an empty line in between.
2913 (save-excursion (re-search-forward "^[ \t]*$" pos t
)))
2914 ;; If the first char was not an open-paren, there's
2915 ;; a risk that this is really not an argument to the
2919 (if (< (line-end-position)
2920 (save-excursion (forward-comment (point-max))
2922 ;; we're indenting the first argument.
2923 (min (current-column) (+ tex-indent-arg col
))
2924 (skip-syntax-forward " ")
2925 (current-column)))))))))))
2928 (defun doctex-font-lock-^^A
()
2929 (if (eq (char-after (line-beginning-position)) ?\%
)
2932 (1- (match-beginning 1)) (match-beginning 1)
2934 (if (= (1+ (line-beginning-position)) (match-beginning 1))
2935 ;; The `%' is a single-char comment, which Emacs
2936 ;; syntax-table can't deal with. We could turn it
2937 ;; into a non-comment, or use `\n%' or `%^' as the comment.
2938 ;; Instead, we include it in the ^^A comment.
2939 (string-to-syntax "< b")
2940 (string-to-syntax ">")))
2941 (let ((end (line-end-position)))
2942 (if (< end
(point-max))
2946 (string-to-syntax "> b"))))
2947 (string-to-syntax "< b"))))
2949 (defun doctex-font-lock-syntactic-face-function (state)
2950 ;; Mark DocTeX documentation, which is parsed as a style A comment
2951 ;; starting in column 0.
2952 (if (or (nth 3 state
) (nth 7 state
)
2953 (not (memq (char-before (nth 8 state
))
2955 ;; Anything else is just as for LaTeX.
2956 (tex-font-lock-syntactic-face-function state
)
2957 font-lock-doc-face
))
2960 (defconst doctex-syntax-propertize-rules
2961 (syntax-propertize-precompile-rules
2962 latex-syntax-propertize-rules
2963 ;; For DocTeX comment-in-doc.
2964 ("\\(\\^\\)\\^A" (1 (doctex-font-lock-^^A
))))))
2966 (defvar doctex-font-lock-keywords
2967 (append tex-font-lock-keywords
2968 '(("^%<[^>]*>" (0 font-lock-preprocessor-face t
)))))
2971 (define-derived-mode doctex-mode latex-mode
"DocTeX"
2972 "Major mode to edit DocTeX files."
2973 (setq font-lock-defaults
2974 (cons (append (car font-lock-defaults
) '(doctex-font-lock-keywords))
2978 (`font-lock-syntactic-face-function
2979 (cons (car x
) 'doctex-font-lock-syntactic-face-function
))
2981 (cdr font-lock-defaults
))))
2982 (setq-local syntax-propertize-function
2983 (syntax-propertize-rules doctex-syntax-propertize-rules
)))
2985 ;;; Prettify Symbols Support
2987 (defvar tex--prettify-symbols-alist
2988 '( ;; Lowercase Greek letters.
3003 ;; There is no \omicron because it looks like a latin o.
3013 ;; Uppercase Greek letters.
3026 ;; Other math symbols (taken from leim/quail/latin-ltx.el).
3032 ("\\Downarrow" . ?⇓
)
3036 ("\\Leftarrow" . ?⇐
)
3037 ("\\Leftrightarrow" . ?⇔
)
3039 ("\\Lleftarrow" . ?⇚
)
3040 ("\\Longleftarrow" . ?⇐
)
3041 ("\\Longleftrightarrow" . ?⇔
)
3042 ("\\Longrightarrow" . ?⇒
)
3045 ("\\Rightarrow" . ?⇒
)
3046 ("\\Rrightarrow" . ?⇛
)
3051 ("\\Updownarrow" . ?⇕
)
3063 ("\\backepsilon" . ?∍
)
3064 ("\\backprime" . ?‵
)
3066 ("\\backsimeq" . ?⋍
)
3067 ("\\backslash" . ?
\\)
3076 ("\\bigtriangledown" . ?▽
)
3077 ("\\bigtriangleup" . ?△
)
3080 ("\\blacklozenge" . ?✦
)
3081 ("\\blacksquare" . ?▪
)
3082 ("\\blacktriangle" . ?▴
)
3083 ("\\blacktriangledown" . ?▾
)
3084 ("\\blacktriangleleft" . ?◂
)
3085 ("\\blacktriangleright" . ?▸
)
3095 ("\\centerdot" . ?·
)
3096 ("\\checkmark" . ?✓
)
3102 ("\\circlearrowleft" . ?↺
)
3103 ("\\circlearrowright" . ?↻
)
3106 ("\\circledast" . ?⊛
)
3107 ("\\circledcirc" . ?⊚
)
3108 ("\\circleddash" . ?⊝
)
3111 ("\\complement" . ?∁
)
3115 ("\\curlyeqprec" . ?⋞
)
3116 ("\\curlyeqsucc" . ?⋟
)
3117 ("\\curlypreceq" . ?≼
)
3119 ("\\curlywedge" . ?⋏
)
3120 ("\\curvearrowleft" . ?↶
)
3121 ("\\curvearrowright" . ?↷
)
3130 ("\\diamondsuit" . ?♢
)
3131 ("\\divideontimes" . ?⋇
)
3135 ("\\dotsquare" . ?⊡
)
3136 ("\\downarrow" . ?↓
)
3137 ("\\downdownarrows" . ?⇊
)
3138 ("\\downleftharpoon" . ?⇃
)
3139 ("\\downrightharpoon" . ?⇂
)
3144 ("\\eqslantgtr" . ?⋝
)
3145 ("\\eqslantless" . ?⋜
)
3148 ("\\fallingdotseq" . ?≒
)
3164 ("\\gtrapprox" . ?≳
)
3166 ("\\gtreqless" . ?⋛
)
3167 ("\\gtreqqless" . ?⋛
)
3170 ("\\gvertneqq" . ?≩
)
3172 ("\\heartsuit" . ?♥
)
3173 ("\\hookleftarrow" . ?↩
)
3174 ("\\hookrightarrow" . ?↪
)
3181 ("\\langle" .
10216) ; Literal ?⟨ breaks indentation.
3188 ("\\leftarrow" . ?←
)
3189 ("\\leftarrowtail" . ?↢
)
3190 ("\\leftharpoondown" . ?↽
)
3191 ("\\leftharpoonup" . ?↼
)
3192 ("\\leftleftarrows" . ?⇇
)
3193 ;; ("\\leftparengtr" ?〈), see bug#12948.
3194 ("\\leftrightarrow" . ?↔
)
3195 ("\\leftrightarrows" . ?⇆
)
3196 ("\\leftrightharpoons" . ?⇋
)
3197 ("\\leftrightsquigarrow" . ?↭
)
3198 ("\\leftthreetimes" . ?⋋
)
3202 ("\\lessapprox" . ?≲
)
3204 ("\\lesseqgtr" . ?⋚
)
3205 ("\\lesseqqgtr" . ?⋚
)
3217 ("\\longleftarrow" . ?←
)
3218 ("\\longleftrightarrow" . ?↔
)
3219 ("\\longmapsto" . ?↦
)
3220 ("\\longrightarrow" . ?→
)
3221 ("\\looparrowleft" . ?↫
)
3222 ("\\looparrowright" . ?↬
)
3227 ("\\lvertneqq" . ?≨
)
3230 ("\\measuredangle" . ?∡
)
3236 ("\\nLeftarrow" . ?⇍
)
3237 ("\\nLeftrightarrow" . ?⇎
)
3238 ("\\nRightarrow" . ?⇏
)
3254 ("\\ngeqslant" . ?≱
)
3257 ("\\nleftarrow" . ?↚
)
3258 ("\\nleftrightarrow" . ?↮
)
3261 ("\\nleqslant" . ?≰
)
3264 ;; ("\\not" ?̸) ;FIXME: conflict with "NOT SIGN" ¬.
3266 ("\\nparallel" . ?∦
)
3269 ("\\nrightarrow" . ?↛
)
3270 ("\\nshortmid" . ?∤
)
3271 ("\\nshortparallel" . ?∦
)
3275 ("\\nsubseteq" . ?⊈
)
3276 ("\\nsubseteqq" . ?⊈
)
3280 ("\\nsupseteq" . ?⊉
)
3281 ("\\nsupseteqq" . ?⊉
)
3282 ("\\ntriangleleft" . ?⋪
)
3283 ("\\ntrianglelefteq" . ?⋬
)
3284 ("\\ntriangleright" . ?⋫
)
3285 ("\\ntrianglerighteq" . ?⋭
)
3299 ("\\pitchfork" . ?⋔
)
3301 ("\\precapprox" . ?≾
)
3303 ("\\precnapprox" . ?⋨
)
3312 ("\\rangle" .
10217) ; Literal ?⟩ breaks indentation.
3317 ("\\rightarrow" . ?→
)
3318 ("\\rightarrowtail" . ?↣
)
3319 ("\\rightharpoondown" . ?⇁
)
3320 ("\\rightharpoonup" . ?⇀
)
3321 ("\\rightleftarrows" . ?⇄
)
3322 ("\\rightleftharpoons" . ?⇌
)
3323 ;; ("\\rightparengtr" ?⦔) ;; Was ?〉, see bug#12948.
3324 ("\\rightrightarrows" . ?⇉
)
3325 ("\\rightthreetimes" . ?⋌
)
3326 ("\\risingdotseq" . ?≓
)
3334 ("\\shortparallel" . ?∥
)
3337 ("\\smallamalg" . ?∐
)
3338 ("\\smallsetminus" . ?∖
)
3339 ("\\smallsmile" . ?⌣
)
3341 ("\\spadesuit" . ?♠
)
3342 ("\\sphericalangle" . ?∢
)
3346 ("\\sqsubseteq" . ?⊑
)
3348 ("\\sqsupseteq" . ?⊒
)
3350 ("\\squigarrowright" . ?⇝
)
3352 ("\\straightphi" . ?φ
)
3355 ("\\subseteqq" . ?⊆
)
3356 ("\\subsetneq" . ?⊊
)
3357 ("\\subsetneqq" . ?⊊
)
3359 ("\\succapprox" . ?≿
)
3360 ("\\succcurlyeq" . ?≽
)
3362 ("\\succnapprox" . ?⋩
)
3368 ("\\supseteqq" . ?⊇
)
3369 ("\\supsetneq" . ?⊋
)
3370 ("\\supsetneqq" . ?⊋
)
3373 ("\\therefore" . ?∴
)
3374 ("\\thickapprox" . ?≈
)
3379 ("\\triangledown" . ?▿
)
3380 ("\\triangleleft" . ?◃
)
3381 ("\\trianglelefteq" . ?⊴
)
3382 ("\\triangleq" . ?≜
)
3383 ("\\triangleright" . ?▹
)
3384 ("\\trianglerighteq" . ?⊵
)
3385 ("\\twoheadleftarrow" . ?↞
)
3386 ("\\twoheadrightarrow" . ?↠
)
3389 ("\\updownarrow" . ?↕
)
3390 ("\\upleftharpoon" . ?↿
)
3392 ("\\uprightharpoon" . ?↾
)
3393 ("\\upuparrows" . ?⇈
)
3397 ("\\varepsilon" . ?ε
)
3400 ("\\varpropto" . ?∝
)
3403 ("\\vartriangleleft" . ?⊲
)
3404 ("\\vartriangleright" . ?⊳
)
3413 ("\\Bbb{N}" . ?ℕ
) ; AMS commands for blackboard bold
3414 ("\\Bbb{P}" . ?ℙ
) ; Also sometimes \mathbb.
3420 ("\\ordfeminine" . ?ª
)
3421 ("\\ordmasculine" . ?º
)
3422 ("\\lambdabar" . ?ƛ
)
3425 ("\\textfractionsolidus" . ?⁄
)
3426 ("\\textbigcircle" . ?⃝
)
3427 ("\\textmusicalnote" . ?♪
)
3429 ("\\textcolonmonetary" . ?₡
)
3431 ("\\textnaira" . ?₦
)
3434 ("\\textrecipe" . ?℞
)
3435 ("\\textinterrobang" . ?‽
)
3436 ("\\textpertenthousand" . ?‱
)
3438 ("\\textnumero" . ?№
)
3439 ("\\textdiscount" . ?⁒
)
3440 ("\\textestimated" . ?℮
)
3441 ("\\textopenbullet" . ?◦
)
3442 ("\\textlquill" .
8261) ; Literal ?⁅ breaks indentation.
3443 ("\\textrquill" .
8262) ; Literal ?⁆ breaks indentation.
3444 ("\\textcircledP" . ?℗
)
3445 ("\\textreferencemark" . ?※
))
3446 "A `prettify-symbols-alist' usable for (La)TeX modes.")
3448 (defun tex--prettify-symbols-compose-p (_start end _match
)
3450 ;; If the matched symbol doesn't end in a word character, then we
3451 ;; simply allow composition. The symbol is probably something like
3453 (not (eq ?w
(char-syntax (char-before end
))))
3454 ;; Else we look at what follows the match in order to decide.
3455 (let* ((after-char (char-after end
))
3456 (after-syntax (char-syntax after-char
)))
3458 ;; Don't compose \alpha@foo.
3460 ;; The \alpha in \alpha2 or \alpha-\beta may be composed but
3461 ;; of course \alphax may not.
3462 (and (eq after-syntax ?w
)
3463 (not (memq after-char
3464 '(?
0 ?
1 ?
2 ?
3 ?
4 ?
5 ?
6 ?
7 ?
8 ?
9 ?
+ ?- ?
' ?
\"))))
3465 ;; Don't compose inside verbatim blocks.
3466 (eq 2 (nth 7 (syntax-ppss))))))))
3468 (run-hooks 'tex-mode-load-hook
)
3472 ;;; tex-mode.el ends here