emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Sebastian Hofer <sebhofer@gmail.com>
Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org
Subject: Re: [PATCH] latex export - title placement
Date: Fri, 03 Jun 2011 00:23:25 -0400	[thread overview]
Message-ID: <5772.1307075005@alphaville.dokosmarshall.org> (raw)

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

             reply	other threads:[~2011-06-03  4:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03  4:23 Nick Dokos [this message]
2011-06-03  8:11 ` [PATCH] latex export - title placement 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5772.1307075005@alphaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=sebhofer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).