247 lines
7.8 KiB
EmacsLisp
247 lines
7.8 KiB
EmacsLisp
|
|
;;;
|
||
|
|
|
||
|
|
(require 'cl)
|
||
|
|
|
||
|
|
(defvar *backend* nil)
|
||
|
|
(defvar org-generate-default-toc t)
|
||
|
|
(defvar org-tex-engine "default")
|
||
|
|
|
||
|
|
(setq org-babel-temporary-directory
|
||
|
|
(format "/tmp/emacs.babel.%d" (emacs-pid)))
|
||
|
|
|
||
|
|
(defun choose-tex-engine (name)
|
||
|
|
(let ((tex-engines '(("pdflatex2" .
|
||
|
|
("pdflatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"pdflatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("pdflatex3" .
|
||
|
|
("pdflatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"pdflatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"pdflatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("pdflatex3-bibtex" .
|
||
|
|
("pdflatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"bibtex %b"
|
||
|
|
"pdflatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"pdflatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("xelatex2" .
|
||
|
|
("xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("xelatex3" .
|
||
|
|
("xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("xelatex3-bibtex" .
|
||
|
|
("xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"bibtex %b"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"))
|
||
|
|
("texi2dvi" . ("texi2dvi -p -b -V %f"))
|
||
|
|
("rubber" . ("rubber -d --into %o %f"))
|
||
|
|
("latexmk" . ("latexmk -g -pdf %f")))))
|
||
|
|
(let ((engine (assoc name tex-engines)))
|
||
|
|
(if engine
|
||
|
|
(cdr engine)
|
||
|
|
(cdr (assoc "pdflatex2" tex-engines))))))
|
||
|
|
|
||
|
|
|
||
|
|
(defun add-moderncv-class (backend)
|
||
|
|
(unless (member "moderncv" (mapcar #'car org-latex-classes))
|
||
|
|
(setq org-latex-classes
|
||
|
|
(append '(("moderncv" "\\documentclass[10pt,a4paper,roman]{moderncv}"
|
||
|
|
("\\section{%s}" . "\\section*{%s}")
|
||
|
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
||
|
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
|
||
|
|
("\\paragraph{%s}" . "\\paragraph*{%s}")
|
||
|
|
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
|
||
|
|
org-latex-classes))))
|
||
|
|
|
||
|
|
|
||
|
|
(defun do-foreach (tag action)
|
||
|
|
(save-excursion
|
||
|
|
(progn (goto-char (point-min))
|
||
|
|
(while (re-search-forward tag nil t)
|
||
|
|
(progn (funcall action)
|
||
|
|
(forward-line 1))))))
|
||
|
|
|
||
|
|
;; update all radio tables
|
||
|
|
;; in the document
|
||
|
|
(defun send-all-tables (backend)
|
||
|
|
(interactive)
|
||
|
|
(let ((*backend* backend))
|
||
|
|
(do-foreach "[ \t]*#\\+ORGTBL:"
|
||
|
|
#'(lambda ()
|
||
|
|
(forward-line)
|
||
|
|
(call-interactively 'orgtbl-send-table)))))
|
||
|
|
|
||
|
|
(defun org-use-xelatex ()
|
||
|
|
(interactive)
|
||
|
|
(setq org-latex-pdf-process
|
||
|
|
(quote ("xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"bibtex %b" "xelatex -interaction nonstopmode -output-directory %o %f"
|
||
|
|
"xelatex -interaction nonstopmode -output-directory %o %f"))))
|
||
|
|
|
||
|
|
|
||
|
|
(defun org-odt-publish-to-odt (plist filename pub-dir)
|
||
|
|
(message "odt publishing\n")
|
||
|
|
(org-publish-org-to 'odt filename
|
||
|
|
(concat "." (or (plist-get plist :odt-extension)
|
||
|
|
org-html-extension "odt"))
|
||
|
|
plist pub-dir))
|
||
|
|
|
||
|
|
(defun org-before-publish (backend)
|
||
|
|
(org-choose-tex-engine)
|
||
|
|
(if (boundp 'org-babel-temporary-directory)
|
||
|
|
(unless (file-exists-p org-babel-temporary-directory)
|
||
|
|
(progn
|
||
|
|
(make-directory org-babel-temporary-directory t)))))
|
||
|
|
|
||
|
|
(defun my-org-before-parsing-hook (backend)
|
||
|
|
(progn
|
||
|
|
(send-all-tables backend)
|
||
|
|
(add-moderncv-class backend))) ;; update radio tables
|
||
|
|
|
||
|
|
(defun position-of-match (pattern)
|
||
|
|
(if (re-search-forward pattern nil t 1)
|
||
|
|
(progn
|
||
|
|
(list (match-beginning 0)
|
||
|
|
(match-end 0)))
|
||
|
|
nil))
|
||
|
|
|
||
|
|
(defun my-org-before-processing-hook (backend)
|
||
|
|
t)
|
||
|
|
|
||
|
|
|
||
|
|
(defun org-choose-tex-engine ()
|
||
|
|
(hack-local-variables)
|
||
|
|
(setq org-latex-pdf-process
|
||
|
|
(choose-tex-engine (if org-tex-engine
|
||
|
|
org-tex-engine
|
||
|
|
"default"))))
|
||
|
|
|
||
|
|
(defun customize-org ()
|
||
|
|
(custom-set-variables
|
||
|
|
'(org-babel-load-languages
|
||
|
|
(quote ((emacs-lisp . t)
|
||
|
|
(C . t)
|
||
|
|
(calc . t)
|
||
|
|
(ditaa . t)
|
||
|
|
(gnuplot . t)
|
||
|
|
(mscgen . t)
|
||
|
|
(octave . t)
|
||
|
|
(plantuml . t)
|
||
|
|
(sh . t)
|
||
|
|
(haskell . t)
|
||
|
|
(metapost . t)
|
||
|
|
(dot . t)
|
||
|
|
(R . t)
|
||
|
|
(latex . t)
|
||
|
|
(tikz . t))))
|
||
|
|
'(org-babel-tangle-lang-exts
|
||
|
|
(quote (("emacs-lisp" . "el")
|
||
|
|
("metapost" . "mp")
|
||
|
|
("Language name" . "File Extension"))))
|
||
|
|
'(org-confirm-babel-evaluate nil)
|
||
|
|
'(org-ditaa-jar-path "~/.emacs.d/misc/ditaa.jar")
|
||
|
|
'(org-enforce-todo-dependencies t)
|
||
|
|
'(org-export-backends (quote (ascii html icalendar latex odt md beamer)))
|
||
|
|
'(org-latex-default-packages-alist
|
||
|
|
(quote (("T1" "fontenc" t)
|
||
|
|
("" "fixltx2e" nil)
|
||
|
|
("" "graphicx" t)
|
||
|
|
("" "longtable" nil)
|
||
|
|
("" "float" nil)
|
||
|
|
;; ("" "wrapfig" nil)
|
||
|
|
("" "soul" t)
|
||
|
|
("" "textcomp" t)
|
||
|
|
("" "marvosym" t)
|
||
|
|
("" "wasysym" t)
|
||
|
|
("" "latexsym" t)
|
||
|
|
("" "amssymb" t)
|
||
|
|
("" "amstext" nil)
|
||
|
|
("" "hyperref" nil) "\\tolerance=1000")))
|
||
|
|
`(org-plantuml-jar-path ,(concat *custom-dir* "/misc/plantuml.jar"))))
|
||
|
|
|
||
|
|
(defun my-org-init ()
|
||
|
|
(make-local-variable 'org-tex-engine)
|
||
|
|
(make-local-variable 'buffer-file-coding-system)
|
||
|
|
(setq org-babel-load-languages nil)
|
||
|
|
(customize-org)
|
||
|
|
(put 'org-latex-default-packages-alist 'safe-local-variable 'listp)
|
||
|
|
(put 'org-tex-engine 'safe-local-variable 'stringp)
|
||
|
|
(put 'buffer-file-coding-system 'safe-local-variable 'symbolp)
|
||
|
|
(put 'org-latex-title-command 'safe-local-variable 'stringp)
|
||
|
|
(put 'org-latex-toc-command 'safe-local-variable 'stringp)
|
||
|
|
(unless (file-exists-p org-babel-temporary-directory)
|
||
|
|
(make-directory org-babel-temporary-directory)))
|
||
|
|
|
||
|
|
(defun my-org-config ()
|
||
|
|
;; (add-hook 'org-babel-after-execute-hook
|
||
|
|
;; 'org-display-inline-images)
|
||
|
|
;; (setq org-startup-with-inline-images t)
|
||
|
|
;; Using xelatex to enable
|
||
|
|
;; CJK support
|
||
|
|
;;(add-hook 'org-mode-hook 'org-use-xelatex)
|
||
|
|
(add-hook 'org-mode-hook 'orgtbl-mode)
|
||
|
|
(add-hook 'org-export-before-parsing-hook 'my-org-before-parsing-hook)
|
||
|
|
(add-hook 'org-export-before-processing-hook 'my-org-before-processing-hook)
|
||
|
|
(add-hook 'org-export-before-processing-hook 'org-before-publish)
|
||
|
|
(add-hook 'org-mode-hook 'turn-on-org-cdlatex)
|
||
|
|
(setq org-export-allow-bind-keywords t)
|
||
|
|
(setq org-latex-to-mathml-convert-command
|
||
|
|
"java -jar %j -unicode -force -df %o %I"
|
||
|
|
org-latex-to-mathml-jar-file
|
||
|
|
"~/.emacs.d/misc/mathtoweb.jar")
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
(defun org-use-template (template)
|
||
|
|
(interactive
|
||
|
|
(let ((template-used (read-file-name "choose template: "
|
||
|
|
(expand-file-name "~/.emacs.d/templates/")
|
||
|
|
nil nil nil)))
|
||
|
|
(list template-used)))
|
||
|
|
(when template
|
||
|
|
(insert-file-contents template)
|
||
|
|
;; enable file local variables defined in template
|
||
|
|
;;
|
||
|
|
(hack-local-variables)))
|
||
|
|
|
||
|
|
(defun refill-org-paragraphs ()
|
||
|
|
(interactive)
|
||
|
|
(save-excursion
|
||
|
|
(goto-char (point-min))
|
||
|
|
(while (not (eql (point) (point-max)))
|
||
|
|
(org-fill-paragraph)
|
||
|
|
(org-forward-paragraph))))
|
||
|
|
|
||
|
|
;; reshape-web-paragraph ()
|
||
|
|
;; this function is used to reshape the paragraph copied from
|
||
|
|
;; web browser which a paragraph is just a very log line
|
||
|
|
(defun reshape-web-paragraph ()
|
||
|
|
(interactive)
|
||
|
|
(save-excursion
|
||
|
|
(goto-char (point-min))
|
||
|
|
(when (< (point) (point-max))
|
||
|
|
(forward-sentence)
|
||
|
|
(when (< (point) (point-max))
|
||
|
|
(insert "\n")
|
||
|
|
(reshape-web-paragraph)))))
|
||
|
|
|
||
|
|
(defun delete-extra-empty-lines ()
|
||
|
|
(interactive)
|
||
|
|
(save-excursion
|
||
|
|
(goto-char (point-min))
|
||
|
|
(my-zap-multiple-empty-lines)))
|
||
|
|
|
||
|
|
(register-mypkg
|
||
|
|
(list :name "org"
|
||
|
|
:enabled t
|
||
|
|
:packages '(auctex org puml-mode cdlatex ox-ioslide
|
||
|
|
gnuplot gnuplot-mode)
|
||
|
|
:init #'(lambda ()
|
||
|
|
(my-org-init)
|
||
|
|
(setq puml-plantuml-jar-path
|
||
|
|
(expand-file-name (concat *custom-dir* "/misc/plantuml.jar")))
|
||
|
|
(setenv "GRAPHVIZ_DOT" (which "dot")))
|
||
|
|
:config #'(lambda ()
|
||
|
|
(my-org-config))))
|