From e0f0e26a43868b883efd641f061897e08c822710 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 29 Jun 2010 10:10:52 -0700 Subject: [PATCH 1/5] library-of-babel: adding a booktabs latex exporting function --- contrib/babel/library-of-babel.org | 46 +++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org index 2e34e1d78..49172e0af 100644 --- a/contrib/babel/library-of-babel.org +++ b/contrib/babel/library-of-babel.org @@ -98,6 +98,50 @@ plot(data) * Tables ** LaTeX Table export +*** booktabs +This block can be used to wrap a table in the latex =booktabs= +environment, it takes the following arguments -- all but the first two +are optional. +| arg | description | +|-------+--------------------------------------------| +| table | a reference to the table | +| align | optional alignment string | +| env | optional environment, default to "tabular" | +| width | optional width specification string | + +#+srcname: booktabs +#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var align='() :var env="tabular" :var width='() :noweb yes :results latex + (flet ((to-tab (tab) + (orgtbl-to-generic + (mapcar (lambda (lis) + (if (listp lis) + (mapcar (lambda (el) + (if (stringp el) + el + (format "%S" el))) lis) + lis)) tab) + (list :lend " \\\\" :sep " & " :hline "\\hline")))) + (org-fill-template + " + \\begin{%env}%width%align + \\toprule + %table + \\bottomrule + \\end{%env}\n" + (list + (cons "env" (or env "table")) + (cons "width" (if width (format "{%s}" width) "")) + (cons "align" (if align (format "{%s}" align) "")) + (cons "table" + ;; only use \midrule if it looks like there are column headers + (if (equal 'hline (second table)) + (concat (to-tab (list (first table))) + "\n\\midrule\n" + (to-tab (cddr table))) + (to-tab table)))))) +#+end_src + +*** longtable This block can be used to wrap a table in the latex =longtable= environment, it takes the following arguments -- all but the first two are optional. @@ -113,7 +157,7 @@ are optional. | lastfoot | optional "lastfoot" string | #+srcname: longtable -#+begin_src emacs-lisp :var table='((:table)) :var env="table" :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex +#+begin_src emacs-lisp :var table='((:table)) :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex (org-fill-template " \\begin{longtable}%width%align From 6ffe2f66d54a0a3d14ce64c7301e1e44987c4c31 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 30 Jun 2010 11:56:11 -0700 Subject: [PATCH 2/5] Makefile now installs babel and babel-language files in subdirectories --- Makefile | 208 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 121 insertions(+), 87 deletions(-) diff --git a/Makefile b/Makefile index d4da79de3..360a37c99 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ # To create the PDF and HTML documentation files, type `make doc'. ##---------------------------------------------------------------------- -## YOU MUST EDIT THE FOLLOWING LINES +## YOU MUST EDIT THE FOLLOWING LINES ##---------------------------------------------------------------------- # Name of your emacs binary @@ -17,7 +17,9 @@ EMACS=emacs prefix=/usr/local # Where local lisp files go. -lispdir = $(prefix)/share/emacs/site-lisp +lispdir = $(prefix)/share/emacs/site-lisp +lispbdir = $(lispdir)/babel +lispbldir = $(lispbdir)/langs # Where info files go. infodir = $(prefix)/share/info @@ -62,83 +64,109 @@ INSTALL_INFO=install-info ##---------------------------------------------------------------------- # The following variables need to be defined by the maintainer -LISPF = org.el \ - org-agenda.el \ - org-ascii.el \ - org-attach.el \ - org-archive.el \ - org-bbdb.el \ - org-beamer.el \ - org-bibtex.el \ - org-capture.el \ - org-clock.el \ - org-colview.el \ - org-colview-xemacs.el \ - org-compat.el \ - org-crypt.el \ - org-ctags.el \ - org-datetree.el \ - org-docview.el \ - org-entities.el \ - org-exp.el \ - org-exp-blocks.el \ - org-docbook.el \ - org-faces.el \ - org-feed.el \ - org-footnote.el \ - org-freemind.el \ - org-gnus.el \ - org-habit.el \ - org-html.el \ - org-icalendar.el \ - org-id.el \ - org-indent.el \ - org-info.el \ - org-inlinetask.el \ - org-jsinfo.el \ - org-irc.el \ - org-latex.el \ - org-list.el \ - org-mac-message.el \ - org-macs.el \ - org-mew.el \ - org-mhe.el \ - org-mks.el \ - org-mobile.el \ - org-mouse.el \ - org-publish.el \ - org-plot.el \ - org-protocol.el \ - org-remember.el \ - org-rmail.el \ - org-src.el \ - org-table.el \ - org-taskjuggler.el \ - org-timer.el \ - org-vm.el \ - org-w3m.el \ - org-wl.el \ - org-xoxo.el \ - babel/ob.el \ - babel/ob-table.el \ - babel/ob-lob.el \ - babel/ob-ref.el \ - babel/ob-exp.el \ - babel/ob-tangle.el \ - babel/ob-comint.el \ - babel/ob-keys.el \ - babel/langs/ob-emacs-lisp.el +LISPF = org.el \ + org-agenda.el \ + org-ascii.el \ + org-attach.el \ + org-archive.el \ + org-bbdb.el \ + org-beamer.el \ + org-bibtex.el \ + org-capture.el \ + org-clock.el \ + org-colview.el \ + org-colview-xemacs.el \ + org-compat.el \ + org-crypt.el \ + org-ctags.el \ + org-datetree.el \ + org-docview.el \ + org-entities.el \ + org-exp.el \ + org-exp-blocks.el \ + org-docbook.el \ + org-faces.el \ + org-feed.el \ + org-footnote.el \ + org-freemind.el \ + org-gnus.el \ + org-habit.el \ + org-html.el \ + org-icalendar.el \ + org-id.el \ + org-indent.el \ + org-info.el \ + org-inlinetask.el \ + org-jsinfo.el \ + org-irc.el \ + org-latex.el \ + org-list.el \ + org-mac-message.el \ + org-macs.el \ + org-mew.el \ + org-mhe.el \ + org-mks.el \ + org-mobile.el \ + org-mouse.el \ + org-publish.el \ + org-plot.el \ + org-protocol.el \ + org-remember.el \ + org-rmail.el \ + org-src.el \ + org-table.el \ + org-taskjuggler.el \ + org-timer.el \ + org-vm.el \ + org-w3m.el \ + org-wl.el \ + org-xoxo.el -LISPFILES0 = $(LISPF:%=lisp/%) -LISPFILES = $(LISPFILES0) lisp/org-install.el -ELCFILES0 = $(LISPFILES0:.el=.elc) -ELCFILES = $(LISPFILES:.el=.elc) -DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir \ - doc/pdflayout.sty doc/.nosearch \ - doc/orgguide.texi doc/orgguide.pdf -CARDFILES = doc/orgcard.tex doc/orgcard.pdf doc/orgcard_letter.pdf -TEXIFILES = doc/org.texi -INFOFILES = doc/org +LISPBF = ob.el \ + ob-table.el \ + ob-lob.el \ + ob-ref.el \ + ob-exp.el \ + ob-tangle.el \ + ob-comint.el \ + ob-keys.el + +LISPBLF = ob-C.el \ + ob-ditaa.el \ + ob-haskell.el \ + ob-perl.el \ + ob-sh.el \ + ob-R.el \ + ob-dot.el \ + ob-latex.el \ + ob-python.el \ + ob-sql.el \ + ob-asymptote.el \ + ob-emacs-lisp.el \ + ob-matlab.el \ + ob-ruby.el \ + ob-sqlite.el \ + ob-clojure.el \ + ob-ocaml.el \ + ob-sass.el \ + ob-css.el \ + ob-gnuplot.el \ + ob-octave.el \ + ob-screen.el + +LISPFILES0 = $(LISPF:%=lisp/%) +LISPFILES = $(LISPFILES0) lisp/org-install.el +LISPBFILES = $(LISPBF:%=lisp/babel/%) +LISPBLFILES = $(LISPBLF:%=lisp/babel/langs/%) +ELCFILES0 = $(LISPFILES0:.el=.elc) +ELCFILES = $(LISPFILES:.el=.elc) +ELCBFILES = $(LISPBFILES:.el=.elc) +DOCFILES = doc/org.texi doc/org.pdf doc/org doc/dir \ + doc/pdflayout.sty doc/.nosearch \ + doc/orgguide.texi doc/orgguide.pdf +CARDFILES = doc/orgcard.tex doc/orgcard.pdf doc/orgcard_letter.pdf +TEXIFILES = doc/org.texi +INFOFILES = doc/org .SUFFIXES: .el .elc .texi @@ -148,9 +176,9 @@ SHELL = /bin/sh DISTFILES_extra= Makefile ChangeLog request-assign-future.txt contrib DISTFILES_xemacs= xemacs/noutline.el xemacs/ps-print-invisible.el xemacs/README -default: $(ELCFILES) +default: $(ELCFILES) $(ELCBFILES) -all: $(ELCFILES) $(INFOFILES) +all: $(ELCFILES) $(ELCBFILES) $(INFOFILES) up2: update sudo ${MAKE} install @@ -160,7 +188,7 @@ update: ${MAKE} clean ${MAKE} all -compile: $(ELCFILES0) +compile: $(ELCFILES0) $(ELCBFILES) install: install-lisp @@ -172,10 +200,15 @@ p: g: ${MAKE} pdf && open doc/orgguide.pdf -install-lisp: $(LISPFILES) $(ELCFILES) +install-lisp: $(LISPFILES) $(LISPBFILES) $(ELCFILES) if [ ! -d $(lispdir) ]; then $(MKDIR) $(lispdir); else true; fi ; - $(CP) $(LISPFILES) $(lispdir) - $(CP) $(ELCFILES) $(lispdir) + if [ ! -d $(lispbdir) ]; then $(MKDIR) $(lispbdir); else true; fi ; + if [ ! -d $(lispbldir) ]; then $(MKDIR) $(lispbldir); else true; fi ; + $(CP) $(LISPFILES) $(lispdir) + $(CP) $(ELCFILES) $(lispdir) + $(CP) $(LISPBFILES) $(lispbdir) + $(CP) $(ELCBFILES) $(lispbdir) + $(CP) $(LISPBLFILES) $(lispbldir) install-info: $(INFOFILES) if [ ! -d $(infodir) ]; then $(MKDIR) $(infodir); else true; fi ; @@ -191,7 +224,7 @@ install-noutline: xemacs/noutline.elc autoloads: lisp/org-install.el -lisp/org-install.el: $(LISPFILES0) Makefile +lisp/org-install.el: $(LISPFILES0) $(LISPBFILES) Makefile $(BATCH) --eval "(require 'autoload)" \ --eval '(find-file "org-install.el")' \ --eval '(erase-buffer)' \ @@ -268,6 +301,7 @@ distfile: $(MKDIR) org-$(TAG)/doc $(MKDIR) org-$(TAG)/lisp cp -r $(LISPFILES) org-$(TAG)/lisp + cp -r $(LISPBFILES) org-$(TAG)/lisp/babel cp -r $(DOCFILES) $(CARDFILES) org-$(TAG)/doc cp -r $(DISTFILES_extra) org-$(TAG)/ cp -r README_DIST org-$(TAG)/README @@ -374,7 +408,7 @@ lisp/org-crypt.elc: lisp/org-crypt.el lisp/org.el lisp/org-ctags.elc: lisp/org.el lisp/org-datetree.elc: lisp/org.el lisp/org-docview.elc: lisp/org.el -lisp/org-entities.elc: +lisp/org-entities.elc: lisp/org-exp.elc: lisp/org.el lisp/org-agenda.el lisp/org-exp-blocks.elc: lisp/org.el lisp/org-latex.elc: lisp/org.el lisp/org-exp.el lisp/org-beamer.el @@ -398,7 +432,7 @@ lisp/org-mac-message.elc: lisp/org.el lisp/org-macs.elc: lisp/org-mew.elc: lisp/org.el lisp/org-mhe.elc: lisp/org.el -lisp/org-mks.elc: +lisp/org-mks.elc: lisp/org-mobile.elc: lisp/org.el lisp/org-mouse.elc: lisp/org.el lisp/org-plot.elc: lisp/org.el lisp/org-exp.el lisp/org-table.el From 37b5faec0f7bed7ad6ecfaa469ac4581b74b98bc Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 30 Jun 2010 13:19:41 -0700 Subject: [PATCH 3/5] in Makefile replacing babel files in construction of org-install.el * Makefile (lisp/org-install.el): replacing babel files in construction of org-install.el --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 360a37c99..a1b744243 100644 --- a/Makefile +++ b/Makefile @@ -228,7 +228,7 @@ lisp/org-install.el: $(LISPFILES0) $(LISPBFILES) Makefile $(BATCH) --eval "(require 'autoload)" \ --eval '(find-file "org-install.el")' \ --eval '(erase-buffer)' \ - --eval '(mapc (lambda (x) (generate-file-autoloads (symbol-name x))) (quote ($(LISPFILES0))))' \ + --eval '(mapc (lambda (x) (generate-file-autoloads (symbol-name x))) (quote ($(LISPFILES0) $(LISPBFILES))))' \ --eval "(insert \"(add-to-list 'load-path (expand-file-name \\\"babel\\\" (file-name-directory (or load-file-name (buffer-file-name)))))\")" \ --eval "(insert \"\n(add-to-list 'load-path (expand-file-name \\\"langs\\\" (expand-file-name \\\"babel\\\" (file-name-directory (or load-file-name (buffer-file-name))))))\")\n" \ --eval '(insert "\n(provide (quote org-install))\n")' \ From 011553652e2be62714886885233b9a2a7bac3ff9 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 30 Jun 2010 12:28:32 +0200 Subject: [PATCH 4/5] Remove unwanted #+ATTR_Backend and #+Backend during export. * lisp/org-exp.el: (org-export-select-backend-specific-text) Properly get rid of #+Backend and #+ATTR_Backend specifics to backends not matching the one we're exporting to. --- lisp/org-exp.el | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 54afdace8..d7a9e1988 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1526,15 +1526,25 @@ from the buffer." (while formatters (setq fmt (pop formatters)) - (when (eq (car fmt) backend) - ;; This is selected code, put it into the file for real - (goto-char (point-min)) - (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt) - ":[ \t]*\\(.*\\)") nil t) + ;; Handle #+Backend: stuff + (goto-char (point-min)) + (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt) + ":[ \t]*\\(.*\\)") nil t) + (if (not (eq (car fmt) backend)) + (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))) (replace-match "\\1\\2" t) (add-text-properties (point-at-bol) (min (1+ (point-at-eol)) (point-max)) '(org-protected t)))) + ;; Delete #+attr_Backend: stuff of another backend. Those + ;; matching the current backend will be taken care of by + ;; `org-export-attach-captions-and-attributes' + (goto-char (point-min)) + (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt) + ":[ \t]*\\(.*\\)") nil t) + (when (not (eq (car fmt) backend)) + (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))))) + ;; Handle #+begin_Backend and #+end_Backend stuff (goto-char (point-min)) (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?") nil t) @@ -1598,11 +1608,17 @@ table line. If it is a link, add it to the line containing the link." (while (re-search-forward re nil t) (cond ((match-end 1) - (setq cap (concat cap (if cap " " "") (org-trim (match-string 1))))) + (progn + (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))) + (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))))) ((match-end 2) - (setq attr (concat attr (if attr " " "") (org-trim (match-string 2))))) + (progn + (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))) + (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))))) ((match-end 3) - (setq label (org-trim (match-string 3)))) + (progn + (setq label (org-trim (match-string 3))) + (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))))) (t (setq end (if (match-end 4) (let ((ee (org-table-end))) From f44832eed05dd42f6d4ea16e231f7570ae08e8bd Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 30 Jun 2010 16:01:38 -0700 Subject: [PATCH 5/5] org-exp: now removing table meta (e.g. #+TBLNAME, #+TBLFM) from export * lisp/org-exp.el (org-export-handle-table-metalines): this function removes table specific meta-lines, now that we aren't wiping everything that looks remotely like a comment at the end of the export process we have to be sure to catch all of the specific lines in org-exp.el --- lisp/org-exp.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index d7a9e1988..5a7328c90 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1161,6 +1161,9 @@ on this string to produce the exported version." ;; Remove or replace comments (org-export-handle-comments (plist-get parameters :comments)) + ;; Remove #+TBLFM and #+TBLNAME lines + (org-export-handle-table-metalines) + ;; Run the final hook (run-hooks 'org-export-preprocess-final-hook) @@ -1671,6 +1674,19 @@ When it is nil, all comments will be removed." (replace-match "") (goto-char (max (point-min) (1- pos)))))))) +(defun org-export-handle-table-metalines () + "Remove table specific metalines #+TBLNAME: and #+TBLFM:." + (let ((re "^[ \t]*#\\+TBL\\(NAME\\|FM\\):\\(.*\n?\\)") + pos) + (goto-char (point-min)) + (while (or (looking-at re) + (re-search-forward re nil t)) + (setq pos (match-beginning 0)) + (if (get-text-property (point) 'org-protected) + (goto-char (1+ pos)) + (goto-char (1+ pos)) + (replace-match "") + (goto-char (max (point-min) (1- pos))))))) (defun org-export-mark-radio-links () "Find all matches for radio targets and turn them into internal links."