AUCTeX Sync -- New Style Files
[packages] / xemacs-packages / auctex / style / subfiles.el
1 ;;; subfiles.el --- AUCTeX style for the subfiles package.
2
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5 ;; Author: Uwe Brauer <oub@mat.ucm.es>
6 ;; Created: 07 Nov 2016
7 ;; Keywords: tex
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;; Acknowledgements
27 ;; Mosè Giordano <mose@gnu.org>
28 ;; Arash Esbati <arash@gnu.org>
29
30 ;;; Commentary:
31
32 ;; This file adds support for the subfiles package.
33
34 ;;; Code:
35
36 (defvar LaTeX-subfiles-package-options nil
37   "Package options for the subfiles package.")
38
39 (defun LaTeX-subfiles-class-options ()
40   "Return name of the main file relative to current subfile."
41   (file-relative-name
42    (read-file-name
43     "Main file: " nil nil nil nil
44     (lambda (texfiles)
45       (string-match "\\.tex$" texfiles)))
46    (TeX-master-directory)))
47
48 (TeX-add-style-hook
49  "subfiles"
50  (lambda ()
51
52    ;; The following code will run `TeX-run-style-hooks' on the subfile
53    ;; master file.  Thanks to Mosè Giordano <mose@gnu.org> for
54    ;; presenting a better solution using `assoc'.
55    (let ((master-file (cadr (assoc "subfiles" LaTeX-provided-class-options))))
56      (when (stringp master-file)
57        (TeX-run-style-hooks
58         (file-name-sans-extension master-file))))
59
60    (TeX-add-symbols
61     '("subfile" TeX-arg-file))
62
63    ;; Ensure that \subfile stays in one line
64    (LaTeX-paragraph-commands-add-locally "subfile")
65
66    ;; Tell AUCTeX that \subfile loads a file.  regexp is the same as
67    ;; for \input or \include.  This will run `TeX-run-style-hooks' on
68    ;; subfile(s) when master file is loaded.
69    (TeX-auto-add-regexp
70     `(,(concat
71         "\\\\subfile"
72         "{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}")
73       1 TeX-auto-file))
74
75    ;; Tell RefTeX the same thing.
76    (when (and (boundp 'reftex-include-file-commands)
77               (not (member "subfile" reftex-include-file-commands)))
78      (add-to-list 'reftex-include-file-commands "subfile" t)
79      (reftex-compile-variables))
80
81    ;; The following code will fontify `\subfile{}' like \input.
82    (when (and (featurep 'font-latex)
83               (eq TeX-install-font-lock 'font-latex-setup))
84      (font-latex-add-keywords '(("subfile" "{"))
85                               'reference)))
86  LaTeX-dialect)
87
88 ;;; subfiles.el ends here