From mboxrd@z Thu Jan 1 00:00:00 1970 From: "R. Michael Weylandt " Subject: Re: Accessing #+EMAIL in LaTeX Export Date: Tue, 4 Feb 2014 16:46:39 -0500 Message-ID: References: <871tzj4e4c.fsf@gmail.com> <87wqhb2c08.fsf@gmail.com> <87ppn2vl7s.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 (1.0) Content-Type: multipart/alternative; boundary=Apple-Mail-CD88A44B-281F-4986-9717-23FC58431B9D Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAnpe-0002Ta-7W for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:47:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WAnpY-0007i4-25 for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:47:02 -0500 Received: from mail-ob0-x22e.google.com ([2607:f8b0:4003:c01::22e]:63905) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAnpX-0007hl-Oq for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:46:55 -0500 Received: by mail-ob0-f174.google.com with SMTP id uy5so10276793obc.33 for ; Tue, 04 Feb 2014 13:46:55 -0800 (PST) Received: from [10.27.228.44] ([166.137.87.181]) by mx.google.com with ESMTPSA id o7sm153248138oed.3.2014.02.04.13.46.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 13:46:52 -0800 (PST) In-Reply-To: <87ppn2vl7s.fsf@alphaville.bos.redhat.com> 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: emacs-orgmode@gnu.org --Apple-Mail-CD88A44B-281F-4986-9717-23FC58431B9D Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable On Feb 4, 2014, at 12:31, Nick Dokos wrote: > Nick Dokos writes: >=20 >> "R. Michael Weylandt" writes: >>=20 >>> I want org-mode to export to the "amsart" class by default. In >>> addition to the regular \title, \author, \date macros, amsart also >>> allows for "email". >>>=20 >>> (add-to-list 'org-latex-classes >>> '("amsart" >>> "\\documentclass{amsart} >>> [DEFAULT-PACKAGES] >>> [PACKAGES] >>> [EXTRA] >>> \\email{ {{{email}}} }" >>> ("\\section{%s}" . "\\section{%s}") >>> ("\\subsection{%s}" . "\\subsection{%s}") >>> ("\\subsubsection{%s}" . "\\subsubsection{%s}"))) >>>=20 >>> Running this on a document like: >>>=20 >>> #+TITLE: Test 1 >>> #+AUTHOR: Michael Weylandt >>> #+EMAIL: Michael.Weylandt@gmail.com >>> #+LATEX_CLASS: amsart >>> * Header 1 >>> Hello World >>>=20 >>> leaves me with "\email{email}" in the resulting LaTeX instead of >>> "\email{Michael.Weylandt@mail.com}". Since this is used as part of >>> \maketitle, doing something in the body (like your example) is too >>> late. >>>=20 >>> The #+EMAIL: value is handled by ox-latex.el, but it's only placed >>> inside the \author{} macro instead of in a stand alone \email{}. >>> That's the behavior I'm hoping to tweak. >>>=20 >>> Is that clearer? >>=20 >> Much - thanks. I haven't thought much about it but my knee-jerk reaction >> is to use a marker (something like \email{@EMAIL@}) when defining the >> class and use a filter to replace it at the end. But there are might be >> more elegant solutions around. >=20 > So here's a brute-force solution along the above lines: >=20 > --8<---------------cut here---------------start------------->8--- > #+EMAIL: ndokos@gmail.com > #+LATEX_CLASS: amsart >=20 > * foo > bar >=20 > * code :noexport:= > This should probably go in some initialization file - for testing, I just e= xecuted > the code blocks by hand: >=20 > #+name: email-filter > #+BEGIN_SRC elisp :results none > (defun nd-email-filter (contents backend info) > (let ((email (plist-get info :email))) > (replace-regexp-in-string "@EMAIL@" email contents t))) >=20 > (add-to-list 'org-export-filter-final-output-functions (function nd-email= -filter)) > #+END_SRC >=20 > #+name: amsart > #+BEGIN_SRC elisp :results none > (setq amsart-class > '("amsart" > "\\documentclass{amsart} > [DEFAULT-PACKAGES] > [PACKAGES] > [EXTRA] > \\email{@EMAIL@ }" > ("\\section{%s}" . "\\section{%s}") > ("\\subsection{%s}" . "\\subsection{%s}") > ("\\subsubsection{%s}" . "\\subsubsection{%s}"))) >=20 > (add-to-list 'org-latex-classes amsart-class) > #+END_SRC >=20 > This deletes the amsart from the org-latex-classes list: >=20 > #+BEGIN_SRC elisp > (setq org-latex-classes (cdr org-latex-classes)) > #+END_SRC > --8<---------------cut here---------------end--------------->8--- >=20 > Nick Hi Nick, Thanks for the example; the filter seems to work well. Two possible issues: 1. I only want to use it for some latex classes 2. When using \email{} I want to get rid of the \thanks{} in \author{}.=20 I came up with the following:=20 <----------------------> (require 'cl-lib) (defun any (x) (cl-reduce (lambda (x y) (if x x y)) x)) =20 ;; For certain latex classes, the org-mode default of \author{NAME\thanks{EM= AIL}} ;; isn't what the class wants (defvar org-latex-classes-with-email '("amsart" "amsbook")) =20 ;; After completing latex export, check if we are in one of the classes list= ed in 'org-latex-classes-with-email; ;; if we are, we need to ;; 1) Remove the \thanks{} macro inside \author{} ;; 2) Add an \email{} macro ;; This can be done with a single regex replace using captures. (defun org-latex-classes-with-email-filter (contents backend info) (if (any (mapcar (lambda (x) (string-match x contents)) org-latex-classes-= with-email)) (replace-regexp-in-string "\\\\author{\\(.*\\)\\\\thanks{\\(.*\\)}}" "= \\\\author{\\1}\n\\\\email{\\2}" contents))) =20 ;; Thanks to Nick Dokos for the filter setup help --http://lists.gnu.org/arc= hive/html/emacs-orgmode/2014-02/msg00130.html (add-to-list 'org-export-filter-final-output-functions (function org-latex-c= lasses-with-email-filter)) <-------------------> It's regex based so there may be some false positives, but it seems to work w= ell enough for me.=20 Michael= --Apple-Mail-CD88A44B-281F-4986-9717-23FC58431B9D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Feb 4,= 2014, at 12:31, Nick Dokos <ndokos@g= mail.com> wrote:

Nick Dokos <ndokos@gmail.com> writes:

=
"R. Michael Weylandt" <michael.weylandt@gmail.com> writes:

I want org-mode to e= xport to the "amsart" class by default. In
addition to the= regular \title, \author, \date macros, amsart also
<= /blockquote>
allows= for "email".
=

(add-to-list 'org-latex-c= lasses
      '("amsart"
        "\\documentcla= ss{amsart}
       &nbs= p; [DEFAULT-PACKAGES]
     =     [PACKAGES]
   &nbs= p;     [EXTRA]
=
   = ;      \\email{ {{{email}}} }"
         ("\\section{%s}" .= "\\section{%s}")
      &nb= sp;   ("\\subsection{%s}" . "\\subsection{%s}")
<= span>           ("\\subsub= section{%s}" . "\\subsubsection{%s}")))
=

Running this on a document like:

=
#+TIT= LE: Test 1
#+AUTHOR: Michael Weylandt
#+= EMAIL: Michael.Weylandt@gmail.= com
#+LATEX_CLASS: amsart
* Header 1=
Hello World

leaves m= e with "\email{email}" in the resulting LaTeX instead of
"= \email{Michael.Weylandt@mail.co= m}". Since this is used as part of
<= blockquote type=3D"cite">
\maketitle, doing s= omething in the body (like your example) is too
late.

=
The #+EMAIL: value is handled by ox-latex.el= , but it's only placed
inside the \author{} macro instead of= in a stand alone \email{}.
That's the behavior I'm hoping t= o tweak.

Is that clearer?


Much - thanks. I haven'= t thought much about it but my knee-jerk reaction
is to use a marker (something like \email{@EMAI= L@}) when defining the
class and use a filter to replace it at the end. But there are might be
more elegant solutions a= round.

So here's a brute-force= solution along the above lines:

--8<---= ------------cut here---------------start------------->8---
#+EMAIL: ndokos@gmail.com#+LATEX_CLASS: amsart

* foo<= br>bar

* code       &n= bsp;                     &= nbsp;                     &= nbsp;      :noexport:
This should p= robably go in some initialization file - for testing, I just executed=
the code blocks by hand:

#+name: e= mail-filter
#+BEGIN_SRC elisp :results none
=  (defun nd-email-filter (contents backend info)
 = ;  (let ((email (plist-get info :email)))
 &= nbsp;   (replace-regexp-in-string "@EMAIL@" email contents t)= ))

 (add-to-list 'org-export-filter-f= inal-output-functions (function nd-email-filter))
#+END_SRC<= /span>

#+name: amsart
#+BEGIN_SRC e= lisp :results none
 (setq amsart-class
       '("amsart"

&nbs= p;        "\\documentclass{amsart}
          =  [DEFAULT-PACKAGES]
     &nbs= p;     [PACKAGES]
  &nbs= p;        [EXTRA]
&= nbsp;          \\email{@EM= AIL@ }"
        &nb= sp;  ("\\section{%s}" . "\\section{%s}")
 &n= bsp;          ("\\subsecti= on{%s}" . "\\subsection{%s}")
     = ;       ("\\subsubsection{%s}" . "\\subsu= bsection{%s}")))

 (add-to-list 'org-l= atex-classes amsart-class)
#+END_SRC
=
This deletes the amsart from the org-latex-classes list:
#+BEGIN_SRC elisp
 (setq org-l= atex-classes (cdr org-latex-classes))
#+END_SRC
--8<---------------cut here---------------end--------------->8---<= /span>

Nick

Hi Nick,

Thanks for the example; the filter seems to work well. Two possibl= e issues:
1. I only wan= t to use it for some latex classes
2. When using \email{} I want to get rid of the \thanks{} in \au= thor{}. 

I came up with the followin= g: 

<---------------------->

(require 'cl-= lib)

(defun any (x) (cl-reduce (lambda (x y) (if x x y)) x= ))

 

;; For certain latex classes, the org-m= ode default of \author{NAME\thanks{EMAIL}}

;; isn't what t= he class wants

(defvar org-latex-classes-with-email '("ams= art" "amsbook"))

 

;; After completing latex e= xport, check if we are in one of the classes listed in 'org-latex-classes-wi= th-email;

;; if we are, we need to

<= p class=3D"MsoNormal" style=3D"margin: 0in 0in 0.0001pt; ">;; 1= ) Remove the \thanks{} macro inside \author{}

;; 2) Add an \= email{} macro

;; This can be done with a single regex rep= lace using captures.

(defun org-latex-classes-with-email-= filter (contents backend info)

  (if (any (mapcar (l= ambda (x) (string-match x contents)) org-latex-classes-with-email))

      (replace-regexp-in-string "\\\\aut= hor{\\(.*\\)\\\\thanks{\\(.*\\)}}" "\\\\author{\\1}\n\\\\email{\\2}" content= s)))

 

;; Thanks to Nick Dokos for the filte= r setup help --http://lists.gnu.org/archi= ve/html/emacs-orgmode/2014-02/msg00130.html

(add-to-l= ist 'org-export-filter-final-output-functions (function org-latex-classes-wi= th-email-filter))



<------------------->= ;


It's regex based so t= here may be some false positives, but it seems to work well enough for me.&n= bsp;

<= span style=3D"-webkit-text-size-adjust: auto;">

Michael

= --Apple-Mail-CD88A44B-281F-4986-9717-23FC58431B9D--