Suvayu Ali <[email protected]> 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
>From df91d417df3223c0698e56be219f8f1a303ce566 Mon Sep 17 00:00:00 2001
From: Rasmus <[email protected]>
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
>From 54bcf8f1ae26c91fa856b64071dca65d3f31e1f2 Mon Sep 17 00:00:00 2001
From: Rasmus <[email protected]>
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