emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] latex export - title placement
@ 2011-05-28 12:42 Sebastian Hofer
  2011-05-28 12:59 ` Sebastian Hofer
  2011-05-28 17:27 ` Thomas S. Dye
  0 siblings, 2 replies; 12+ messages in thread
From: Sebastian Hofer @ 2011-05-28 12:42 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]

Hi all,

This patch addresses the problem of ambiguous conventions for the
placement of the title related macros (\author, \date,...) with
respect to the main document body in different latex classes. It
introduces the following changes:

* org-exp.el:
    - added the following options:
      - title-position (tpos)
      - with-title (wtitle)
      - with-author (wauth)
      - with-date (wdate)
      - with-maketitle (wmtitle)
    
* org-latex.el:
    - implemented handling of new options (see above):
      - title-position controls placement of \title, \author, \date;
        possible values are "b" = before \begin{document},
        any other values default to after \begin{document}
      - with-* controls if the corresponding macro is exported at all
        this can be convenient for more complex titles (e.g. several
        authors including affiliations,...)

The patch seems to work for me so far. What do you all think? IMO it
would be useful to integrate this, as it gives slightly more control
over the export process. Of course one might want to think about
better option names. The diff is done against commit
bc161ded3693f752616dcd247fc9d638789025ee.

Let me briefly describe my current use case:
I disable all commands except \title, use babel to created a title.tex
file (including several authors and affiliations) by tangling latex
code and then include the file (into the main body of the document,
not the preamble). That's the only decent way I've found to do this,
if anyone knows an easier way (I have the feeling that I might be
overlooking an obvious solution) please let me know!

Cheers
Sebastian


[-- Attachment #2: org-patch.diff --]
[-- Type: application/octet-stream, Size: 5733 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index d6ed193..e8086a6 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -618,6 +618,8 @@ table.el tables."
 (defvar org-min-level nil) ; dynamically scoped variable
 (defvar org-levels-open nil) ; dynamically scoped parameter
 
+;; patched
+;; Time-stamp: <2011-05-27 19:12:11 c705264>
 (defconst org-export-plist-vars
   '((:link-up		      nil	  org-export-html-link-up)
     (:link-home		      nil	  org-export-html-link-home)
@@ -672,7 +674,13 @@ table.el tables."
     (:select-tags	      nil	  org-export-select-tags)
     (:exclude-tags	      nil	  org-export-exclude-tags)
 
-    (:latex-image-options     nil	  org-export-latex-image-default-option))
+    (:latex-image-options     nil	  org-export-latex-image-default-option)
+    (:latex-title-position    "tpos"	  org-export-latex-title-position)
+    (:latex-with-author       "wauth"	  org-export-latex-with-author)
+    (:latex-with-date         "wdate"	  org-export-latex-with-date)
+    (:latex-with-title        "wtitle"	  org-export-latex-with-title)
+    (:latex-with-maketitle    "wmtitle"	  org-export-latex-with-maketitle)
+    )
   "List of properties that represent export/publishing variables.
 Each element is a list of 3 items:
 1. The property that is used internally, and also for org-publish-project-alist
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 764a48d..c2dc8df 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -78,6 +78,26 @@
 
 ;;; User variables:
 
+;; begin patched
+;; Time-stamp: <2011-05-27 18:31:51 c705264>
+
+(defvar org-export-latex-title-position "b"
+  "Determines if \\title, \\author, \\email and \\date commands are inserted before (default) or
+  after (\"a\") \\begin{document}.")
+
+(defvar org-export-latex-with-maketitle t
+  "Determines if \\maketitle is inserted")
+
+(defvar org-export-latex-with-author t
+  "Determines if \\author is inserted")
+
+(defvar org-export-latex-with-date t
+  "Determines if \\date is inserted")
+
+(defvar org-export-latex-with-title t
+  "Determines if \\title is inserted")
+;; end patched
+
 (defgroup org-export-latex nil
   "Options for exporting Org-mode files to LaTeX."
   :tag "Org Export LaTeX"
@@ -1334,6 +1354,8 @@ LEVEL indicates the default depth for export."
   "The function formatting returning the string to create the table of contents.
 The function mus take one parameter, the depth of the table of contents.")
 
+;; patched
+;; Time-stamp: <2011-05-27 19:06:33 c705264>
 (defun org-export-latex-make-header (title opt-plist)
   "Make the LaTeX header and return it as a string.
 TITLE is the current title from the buffer or region.
@@ -1344,7 +1366,12 @@ OPT-PLIST is the options plist for current buffer."
 	(email (replace-regexp-in-string
 		"_" "\\\\_"
 		(org-export-apply-macros-in-string
-		 (plist-get opt-plist :email)))))
+		 (plist-get opt-plist :email))))
+	(title-position (plist-get opt-plist :latex-title-position))
+	(with-author (plist-get opt-plist :latex-with-author))
+	(with-date (plist-get opt-plist :latex-with-date))
+	(with-title (plist-get opt-plist :latex-with-title))
+	(with-maketitle (plist-get opt-plist :latex-with-maketitle)))
     (concat
      (if (plist-get opt-plist :time-stamp-file)
 	 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
@@ -1359,33 +1386,43 @@ OPT-PLIST is the options plist for current buffer."
      (org-export-apply-macros-in-string org-export-latex-append-header)
      ;; define alert if not yet defined
      "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
+     "\n\n"
+     ;; beginning of the document (title after \begin{document})
+     (when (not (string= "b" title-position))
+       "\n\\begin{document}\n\n")
      ;; insert the title
-     (format
-      "\n\n\\title{%s}\n"
-      (org-export-latex-fontify-headline title))
+     (when with-title
+       (format
+       "\\title{%s}\n"
+       (org-export-latex-fontify-headline title)))
      ;; insert author info
-     (if (plist-get opt-plist :author-info)
-	 (format "\\author{%s%s}\n"
-		 (org-export-latex-fontify-headline (or author user-full-name))
-		 (if (and (plist-get opt-plist :email-info) email
-			  (string-match "\\S-" email))
-		     (format "\\thanks{%s}" email)
-		   ""))
-       (format "%%\\author{%s}\n"
-	       (org-export-latex-fontify-headline (or author user-full-name))))
+     (when with-author
+       (if (plist-get opt-plist :author-info)
+	  (format "\\author{%s%s}\n"
+		  (org-export-latex-fontify-headline (or author user-full-name))
+		  (if (and (plist-get opt-plist :email-info) email
+			   (string-match "\\S-" email))
+		      (format "\\thanks{%s}" email)
+		    ""))
+	(format "%%\\author{%s}\n"
+		(org-export-latex-fontify-headline (or author user-full-name)))))
      ;; insert the date
-     (format "\\date{%s}\n"
-	     (format-time-string
-	      (or (plist-get opt-plist :date)
-		  org-export-latex-date-format)))
-     ;; beginning of the document
-     "\n\\begin{document}\n\n"
+     (when with-date
+       (format "\\date{%s}\n"
+	      (format-time-string
+	       (or (plist-get opt-plist :date)
+		   org-export-latex-date-format))))
+
      ;; insert the title command
-     (when (string-match "\\S-" title)
+     (when (and (string-match "\\S-" title) with-maketitle)
+       "\n\n"
        (if (string-match "%s" org-export-latex-title-command)
 	   (format org-export-latex-title-command title)
 	 org-export-latex-title-command))
      "\n\n"
+     ;; beginning of the document (maketitle before \begin{document})
+     (when (string= "b" title-position)
+       "\n\\begin{document}\n\n")
      ;; table of contents
      (when (and org-export-with-toc
 		(plist-get opt-plist :section-numbers))

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-05-28 12:42 Sebastian Hofer
@ 2011-05-28 12:59 ` Sebastian Hofer
  2011-05-28 17:27 ` Thomas S. Dye
  1 sibling, 0 replies; 12+ messages in thread
From: Sebastian Hofer @ 2011-05-28 12:59 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 157 bytes --]

I just now saw the FAQ entry on sending patches, sorry for that!
I'm reposting the patch with the proper mime-type. Hope it's correct this time!

Sebastian


[-- Attachment #2: org-patch.diff --]
[-- Type: text/plain, Size: 5733 bytes --]

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index d6ed193..e8086a6 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -618,6 +618,8 @@ table.el tables."
 (defvar org-min-level nil) ; dynamically scoped variable
 (defvar org-levels-open nil) ; dynamically scoped parameter
 
+;; patched
+;; Time-stamp: <2011-05-27 19:12:11 c705264>
 (defconst org-export-plist-vars
   '((:link-up		      nil	  org-export-html-link-up)
     (:link-home		      nil	  org-export-html-link-home)
@@ -672,7 +674,13 @@ table.el tables."
     (:select-tags	      nil	  org-export-select-tags)
     (:exclude-tags	      nil	  org-export-exclude-tags)
 
-    (:latex-image-options     nil	  org-export-latex-image-default-option))
+    (:latex-image-options     nil	  org-export-latex-image-default-option)
+    (:latex-title-position    "tpos"	  org-export-latex-title-position)
+    (:latex-with-author       "wauth"	  org-export-latex-with-author)
+    (:latex-with-date         "wdate"	  org-export-latex-with-date)
+    (:latex-with-title        "wtitle"	  org-export-latex-with-title)
+    (:latex-with-maketitle    "wmtitle"	  org-export-latex-with-maketitle)
+    )
   "List of properties that represent export/publishing variables.
 Each element is a list of 3 items:
 1. The property that is used internally, and also for org-publish-project-alist
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 764a48d..c2dc8df 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -78,6 +78,26 @@
 
 ;;; User variables:
 
+;; begin patched
+;; Time-stamp: <2011-05-27 18:31:51 c705264>
+
+(defvar org-export-latex-title-position "b"
+  "Determines if \\title, \\author, \\email and \\date commands are inserted before (default) or
+  after (\"a\") \\begin{document}.")
+
+(defvar org-export-latex-with-maketitle t
+  "Determines if \\maketitle is inserted")
+
+(defvar org-export-latex-with-author t
+  "Determines if \\author is inserted")
+
+(defvar org-export-latex-with-date t
+  "Determines if \\date is inserted")
+
+(defvar org-export-latex-with-title t
+  "Determines if \\title is inserted")
+;; end patched
+
 (defgroup org-export-latex nil
   "Options for exporting Org-mode files to LaTeX."
   :tag "Org Export LaTeX"
@@ -1334,6 +1354,8 @@ LEVEL indicates the default depth for export."
   "The function formatting returning the string to create the table of contents.
 The function mus take one parameter, the depth of the table of contents.")
 
+;; patched
+;; Time-stamp: <2011-05-27 19:06:33 c705264>
 (defun org-export-latex-make-header (title opt-plist)
   "Make the LaTeX header and return it as a string.
 TITLE is the current title from the buffer or region.
@@ -1344,7 +1366,12 @@ OPT-PLIST is the options plist for current buffer."
 	(email (replace-regexp-in-string
 		"_" "\\\\_"
 		(org-export-apply-macros-in-string
-		 (plist-get opt-plist :email)))))
+		 (plist-get opt-plist :email))))
+	(title-position (plist-get opt-plist :latex-title-position))
+	(with-author (plist-get opt-plist :latex-with-author))
+	(with-date (plist-get opt-plist :latex-with-date))
+	(with-title (plist-get opt-plist :latex-with-title))
+	(with-maketitle (plist-get opt-plist :latex-with-maketitle)))
     (concat
      (if (plist-get opt-plist :time-stamp-file)
 	 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
@@ -1359,33 +1386,43 @@ OPT-PLIST is the options plist for current buffer."
      (org-export-apply-macros-in-string org-export-latex-append-header)
      ;; define alert if not yet defined
      "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
+     "\n\n"
+     ;; beginning of the document (title after \begin{document})
+     (when (not (string= "b" title-position))
+       "\n\\begin{document}\n\n")
      ;; insert the title
-     (format
-      "\n\n\\title{%s}\n"
-      (org-export-latex-fontify-headline title))
+     (when with-title
+       (format
+       "\\title{%s}\n"
+       (org-export-latex-fontify-headline title)))
      ;; insert author info
-     (if (plist-get opt-plist :author-info)
-	 (format "\\author{%s%s}\n"
-		 (org-export-latex-fontify-headline (or author user-full-name))
-		 (if (and (plist-get opt-plist :email-info) email
-			  (string-match "\\S-" email))
-		     (format "\\thanks{%s}" email)
-		   ""))
-       (format "%%\\author{%s}\n"
-	       (org-export-latex-fontify-headline (or author user-full-name))))
+     (when with-author
+       (if (plist-get opt-plist :author-info)
+	  (format "\\author{%s%s}\n"
+		  (org-export-latex-fontify-headline (or author user-full-name))
+		  (if (and (plist-get opt-plist :email-info) email
+			   (string-match "\\S-" email))
+		      (format "\\thanks{%s}" email)
+		    ""))
+	(format "%%\\author{%s}\n"
+		(org-export-latex-fontify-headline (or author user-full-name)))))
      ;; insert the date
-     (format "\\date{%s}\n"
-	     (format-time-string
-	      (or (plist-get opt-plist :date)
-		  org-export-latex-date-format)))
-     ;; beginning of the document
-     "\n\\begin{document}\n\n"
+     (when with-date
+       (format "\\date{%s}\n"
+	      (format-time-string
+	       (or (plist-get opt-plist :date)
+		   org-export-latex-date-format))))
+
      ;; insert the title command
-     (when (string-match "\\S-" title)
+     (when (and (string-match "\\S-" title) with-maketitle)
+       "\n\n"
        (if (string-match "%s" org-export-latex-title-command)
 	   (format org-export-latex-title-command title)
 	 org-export-latex-title-command))
      "\n\n"
+     ;; beginning of the document (maketitle before \begin{document})
+     (when (string= "b" title-position)
+       "\n\\begin{document}\n\n")
      ;; table of contents
      (when (and org-export-with-toc
 		(plist-get opt-plist :section-numbers))

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-05-28 12:42 Sebastian Hofer
  2011-05-28 12:59 ` Sebastian Hofer
@ 2011-05-28 17:27 ` Thomas S. Dye
  2011-06-01 22:05   ` Nick Dokos
  1 sibling, 1 reply; 12+ messages in thread
From: Thomas S. Dye @ 2011-05-28 17:27 UTC (permalink / raw)
  To: Sebastian Hofer; +Cc: emacs-orgmode

Sebastian Hofer <sebhofer@gmail.com> writes:

> Hi all,
>
> This patch addresses the problem of ambiguous conventions for the
> placement of the title related macros (\author, \date,...) with
> respect to the main document body in different latex classes. It
> introduces the following changes:
>
> * org-exp.el:
>     - added the following options:
>       - title-position (tpos)
>       - with-title (wtitle)
>       - with-author (wauth)
>       - with-date (wdate)
>       - with-maketitle (wmtitle)
>     
> * org-latex.el:
>     - implemented handling of new options (see above):
>       - title-position controls placement of \title, \author, \date;
>         possible values are "b" = before \begin{document},
>         any other values default to after \begin{document}
>       - with-* controls if the corresponding macro is exported at all
>         this can be convenient for more complex titles (e.g. several
>         authors including affiliations,...)
>
> The patch seems to work for me so far. What do you all think? IMO it
> would be useful to integrate this, as it gives slightly more control
> over the export process. Of course one might want to think about
> better option names. The diff is done against commit
> bc161ded3693f752616dcd247fc9d638789025ee.
>
> Let me briefly describe my current use case:
> I disable all commands except \title, use babel to created a title.tex
> file (including several authors and affiliations) by tangling latex
> code and then include the file (into the main body of the document,
> not the preamble). That's the only decent way I've found to do this,
> if anyone knows an easier way (I have the feeling that I might be
> overlooking an obvious solution) please let me know!
>
> Cheers
> Sebastian
>
>
Aloha Sebastian,

Your patch should prove useful in the situation where one has to use a
particular class file that requires \title and friends to be declared in
the body of the document rather than the preamble.  That functionality
is a welcome addition to the LaTeX exporter, IMO.

Another way to achieve your current use case, IIUC, which might or might
not seem easier, is to redefine \maketitle along the lines suggested by
Nick Dokos (see
http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-11_2).

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-05-28 17:27 ` Thomas S. Dye
@ 2011-06-01 22:05   ` Nick Dokos
  2011-06-01 23:19     ` Thomas S. Dye
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Nick Dokos @ 2011-06-01 22:05 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Sebastian Hofer, nicholas.dokos, emacs-orgmode

Thomas S. Dye <tsd@tsdye.com> wrote:

> Sebastian Hofer <sebhofer@gmail.com> writes:
> 
> > Hi all,
> >
> > This patch addresses the problem of ambiguous conventions for the
> > placement of the title related macros (\author, \date,...) with
> > respect to the main document body in different latex classes. It
> > introduces the following changes:
> >
> > * org-exp.el:
> >     - added the following options:
> >       - title-position (tpos)
> >       - with-title (wtitle)
> >       - with-author (wauth)

[This is mostly addressed to Sebastian even though I'm replying to Tom's
reply.]

An empty

#+AUTHOR:

disables the insertion of author (assuming that TITLE is not empty -
see below.)


> >       - with-date (wdate)

An empty

#+DATE:

disables the insertion of date (same assumption.)

> >       - with-maketitle (wmtitle)

An empty

#+TITLE:

disables the insertion of \maketitle.

So if TITLE is not empty, you can get what you want with existing
machinery. I could not find a way to make the title empty  and still
have author and/or date fields.

Given all this, I think the only things you need is title-position and
with-title, the latter in the unlikely event that you want a title page
with author or date but without a title. Personally, I'd consider this
last one unimportant and not worry about it, but you may disagree.

> >     
> > * org-latex.el:
> >     - implemented handling of new options (see above):
> >       - title-position controls placement of \title, \author, \date;
> >         possible values are "b" = before \begin{document},
> >         any other values default to after \begin{document}
> >       - with-* controls if the corresponding macro is exported at all
> >         this can be convenient for more complex titles (e.g. several
> >         authors including affiliations,...)
> >
> > The patch seems to work for me so far. What do you all think? IMO it
> > would be useful to integrate this, as it gives slightly more control
> > over the export process. Of course one might want to think about
> > better option names. The diff is done against commit
> > bc161ded3693f752616dcd247fc9d638789025ee.
> >
> > Let me briefly describe my current use case:
> > I disable all commands except \title, use babel to created a title.tex
> > file (including several authors and affiliations) by tangling latex
> > code and then include the file (into the main body of the document,
> > not the preamble). That's the only decent way I've found to do this,
> > if anyone knows an easier way (I have the feeling that I might be
> > overlooking an obvious solution) please let me know!
> >

I'm not sure what problem you are trying to solve here: can you explain?
It seems to me that all this can be done in standard ways.

> > Cheers
> > Sebastian
> >
> >
> Aloha Sebastian,
> 
> Your patch should prove useful in the situation where one has to use a
> particular class file that requires \title and friends to be declared in
> the body of the document rather than the preamble.  That functionality
> is a welcome addition to the LaTeX exporter, IMO.
> 

IIUC, the only remaining thing is the position of the \title etc macros
in the preamble or the body (or both).

There are three categories of LaTeX classes: the ones that implement
Lamport's dictum that \title etc can come anywhere before \maketitle,
the ones like RevTeX that insist on having them in the body and the ones
like the thesis document class at Suvayu's university, that insist on
having them in the preamble. I consider both of the latter two as buggy:
has anybody submitted a bug report on them?

Has anybody researched the prevalence of these bugs? Are there lots of
classes in one or the other of the buggy categories?

Be that as it may, it seems that org needs a patch to work around these
bugs.  Personally, since it is a class problem, I'd rather have this
kind of information in the class template.  You set it once for each
class that needs it and you forget about it. Assuming the maintainers
agree, any chance of reworking the patch along these lines? Maybe make
it extensible as well: a property list that can accumulate all the junk
in one place perhaps. That way the RevTeX class can be configured
appropriately and the rest of the world can live in blissful ignorance
of the problem. You might detect a bias here: I prefer these things in
the preamble by default.

> Another way to achieve your current use case, IIUC, which might or might
> not seem easier, is to redefine \maketitle along the lines suggested by
> Nick Dokos (see
> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-11_2).
> 

As I mentioned, I'm not really sure what Sebastian is looking for, so I
can't really say whether the above would help, but if it can be done
this way, I think it would be preferable to introducing new user options
for the exlusive use of the org latex exporter. There are legitimate uses
for user options but working around bugs in downstream packages is
not one of them. IMO, of course.

Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-01 22:05   ` Nick Dokos
@ 2011-06-01 23:19     ` Thomas S. Dye
  2011-06-01 23:55     ` Nick Dokos
  2011-06-02  8:12     ` Sebastian Hofer
  2 siblings, 0 replies; 12+ messages in thread
From: Thomas S. Dye @ 2011-06-01 23:19 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Sebastian Hofer, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> Thomas S. Dye <tsd@tsdye.com> wrote:
>
>> Sebastian Hofer <sebhofer@gmail.com> writes:
>> 
>> > Hi all,
>> >
>> > This patch addresses the problem of ambiguous conventions for the
>> > placement of the title related macros (\author, \date,...) with
>> > respect to the main document body in different latex classes. It
>> > introduces the following changes:
>> >
>> > * org-exp.el:
>> >     - added the following options:
>> >       - title-position (tpos)
>> >       - with-title (wtitle)
>> >       - with-author (wauth)
>
> [This is mostly addressed to Sebastian even though I'm replying to Tom's
> reply.]
>
> An empty
>
> #+AUTHOR:
>
> disables the insertion of author (assuming that TITLE is not empty -
> see below.)
>
>
>> >       - with-date (wdate)
>
> An empty
>
> #+DATE:
>
> disables the insertion of date (same assumption.)
>
>> >       - with-maketitle (wmtitle)
>
> An empty
>
> #+TITLE:
>
> disables the insertion of \maketitle.
>
> So if TITLE is not empty, you can get what you want with existing
> machinery. I could not find a way to make the title empty  and still
> have author and/or date fields.
>
> Given all this, I think the only things you need is title-position and
> with-title, the latter in the unlikely event that you want a title page
> with author or date but without a title. Personally, I'd consider this
> last one unimportant and not worry about it, but you may disagree.
>
>> >     
>> > * org-latex.el:
>> >     - implemented handling of new options (see above):
>> >       - title-position controls placement of \title, \author, \date;
>> >         possible values are "b" = before \begin{document},
>> >         any other values default to after \begin{document}
>> >       - with-* controls if the corresponding macro is exported at all
>> >         this can be convenient for more complex titles (e.g. several
>> >         authors including affiliations,...)
>> >
>> > The patch seems to work for me so far. What do you all think? IMO it
>> > would be useful to integrate this, as it gives slightly more control
>> > over the export process. Of course one might want to think about
>> > better option names. The diff is done against commit
>> > bc161ded3693f752616dcd247fc9d638789025ee.
>> >
>> > Let me briefly describe my current use case:
>> > I disable all commands except \title, use babel to created a title.tex
>> > file (including several authors and affiliations) by tangling latex
>> > code and then include the file (into the main body of the document,
>> > not the preamble). That's the only decent way I've found to do this,
>> > if anyone knows an easier way (I have the feeling that I might be
>> > overlooking an obvious solution) please let me know!
>> >
>
> I'm not sure what problem you are trying to solve here: can you explain?
> It seems to me that all this can be done in standard ways.
>
>> > Cheers
>> > Sebastian
>> >
>> >
>> Aloha Sebastian,
>> 
>> Your patch should prove useful in the situation where one has to use a
>> particular class file that requires \title and friends to be declared in
>> the body of the document rather than the preamble.  That functionality
>> is a welcome addition to the LaTeX exporter, IMO.
>> 
>
> IIUC, the only remaining thing is the position of the \title etc macros
> in the preamble or the body (or both).
>
> There are three categories of LaTeX classes: the ones that implement
> Lamport's dictum that \title etc can come anywhere before \maketitle,
> the ones like RevTeX that insist on having them in the body and the ones
> like the thesis document class at Suvayu's university, that insist on
> having them in the preamble. I consider both of the latter two as buggy:
> has anybody submitted a bug report on them?
>
> Has anybody researched the prevalence of these bugs? Are there lots of
> classes in one or the other of the buggy categories?
>
> Be that as it may, it seems that org needs a patch to work around these
> bugs.  Personally, since it is a class problem, I'd rather have this
> kind of information in the class template.  You set it once for each
> class that needs it and you forget about it. Assuming the maintainers
> agree, any chance of reworking the patch along these lines? Maybe make
> it extensible as well: a property list that can accumulate all the junk
> in one place perhaps. That way the RevTeX class can be configured
> appropriately and the rest of the world can live in blissful ignorance
> of the problem. You might detect a bias here: I prefer these things in
> the preamble by default.
>
>> Another way to achieve your current use case, IIUC, which might or might
>> not seem easier, is to redefine \maketitle along the lines suggested by
>> Nick Dokos (see
>> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-11_2).
>> 
>
> As I mentioned, I'm not really sure what Sebastian is looking for, so I
> can't really say whether the above would help, but if it can be done
> this way, I think it would be preferable to introducing new user options
> for the exlusive use of the org latex exporter. There are legitimate uses
> for user options but working around bugs in downstream packages is
> not one of them. IMO, of course.
>
> Nick
>

Aloha Nick,

Your analysis and explanation makes it clear to me that the class
template is the best place for title-position.  I hope it proves
possible to put it there.

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-01 22:05   ` Nick Dokos
  2011-06-01 23:19     ` Thomas S. Dye
@ 2011-06-01 23:55     ` Nick Dokos
  2011-06-02  8:36       ` Sebastian Hofer
  2011-06-02  8:12     ` Sebastian Hofer
  2 siblings, 1 reply; 12+ messages in thread
From: Nick Dokos @ 2011-06-01 23:55 UTC (permalink / raw)
  Cc: Sebastian Hofer, nicholas.dokos, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> wrote:

> IIUC, the only remaining thing is the position of the \title etc macros
> in the preamble or the body (or both).
> 
> There are three categories of LaTeX classes: the ones that implement
> Lamport's dictum that \title etc can come anywhere before \maketitle,
> the ones like RevTeX that insist on having them in the body and the ones
> like the thesis document class at Suvayu's university, that insist on
> having them in the preamble. I consider both of the latter two as buggy:
> has anybody submitted a bug report on them?
> 

I tried an experiment:

I cannot get at the thesis document class at Suvayu's university but I
most certainly can get to RevTeX. So I started with a simple org file:

,----
| #+LATEX_CLASS: revtex4-1
| #+TITLE: foo
| #+AUTHOR: nick
| #+DATE:
| 
| * foo
| 
| bar
`----


I then added a definition for the revtex4-1 class to org-export-latex-classes.
I just copied the article class and renamed appropriately:

,----
|     ...
|     ("revtex4-1"
|      "\\documentclass[11pt]{revtex4-1}"
|      ("\\section{%s}" . "\\section*{%s}")
|      ("\\subsection{%s}" . "\\subsection*{%s}")
|      ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
|      ("\\paragraph{%s}" . "\\paragraph*{%s}")
|      ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
|     ...
`----


Exporting to latex and compiling gives errors, the first one of which says:

,----
| ...
| *hyperref using default driver hpdftex*
| (/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def)
| ! Undefined control sequence.
| <argument> \collaboration@sw 
|                              {\advance \c@collab \@ne \@argswap {\CO@grp \CO...
| l.21 \author{nick}
| ...
`----

Basically, \author{nick} got expanded into something involving \collaboration@sw which
is currently undefined. So off to /usr/share/texmf-texlive/tex/latex/revtex/revtex4-1.cls
I went and found the following expansion sequence:

   \author -> \frontmatter@author -> \@author@def -> \move@AU -> \collaboration@sw -> ...

So let's see where the latter is initialized:

,----
| \def\collaboration{% implicit #1
|  \@author@def{\@booleantrue\collaboration@sw}% implicit #2
| }%
| 
| \appdef\frontmatter@init{%
|  \@booleanfalse\collaboration@sw
| }%
| 
| \def\@author@init{%
|  \let\@author\@author@cleared
|  \@booleanfalse\collaboration@sw
| }%
`----


So \collaboration@sw is a boolean (when it is defined) and I gueesed that the most likely place
was the \frontmatter@init macro. So what happens if we call the macro in the preamble just before
the \title, \author and \date junk?
To do that, create a revtexbug.sty file with the following contents:

--8<---------------cut here---------------start------------->8---
\makeatletter
\frontmatter@init
\makeatother
--8<---------------cut here---------------end--------------->8---

and modify the org file to

--8<---------------cut here---------------start------------->8---
#+LATEX_CLASS: revtex4-1
#+TITLE: foo
#+AUTHOR: nick
#+DATE:

#+LATEX_HEADER: \usepackage{revtexbug}

* foo

bar
--8<---------------cut here---------------end--------------->8---

Export to latex, process and voilà: no errors.

I don't want to pretend of course that this solves the problem: it might
cause more problems than it solves, particularly since I know nothing about
revtex and all the above is (more-or-less informed) guesswork.

Nevertheless, it might be worth trying on a real document and seeing if
it resolves the problem without causing undue misery. If it does, you
can have a more-or-less permanent solution by just moving the
revtexbug.sty file to some directory where latex can find it (don't
forget to run texhash) and use the above as a template. You can probably
customize the class template to do the \usepackage for you.

Please report back whether it works or not. If it does, maybe you can
ask the RevTeX maintainers to fix the package: it's much more likely to
happen if you tell them how to fix it ;-) And we can add an item to the
FAQ. I just hope that there are no other classes that misbehave this way...

Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-01 22:05   ` Nick Dokos
  2011-06-01 23:19     ` Thomas S. Dye
  2011-06-01 23:55     ` Nick Dokos
@ 2011-06-02  8:12     ` Sebastian Hofer
  2011-06-02 15:57       ` Nick Dokos
  2 siblings, 1 reply; 12+ messages in thread
From: Sebastian Hofer @ 2011-06-02  8:12 UTC (permalink / raw)
  To: emacs-orgmode

At Wed, 01 Jun 2011 18:05:28 -0400,
Nick Dokos wrote:
> 
> Thomas S. Dye <tsd@tsdye.com> wrote:
> 
> > Sebastian Hofer <sebhofer@gmail.com> writes:
> > 
> > > Hi all,
> > >
> > > This patch addresses the problem of ambiguous conventions for the
> > > placement of the title related macros (\author, \date,...) with
> > > respect to the main document body in different latex classes. It
> > > introduces the following changes:
> > >
> > > * org-exp.el:
> > >     - added the following options:
> > >       - title-position (tpos)
> > >       - with-title (wtitle)
> > >       - with-author (wauth)
> 
> [This is mostly addressed to Sebastian even though I'm replying to Tom's
> reply.]
> 
> An empty
> 
> #+AUTHOR:
> 
> disables the insertion of author (assuming that TITLE is not empty -
> see below.)
> 
> 
> > >       - with-date (wdate)
> 
> An empty
> 
> #+DATE:
> 
> disables the insertion of date (same assumption.)
> 
> > >       - with-maketitle (wmtitle)
> 
> An empty
> 
> #+TITLE:
> 
> disables the insertion of \maketitle.

To be honest, I didn't try setting empty author and date (which of
course makes sense) I just tried not setting them at all, which gives
default values. The main reason I submitted this patch, however, is
having better control of \maketitle. Personally I would like to be
able to have the title and author at the beginning of the file, just
for the looks, and still be able to produce a customized title. Of
course it is highly debatable if this is a sound reason to introduce
new options (I would argue yes).

> So if TITLE is not empty, you can get what you want with existing
> machinery. I could not find a way to make the title empty  and still
> have author and/or date fields.
> 
> Given all this, I think the only things you need is title-position and
> with-title, the latter in the unlikely event that you want a title page
> with author or date but without a title. Personally, I'd consider this
> last one unimportant and not worry about it, but you may disagree.

I agree concerning the author but no title case, this also does not
seem interesting to me.

> > >     
> > > * org-latex.el:
> > >     - implemented handling of new options (see above):
> > >       - title-position controls placement of \title, \author, \date;
> > >         possible values are "b" = before \begin{document},
> > >         any other values default to after \begin{document}
> > >       - with-* controls if the corresponding macro is exported at all
> > >         this can be convenient for more complex titles (e.g. several
> > >         authors including affiliations,...)
> > >
> > > The patch seems to work for me so far. What do you all think? IMO it
> > > would be useful to integrate this, as it gives slightly more control
> > > over the export process. Of course one might want to think about
> > > better option names. The diff is done against commit
> > > bc161ded3693f752616dcd247fc9d638789025ee.
> > >
> > > Let me briefly describe my current use case:
> > > I disable all commands except \title, use babel to created a title.tex
> > > file (including several authors and affiliations) by tangling latex
> > > code and then include the file (into the main body of the document,
> > > not the preamble). That's the only decent way I've found to do this,
> > > if anyone knows an easier way (I have the feeling that I might be
> > > overlooking an obvious solution) please let me know!
> > >
> 
> I'm not sure what problem you are trying to solve here: can you explain?
> It seems to me that all this can be done in standard ways.
> 

I'm using revtex4-1 at the moment. I need a title which looks like
this (within the document environment):

\begin{abstract}
 some blabla
\end{abstract}
\author{First author}
\affiliation{First affiliation}
\affiliation{Second affiliation}
\author{Second author}
\affiliation{Third affiliation}
...
\keywords{optional keywords}
\pacs{optional pacs}
\maketitle

How would you solve this problem?

> > > Cheers
> > > Sebastian
> > >
> > >
> > Aloha Sebastian,
> > 
> > Your patch should prove useful in the situation where one has to use a
> > particular class file that requires \title and friends to be declared in
> > the body of the document rather than the preamble.  That functionality
> > is a welcome addition to the LaTeX exporter, IMO.
> > 
> 
> IIUC, the only remaining thing is the position of the \title etc macros
> in the preamble or the body (or both).
> 
> There are three categories of LaTeX classes: the ones that implement
> Lamport's dictum that \title etc can come anywhere before \maketitle,
> the ones like RevTeX that insist on having them in the body and the ones
> like the thesis document class at Suvayu's university, that insist on
> having them in the preamble. I consider both of the latter two as buggy:
> has anybody submitted a bug report on them?
> 
> Has anybody researched the prevalence of these bugs? Are there lots of
> classes in one or the other of the buggy categories?
> 
> Be that as it may, it seems that org needs a patch to work around these
> bugs.  Personally, since it is a class problem, I'd rather have this
> kind of information in the class template.  You set it once for each
> class that needs it and you forget about it. Assuming the maintainers
> agree, any chance of reworking the patch along these lines? Maybe make
> it extensible as well: a property list that can accumulate all the junk
> in one place perhaps. That way the RevTeX class can be configured
> appropriately and the rest of the world can live in blissful ignorance
> of the problem. You might detect a bias here: I prefer these things in
> the preamble by default.

Last time this topic came up (because of Suvayu Ali's thesis) I posted
something along these lines (http://article.gmane.org/gmane.emacs.orgmode/41129),
wondering what's the best place to fix this problem. I never got any replies
(maybe also because the thread was already a month old by that time).
Back then I concluded that the class templates are not the best place
to handle this, as they are only concerned with the preamble, but not
with the body of the document. And I still don't see how this should
fit in exactly. I agree of course that it would be the nicest thing to
set this on a per class basis.
 
> > Another way to achieve your current use case, IIUC, which might or might
> > not seem easier, is to redefine \maketitle along the lines suggested by
> > Nick Dokos (see
> > http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-11_2).
> > 
> 
> As I mentioned, I'm not really sure what Sebastian is looking for, so I
> can't really say whether the above would help, but if it can be done
> this way, I think it would be preferable to introducing new user options
> for the exlusive use of the org latex exporter. There are legitimate uses
> for user options but working around bugs in downstream packages is
> not one of them. IMO, of course.
> 
> Nick
> 

Thanks for the detailed response, I'm hopeful that we can finally find
a solution to this problem. I have some other comments to your later
post about revtex, I will reply to this separately.

Sebastian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-01 23:55     ` Nick Dokos
@ 2011-06-02  8:36       ` Sebastian Hofer
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastian Hofer @ 2011-06-02  8:36 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Sebastian Hofer

At Wed, 01 Jun 2011 19:55:51 -0400,
Nick Dokos wrote:
> 
> Nick Dokos <nicholas.dokos@hp.com> wrote:
> 
> > IIUC, the only remaining thing is the position of the \title etc macros
> > in the preamble or the body (or both).
> > 
> > There are three categories of LaTeX classes: the ones that implement
> > Lamport's dictum that \title etc can come anywhere before \maketitle,
> > the ones like RevTeX that insist on having them in the body and the ones
> > like the thesis document class at Suvayu's university, that insist on
> > having them in the preamble. I consider both of the latter two as buggy:
> > has anybody submitted a bug report on them?
> > 
> 
> I tried an experiment:
> 
> I cannot get at the thesis document class at Suvayu's university but I
> most certainly can get to RevTeX. So I started with a simple org file:
> 
> ,----
> | #+LATEX_CLASS: revtex4-1
> | #+TITLE: foo
> | #+AUTHOR: nick
> | #+DATE:
> | 
> | * foo
> | 
> | bar
> `----
> 
> 
> I then added a definition for the revtex4-1 class to org-export-latex-classes.
> I just copied the article class and renamed appropriately:
> 
> ,----
> |     ...
> |     ("revtex4-1"
> |      "\\documentclass[11pt]{revtex4-1}"
> |      ("\\section{%s}" . "\\section*{%s}")
> |      ("\\subsection{%s}" . "\\subsection*{%s}")
> |      ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
> |      ("\\paragraph{%s}" . "\\paragraph*{%s}")
> |      ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
> |     ...
> `----
> 
> 
> Exporting to latex and compiling gives errors, the first one of which says:
> 
> ,----
> | ...
> | *hyperref using default driver hpdftex*
> | (/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def)
> | ! Undefined control sequence.
> | <argument> \collaboration@sw 
> |                              {\advance \c@collab \@ne \@argswap {\CO@grp \CO...
> | l.21 \author{nick}
> | ...
> `----
> 
> Basically, \author{nick} got expanded into something involving \collaboration@sw which
> is currently undefined. So off to /usr/share/texmf-texlive/tex/latex/revtex/revtex4-1.cls
> I went and found the following expansion sequence:
> 
>    \author -> \frontmatter@author -> \@author@def -> \move@AU -> \collaboration@sw -> ...
> 
> So let's see where the latter is initialized:
> 
> ,----
> | \def\collaboration{% implicit #1
> |  \@author@def{\@booleantrue\collaboration@sw}% implicit #2
> | }%
> | 
> | \appdef\frontmatter@init{%
> |  \@booleanfalse\collaboration@sw
> | }%
> | 
> | \def\@author@init{%
> |  \let\@author\@author@cleared
> |  \@booleanfalse\collaboration@sw
> | }%
> `----
> 
> 
> So \collaboration@sw is a boolean (when it is defined) and I gueesed that the most likely place
> was the \frontmatter@init macro. So what happens if we call the macro in the preamble just before
> the \title, \author and \date junk?
> To do that, create a revtexbug.sty file with the following contents:
> 
> --8<---------------cut here---------------start------------->8---
> \makeatletter
> \frontmatter@init
> \makeatother
> --8<---------------cut here---------------end--------------->8---
> 
> and modify the org file to
> 
> --8<---------------cut here---------------start------------->8---
> #+LATEX_CLASS: revtex4-1
> #+TITLE: foo
> #+AUTHOR: nick
> #+DATE:
> 
> #+LATEX_HEADER: \usepackage{revtexbug}
> 
> * foo
> 
> bar
> --8<---------------cut here---------------end--------------->8---
> 
> Export to latex, process and voilà: no errors.
> 
> I don't want to pretend of course that this solves the problem: it might
> cause more problems than it solves, particularly since I know nothing about
> revtex and all the above is (more-or-less informed) guesswork.
> 
> Nevertheless, it might be worth trying on a real document and seeing if
> it resolves the problem without causing undue misery. If it does, you
> can have a more-or-less permanent solution by just moving the
> revtexbug.sty file to some directory where latex can find it (don't
> forget to run texhash) and use the above as a template. You can probably
> customize the class template to do the \usepackage for you.
> 
> Please report back whether it works or not. If it does, maybe you can
> ask the RevTeX maintainers to fix the package: it's much more likely to
> happen if you tell them how to fix it ;-) And we can add an item to the
> FAQ. I just hope that there are no other classes that misbehave this way...


Unfortunately I couldn't get this to work just right now, also not for
the minimal example you provided. I will probably look into it when I
have more time on my hands. 
The real problem, however, is a different one: I use the revtex class
to submit research papers to the American Physical Society. And I
don't think they will be happy with me providing my own package which
works around one of the "features" of their own class. So unless we
can get them to fix the class, we (or I for that matter) are out of
luck. I haven't consider reporting this to them as I thought it would
be useless, but of course one could always try...
 
I still think that we should implement a way to handle this situation
in org, I'm pretty sure this is not the only class which doesn't
conform to the standards out there.

Sebastian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-02  8:12     ` Sebastian Hofer
@ 2011-06-02 15:57       ` Nick Dokos
  2011-06-02 19:05         ` Sebastian Hofer
  0 siblings, 1 reply; 12+ messages in thread
From: Nick Dokos @ 2011-06-02 15:57 UTC (permalink / raw)
  To: Sebastian Hofer; +Cc: nicholas.dokos, emacs-orgmode

Sebastian Hofer <sebhofer@gmail.com> wrote:

> At Wed, 01 Jun 2011 18:05:28 -0400,
> Nick Dokos wrote:
> > 
> > Thomas S. Dye <tsd@tsdye.com> wrote:
> > 
> > > Sebastian Hofer <sebhofer@gmail.com> writes:
> > > 
> > > > Hi all,
> > > >
> > > > This patch addresses the problem of ambiguous conventions for the
> > > > placement of the title related macros (\author, \date,...) with
> > > > respect to the main document body in different latex classes. It
> > > > introduces the following changes:
> > > >
> > > > * org-exp.el:
> > > >     - added the following options:
> > > >       - title-position (tpos)
> > > >       - with-title (wtitle)
> > > >       - with-author (wauth)
> > 
> > [This is mostly addressed to Sebastian even though I'm replying to Tom's
> > reply.]
> > 
> > An empty
> > 
> > #+AUTHOR:
> > 
> > disables the insertion of author (assuming that TITLE is not empty -
> > see below.)
> > 
> > 
> > > >       - with-date (wdate)
> > 
> > An empty
> > 
> > #+DATE:
> > 
> > disables the insertion of date (same assumption.)
> > 
> > > >       - with-maketitle (wmtitle)
> > 
> > An empty
> > 
> > #+TITLE:
> > 
> > disables the insertion of \maketitle.
> 
> To be honest, I didn't try setting empty author and date (which of
> course makes sense) I just tried not setting them at all, which gives
> default values. The main reason I submitted this patch, however, is
> having better control of \maketitle. Personally I would like to be
> able to have the title and author at the beginning of the file, just
> for the looks, and still be able to produce a customized title. Of
> course it is highly debatable if this is a sound reason to introduce
> new options (I would argue yes).
> 

Before anybody else wastes their time on this: I'm not sure whether I
was in an alternative universe yesterday, or I am in one today, but
I can't even reproduce my own results. I'll start again and try to get it
right this time, but I'm not going to be able to do that immediately.

Apologies for the confusion.

Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-02 15:57       ` Nick Dokos
@ 2011-06-02 19:05         ` Sebastian Hofer
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastian Hofer @ 2011-06-02 19:05 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Sebastian Hofer

At Thu, 02 Jun 2011 11:57:07 -0400,
Nick Dokos wrote:
> 
> Sebastian Hofer <sebhofer@gmail.com> wrote:
> 
> > At Wed, 01 Jun 2011 18:05:28 -0400,
> > Nick Dokos wrote:
> > > 
> > > Thomas S. Dye <tsd@tsdye.com> wrote:
> > > 
> > > > Sebastian Hofer <sebhofer@gmail.com> writes:
> > > > 
> > > > > Hi all,
> > > > >
> > > > > This patch addresses the problem of ambiguous conventions for the
> > > > > placement of the title related macros (\author, \date,...) with
> > > > > respect to the main document body in different latex classes. It
> > > > > introduces the following changes:
> > > > >
> > > > > * org-exp.el:
> > > > >     - added the following options:
> > > > >       - title-position (tpos)
> > > > >       - with-title (wtitle)
> > > > >       - with-author (wauth)
> > > 
> > > [This is mostly addressed to Sebastian even though I'm replying to Tom's
> > > reply.]
> > > 
> > > An empty
> > > 
> > > #+AUTHOR:
> > > 
> > > disables the insertion of author (assuming that TITLE is not empty -
> > > see below.)
> > > 
> > > 
> > > > >       - with-date (wdate)
> > > 
> > > An empty
> > > 
> > > #+DATE:
> > > 
> > > disables the insertion of date (same assumption.)
> > > 
> > > > >       - with-maketitle (wmtitle)
> > > 
> > > An empty
> > > 
> > > #+TITLE:
> > > 
> > > disables the insertion of \maketitle.
> > 
> > To be honest, I didn't try setting empty author and date (which of
> > course makes sense) I just tried not setting them at all, which gives
> > default values. The main reason I submitted this patch, however, is
> > having better control of \maketitle. Personally I would like to be
> > able to have the title and author at the beginning of the file, just
> > for the looks, and still be able to produce a customized title. Of
> > course it is highly debatable if this is a sound reason to introduce
> > new options (I would argue yes).
> > 
> 
> Before anybody else wastes their time on this: I'm not sure whether I
> was in an alternative universe yesterday, or I am in one today, but
> I can't even reproduce my own results. I'll start again and try to get it
> right this time, but I'm not going to be able to do that immediately.
> 
> Apologies for the confusion.

Concerning confusion: What I actually wanted to say above was that the
main focus of the patch was to provide means for controlling the
placement of \author, \date, \email etc., not \maketitle.

Apologies for the confusion :)

Sebastian

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
@ 2011-06-03  4:23 Nick Dokos
  2011-06-03  8:11 ` Sebastian Hofer
  0 siblings, 1 reply; 12+ messages in thread
From: Nick Dokos @ 2011-06-03  4:23 UTC (permalink / raw)
  To: Sebastian Hofer; +Cc: nicholas.dokos, emacs-orgmode

Sebastian Hofer <sebhofer@gmail.com> wrote:

> At Thu, 02 Jun 2011 11:57:07 -0400,
> Nick Dokos wrote:
> > 
> > > At Wed, 01 Jun 2011 18:05:28 -0400,
> > > Nick Dokos wrote:
> > > > 
> > > > An empty
> > > > 
> > > > #+AUTHOR:
> > > > 
> > > > disables the insertion of author (assuming that TITLE is not empty -
> > > > see below.)
> > > > 
> > > > 
> > > > > >       - with-date (wdate)
> > > > 
> > > > An empty
> > > > 
> > > > #+DATE:
> > > > 
> > > > disables the insertion of date (same assumption.)
> > > > 
> > > > > >       - with-maketitle (wmtitle)
> > > > 
> > > > An empty
> > > > 
> > > > #+TITLE:
> > > > 
> > > > disables the insertion of \maketitle.
> > > 
> > > To be honest, I didn't try setting empty author and date (which of
> > > course makes sense) I just tried not setting them at all, which gives
> > > default values. The main reason I submitted this patch, however, is
> > > having better control of \maketitle. Personally I would like to be
> > > able to have the title and author at the beginning of the file, just
> > > for the looks, and still be able to produce a customized title. Of
> > > course it is highly debatable if this is a sound reason to introduce
> > > new options (I would argue yes).
> > > 
> > 
> > Before anybody else wastes their time on this: I'm not sure whether I
> > was in an alternative universe yesterday, or I am in one today, but
> > I can't even reproduce my own results. I'll start again and try to get it
> > right this time, but I'm not going to be able to do that immediately.
> > 
> > Apologies for the confusion.
> 
> Concerning confusion: What I actually wanted to say above was that the
> main focus of the patch was to provide means for controlling the
> placement of \author, \date, \email etc., not \maketitle.
> 
> Apologies for the confusion :)
> 

OK, let me restate my current conclusions (or confusions, as the case may be).
First, I have to correct the empty cases:

  o an empty #+TITLE: generates a \title{} (in the preamble currently)
    but does not generate a \maketitle.

  o an empty #+AUTHOR generates an \author{}.

  o an empty #+DATE   generates a  \date{}.

I don't know what I was smoking yesterday, but I was definitely hallucinating.

Then the absent cases:

  o an absent #+TITLE: generates a \title{foo} where "foo" is
    heuristically obtained either from the buffer (it grabs the first
    "text" (i.e. not starting with | or #) line before the first
    headline - this seems a somewhat random heuristic to me) or from the
    filename.

  o an absent #+AUTHOR generates an \author{foo} where foo is generated
    from the user-full-name variable (and optionally additional email info).  

  o an absent #+DATE: generates a \date{\today}.

The author info can be suppressed by using

#+OPTIONS: author:nil

but the other two cannot - if Sebastian wants to modify his patch,
suppressing these two might be useful.  For a model to imitate, look
for :auth-info in org-exp.el and org-latex.el, and add e.g. :title-info
and :date-info. I would make them generic, not specific to latex. Only
the latex exporter will use them to begin with, but the other exporters
can do so in the future. 

I hope that I have described things correctly, but I'd be happy to
get corrections.

OTOH, none of this is necessary for revtex4-1. The main constituent of
the solution to that problem is that \maketitle is not hardcoded into
the latex exporter: it is instead the value of the variable
org-export-latex-title-command. By redefining this variable, you can put
all the frontmatter stuff where revtex wants it. That does not solve the
whole problem since the exporter puts frontmatter stuff in the preamble as
well and revtex chokes on that. So here's the plan:

- you have a file, ff2.tex, with the front page stuff: \title, \author,
  \affiliation etc.

- you have a file, abstract2.tex, with the abstract - this is not
  strictly necessary, but I like the separation of the two files
  and it's as easy to deal with two files as it is to deal with one.

- you redefine the above variable to be
  "\\input{ff2}\\input{abstract2}\\maketitle", so that they all end up
  inside the document body and revtex is happy - well, almost.

- there is still the matter of all the stuff (\title, \author, \date)
  that the exporter puts in the preamble. But since they are all
  redefined later, they don't matter.

- except that revtex still chokes on them because they are in the
  "wrong" place. But that is easily dealt with, with the revtexbug.sty
  trick I sent out yesterday.

Originally, I had the two files above (then named ff.tex and abstract.tex)
as separate files, but since you mentioned that you were tangling them, I
assume you wanted everything in the same file. So I tacked on the "2" suffix
to distinguish the tangled files from the originals.

Here's the org file:

--8<---------------cut here---------------start------------->8---
#+LaTeX_CLASS: revtex4-1

#+TITLE: foo
#+OPTIONS: author:nil

#+LaTeX_HEADER: \usepackage{revtexbug}

#+BIND: org-export-latex-title-command "\\input{ff2}\\input{abstract2}\\maketitle"

#+begin_src latex :tangle ff2.tex :exports none :results silent
 \title{{{{title}}}}
 \author{First author}
 \affiliation{First affiliation}
 \affiliation{Second affiliation}
 \author{Second author}
 \affiliation{Third affiliation}
 \keywords{optional keywords}
 \pacs{optional pacs}
 \date{{{{date(%Y-%m-%d)}}}}
#+end_src

#+begin_src latex :tangle abstract2.tex :exports none :results silent
 \begin{abstract}
  some blabla
 \end{abstract}
#+end_src

* Bar

Hunoz, hukerz?

* Baz

Euler says:

#+begin_latex
\[
\int_0^\infty e^{-x^2} dx = {{\sqrt{\pi}} \over {2}}
\]
#+end_latex

## Local Variables:
## org-export-allow-BIND: t
## End:
--8<---------------cut here---------------end--------------->8---

The #+BIND construct redefines the org-export-latex-title-command to get
the front matter stuff and the abstract and put them just before the
\maketitle.

The local variables section at the end allows the use of BIND with no
questions asked.

The first latex block uses the {{{title}}} and {{{date(...)}}} macros to
get the title from the #+TITLE construct and the current date (see
section 11.4 of the Org manual). That requires the use of a hook:

(add-to-list 'org-babel-tangle-body-hook (lambda () (org-export-preprocess-apply-macros)))

in order to expand the macros in the body of the source block when
tangling.  Eric Schulte describes this in

     http://thread.gmane.org/gmane.emacs.orgmode/39350/focus=39355

Alternatively, you can put the actual title and date in there and
dispense with the macros.

The final thing is to make sure to tangle before exporting in order to
produce the two files that are \input. You can do that manually or you
can use an export hook:

(add-to-list 'org-export-first-hook (lambda () (org-babel-tangle)))

When you export, the first thing that's done is the tangling of the
two files.

For completeness, here is the revtexbug.sty file again:

--8<---------------cut here---------------start------------->8---
\makeatletter
\frontmatter@init
\makeatother
--8<---------------cut here---------------end--------------->8---

and here's a minimal.emacs file that contains all of the stuff that's
needed (modulo the pathname  in load-path of course):

--8<---------------cut here---------------start------------->8---
;;; -*- mode: emacs-lisp -*-
(add-to-list 'load-path (expand-file-name "~/src/emacs/org/org-mode/lisp"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(require 'org-install)
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)

(require 'org-latex)
(require 'ob)

;; revtex4-1 latex class
(setq revtex-class
      '("revtex4-1" "\\documentclass[11pt]{revtex4-1}"
        ("\\section{%s}" . "\\section*{%s}")
        ("\\subsection{%s}" . "\\subsection*{%s}")
        ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
        ("\\paragraph{%s}" . "\\paragraph*{%s}")
        ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

(add-to-list 'org-export-latex-classes revtex-class t)

;; hooks
(add-to-list 'org-babel-tangle-body-hook (lambda () (org-export-preprocess-apply-macros)))
(add-to-list 'org-export-first-hook (lambda () (org-babel-tangle)))

;; mark the org-export-allow-BIND variable as safe to forego the questioning
(setq safe-local-variable-values '((org-export-allow-BIND . t)))

--8<---------------cut here---------------end--------------->8---

Note that there are a couple of questionable security practices in the
above: the marking of the org-export-allow-BIND variable as safe and the
setting of this variable in the org file. I did that to avoid the
nagging questions, but you should of course evaluate the convenience against
the potential damage for yourself.

To summarize:

o copy the org file and the revtexbug.sty file into some directory.

o Start emacs with ``emacs -Q -l minimal.emacs'', visit the file and
export to PDF.

Comments, questions, corrections and suggestions for improvement are
welcome.

Nick

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] latex export - title placement
  2011-06-03  4:23 [PATCH] latex export - title placement Nick Dokos
@ 2011-06-03  8:11 ` Sebastian Hofer
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastian Hofer @ 2011-06-03  8:11 UTC (permalink / raw)
  To: emacs-orgmode

At Fri, 03 Jun 2011 00:23:25 -0400,
Nick Dokos wrote:
> 
> Sebastian Hofer <sebhofer@gmail.com> wrote:
> 
> > At Thu, 02 Jun 2011 11:57:07 -0400,
> > Nick Dokos wrote:
> > > 
> > > > At Wed, 01 Jun 2011 18:05:28 -0400,
> > > > Nick Dokos wrote:
> > > > > 
> > > > > An empty
> > > > > 
> > > > > #+AUTHOR:
> > > > > 
> > > > > disables the insertion of author (assuming that TITLE is not empty -
> > > > > see below.)
> > > > > 
> > > > > 
> > > > > > >       - with-date (wdate)
> > > > > 
> > > > > An empty
> > > > > 
> > > > > #+DATE:
> > > > > 
> > > > > disables the insertion of date (same assumption.)
> > > > > 
> > > > > > >       - with-maketitle (wmtitle)
> > > > > 
> > > > > An empty
> > > > > 
> > > > > #+TITLE:
> > > > > 
> > > > > disables the insertion of \maketitle.
> > > > 
> > > > To be honest, I didn't try setting empty author and date (which of
> > > > course makes sense) I just tried not setting them at all, which gives
> > > > default values. The main reason I submitted this patch, however, is
> > > > having better control of \maketitle. Personally I would like to be
> > > > able to have the title and author at the beginning of the file, just
> > > > for the looks, and still be able to produce a customized title. Of
> > > > course it is highly debatable if this is a sound reason to introduce
> > > > new options (I would argue yes).
> > > > 
> > > 
> > > Before anybody else wastes their time on this: I'm not sure whether I
> > > was in an alternative universe yesterday, or I am in one today, but
> > > I can't even reproduce my own results. I'll start again and try to get it
> > > right this time, but I'm not going to be able to do that immediately.
> > > 
> > > Apologies for the confusion.
> > 
> > Concerning confusion: What I actually wanted to say above was that the
> > main focus of the patch was to provide means for controlling the
> > placement of \author, \date, \email etc., not \maketitle.
> > 
> > Apologies for the confusion :)
> > 
> 
> OK, let me restate my current conclusions (or confusions, as the case may be).
> First, I have to correct the empty cases:
> 
>   o an empty #+TITLE: generates a \title{} (in the preamble currently)
>     but does not generate a \maketitle.
> 
>   o an empty #+AUTHOR generates an \author{}.
> 
>   o an empty #+DATE   generates a  \date{}.
> 
> I don't know what I was smoking yesterday, but I was definitely hallucinating.
> 
> Then the absent cases:
> 
>   o an absent #+TITLE: generates a \title{foo} where "foo" is
>     heuristically obtained either from the buffer (it grabs the first
>     "text" (i.e. not starting with | or #) line before the first
>     headline - this seems a somewhat random heuristic to me) or from the
>     filename.
> 
>   o an absent #+AUTHOR generates an \author{foo} where foo is generated
>     from the user-full-name variable (and optionally additional email info).  
> 
>   o an absent #+DATE: generates a \date{\today}.
> 
> The author info can be suppressed by using
> 
> #+OPTIONS: author:nil
> 
> but the other two cannot - if Sebastian wants to modify his patch,
> suppressing these two might be useful.  For a model to imitate, look
> for :auth-info in org-exp.el and org-latex.el, and add e.g. :title-info
> and :date-info. I would make them generic, not specific to latex. Only
> the latex exporter will use them to begin with, but the other exporters
> can do so in the future. 
> 
> I hope that I have described things correctly, but I'd be happy to
> get corrections.
> 
> OTOH, none of this is necessary for revtex4-1. The main constituent of
> the solution to that problem is that \maketitle is not hardcoded into
> the latex exporter: it is instead the value of the variable
> org-export-latex-title-command. By redefining this variable, you can put
> all the frontmatter stuff where revtex wants it. That does not solve the
> whole problem since the exporter puts frontmatter stuff in the preamble as
> well and revtex chokes on that. So here's the plan:
> 
> - you have a file, ff2.tex, with the front page stuff: \title, \author,
>   \affiliation etc.
> 
> - you have a file, abstract2.tex, with the abstract - this is not
>   strictly necessary, but I like the separation of the two files
>   and it's as easy to deal with two files as it is to deal with one.
> 
> - you redefine the above variable to be
>   "\\input{ff2}\\input{abstract2}\\maketitle", so that they all end up
>   inside the document body and revtex is happy - well, almost.
> 
> - there is still the matter of all the stuff (\title, \author, \date)
>   that the exporter puts in the preamble. But since they are all
>   redefined later, they don't matter.
> 
> - except that revtex still chokes on them because they are in the
>   "wrong" place. But that is easily dealt with, with the revtexbug.sty
>   trick I sent out yesterday.
> 
> Originally, I had the two files above (then named ff.tex and abstract.tex)
> as separate files, but since you mentioned that you were tangling them, I
> assume you wanted everything in the same file. So I tacked on the "2" suffix
> to distinguish the tangled files from the originals.
> 
> Here's the org file:
> 
> --8<---------------cut here---------------start------------->8---
> #+LaTeX_CLASS: revtex4-1
> 
> #+TITLE: foo
> #+OPTIONS: author:nil
> 
> #+LaTeX_HEADER: \usepackage{revtexbug}
> 
> #+BIND: org-export-latex-title-command "\\input{ff2}\\input{abstract2}\\maketitle"
> 
> #+begin_src latex :tangle ff2.tex :exports none :results silent
>  \title{{{{title}}}}
>  \author{First author}
>  \affiliation{First affiliation}
>  \affiliation{Second affiliation}
>  \author{Second author}
>  \affiliation{Third affiliation}
>  \keywords{optional keywords}
>  \pacs{optional pacs}
>  \date{{{{date(%Y-%m-%d)}}}}
> #+end_src
> 
> #+begin_src latex :tangle abstract2.tex :exports none :results silent
>  \begin{abstract}
>   some blabla
>  \end{abstract}
> #+end_src
> 
> * Bar
> 
> Hunoz, hukerz?
> 
> * Baz
> 
> Euler says:
> 
> #+begin_latex
> \[
> \int_0^\infty e^{-x^2} dx = {{\sqrt{\pi}} \over {2}}
> \]
> #+end_latex
> 
> ## Local Variables:
> ## org-export-allow-BIND: t
> ## End:
> --8<---------------cut here---------------end--------------->8---
> 
> The #+BIND construct redefines the org-export-latex-title-command to get
> the front matter stuff and the abstract and put them just before the
> \maketitle.
> 
> The local variables section at the end allows the use of BIND with no
> questions asked.
> 
> The first latex block uses the {{{title}}} and {{{date(...)}}} macros to
> get the title from the #+TITLE construct and the current date (see
> section 11.4 of the Org manual). That requires the use of a hook:
> 
> (add-to-list 'org-babel-tangle-body-hook (lambda () (org-export-preprocess-apply-macros)))
> 
> in order to expand the macros in the body of the source block when
> tangling.  Eric Schulte describes this in
> 
>      http://thread.gmane.org/gmane.emacs.orgmode/39350/focus=39355
> 
> Alternatively, you can put the actual title and date in there and
> dispense with the macros.
> 
> The final thing is to make sure to tangle before exporting in order to
> produce the two files that are \input. You can do that manually or you
> can use an export hook:
> 
> (add-to-list 'org-export-first-hook (lambda () (org-babel-tangle)))
> 
> When you export, the first thing that's done is the tangling of the
> two files.
> 
> For completeness, here is the revtexbug.sty file again:
> 
> --8<---------------cut here---------------start------------->8---
> \makeatletter
> \frontmatter@init
> \makeatother
> --8<---------------cut here---------------end--------------->8---
> 
> and here's a minimal.emacs file that contains all of the stuff that's
> needed (modulo the pathname  in load-path of course):
> 
> --8<---------------cut here---------------start------------->8---
> ;;; -*- mode: emacs-lisp -*-
> (add-to-list 'load-path (expand-file-name "~/src/emacs/org/org-mode/lisp"))
> (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
> (require 'org-install)
> (global-set-key "\C-cl" 'org-store-link)
> (global-set-key "\C-ca" 'org-agenda)
> 
> (require 'org-latex)
> (require 'ob)
> 
> ;; revtex4-1 latex class
> (setq revtex-class
>       '("revtex4-1" "\\documentclass[11pt]{revtex4-1}"
>         ("\\section{%s}" . "\\section*{%s}")
>         ("\\subsection{%s}" . "\\subsection*{%s}")
>         ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
>         ("\\paragraph{%s}" . "\\paragraph*{%s}")
>         ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
> 
> (add-to-list 'org-export-latex-classes revtex-class t)
> 
> ;; hooks
> (add-to-list 'org-babel-tangle-body-hook (lambda () (org-export-preprocess-apply-macros)))
> (add-to-list 'org-export-first-hook (lambda () (org-babel-tangle)))
> 
> ;; mark the org-export-allow-BIND variable as safe to forego the questioning
> (setq safe-local-variable-values '((org-export-allow-BIND . t)))
> 
> --8<---------------cut here---------------end--------------->8---
> 
> Note that there are a couple of questionable security practices in the
> above: the marking of the org-export-allow-BIND variable as safe and the
> setting of this variable in the org file. I did that to avoid the
> nagging questions, but you should of course evaluate the convenience against
> the potential damage for yourself.
> 
> To summarize:
> 
> o copy the org file and the revtexbug.sty file into some directory.
> 
> o Start emacs with ``emacs -Q -l minimal.emacs'', visit the file and
> export to PDF.
> 
> Comments, questions, corrections and suggestions for improvement are
> welcome.
> 
> Nick

Hi Nick,

this all is very interesting and I certainly will learn a few tricks
from that once I have the time to try it (hopefully later today). I
will get back to you then. In the meantime I have two quick
remarks/questions:

- Do you think that this is the most elegant solution? There is
certainly a lot of additional configuration required to get this to
work and I would still prefer a solution where you can just set a
variable and be done with it (and certainly many users who are new to
org feel the same)

- You probably missed my follow-up to your second post yesterday, I
forgot to forward it to you directly - sorry for that. Please read
here: http://article.gmane.org/gmane.emacs.orgmode/42468.
The main problem for me is, that I can't patch the revtex class as I
want to submit the tex file to APS, which won't access the revtexbug
solution I guess.

Regarding my patch, I certainly agree to modify it in the way you
proposed. Still I think it would be good to go one step further.

Sebastian

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-06-03  8:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-03  4:23 [PATCH] latex export - title placement Nick Dokos
2011-06-03  8:11 ` Sebastian Hofer
  -- strict thread matches above, loose matches on Subject: below --
2011-05-28 12:42 Sebastian Hofer
2011-05-28 12:59 ` Sebastian Hofer
2011-05-28 17:27 ` Thomas S. Dye
2011-06-01 22:05   ` Nick Dokos
2011-06-01 23:19     ` Thomas S. Dye
2011-06-01 23:55     ` Nick Dokos
2011-06-02  8:36       ` Sebastian Hofer
2011-06-02  8:12     ` Sebastian Hofer
2011-06-02 15:57       ` Nick Dokos
2011-06-02 19:05         ` Sebastian Hofer

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).