From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: ox-latex: default packages cleaning Date: Wed, 08 Jul 2015 14:53:46 +0200 Message-ID: <87y4iq24kl.fsf@gmx.us> References: <87r3ok589c.fsf@gmx.us> <20150707193522.GB30985@chitra.no-ip.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCore-0004ju-JI for emacs-orgmode@gnu.org; Wed, 08 Jul 2015 08:54:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCorb-0007dz-7w for emacs-orgmode@gnu.org; Wed, 08 Jul 2015 08:54:14 -0400 Received: from plane.gmane.org ([80.91.229.3]:43056) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCora-0007df-Tu for emacs-orgmode@gnu.org; Wed, 08 Jul 2015 08:54:11 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZCorY-0007H3-1S for emacs-orgmode@gnu.org; Wed, 08 Jul 2015 14:54:08 +0200 Received: from ip5b4025d5.dynamic.kabel-deutschland.de ([91.64.37.213]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 08 Jul 2015 14:54:08 +0200 Received: from rasmus by ip5b4025d5.dynamic.kabel-deutschland.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 08 Jul 2015 14:54:08 +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 Suvayu Ali writes: > We could also take this opportunity to provide users an easy way to > switch between TeX engines. These two patches goes some of the way towards what you want. org-latex-pdf-process would also have to patched as well, though. Test document: #+title: test xetex #+language: en #+options: tex-variant:xetex * header #+BEGIN_SRC emacs-lisp (add-to-list 'org-latex-packages-alist '("AUTO, french" "polyglossia" nil (luatex xetex))) #+END_SRC Result (node the missing inputenc and fontenc): \documentclass[11pt]{article} \usepackage{graphicx} \usepackage{grffile} \usepackage{longtable} \usepackage{wrapfig} \usepackage{rotating} \usepackage[normalem]{ulem} \usepackage{amsmath} \usepackage{textcomp} \usepackage{amssymb} \usepackage{capt-of} \usepackage{hyperref} \usepackage{polyglossia} \setmainlanguage{english} \setotherlanguage{french} \author{Rasmus} \date{\textit{<2015-07-07 mar>}} \title{test xetex} \hypersetup{ pdfauthor={Rasmus}, pdftitle={test xetex}, pdfkeywords={}, pdfsubject={}, pdfcreator={Emacs 25.0.50.1 (Org mode 8.3beta)}, pdflang={English}} \begin{document} \maketitle \tableofcontents \section{add polyglossia} \label{sec:orgheadline1} \begin{verbatim} (add-to-list 'org-latex-packages-alist '("AUTO, french" "polyglossia" nil (luatex xetex))) \end{verbatim} \end{document} Rasmus -- However beautiful the theory, you should occasionally look at the evidence --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0008-ox-latex-Add-polyglossia-support.patch >From df91d417df3223c0698e56be219f8f1a303ce566 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 8 Jul 2015 14:12:21 +0200 Subject: [PATCH 8/9] ox-latex: Add polyglossia support * ox-latex.el (org-latex-guess-polyglossia-language): New function. (org-latex-template): Apply new function. --- lisp/ox-latex.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index ff42843..058d7f8 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1195,6 +1195,45 @@ Return the new header." ", ") t nil header 1))))) +(defun org-latex-guess-polyglossia-language (header info) + "Set the Polyglossia language according to the LANGUAGE keyword. + +HEADER is the LaTeX header string. INFO is the plist used as +a communication channel. + +Insertion of guessed language only happens when the Polyglossia +package has been explicitly loaded. + +The argument to Polyglossia may be \"AUTO\" which is then +replaced with the language of the document or +`org-export-default-language'. Note, the language is really set +using \setdefaultlanguage and not as an option to the package. + +Return the new header." + (let ((language-code (plist-get info :language))) + ;; If no language is set or Polyglossia is not loaded, return + ;; HEADER as-is. + (if (or (not (stringp language-code)) + (not (string-match "\\\\usepackage\\[?\\(.*?\\)?\\]?{polyglossia}" header))) + header + (let* ((language (cdr (assoc language-code + org-latex-babel-language-alist))) + (options (or (org-string-nw-p (match-string 1 header)) "AUTO")) + (languages (save-match-data + (org-split-string + (replace-regexp-in-string + "AUTO" (if (string-match-p language options) "" language) + options t) + ",[ \t]*"))) + (main-language-set (string-match-p "\\\\setmainlanguage{.*?}" header))) + (replace-match + (concat "\\usepackage{polyglossia}\n" + (when (and languages (not main-language-set)) + (format "\\setmainlanguage{%s}" (pop languages))) + (when languages + (format "\n\\setotherlanguage{%s}\n" (mapconcat 'identity languages ", ")))) + t t header 0))))) + (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." @@ -1349,16 +1388,18 @@ holding export options." class-options header t nil 1))))) (if (not document-class-string) (user-error "Unknown LaTeX class `%s'" class) - (org-latex-guess-babel-language - (org-latex-guess-inputenc - (org-element-normalize-string - (org-splice-latex-header - document-class-string - org-latex-default-packages-alist - org-latex-packages-alist nil - (concat (org-element-normalize-string - (plist-get info :latex-header)) - (plist-get info :latex-header-extra))))) + (org-latex-guess-polyglossia-language + (org-latex-guess-babel-language + (org-latex-guess-inputenc + (org-element-normalize-string + (org-splice-latex-header + document-class-string + org-latex-default-packages-alist + org-latex-packages-alist nil + (concat (org-element-normalize-string + (plist-get info :latex-header)) + (plist-get info :latex-header-extra))))) + info) info))) ;; Possibly limit depth for headline numbering. (let ((sec-num (plist-get info :section-numbers))) -- 2.4.5 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0009-ox-latex-Support-TeX-variants.patch >From 54bcf8f1ae26c91fa856b64071dca65d3f31e1f2 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 8 Jul 2015 14:44:56 +0200 Subject: [PATCH 9/9] 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-tex-variant. (org-latex-tex-variant): New defcustom. (org-latex--remove-packages): New function. (org-latex-template): Use new function. --- lisp/org.el | 4 ++-- lisp/ox-latex.el | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index f10ccf9..3324138 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -4069,8 +4069,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 pdftex) + ("T1" "fontenc" t pdftex) ("" "graphicx" t) ("" "grffile" t) ("" "longtable" nil) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 058d7f8..e7337e1 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-tex-variant nil "tex-variant" org-latex-tex-variant) ;; Redefine regular options. (:date "DATE" nil "\\today" parse))) @@ -305,6 +306,16 @@ references." :version "25.1" :package-version '(Org . "8.3")) +(defcustom org-latex-tex-variant 'pdftex + "Tex variant to use." + :group 'org-export-latex + :type '(choice + (cons :tag "pdfTeX" pdftex) + (cons :tag "XeTeX" xetex) + (cons :tag "luaTeX" luatex)) + :version "25.1" + :package-version '(Org . "8.3")) + ;;;; Preamble (defcustom org-latex-default-class "article" @@ -1234,6 +1245,24 @@ Return the new header." (format "\n\\setotherlanguage{%s}\n" (mapconcat 'identity languages ", ")))) t t header 0))))) +(defun org-latex--remove-packages (pkg-alist info) + "Remove packages based on the current TeX variant. + +If the fourth argument of an element is set in pkg-alist, and it +is not a member of the tex variant of the document, the packages +is removed. See also `org-latex-tex-variant'. + +Return modified pkg-alist." + (delq nil + (mapcar (lambda (pkg) + (unless (and (listp pkg) + (let ((third (nth 3 pkg))) + (and third + (not (member (plist-get info :latex-tex-variant) + (if (listp third) third (list third))))))) + pkg)) + 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." @@ -1394,8 +1423,9 @@ holding export options." (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))))) -- 2.4.5 --=-=-=--