From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: ox-latex: default packages cleaning
Date: Wed, 08 Jul 2015 14:53:46 +0200 [thread overview]
Message-ID: <87y4iq24kl.fsf@gmx.us> (raw)
In-Reply-To: 20150707193522.GB30985@chitra.no-ip.org
[-- Attachment #1: Type: text/plain, Size: 1695 bytes --]
Suvayu Ali <fatkasuvayu+linux@gmail.com> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0008-ox-latex-Add-polyglossia-support.patch --]
[-- Type: text/x-diff, Size: 3517 bytes --]
From df91d417df3223c0698e56be219f8f1a303ce566 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0009-ox-latex-Support-TeX-variants.patch --]
[-- Type: text/x-diff, Size: 3356 bytes --]
From 54bcf8f1ae26c91fa856b64071dca65d3f31e1f2 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
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
next prev parent reply other threads:[~2015-07-08 12:54 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 14:53 ox-latex: default packages cleaning Rasmus
2015-07-07 15:48 ` Eric S Fraga
2015-07-07 19:35 ` Suvayu Ali
2015-07-07 20:05 ` Rasmus
2015-07-07 20:52 ` Suvayu Ali
2015-07-07 21:07 ` Rasmus
2015-07-08 12:53 ` Rasmus [this message]
2015-07-08 13:43 ` Suvayu Ali
2015-07-08 13:53 ` Rasmus
2015-07-08 14:09 ` Suvayu Ali
2015-07-08 14:26 ` Rasmus
2015-07-08 14:55 ` Suvayu Ali
2015-07-08 15:41 ` Suvayu Ali
2015-07-08 16:06 ` Rasmus
2015-07-08 18:35 ` Rasmus
2015-07-16 8:29 ` Suvayu Ali
2015-07-16 8:49 ` Rasmus
2015-07-27 8:22 ` Sebastien Vauban
2015-07-27 8:30 ` Rasmus
2015-07-27 9:22 ` Sebastien Vauban
2015-07-27 9:31 ` Rasmus
2015-07-29 16:21 ` Rasmus
2015-07-08 12:54 ` Rasmus
2015-07-08 13:44 ` Suvayu Ali
2015-07-14 22:31 ` Marcin Borkowski
2015-07-15 8:33 ` Rasmus
2015-07-10 11:25 ` Robert Klein
2015-07-11 10:48 ` Rasmus
2015-07-11 18:53 ` Robert Klein
2015-07-13 10:08 ` Rasmus
2015-07-14 22:16 ` Marcin Borkowski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4iq24kl.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).