From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: [patch] support latex variants Date: Sun, 13 Sep 2015 18:04:10 +0200 Message-ID: <87wpvu4879.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zb9lR-000867-9e for emacs-orgmode@gnu.org; Sun, 13 Sep 2015 12:04:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zb9lN-0007NN-7B for emacs-orgmode@gnu.org; Sun, 13 Sep 2015 12:04:25 -0400 Received: from plane.gmane.org ([80.91.229.3]:36973) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zb9lM-0007NF-Rr for emacs-orgmode@gnu.org; Sun, 13 Sep 2015 12:04:21 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Zb9lK-00074I-P7 for emacs-orgmode@gnu.org; Sun, 13 Sep 2015 18:04:18 +0200 Received: from x590cd54b.dyn.telefonica.de ([89.12.213.75]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 13 Sep 2015 18:04:18 +0200 Received: from rasmus by x590cd54b.dyn.telefonica.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 13 Sep 2015 18:04:18 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi, This series of patches adds support for specifying a latex program, i.e. {pdf,lua,xe}latex (plain latex is not in the list since we don't really target dvi output). You can add lines like #+latex_program: lualatex This is fairly useful as I typically is doing some weighting of the usefulness of microtype versus unicode-math in a document-to-document basis. You can drop certain packages in org-latex-{default-,}packages-alist depending on the selected program. E.g. you'd only want {input,font}enc with pdflatex. Likewise, you'd only want polyglossia when using {xe,lua}latex. This is supported by an optional fourth argument in the mentioned alists. It makes it easier (IMO) to write declarations for org-latex-pdf-process as you can simply specify %latex, which is then changed to the correct form (though there's some hackery in org-latex-compile). The patch-set drops "rubber" as it's not easy to configure a latex program on the go. There's also a %bibtex but it's not configurable on a file basis, though I could add it, if there's a demand for it. The "right" latex program is written to the file, optionally as a file-variable (AUCTeX and latex-mode; I could add texworks as well, if desirable). Perhaps the latex program and the creation date should be written on the same line? Suvayu tested a previous version of the patch-set, though I don't know for how long. Rasmus -- Don't panic!!! --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0004-ox-latex-Small-refactor.patch >From 8470f65bf5be29d173e547ca16dd874306b43dd1 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sun, 13 Sep 2015 16:45:48 +0200 Subject: [PATCH 4/4] ox-latex: Small refactor * ox-latex.el (org-latex-compile): Use format-spec. --- lisp/ox-latex.el | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 0ee0c15..61594a9 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -3499,24 +3499,26 @@ Return PDF file name or an error if it couldn't be produced." ((functionp org-latex-pdf-process) (funcall org-latex-pdf-process (shell-quote-argument texfile))) ;; A list is provided: Replace %b, %f and %o with appropriate - ;; values in each command before applying it. Output is - ;; redirected to "*Org PDF LaTeX Output*" buffer. + ;; values in each command before applying it. Note that while + ;; "%latex" and "%bibtex" is used in `org-latex-pdf-process', + ;; they are replaced with "%L" and "%B" to adhere to + ;; format-spec. Output is redirected to "*Org PDF LaTeX + ;; Output*" buffer. ((consp org-latex-pdf-process) (let ((outbuf (and (not snippet) - (get-buffer-create "*Org PDF LaTeX Output*")))) - (dolist (command org-latex-pdf-process) - (shell-command - (replace-regexp-in-string - "%bib" (shell-quote-argument org-latex-bib-process) - (replace-regexp-in-string - "%latex" (shell-quote-argument compiler) - (replace-regexp-in-string - "%b" (shell-quote-argument base-name) - (replace-regexp-in-string - "%f" (shell-quote-argument full-name) - (replace-regexp-in-string - "%o" (shell-quote-argument out-dir) command t t) t t) t t) t) t) - outbuf)) + (get-buffer-create "*Org PDF LaTeX Output*"))) + (spec (list (cons ?B (shell-quote-argument org-latex-bib-process)) + (cons ?L (shell-quote-argument compiler)) + (cons ?b (shell-quote-argument base-name)) + (cons ?f (shell-quote-argument full-name)) + (cons ?o (shell-quote-argument out-dir))))) + (mapc (lambda (command) + (shell-command (format-spec command spec) outbuf)) + (mapcar (lambda (command) + (replace-regexp-in-string "%\\(latex\\|bibtex\\)\\>" + (lambda (str) (upcase (substring str 0 2))) + command)) + org-latex-pdf-process)) ;; Collect standard errors from output buffer. (setq warnings (and (not snippet) (org-latex--collect-warnings outbuf))))) -- 2.5.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0003-ox-latex-Support-arbitrary-bibtex-like-program.patch >From c365b1e6016b3f11fc64a0fe0ce78e3848d5dfa9 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 8 Jul 2015 18:32:40 +0200 Subject: [PATCH 3/4] ox-latex: Support arbitrary bibtex-like program. * ox-latex.el (org-latex-bib-process): New defcustom. (org-latex-pdf-process, org-latex-compile): Use new defcustom. --- lisp/ox-latex.el | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 233e9e9..0ee0c15 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1064,6 +1064,21 @@ during latex export it will output ;;;; Compilation +(defcustom org-latex-bib-process "bibtex" + "Command used to process a LaTeX files bibliography. + +The shorthand %bib in `org-latex-pdf-process' is replaced with +this value. + +A better approach is to use a compiler suit such as `latexmk'. +" + :group 'org-export-latex + :type '(choice (const :tag "BibTeX" "bibtex") + (const :tag "Biber" "biber") + (string :tag "Other process")) + :version "25.1" + :package-version '(Org . "8.3")) + (defcustom org-latex-pdf-process '("%latex -interaction nonstopmode -output-directory %o %f" "%latex -interaction nonstopmode -output-directory %o %f" @@ -1101,7 +1116,7 @@ file name as its single argument." "%latex -interaction nonstopmode -output-directory %o %f")) (const :tag "latex,bibtex,latex,latex" ("%latex -interaction nonstopmode -output-directory %o %f" - "bibtex %b" + "%bib %b" "%latex -interaction nonstopmode -output-directory %o %f" "%latex -interaction nonstopmode -output-directory %o %f")) (const :tag "texi2dvi" @@ -3492,13 +3507,15 @@ Return PDF file name or an error if it couldn't be produced." (dolist (command org-latex-pdf-process) (shell-command (replace-regexp-in-string - "%latex" (shell-quote-argument compiler) + "%bib" (shell-quote-argument org-latex-bib-process) (replace-regexp-in-string - "%b" (shell-quote-argument base-name) + "%latex" (shell-quote-argument compiler) (replace-regexp-in-string - "%f" (shell-quote-argument full-name) + "%b" (shell-quote-argument base-name) (replace-regexp-in-string - "%o" (shell-quote-argument out-dir) command t t) t t) t t) t) + "%f" (shell-quote-argument full-name) + (replace-regexp-in-string + "%o" (shell-quote-argument out-dir) command t t) t t) t t) t) t) outbuf)) ;; Collect standard errors from output buffer. (setq warnings (and (not snippet) -- 2.5.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-ox-latex-Support-TeX-variants.patch >From b904dbade17fa9243edb6b7fb5ea57d52ebeda3b Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 8 Jul 2015 14:44:56 +0200 Subject: [PATCH 2/4] ox-latex: Support TeX variants * org.el (org-latex-default-packages-alist): Only use inputenc and fontenc in pdftex. * ox-latex.el (latex): Add :latex-program. (org-latex-program): New defcustom. (org-latex-programs): New defconst. (org-latex--remove-packages): New function. (org-latex-template): Use new function. (org-latex-pdf-process): Update to use %latex shorthand. (org-latex-compile): Check and use intended compiler. Adds #+latex_program keyword. Note that rubber is dropped from `org-latex-pdf-process' since it does not allow arbitrary latex commands. Suggested-by: Suvayu Ali --- lisp/org.el | 4 +- lisp/ox-latex.el | 136 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 90 insertions(+), 50 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index ce80129..b9b5838 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -4066,8 +4066,8 @@ header, or they will be appended." (default-value var))) (defcustom org-latex-default-packages-alist - '(("AUTO" "inputenc" t) - ("T1" "fontenc" t) + '(("AUTO" "inputenc" t ("pdflatex")) + ("T1" "fontenc" t ("pdflatex")) ("" "graphicx" t) ("" "grffile" t) ("" "longtable" nil) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index ddbbd33..233e9e9 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -144,6 +144,7 @@ (:latex-text-markup-alist nil nil org-latex-text-markup-alist) (:latex-title-command nil nil org-latex-title-command) (:latex-toc-command nil nil org-latex-toc-command) + (:latex-program "LATEX_PROGRAM" nil org-latex-program) ;; Redefine regular options. (:date "DATE" nil "\\today" parse))) @@ -393,6 +394,30 @@ references." :version "25.1" :package-version '(Org . "8.3")) +(defcustom org-latex-program-file-string "%% Indented LaTeX compiler: %s\n" + "LaTeX program format-string." + :group 'org-export-latex + :type '(choice + (const :tag "Comment" "%% Indented LaTeX compiler: %s\n") + (const :tag "latex-mode file variable" "%% -*- latex-run-command: %s -*-\n") + (const :tag "AUCTeX file variable" "%% -*- LaTeX-command: %s -*-\n") + (string :tag "custom format" "%% ")) + :version "25.1" + :package-version '(Org . "9.0")) + +(defcustom org-latex-program "pdflatex" + "LaTeX program to use." + :group 'org-export-latex + :type '(choice + (const :tag "pdfLaTeX" "pdflatex") + (const :tag "XeLaTeX" "xelatex") + (const :tag "LuaLaTeX" "lualatex")) + :version "25.1" + :package-version '(Org . "9.0")) + +(defconst org-latex-programs '("pdflatex" "xelatex" "lualatex") + "Known LaTeX programs.") + ;;;; Preamble (defcustom org-latex-default-class "article" @@ -1040,14 +1065,15 @@ during latex export it will output ;;;; Compilation (defcustom org-latex-pdf-process - '("pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f") + '("%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f") "Commands to process a LaTeX file to a PDF file. This is a list of strings, each of them will be given to the shell as a command. %f in the command will be replaced by the full file name, %b by the file base name (i.e. without directory -and extension parts) and %o by the base directory of the file. +and extension parts), %o by the base directory of the file, +and %latex is the latex program (see `org-latex-program'). The reason why this is a list is that it usually takes several runs of `pdflatex', maybe mixed with a call to `bibtex'. Org @@ -1055,18 +1081,8 @@ does not have a clever mechanism to detect which of these commands have to be run to get to a stable result, and it also does not do any error checking. -By default, Org uses 3 runs of `pdflatex' to do the processing. -If you have texi2dvi on your system and if that does not cause -the infamous egrep/locale bug: - - http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html - -then `texi2dvi' is the superior choice as it automates the LaTeX -build process by calling the \"correct\" combinations of -auxiliary programs. Org does offer `texi2dvi' as one of the -customize options. Alternatively, `rubber' and `latexmk' also -provide similar functionality. The latter supports `biber' out -of the box. +Consider a smart LaTeX compiler such as `texi2dvi' or `latexmk', +which calls the \"correct\" combinations of auxiliary programs. Alternatively, this may be a Lisp function that does the processing, so you could use this to apply the machinery of @@ -1076,36 +1092,22 @@ file name as its single argument." :type '(choice (repeat :tag "Shell command sequence" (string :tag "Shell command")) - (const :tag "2 runs of pdflatex" - ("pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f")) - (const :tag "3 runs of pdflatex" - ("pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f")) - (const :tag "pdflatex,bibtex,pdflatex,pdflatex" - ("pdflatex -interaction nonstopmode -output-directory %o %f" - "bibtex %b" - "pdflatex -interaction nonstopmode -output-directory %o %f" - "pdflatex -interaction nonstopmode -output-directory %o %f")) - (const :tag "2 runs of xelatex" - ("xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f")) - (const :tag "3 runs of xelatex" - ("xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f")) - (const :tag "xelatex,bibtex,xelatex,xelatex" - ("xelatex -interaction nonstopmode -output-directory %o %f" + (const :tag "2 runs of latex" + ("%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f")) + (const :tag "3 runs of latex" + ("%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f")) + (const :tag "latex,bibtex,latex,latex" + ("%latex -interaction nonstopmode -output-directory %o %f" "bibtex %b" - "xelatex -interaction nonstopmode -output-directory %o %f" - "xelatex -interaction nonstopmode -output-directory %o %f")) + "%latex -interaction nonstopmode -output-directory %o %f" + "%latex -interaction nonstopmode -output-directory %o %f")) (const :tag "texi2dvi" - ("texi2dvi -p -b -V %f")) - (const :tag "rubber" - ("rubber -d --into %o %f")) + ("LATEX=\"%latex\" texi2dvi -p -b -V %f")) (const :tag "latexmk" - ("latexmk -g -pdf %f")) + ("latexmk -g -pdflatex=\"%latex\" %f")) (function))) (defcustom org-latex-logfiles-extensions @@ -1346,6 +1348,30 @@ Return the new header." "")) t t header 0))))) +(defun org-latex--remove-packages (pkg-alist info) + "Remove packages based on the current LaTeX program. + +If the fourth argument of an element is set in pkg-alist, and it +is not a member of the LaTeX program of the document, the packages +is removed. See also `org-latex-program'. + +Return modified pkg-alist." + (let ((program (org-trim (or (plist-get info :latex-program) "")))) + (if (member-ignore-case program org-latex-programs) + (delq nil + (mapcar (lambda (pkg) + (unless + (and + (listp pkg) + (let ((third (nth 3 pkg))) + (and third + (not (member-ignore-case + program + (if (listp third) third (list third))))))) + pkg)) + pkg-alist)) + pkg-alist))) + (defun org-latex--find-verb-separator (s) "Return a character not used in string S. This is used to choose a separator for constructs like \\verb." @@ -1495,8 +1521,9 @@ INFO is a plist used as a communication channel." (org-element-normalize-string (org-splice-latex-header document-class-string - org-latex-default-packages-alist - org-latex-packages-alist nil + (org-latex--remove-packages org-latex-default-packages-alist info) + (org-latex--remove-packages org-latex-packages-alist info) + nil (concat (org-element-normalize-string (plist-get info :latex-header)) (plist-get info :latex-header-extra))))) @@ -1513,6 +1540,11 @@ holding export options." (let ((title (org-export-data (plist-get info :title) info)) (spec (org-latex--format-spec info))) (concat + ;; LaTeX program + (let ((program (plist-get info :latex-program))) + (and (org-string-nw-p org-latex-program-file-string) + (string-match-p (regexp-opt org-latex-programs) program) + (format org-latex-program-file-string program))) ;; Time-stamp. (and (plist-get info :time-stamp-file) (format-time-string "%% Created %Y-%m-%d %a %H:%M\n")) @@ -3432,6 +3464,12 @@ create a log buffer and do not bother removing log files. Return PDF file name or an error if it couldn't be produced." (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile))) (full-name (file-truename texfile)) + (compiler (or (with-temp-buffer + (save-excursion (insert-file-contents full-name)) + (when (search-forward-regexp + (regexp-opt org-latex-programs) (line-end-position) t) + (match-string 0))) + "pdflatex")) (out-dir (file-name-directory texfile)) ;; Properly set working directory for compilation. (default-directory (if (file-name-absolute-p texfile) @@ -3454,11 +3492,13 @@ Return PDF file name or an error if it couldn't be produced." (dolist (command org-latex-pdf-process) (shell-command (replace-regexp-in-string - "%b" (shell-quote-argument base-name) + "%latex" (shell-quote-argument compiler) (replace-regexp-in-string - "%f" (shell-quote-argument full-name) + "%b" (shell-quote-argument base-name) (replace-regexp-in-string - "%o" (shell-quote-argument out-dir) command t t) t t) t t) + "%f" (shell-quote-argument full-name) + (replace-regexp-in-string + "%o" (shell-quote-argument out-dir) command t t) t t) t t) t) outbuf)) ;; Collect standard errors from output buffer. (setq warnings (and (not snippet) -- 2.5.1 --=-=-=--