* [PATCH] Override the default class name with a new one.
@ 2013-06-13 6:14 Feng Shu
2013-06-13 23:55 ` Feng Shu
2013-06-14 13:36 ` Nicolas Goaziou
0 siblings, 2 replies; 12+ messages in thread
From: Feng Shu @ 2013-06-13 6:14 UTC (permalink / raw)
To: orgmode
[-- Attachment #1: Type: text/plain, Size: 216 bytes --]
#+LATEX_CLASS: article
%%output:
\documentclass[11pt]{article}
...
--------------------------------------
#+LATEX_CLASS: article
#+LATEX_CLASS_NAME: ctexart
%%output:
\documentclass[11pt]{ctexart}
....
--
[-- Attachment #2: 0001-Override-the-default-latex-class-name-with-a-new-one.patch --]
[-- Type: text/x-diff, Size: 3077 bytes --]
From 338ce85c306ae400ba8c62bfaecaf8973346faa0 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Thu, 13 Jun 2013 13:36:50 +0800
Subject: [PATCH] Override the default latex class name with a new one
* lisp/ox-latex.el (latex): Add :latex-class-name to :options-alist.
(org-latex-default-latex-class-name): The default name of LaTeX class file.
(org-latex-template): Replace default latex class name with :latex-class-name.
Override the default latex class name in template. It will be very
useful if you are using a class and it's setting is very similar to
one which has been defined in the `org-latex-classes, for example:
If you want to use latex class: "ctexart" and you find that it's
setting will be very similar to "article", you don't need to add a
new list to `org-latex-classes, just type:
#+LATEX_CLASS: article
#+LATEX_CLASS_NAME: ctexart
---
lisp/ox-latex.el | 16 ++++++++++++++--
1 个文件被修改,插入 14 行(+),删除 2 行(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9172cd7..ecfb0ce 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -98,6 +98,7 @@
(if a (org-latex-export-to-pdf t s v b)
(org-open-file (org-latex-export-to-pdf nil s v b)))))))
:options-alist '((:latex-class "LATEX_CLASS" nil org-latex-default-class t)
+ (:latex-class-name "LATEX_CLASS_NAME" nil org-latex-default-latex-class-name t)
(:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
(:latex-header "LATEX_HEADER" nil nil newline)
(:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
@@ -182,6 +183,11 @@
:group 'org-export-latex
:type '(string :tag "LaTeX class"))
+(defcustom org-latex-default-latex-class-name ""
+ "The default name of LaTeX class file."
+ :group 'org-export-latex
+ :type '(string :tag "LaTeX class"))
+
(defcustom org-latex-classes
'(("article"
"\\documentclass[11pt]{article}"
@@ -1061,15 +1067,21 @@ holding export options."
(format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
;; Document class and packages.
(let ((class (plist-get info :latex-class))
+ (latex-class-name (plist-get info :latex-class-name))
(class-options (plist-get info :latex-class-options)))
(org-element-normalize-string
(let* ((header (nth 1 (assoc class org-latex-classes)))
- (document-class-string
+ (document-class-string-tmp
(and (stringp header)
(if (not class-options) header
(replace-regexp-in-string
"^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
- class-options header t nil 1)))))
+ class-options header t nil 1))))
+ (document-class-string
+ (if (not latex-class-name) document-class-string-tmp
+ (replace-regexp-in-string
+ "^[ \t]*\\\\documentclass\\[[^]]*\\]?{\\(.*\\)}"
+ latex-class-name document-class-string-tmp t nil 1))))
(if (not document-class-string)
(user-error "Unknown LaTeX class `%s'" class)
(org-latex-guess-babel-language
--
1.7.10.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-13 6:14 [PATCH] Override the default class name with a new one Feng Shu
@ 2013-06-13 23:55 ` Feng Shu
2013-06-14 9:13 ` Rasmus
2013-06-14 13:36 ` Nicolas Goaziou
1 sibling, 1 reply; 12+ messages in thread
From: Feng Shu @ 2013-06-13 23:55 UTC (permalink / raw)
To: emacs-orgmode, carsten.dominik
Feng Shu <tumashu@gmail.com> writes:
> #+LATEX_CLASS: article
>
> %%output:
>
> \documentclass[11pt]{article}
>
> ...
>
> --------------------------------------
>
> #+LATEX_CLASS: article
> #+LATEX_CLASS_NAME: ctexart
>
> %%output:
>
> \documentclass[11pt]{ctexart}
Hi:
If possible, please merge this patch to master, thanks!
I think it is a way reusing the exist class defines in `org-latex-classes
If your class is similar with a exist one,
For example:
#+begin_example
("article"
"\\documentclass[11pt]{article}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("ctexart"
"\\documentclass[11pt]{ctexart}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
#+end_example
You don't need to add "ctexart" to `org-latex-classes,
just type:
#+LATEX_CLASS: article
#+LATEX_CLASS_NAME: ctexart
>
> ....
>
> --
>
> From 338ce85c306ae400ba8c62bfaecaf8973346faa0 Mon Sep 17 00:00:00 2001
> From: Feng Shu <tumashu@gmail.com>
> Date: Thu, 13 Jun 2013 13:36:50 +0800
> Subject: [PATCH] Override the default latex class name with a new one
>
> * lisp/ox-latex.el (latex): Add :latex-class-name to :options-alist.
> (org-latex-default-latex-class-name): The default name of LaTeX class file.
> (org-latex-template): Replace default latex class name with :latex-class-name.
>
> Override the default latex class name in template. It will be very
> useful if you are using a class and it's setting is very similar to
> one which has been defined in the `org-latex-classes, for example:
>
> If you want to use latex class: "ctexart" and you find that it's
> setting will be very similar to "article", you don't need to add a
> new list to `org-latex-classes, just type:
>
> #+LATEX_CLASS: article
> #+LATEX_CLASS_NAME: ctexart
> ---
> lisp/ox-latex.el | 16 ++++++++++++++--
> 1 个文件被修改,插入 14 行(+),删除 2 行(-)
>
> diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
> index 9172cd7..ecfb0ce 100644
> --- a/lisp/ox-latex.el
> +++ b/lisp/ox-latex.el
> @@ -98,6 +98,7 @@
> (if a (org-latex-export-to-pdf t s v b)
> (org-open-file (org-latex-export-to-pdf nil s v b)))))))
> :options-alist '((:latex-class "LATEX_CLASS" nil org-latex-default-class t)
> + (:latex-class-name "LATEX_CLASS_NAME" nil org-latex-default-latex-class-name t)
> (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
> (:latex-header "LATEX_HEADER" nil nil newline)
> (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
> @@ -182,6 +183,11 @@
> :group 'org-export-latex
> :type '(string :tag "LaTeX class"))
>
> +(defcustom org-latex-default-latex-class-name ""
> + "The default name of LaTeX class file."
> + :group 'org-export-latex
> + :type '(string :tag "LaTeX class"))
> +
> (defcustom org-latex-classes
> '(("article"
> "\\documentclass[11pt]{article}"
> @@ -1061,15 +1067,21 @@ holding export options."
> (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
> ;; Document class and packages.
> (let ((class (plist-get info :latex-class))
> + (latex-class-name (plist-get info :latex-class-name))
> (class-options (plist-get info :latex-class-options)))
> (org-element-normalize-string
> (let* ((header (nth 1 (assoc class org-latex-classes)))
> - (document-class-string
> + (document-class-string-tmp
> (and (stringp header)
> (if (not class-options) header
> (replace-regexp-in-string
> "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
> - class-options header t nil 1)))))
> + class-options header t nil 1))))
> + (document-class-string
> + (if (not latex-class-name) document-class-string-tmp
> + (replace-regexp-in-string
> + "^[ \t]*\\\\documentclass\\[[^]]*\\]?{\\(.*\\)}"
> + latex-class-name document-class-string-tmp t nil 1))))
> (if (not document-class-string)
> (user-error "Unknown LaTeX class `%s'" class)
> (org-latex-guess-babel-language
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-13 23:55 ` Feng Shu
@ 2013-06-14 9:13 ` Rasmus
2013-06-14 9:50 ` Nick Dokos
2013-06-14 9:55 ` Feng Shu
0 siblings, 2 replies; 12+ messages in thread
From: Rasmus @ 2013-06-14 9:13 UTC (permalink / raw)
To: tumashu; +Cc: emacs-orgmode
Feng Shu <tumashu@gmail.com> writes:
> #+LATEX_CLASS: article
> #+LATEX_CLASS_NAME: ctexart
I'm not sure this is the right approach. . . I can certainly see the
value of generating classes on the fly, though. But somehow the
proposed syntax just seems to counter-intuitive. I'm not sure how to
overcome this, but perhaps it would be better to allow for an argument
to LATEX_CLASS, e.g.
(*) #+LATEX_CLASS: myclass :class-name ctexart.
as e.g. the INCLUDE command. Of course (*) is somewhat different from
how stuff like this is usually handled, cf. e.g. LATEX_CLASS_OPTIONS.
–Rasmus
--
A clever person solves a problem. A wise person avoids it
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 9:13 ` Rasmus
@ 2013-06-14 9:50 ` Nick Dokos
2013-06-14 10:09 ` Rasmus
2013-06-14 10:42 ` Feng Shu
2013-06-14 9:55 ` Feng Shu
1 sibling, 2 replies; 12+ messages in thread
From: Nick Dokos @ 2013-06-14 9:50 UTC (permalink / raw)
To: emacs-orgmode
Rasmus <rasmus@gmx.us> writes:
> Feng Shu <tumashu@gmail.com> writes:
>
>> #+LATEX_CLASS: article
>> #+LATEX_CLASS_NAME: ctexart
>
> I'm not sure this is the right approach. . . I can certainly see the
> value of generating classes on the fly, though. But somehow the
> proposed syntax just seems to counter-intuitive. I'm not sure how to
> overcome this, but perhaps it would be better to allow for an argument
> to LATEX_CLASS, e.g.
>
> (*) #+LATEX_CLASS: myclass :class-name ctexart.
>
That was what popped into my head as well - I didn't much care for the
OP's approach. Now that I've thought about it some more, I'm not sure I
like this one much better...
> as e.g. the INCLUDE command. Of course (*) is somewhat different from
> how stuff like this is usually handled, cf. e.g. LATEX_CLASS_OPTIONS.
>
...but this sounds a bit more promising: maybe LATEX_CLASS_OPTIONS can
be eliminated in favor of LATEX_CLASS with arguments:
#+LATEX_CLASS: key :class-name foo :class-options a4paper,12pt
where "key" selects from org-latex-classes (and is optional, default
"article"), class-name is optional and defaults to key (or article if
key is absent).
--
Nick
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 9:50 ` Nick Dokos
@ 2013-06-14 10:09 ` Rasmus
2013-06-14 10:42 ` Feng Shu
1 sibling, 0 replies; 12+ messages in thread
From: Rasmus @ 2013-06-14 10:09 UTC (permalink / raw)
To: emacs-orgmode
Nick Dokos <ndokos@gmail.com> writes:
>> as e.g. the INCLUDE command. Of course (*) is somewhat different from
>> how stuff like this is usually handled, cf. e.g. LATEX_CLASS_OPTIONS.
>>
> ...but this sounds a bit more promising: maybe LATEX_CLASS_OPTIONS can
> be eliminated in favor of LATEX_CLASS with arguments:
>
> #+LATEX_CLASS: key :class-name foo :class-options a4paper,12pt
>
> where "key" selects from org-latex-classes (and is optional, default
> "article"), class-name is optional and defaults to key (or article if
> key is absent).
Yeah, I instantly though of getting rid of class options as well: and
I'm all for it!
Another issue is that class options are overwritten. Perhaps that's
an issue for another thread, however.
–Rasmus
--
A page of history is worth a volume of logic
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 9:50 ` Nick Dokos
2013-06-14 10:09 ` Rasmus
@ 2013-06-14 10:42 ` Feng Shu
1 sibling, 0 replies; 12+ messages in thread
From: Feng Shu @ 2013-06-14 10:42 UTC (permalink / raw)
To: emacs-orgmode
Nick Dokos <ndokos@gmail.com> writes:
> Rasmus <rasmus@gmx.us> writes:
>
>> Feng Shu <tumashu@gmail.com> writes:
>>
>>> #+LATEX_CLASS: article
>>> #+LATEX_CLASS_NAME: ctexart
>>
>> I'm not sure this is the right approach. . . I can certainly see the
>> value of generating classes on the fly, though. But somehow the
>> proposed syntax just seems to counter-intuitive. I'm not sure how to
>> overcome this, but perhaps it would be better to allow for an argument
>> to LATEX_CLASS, e.g.
>>
>> (*) #+LATEX_CLASS: myclass :class-name ctexart.
>>
>
> That was what popped into my head as well - I didn't much care for the
> OP's approach. Now that I've thought about it some more, I'm not sure I
> like this one much better...
>
>> as e.g. the INCLUDE command. Of course (*) is somewhat different from
>> how stuff like this is usually handled, cf. e.g. LATEX_CLASS_OPTIONS.
>>
> ...but this sounds a bit more promising: maybe LATEX_CLASS_OPTIONS can
> be eliminated in favor of LATEX_CLASS with arguments:
>
> #+LATEX_CLASS: key :class-name foo :class-options a4paper,12pt
May be we should add this feature too:
#+LaTEX_CLASS: key :class-name foo :class-options+ twoside
#+LaTEX_CLASS: key :class-name foo :class-options- twoside
>
> where "key" selects from org-latex-classes (and is optional, default
> "article"), class-name is optional and defaults to key (or article if
> key is absent).
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 9:13 ` Rasmus
2013-06-14 9:50 ` Nick Dokos
@ 2013-06-14 9:55 ` Feng Shu
2013-06-14 11:50 ` Suvayu Ali
1 sibling, 1 reply; 12+ messages in thread
From: Feng Shu @ 2013-06-14 9:55 UTC (permalink / raw)
To: Rasmus; +Cc: emacs-orgmode
Rasmus <rasmus@gmx.us> writes:
> Feng Shu <tumashu@gmail.com> writes:
>
>> #+LATEX_CLASS: article
>> #+LATEX_CLASS_NAME: ctexart
>
> I'm not sure this is the right approach. . . I can certainly see the
> value of generating classes on the fly, though. But somehow the
> proposed syntax just seems to counter-intuitive. I'm not sure how to
> overcome this, but perhaps it would be better to allow for an argument
> to LATEX_CLASS, e.g.
>
> (*) #+LATEX_CLASS: myclass :class-name ctexart.
CLASS and class-name are confusing, I think LATEX_CLASS should rename
to LATEX_CLASS_FORMAT or LATEX_CLASS_TEMPLATE, but this will break
compatibility.
>
> as e.g. the INCLUDE command. Of course (*) is somewhat different from
> how stuff like this is usually handled, cf. e.g. LATEX_CLASS_OPTIONS.
>
> –Rasmus
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 9:55 ` Feng Shu
@ 2013-06-14 11:50 ` Suvayu Ali
0 siblings, 0 replies; 12+ messages in thread
From: Suvayu Ali @ 2013-06-14 11:50 UTC (permalink / raw)
To: emacs-orgmode
On Fri, Jun 14, 2013 at 05:55:56PM +0800, Feng Shu wrote:
>
> CLASS and class-name are confusing, I think LATEX_CLASS should rename
> to LATEX_CLASS_FORMAT or LATEX_CLASS_TEMPLATE, but this will break
> compatibility.
IMO compatibility is a big and important issue, and not to be taken
lightly.
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-13 6:14 [PATCH] Override the default class name with a new one Feng Shu
2013-06-13 23:55 ` Feng Shu
@ 2013-06-14 13:36 ` Nicolas Goaziou
2013-06-14 15:13 ` Feng Shu
1 sibling, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-06-14 13:36 UTC (permalink / raw)
To: Feng Shu; +Cc: orgmode
Hello,
Feng Shu <tumashu@gmail.com> writes:
> #+LATEX_CLASS: article
>
> %%output:
>
> \documentclass[11pt]{article}
>
> ...
>
> --------------------------------------
>
> #+LATEX_CLASS: article
> #+LATEX_CLASS_NAME: ctexart
>
> %%output:
>
> \documentclass[11pt]{ctexart}
>
> ....
Thanks for your patch.
Though, it adds another keyword and another defcustom without providing
any new functionality. I understand it is a shortcut, but the cons, IMO,
outweigh the pros : adding a new class to `org-latex-classes' is a bit
more tedious, but needs to be done only once.
Therefore, unless you convince me this feature brings something new, or
clearly eases a process, I'll stand on my ground.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 13:36 ` Nicolas Goaziou
@ 2013-06-14 15:13 ` Feng Shu
2013-06-18 19:34 ` Nicolas Goaziou
0 siblings, 1 reply; 12+ messages in thread
From: Feng Shu @ 2013-06-14 15:13 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Hello,
>
> Feng Shu <tumashu@gmail.com> writes:
>
>> #+LATEX_CLASS: article
>>
>> %%output:
>>
>> \documentclass[11pt]{article}
>>
>> ...
>>
>> --------------------------------------
>>
>> #+LATEX_CLASS: article
>> #+LATEX_CLASS_NAME: ctexart
>>
>> %%output:
>>
>> \documentclass[11pt]{ctexart}
>>
>> ....
>
> Thanks for your patch.
>
> Though, it adds another keyword and another defcustom without providing
> any new functionality. I understand it is a shortcut, but the cons, IMO,
> outweigh the pros : adding a new class to `org-latex-classes' is a bit
> more tedious, but needs to be done only once.
>
> Therefore, unless you convince me this feature brings something new, or
> clearly eases a process, I'll stand on my ground.
Not all the org-mode users are expert of lisp and not all of the org-mode
users are well in English, so finding the variable `org-latex-classes can
customize latex class and adding a lisp block to it may be not a easy
things for many users.
So I expect org-mode can properly export latex without any configure,
but it is impossible for the complexity of tex system. So
reusing exist `org-latex-classes items will become a valuable thing,
it should be implement. My patch is not best way to implement and it can
be deny, but the problem can't be ignore.
1. we can add a function `(defun org-latex-add-deriverd-class (class exist-class) ...) to menupulate `org-latex-classes
2. My patch's approach.
3. others.
>
>
> Regards,
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-14 15:13 ` Feng Shu
@ 2013-06-18 19:34 ` Nicolas Goaziou
2013-06-18 22:33 ` Rasmus
0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-06-18 19:34 UTC (permalink / raw)
To: Feng Shu; +Cc: orgmode
Hello,
Feng Shu <tumashu@gmail.com> writes:
> Not all the org-mode users are expert of lisp and not all of the org-mode
> users are well in English, so finding the variable `org-latex-classes can
> customize latex class and adding a lisp block to it may be not a easy
> things for many users.
I understand, and I agree we should make this very important variable
understandable to any user.
> 1. we can add a function `(defun org-latex-add-deriverd-class (class exist-class) ...) to menupulate `org-latex-classes
> 2. My patch's approach.
> 3. others.
We can modify `org-latex-classes' docstring (e.g. by adding examples) so
it is easier to understand. I'd rather have a patch in that direction
than to add yet another variable and keyword.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH] Override the default class name with a new one.
2013-06-18 19:34 ` Nicolas Goaziou
@ 2013-06-18 22:33 ` Rasmus
0 siblings, 0 replies; 12+ messages in thread
From: Rasmus @ 2013-06-18 22:33 UTC (permalink / raw)
To: n.goaziou; +Cc: tumashu, emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
>> 1. we can add a function `(defun org-latex-add-deriverd-class (class
>> exist-class) ...) to menupulate `org-latex-classes
>> 2. My patch's approach.
>> 3. others.
>
> We can modify `org-latex-classes' docstring (e.g. by adding examples) so
> it is easier to understand. I'd rather have a patch in that direction
> than to add yet another variable and keyword.
Perhaps the users who'd feel uncomfortable with add-to-list of
org-latex-class are more likely to read org.texi (or more likely
org.html).
I'm working on adding a paragraph/example to org.texi.
I still think changing document class on the fly might be useful
although not really necessary
–Rasmus
--
Send from my Emacs
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-06-18 22:42 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-13 6:14 [PATCH] Override the default class name with a new one Feng Shu
2013-06-13 23:55 ` Feng Shu
2013-06-14 9:13 ` Rasmus
2013-06-14 9:50 ` Nick Dokos
2013-06-14 10:09 ` Rasmus
2013-06-14 10:42 ` Feng Shu
2013-06-14 9:55 ` Feng Shu
2013-06-14 11:50 ` Suvayu Ali
2013-06-14 13:36 ` Nicolas Goaziou
2013-06-14 15:13 ` Feng Shu
2013-06-18 19:34 ` Nicolas Goaziou
2013-06-18 22:33 ` Rasmus
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).