emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Generic LaTeX class support (scrlttr2/isodoc)
@ 2010-09-21 17:22 Jambunathan K
  2010-09-21 17:39 ` Jambunathan K
  0 siblings, 1 reply; 4+ messages in thread
From: Jambunathan K @ 2010-09-21 17:22 UTC (permalink / raw)
  To: emacs-orgmode

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


This is a follow upon my earlier posts in the following threads:

[1] 'Composing letters using org-mode and scrlttr2'
[2] Composingletters using Org mode and the LaTeX isodoc clas'

I am attaching four files
- org-latex-generic.el
- org-letter-utils.el 
- org-scrlttr2.el
- org-isodoc.el

Functionality is easily explained by usage rather than by words.

Usage Notes:

1. Load libraries
   - (require 'isodoc)
   - (require 'scrlttr2)

2. C-x C-f 'sample-letter.scrlttr2' and/or 'sample-isodoc.isodoc'. File
   extensions are important and they are indicative of the LaTeX classes
   targetted for export.

3. You will be offered a Org outline structure. Fill in the same. In the
   'To' address field you have an option just to insert a bbdb link as
   opposed to the whole address.

   Remember to fill in the LCO file for scrlttr2 and style file for
   isodoc.

4. Do a C-c C-e l or C-c C-e d.

5. See that your letter is nicely exported.

6. YMMV.

Additional Notes:

Files have helpful docstring. Core functionality is in
org-latex-generic-sectioning. Rest all are bells and whistles.

,----[ C-h f org-latex-generic-sectioning RET ]
| org-latex-generic-sectioning is a Lisp function in
| `org-latex-generic.el'.
| 
| (org-latex-generic-sectioning LEVEL HEADING)
| 
| Rules for emitting Org headings as LaTeX fragments.
| Currently a heading could be configured to start a LaTeX
| environment, emit a LaTeX command, set optional arguments (with
| heading as key and entry body as value) and mandatory
| arguments. See `org-latex-generic-scrlttr2-sectioning-alist' and
| `org-latex-generic-isodoc-sectioning-alist'. 
| 
| [back]
`----

Watch Out For:

1. Have no empty lines in .scrlttr2/.isodoc file. If that doesn't help
   remove it from the generated tex file.

   I have a strong reason to believe org-latex.el is generating
   extraneous newlines in (org-export-latex-subcontent ...) at line 1029
   or thereabouts.

2. Have no commas in the bbdb address field. C-h f
   org-letter-utils-bbdb-export is probably not upto the task.

3. Remove \date directive in the isodoc tex file.

4. Also see FIXME notes in the org-latex-generic.el


Implementation Notes:

The key idea is to mirror the LaTeX commands in terms of Org
headlines. Start with C-h f org-latex-generic-sectioning for further
exploring. Try mapping the headline structure of .scrlttr2/.isodoc file
with the corresponding tex file and compare it against the settings of
of different variables in the org-scrlttr2.el/org-isodoc.el

Footnotes:
[1] http://lists.gnu.org/archive/html/emacs-orgmode/2010-07/msg01060.html
[2] http://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00466.html


Jambunathan K.


Attachments:


[-- Attachment #2: Type: text/plain, Size: 3455 bytes --]

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

(defvar org-latex-classes nil)

(defvar org-latex-generic-sectioning-config
  '(alist :tag "Org LaTeX Generic Known Headings"
	  :key-type
	  (string :tag "heading")
	  :value-type
	  (choice
	   (const :tag "environment" env)		  
	   (const :tag "var" var)
	   (const :tag "command" cmd)
	   (const :tag "command-with-options" cmd-with-opt)		 
	   (const :tag "options" optarg)
	   (const :tag "option" option)
	   (const :tag "arg" arg)
	   (const :tag "text" text))))


(define-minor-mode org-latex-generic-mode
  "Fill an empty file with Org outline tree for easy editing.
The extension of the file serves as an indication of the target
LaTeX class."
  nil " LaTex Generic" nil
  (org-mode)

  (let ((class (file-name-extension buffer-file-name)))

    ;; FIXME: These should be buffer local variables for various
    ;; generic classes to coexist. For now have them as global.

    ;; The main problem is that sectioning callback happens with tex
    ;; file as current buffer and not the original org file in which
    ;; these variables are set.

    (setq org-latex-generic-class class
	  org-latex-generic-setup
	  (symbol-value
	   (intern (format "org-latex-generic-%s-setup" class)))

	  org-latex-generic-template
	  (symbol-value
	   (intern (format "org-latex-generic-%s-template" class)))

	  org-latex-generic-sectioning-alist
	  (symbol-value
	   (intern (format "org-latex-generic-%s-sectioning-alist" class))))

    (when (= (point-min) (point-max))
      (insert org-latex-generic-setup)
      (org-latex-generic-insert-template))))

(defun org-latex-generic-insert-template (&optional template level)
  "Inserts an Org outline structure for the user to fill in.
See `org-latex-generic-isodoc-template' and
`org-latex-generic-scrlttr2-template' for example."
  (interactive)

  (setq template (or template org-latex-generic-template))
  (goto-char (point-max))
  (setq level (or level 1))
  (dolist (e template)
    (if (not (listp e))
	(insert  "\n" (make-string level ?*) " " e "\n")
      (org-latex-generic-insert-template e (+ level 1)))))

(defun org-latex-generic-sectioning (level heading)
  "Rules for emitting Org headings as LaTeX fragments.
Currently a heading could be configured to start a LaTeX
environment, emit a LaTeX command, set optional arguments (with
heading as key and entry body as value) and mandatory
arguments. See `org-latex-generic-scrlttr2-sectioning-alist' and
`org-latex-generic-isodoc-sectioning-alist'. "
  (let* ((heading (replace-regexp-in-string "\\s-+" "" heading))
	 (pair (assoc-string heading org-latex-generic-sectioning-alist t))
	 open close)

    (when pair
      (cond
       ((eq (cdr pair) 'env)
	(setq open (format "\\begin{%s}\n" (car pair))
	      close (format "\\end{%s}" (car pair))))
       ((eq (cdr pair) 'var)
	(setq open (format "\n\\setkomavar{%s} {"  (car pair))
	      close "}"))
       ((eq (cdr pair) 'cmd)
	(setq open "\n\\%s {"
	      close "}"))
       ((eq (cdr pair) 'cmd-with-opt)
	(setq open "\n\\%s"
	      close ""))
       ((eq (cdr pair) 'optarg)
	(setq open "[" close "]"))
       ((eq (cdr pair) 'option)
	(setq open (format "%s =" (car pair)) close ","))
       ((eq (cdr pair) 'arg)
	(setq open " {" close "}"))
       ((eq (cdr pair) 'text)
	(setq open "" close ""))))
    (remove-list-of-text-properties 0 (length heading) '(target) heading)
    (list heading open close open close)))

(provide 'org-latex-generic)

[-- Attachment #3: Type: text/plain, Size: 1192 bytes --]

(require 'org-latex-generic)
(require 'org-letter-utils)

;; An scrlttr2 file starts in org-latex-generic-mode
(setq auto-mode-alist (append '(("\\.scrlttr2$" . org-latex-generic-mode))
                              auto-mode-alist))

;; Register sectioning structure for Scrlttr2 class. For now use the
;; generic routine.

(add-to-list
 'org-export-latex-classes
 '("scrlttr2" "\\documentclass{scrlttr2}" org-latex-generic-sectioning) t)

(defcustom org-latex-generic-scrlttr2-setup  
  "
#+LaTeX_CLASS: scrlttr2
#+LaTeX_CLASS_OPTIONS: [DIN]
#+OPTIONS: toc:nil
"
  "Meta lines for scrlttr2 class. Plug in your LCO file."
  :group 'org-scrlttr2
  :type 'string)

(defvar org-latex-generic-scrlttr2-template
  '("letter"
    ("to" "subject" "opening" "body" "encl" "closing"))
  "Outline structure for scrlttr2 file."
  )

(defcustom org-latex-generic-scrlttr2-sectioning-alist
  '(("letter" . env)
    ("to" . arg)
    ("subject" . var)
    ("opening" . cmd)
    ("body" . text)
    ("encl" . cmd)
    ("closing" . cmd))
  "Common LaTeX commands and Environment for use with scrlttr2 class."
  :group 'org-letter-scrlttr2
  :type org-latex-generic-sectioning-config)

(provide 'org-scrlttr2)

[-- Attachment #4: Type: text/plain, Size: 1301 bytes --]

(require 'org-latex-generic)
(require 'org-letter-utils)

;; An isodoc file starts in org-latex-generic-mode
(setq auto-mode-alist (append '(("\\.isodoc$" . org-latex-generic-mode))
                              auto-mode-alist))

;; Register sectioning structure for isodoc class. For now use the
;; generic routine.
(add-to-list
 'org-export-latex-classes
 '("isodoc" "\\documentclass{isodoc}" org-latex-generic-sectioning) t)

(defcustom org-latex-generic-isodoc-setup
  "
#+LaTeX_CLASS: isodoc
#+LATEX_HEADER: \\usepackage{mystyle}
#+OPTIONS: toc:nil
#+TITLE:
"
  "Meta lines for isodoc class. Insert your own stylesheet."
  :group 'org-letter-isodoc
  :type 'string)

(defvar org-latex-generic-isodoc-template
  '("letter"
    ("options"
     ("date" "to" "opening" "subject" "closing" "enclosures"))
    ("body"))
  "Outline structure for isodoc file."
  )

(defcustom org-latex-generic-isodoc-sectioning-alist
  '(("letter" . cmd-with-opt)
    ("options" . optarg)
    ("date" . option)
    ("to" . option)
    ("opening" . option)
    ("subject" . option)
    ("closing" . option)
    ("enclosures" . option)
    ("body" . arg))
  "Common LaTeX commands and Environment for use with isodoc class."
  :group 'org-letter-isodoc
  :type org-latex-generic-sectioning-config)

(provide 'org-isodoc)

[-- Attachment #5: Type: text/plain, Size: 807 bytes --]

(require 'org-bbdb)

(org-add-link-type "bbdb" 'org-bbdb-open 'org-letter-utils-bbdb-export)

(defun org-letter-utils-bbdb-export (path desc format)
  "Convert a BBDB link to an address.
Customized for Indian style. Commas are a strict No No for
now. Make this sit nicely with `bbdb-format-address' and
friends."
  (when (eq format 'latex)
    (let* ((name path) (separator " \\\\\n")
	   (indent 2) (prefix (make-string indent ? ))
	   (addr (car (bbdb-record-addresses (bbdb-search-simple name nil)))))
      (concat
       prefix name separator
       (mapconcat (lambda (line) (concat prefix line))
		  (bbdb-address-streets addr) separator) separator
       prefix (bbdb-address-city addr) " - " (bbdb-address-zip addr) separator
       prefix (bbdb-address-state addr)))))

(provide 'org-letter-utils)

[-- Attachment #6: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Generic LaTeX class support (scrlttr2/isodoc)
  2010-09-21 17:22 Generic LaTeX class support (scrlttr2/isodoc) Jambunathan K
@ 2010-09-21 17:39 ` Jambunathan K
  2011-02-08 20:54   ` Allen S. Rout
  0 siblings, 1 reply; 4+ messages in thread
From: Jambunathan K @ 2010-09-21 17:39 UTC (permalink / raw)
  To: emacs-orgmode

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


I am attaching sample files from my work-area for ready consumption.


[-- Attachment #2: sample-isodoc.tex --]
[-- Type: text/plain, Size: 983 bytes --]

% Created 2010-09-21 Tue 22:02
\documentclass{isodoc}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{t1enc}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{pdfpages}
\usepackage{mystyle}
\providecommand{\alert}[1]{\textbf{#1}}

\title{}
\author{Jambunathan K}
\date{21 September 2010}

\begin{document}






\letter
[
date =
    20100921
,
to =
      Orgmode Mailing List \\
  GNU Mailing List \\
  World Wide Web \\
  Internet - 111111
,
opening =
    Friends
,
subject =
    Composing letters using isodoc
,
closing =
    Thanks
,
enclosures =
    org-latex-generic.el
    org-scrlttr2.el
    org-isodoc.el
    org-letter-utils.el
,
]
 {
   I would like to share with you a little utility that helps me
   compose formal letters within Org mode. Would you like to try it?
}

\end{document}

[-- Attachment #3: sample-isodoc.isodoc --]
[-- Type: text/plain, Size: 543 bytes --]


#+LaTeX_CLASS: isodoc
#+LATEX_HEADER: \usepackage{mystyle}
#+OPTIONS: toc:nil
#+TITLE:

* letter

** options

*** date
    20100921
*** to
    [[bbdb:Orgmode%20Mailing%20List][bbdb:Orgmode Mailing List]]
*** opening
    Friends
*** subject
    Composing letters using isodoc
*** closing
    Thanks
*** enclosures
    org-latex-generic.el
    org-scrlttr2.el
    org-isodoc.el
    org-letter-utils.el
** body
   I would like to share with you a little utility that helps me
   compose formal letters within Org mode. Would you like to try it?

[-- Attachment #4: sample-scrlttr2.scrlttr2 --]
[-- Type: text/plain, Size: 484 bytes --]


#+LaTeX_CLASS: scrlttr2
#+LaTeX_CLASS_OPTIONS: [jambu]
#+OPTIONS: toc:nil

* letter

** to
   [[bbdb:Orgmode%20Mailing%20List][bbdb:Orgmode Mailing List]]

** subject
   Composing letters using scrlttr2

** opening
   Friends

** body
   I would like to share with you a little utility that helps me
   compose formal letters within Org mode. Would you like to try it?

** encl
   org-latex-generic.el
   org-scrlttr2.el
   org-isodoc.el
   org-letter-utils.el

** closing
   Thanks

[-- Attachment #5: sample-scrlttr2.tex --]
[-- Type: text/plain, Size: 1003 bytes --]

% Created 2010-09-21 Tue 21:51
\documentclass[jambu]{scrlttr2}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{t1enc}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{pdfpages}
\providecommand{\alert}[1]{\textbf{#1}}

\title{sample-scrlttr2}
\author{Jambunathan K}
\date{21 September 2010}

\begin{document}

\maketitle



\begin{letter}
 {
     Orgmode Mailing List \\
  GNU Mailing List \\
  World Wide Web \\
  Internet - 111111 \\
  Cosmos
}

\setkomavar{subject} {
   Composing letters using scrlttr2
}

\opening {
   Friends
}

   I would like to share with you a little utility that helps me
   compose formal letters within Org mode. Would you like to try it?

\encl {
   org-latex-generic.el
   org-scrlttr2.el
   org-isodoc.el
   org-letter-utils.el
}

\closing {
   Thanks
}
\end{letter}

\end{document}

[-- Attachment #6: Type: text/plain, Size: 2972 bytes --]


Let me know if you have any questions or suggestions.

Jambunathan K.




Jambunathan K <kjambunathan@gmail.com> writes:

> This is a follow upon my earlier posts in the following threads:
>
> [1] 'Composing letters using org-mode and scrlttr2'
> [2] Composingletters using Org mode and the LaTeX isodoc clas'
>
> I am attaching four files
> - org-latex-generic.el
> - org-letter-utils.el 
> - org-scrlttr2.el
> - org-isodoc.el
>
> Functionality is easily explained by usage rather than by words.
>
> Usage Notes:
>
> 1. Load libraries
>    - (require 'isodoc)
>    - (require 'scrlttr2)
>
> 2. C-x C-f 'sample-letter.scrlttr2' and/or 'sample-isodoc.isodoc'. File
>    extensions are important and they are indicative of the LaTeX classes
>    targetted for export.
>
> 3. You will be offered a Org outline structure. Fill in the same. In the
>    'To' address field you have an option just to insert a bbdb link as
>    opposed to the whole address.
>
>    Remember to fill in the LCO file for scrlttr2 and style file for
>    isodoc.
>
> 4. Do a C-c C-e l or C-c C-e d.
>
> 5. See that your letter is nicely exported.
>
> 6. YMMV.
>
> Additional Notes:
>
> Files have helpful docstring. Core functionality is in
> org-latex-generic-sectioning. Rest all are bells and whistles.
>
> ,----[ C-h f org-latex-generic-sectioning RET ]
> | org-latex-generic-sectioning is a Lisp function in
> | `org-latex-generic.el'.
> | 
> | (org-latex-generic-sectioning LEVEL HEADING)
> | 
> | Rules for emitting Org headings as LaTeX fragments.
> | Currently a heading could be configured to start a LaTeX
> | environment, emit a LaTeX command, set optional arguments (with
> | heading as key and entry body as value) and mandatory
> | arguments. See `org-latex-generic-scrlttr2-sectioning-alist' and
> | `org-latex-generic-isodoc-sectioning-alist'. 
> | 
> | [back]
> `----
>
> Watch Out For:
>
> 1. Have no empty lines in .scrlttr2/.isodoc file. If that doesn't help
>    remove it from the generated tex file.
>
>    I have a strong reason to believe org-latex.el is generating
>    extraneous newlines in (org-export-latex-subcontent ...) at line 1029
>    or thereabouts.
>
> 2. Have no commas in the bbdb address field. C-h f
>    org-letter-utils-bbdb-export is probably not upto the task.
>
> 3. Remove \date directive in the isodoc tex file.
>
> 4. Also see FIXME notes in the org-latex-generic.el
>
>
> Implementation Notes:
>
> The key idea is to mirror the LaTeX commands in terms of Org
> headlines. Start with C-h f org-latex-generic-sectioning for further
> exploring. Try mapping the headline structure of .scrlttr2/.isodoc file
> with the corresponding tex file and compare it against the settings of
> of different variables in the org-scrlttr2.el/org-isodoc.el
>
> Footnotes:
> [1] http://lists.gnu.org/archive/html/emacs-orgmode/2010-07/msg01060.html
> [2] http://lists.gnu.org/archive/html/emacs-orgmode/2010-09/msg00466.html
>
>
> Jambunathan K.
>
>
> Attachments:

[-- Attachment #7: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Generic LaTeX class support (scrlttr2/isodoc)
  2010-09-21 17:39 ` Jambunathan K
@ 2011-02-08 20:54   ` Allen S. Rout
  2011-02-09 23:59     ` Allen S. Rout
  0 siblings, 1 reply; 4+ messages in thread
From: Allen S. Rout @ 2011-02-08 20:54 UTC (permalink / raw)
  To: emacs-orgmode

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

Jambunathan K <kjambunathan@gmail.com> writes:

> I am attaching sample files from my work-area for ready consumption.


[...]

I'm trying to use your lisp to generate isodoc letters.  I'm wondering
what tex processing commands you are using?

I don't have bbdb in place, so I changed that.  Otherwise, using your
code, I get a similar TeX result (attached) but a PDF result that
doesn't make much sense.  (attached).

Toying around with isodoc natively, I found that I could get things to
look somewhat better by translating the '[key=val]' region inside the
\begin{document} into a \setupdocument{} command _before_ the
\begin{document}.  From your earlier examples, it's clear that you were
getting it to work without that measure.


I saw that there were several notions of "How to turn an Org document
into tasty letter-flavored TeX-like source".... Has anyone else reached
a functional plateau they like?  


- Allen S. Rout





[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Generated TeX --]
[-- Type: text/x-tex, Size: 869 bytes --]

% Created 2011-02-08 Tue 15:47
\documentclass{isodoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{mystyle}
\providecommand{\alert}[1]{\textbf{#1}}
\begin{document}



\title{}
\author{Allen S. Rout}
\date{08 February 2011}





\letter
[
date =

    20100921
,
to =

    Joe, the most remarkable
,
opening =

    Friends
,
subject =

    Composing letters using isodoc
,
closing =

    Thanks
,
enclosures =

    foo
,
]
 {

   I would like to share with you a little utility that helps me
   compose formal letters within Org mode. Would you like to try it?
}

\end{document}

[-- Attachment #3: generated PDF --]
[-- Type: application/pdf, Size: 68438 bytes --]

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: Generic LaTeX class support (scrlttr2/isodoc)
  2011-02-08 20:54   ` Allen S. Rout
@ 2011-02-09 23:59     ` Allen S. Rout
  0 siblings, 0 replies; 4+ messages in thread
From: Allen S. Rout @ 2011-02-09 23:59 UTC (permalink / raw)
  To: emacs-orgmode

asr@ufl.edu (Allen S. Rout) writes:

> I'm trying to use your lisp to generate isodoc letters.  I'm wondering
> what tex processing commands you are using?

I'm closing in on the discrepancy. The exported TeX which Jambunathan
sent was 'similar' to what I'm getting, but there were a few important
differences.

Most importantly, I'm getting an additional newline between key and
value:

---
opening =

    My dear john
,
---
instead of 
---
opening =
    My dear john
,
---

This appears to fotch up the LaTex, and put those strings in a spot out
of the document entirely.


If I remove line 1137

	(insert	"\n")

from org-latex.el, this change in spacing goes away, but of course I
have no idea why it was put there.  Oddly, git-blame suggests that line
went in  in 2009, well before Jambunathan posted his isodoc files.

Does anyone who's been tinkering with the latex export code want to
expound on why that newline's in there?  Is it silly to just suggest
"Can we take it out?" 


- Allen S. Rout

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

end of thread, other threads:[~2011-02-10  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-21 17:22 Generic LaTeX class support (scrlttr2/isodoc) Jambunathan K
2010-09-21 17:39 ` Jambunathan K
2011-02-08 20:54   ` Allen S. Rout
2011-02-09 23:59     ` Allen S. Rout

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