diff --git a/contrib/babel/lisp/langs/org-babel-latex.el b/contrib/babel/lisp/langs/org-babel-latex.el new file mode 100644 index 000000000..4596bc98f --- /dev/null +++ b/contrib/babel/lisp/langs/org-babel-latex.el @@ -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 diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index 25e7d778b..daa2b369b 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -741,12 +741,26 @@ comment) . # <> 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'. + +# <> + +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 + +# <> + +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))