Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

This commit is contained in:
Carsten Dominik 2009-10-29 10:20:27 +01:00
commit ad4859028c
2 changed files with 94 additions and 12 deletions

View File

@ -0,0 +1,63 @@
;;; org-babel-latex.el --- org-babel functions for latex "evaluation"
;; Copyright (C) 2009 Eric Schulte
;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 0.01
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Org-Babel support for evaluating LaTeX source code.
;;
;; Currently on evaluation this returns raw LaTeX code, however at
;; some point it *may* (it may not) make sense to have LaTeX blocks
;; compile small pdfs on evaluation.
;;; Code:
(require 'org-babel)
(org-babel-add-interpreter "latex")
(add-to-list 'org-babel-tangle-langs '("latex" "tex"))
(defvar org-babel-default-header-args:latex
'((:results . "latex") (:exports . "results"))
"Default arguments to use when evaluating a latex source block.")
(defun org-babel-execute:latex (body params)
"Execute a block of Latex code with org-babel. This function is
called by `org-babel-execute-src-block'."
(message "executing Latex source code block")
(mapc (lambda (pair) ;; replace variables
(setq body
(replace-regexp-in-string
(regexp-quote (format "%S" (car pair)))
(if (stringp (cdr pair))
(cdr pair) (format "%S" (cdr pair)))
body))) vars)
body)
(defun org-babel-prep-session:latex (session params)
(error "Latex does not support sessions"))
(provide 'org-babel-latex)
;;; org-babel-latex.el ends here

View File

@ -741,12 +741,26 @@ comment) .
# <<example-block>>
This function must be called from inside of the buffer containing
the source-code block which holds BODY."
the source-code block which holds BODY.
In addition the following syntax can be used to insert the
results of evaluating the source-code block named 'example-block'.
# <<example-block()>>
Any optional arguments can be passed to example-block by placing
the arguments inside the parenthesis following the convention
defined by `org-babel-lob'. For example
# <<example-block(a=9)>>
would set the value of argument \"a\" equal to \"9\". Note that
these arguments are not evaluated in the current source-code block but are passed literally to the \"example-block\"."
(let* ((parent-buffer (or parent-buffer (current-buffer)))
(info (or info (org-babel-get-src-block-info)))
(lang (first info))
(body (second info))
(new-body "") index source-name)
(new-body "") index source-name evaluate)
(flet ((nb-add (text)
(setq new-body (concat new-body text))))
(with-temp-buffer
@ -758,20 +772,25 @@ the source-code block which holds BODY."
(setq index (point))
(while (and (re-search-forward "<<\\(.+\\)>>" nil t))
(save-match-data (setf source-name (match-string 1)))
;; add interval to new-body
(goto-char (match-end 0)) (move-end-of-line nil)
(save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
;; add interval to new-body (removing noweb reference)
(goto-char (match-beginning 0))
(nb-add (buffer-substring index (point)))
(goto-char (match-end 0))
(setq index (point))
;; if found, add body of referenced source-block
(nb-add (save-excursion
(set-buffer parent-buffer)
(let ((point (org-babel-find-named-block source-name)))
(if point
(save-excursion
(goto-char point)
(concat "\n" (org-babel-expand-noweb-references
(org-babel-get-src-block-info))))
"")))))
(if evaluate
(let ((raw (org-babel-ref-resolve-reference
source-name nil)))
(if (stringp raw) raw (format "%S" raw)))
(let ((point (org-babel-find-named-block source-name)))
(if point
(save-excursion
(goto-char point)
(concat "\n" (org-babel-expand-noweb-references
(org-babel-get-src-block-info))))
""))))))
(nb-add (buffer-substring index (point-max)))))
new-body))