From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: [PATCH] latex export - title placement Date: Fri, 03 Jun 2011 00:23:25 -0400 Message-ID: <5772.1307075005@alphaville.dokosmarshall.org> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([140.186.70.92]:34663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSLyL-0003Gx-Vh for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 00:26:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QSLyJ-0002hD-9K for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 00:26:57 -0400 Received: from vms173003pub.verizon.net ([206.46.173.3]:43523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QSLyI-0002ga-0t for emacs-orgmode@gnu.org; Fri, 03 Jun 2011 00:26:54 -0400 Received: from alphaville.dokosmarshall.org ([unknown] [173.76.32.106]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LM700MWS5O41P60@vms173003.mailsrvcs.net> for emacs-orgmode@gnu.org; Thu, 02 Jun 2011 23:26:41 -0500 (CDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastian Hofer Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org Sebastian Hofer 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