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

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