46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			EmacsLisp
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			EmacsLisp
		
	
	
	
	
	
| (require 'cl-lib)
 | |
| (defun my-org-get-docinfo (info)
 | |
|   (interactive)
 | |
|   (save-excursion
 | |
|     (progn
 | |
|       (goto-char (point-min))
 | |
|       (let ((docinfo (if (re-search-forward "^[ \t]*\\*[ \t]+DOCUMENT[ \t]+METADATA" (point-max) t)
 | |
|                          (org-entry-properties (point) nil)
 | |
|                        nil)))
 | |
|         (add-to-list 'docinfo
 | |
|                      (cons "AUTHOR"
 | |
|                            (org-export-data (plist-get info :author) info)))
 | |
|         (add-to-list 'docinfo
 | |
|                      (cons "PROJECT"
 | |
|                            (org-export-data (plist-get info :title) info)))
 | |
|         docinfo))))
 | |
| 
 | |
| 
 | |
| (defun my-org-get-table-name ()
 | |
|   (save-excursion
 | |
|     (if (re-search-backward "^[ \t]*#\\+NAME:[ \t]*\\([^ \t]*\\).*$")
 | |
|         (match-string 1)
 | |
|       "")))
 | |
| 
 | |
| (defvar orgtools-themes nil
 | |
|   "all themes we supported")
 | |
| 
 | |
| (defun orgtools-register-theme (name func)
 | |
|   "add a theme to our supported theme list"
 | |
|   (unless orgtools-themes
 | |
|     (advice-add 'org-latex-template :around #'orgtools-latex-template))
 | |
|   (unless (assoc name orgtools-themes) 
 | |
|     (add-to-list 'orgtools-themes (list name func))))
 | |
| 
 | |
| (defun orgtools-latex-template (orig-fun &rest args)
 | |
|   (let* ((content (car  args))
 | |
|          (info (car (cdr args)))
 | |
|          (docinfo (my-org-get-docinfo info)))
 | |
|     (let* ((theme (cdr (assoc "THEME" docinfo)))
 | |
|            (func (let ((vx (assoc theme orgtools-themes)))
 | |
|                    (if vx
 | |
|                        (car (cdr vx))
 | |
|                      #'(lambda (content info docinfo)
 | |
|                          (list content info )))))) 
 | |
|       (apply orig-fun (apply func (list content info docinfo))))))
 | 
