branch: main commit 4d9b411216083d4aa3529d65af00adf27c8dee16 Author: Mosè Giordano <m...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Check engine before running LaTeX command. * tex-buf.el (TeX-check-engine): New customizable variable. (TeX-check-engine-list): New variable. (TeX-check-engine-add-engines): New function. (TeX-check-engine): New function. (TeX-command): Use `TeX-check-engine' and update docstring accordingly. * style/fontspec.el ("fontspec"): Add engine restrictions. * doc/auctex.texi (Processor Options): Document `TeX-check-engine'. * doc/changes.texi: Mention `TeX-check-engine'. --- ChangeLog | 16 +++++++++ doc/auctex.texi | 14 ++++++++ doc/changes.texi | 5 +++ style/fontspec.el | 1 + tex-buf.el | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 132 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c3acdb1e..e52c015a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2015-08-21 Mos� Giordano <m...@gnu.org> + + * tex-buf.el (TeX-check-engine): New customizable variable. + (TeX-check-engine-list): New variable. + (TeX-check-engine-add-engines): New function. + (TeX-check-engine): New function. + (TeX-command): Use `TeX-check-engine' and update docstring + accordingly. + + * style/fontspec.el ("fontspec"): Add engine restrictions. + + * doc/auctex.texi (Processor Options): Document + `TeX-check-engine'. + + * doc/changes.texi: Mention `TeX-check-engine'. + 2015-08-20 Mos� Giordano <m...@gnu.org> * tex-buf.el (TeX-error-overview-jump-to-source) diff --git a/doc/auctex.texi b/doc/auctex.texi index 09935c93..141afff1 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -2950,6 +2950,20 @@ command can either be a variable or a string. An empty string or nil means there is no command available. @end defopt +Some @LaTeX{} packages requires the document to be compiled with a +specific engine. Notably examples are fontspec and polyglossia +packages, which require Lua@TeX{} and Xe@TeX{} engines. If you try to +compile a document which loads one of such packages and the set engine +is not one of those allowed you will be asked to select a different +engine before running the @LaTeX{} command. If you do not want to be +warned by @AUCTeX{} in these cases, customize the option +@code{TeX-check-engine}. + +@defopt TeX-check-engine +This boolean option controls whether @AUCTeX{} should check the correct +engine has been set before running @LaTeX{} commands. +@end defopt + As shown above, @AUCTeX{} handles in a special way most of the main options that can be given to the @TeX{} processors. When you need to pass to the @TeX{} processor arbitrary options not handled by @AUCTeX{}, diff --git a/doc/changes.texi b/doc/changes.texi index 1dd552d5..21783871 100644 --- a/doc/changes.texi +++ b/doc/changes.texi @@ -34,6 +34,11 @@ Indent @samp{\[...\]} math mode as a regular environment by default. @item @code{TeX-view-program-list} can contain, as third optional element of each item, the name of the executable(s) needed to open the viewer. + +@item +When new option @code{TeX-check-engine} is non-nil, before running +@LaTeX{} commands @AUCTeX{} will check whether the correct engine has +been set, based upon known restrictions posed by @LaTeX{} packages. @end itemize @heading News in 11.88 diff --git a/style/fontspec.el b/style/fontspec.el index 144b976c..5ec7bb4b 100644 --- a/style/fontspec.el +++ b/style/fontspec.el @@ -166,6 +166,7 @@ to retrieve the list of fonts." (TeX-add-style-hook "fontspec" (lambda () + (TeX-check-engine-add-engines 'luatex 'xetex) (TeX-run-style-hooks "expl3" "xparse") (TeX-add-symbols ;; Font selection diff --git a/tex-buf.el b/tex-buf.el index cdd5fe2e..3be47d7f 100644 --- a/tex-buf.el +++ b/tex-buf.el @@ -332,6 +332,96 @@ This works only with TeX commands and if the (defconst TeX-error-overview-buffer-name "*TeX errors*" "Name of the buffer in which to show error list.") +(defcustom TeX-check-engine t + "Whether AUCTeX should check the correct engine has been set before running LaTeX commands." + :group 'TeX-command + :type 'boolean) + +(defvar TeX-check-engine-list '(default luatex omega xetex) + "List of engines required by the loaded TeX packages. + +Do not set this variable directly, use +`TeX-check-engine-add-engines' to specify required engines.") +(make-variable-buffer-local 'TeX-check-engine-list) + +(defun TeX-check-engine-add-engines (&rest engines) + "Add ENGINES to list of required engines. + +Set `TeX-check-engine-list' to the intersection between the list +itself and the list of provided engines. + +See for example style/fontspec.el" + (let ((list TeX-check-engine-list) + (res nil)) + (setq TeX-check-engine-list + ;; The following is based on the definition of `cl-intersection' of + ;; GNU Emacs. + (and list engines + (if (equal list engines) list + (or (>= (length list) (length engines)) + (setq list (prog1 engines (setq engines list)))) + (while engines + (if (memq (car engines) list) + (push (car engines) res)) + (pop engines)) + res))))) + +(defun TeX-check-engine (name) + "Check the correct engine has been set. + +Look into `TeX-check-engine-list' for the required engines. + +NAME is the command to be run. Actually do the check only if the +variable `TeX-check-engine' is non-nil and LaTeX is the command +to be run." + (and + (string= name "LaTeX") + TeX-check-engine + TeX-check-engine-list + (null (memq TeX-engine TeX-check-engine-list)) + (memq TeX-engine '(default luatex omega xetex)) + ;; The set engine is not listed in `TeX-check-engine-list'. We check only + ;; builtin engines because we can't take care of custom ones. Do nothing if + ;; there is no allowed engine, we don't know what to do in that case. + (let ((length (length TeX-check-engine-list)) + (name-alist '((default . "TeX") + (luatex . "LuaTeX") + (omega . "Omega") + (xetex . "XeTeX"))) + (completion-ignore-case t) + (engine nil)) + (when + (cond + ;; There is exactly one allowed engine. + ((= length 1) + (setq engine (car TeX-check-engine-list)) + (y-or-n-p (format "%s is required to build this document. +Do you want to use this engine?" (cdr (assoc engine name-alist))))) + ;; More than one engine is allowed. + ((> length 1) + (if (y-or-n-p (format "%s are required to build this document. +Do you want to select one of these engines?" + (mapconcat + (lambda (elt) (cdr (assoc elt name-alist))) + TeX-check-engine-list ", "))) + (setq engine + (car (rassoc + (completing-read + (format + "Choose between %s: " + (mapconcat + (lambda (elt) (cdr (assoc elt name-alist))) + TeX-check-engine-list ", ")) + (mapcar + (lambda (elt) (cdr (assoc elt name-alist))) + TeX-check-engine-list)) + name-alist)))))) + (TeX-engine-set engine) + (when (and (fboundp 'add-file-local-variable) + (y-or-n-p "Do you want to remember the choice?")) + (add-file-local-variable 'TeX-engine engine) + (save-buffer)))))) + (defun TeX-command (name file &optional override-confirm) "Run command NAME on the file returned by calling FILE. @@ -343,7 +433,12 @@ Use the information in `TeX-command-list' to determine how to run the command. If OVERRIDE-CONFIRM is a prefix argument, confirmation will be -asked if it is positive, and suppressed if it is not." +asked if it is positive, and suppressed if it is not. + +Run function `TeX-check-engine' to check the correct engine has +been set." + (TeX-check-engine name) + (cond ((eq file 'TeX-region-file) (setq TeX-current-process-region-p t)) ((eq file 'TeX-master-file)