From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K Subject: Generic LaTeX class support (scrlttr2/isodoc) Date: Tue, 21 Sep 2010 22:52:09 +0530 Message-ID: <81hbhjf1vi.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=36833 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oy6Y5-0001ei-EW for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 13:22:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oy6Y3-0006hQ-Uv for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 13:22:33 -0400 Received: from mail-pw0-f41.google.com ([209.85.160.41]:36968) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oy6Y3-0006hM-KX for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 13:22:31 -0400 Received: by pwj6 with SMTP id 6so4143205pwj.0 for ; Tue, 21 Sep 2010 10:22:30 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= 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: --=-=-= Content-Disposition: attachment (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) --=-=-= Content-Disposition: attachment (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) --=-=-= Content-Disposition: attachment (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) --=-=-= Content-Disposition: attachment (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) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --=-=-=--