diff options
Diffstat (limited to 'doc/ox-init.el')
| -rw-r--r-- | doc/ox-init.el | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/doc/ox-init.el b/doc/ox-init.el new file mode 100644 index 0000000..3d60dc6 --- /dev/null +++ b/doc/ox-init.el | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | ;;; ox-init --- Initialization script for async org exprort session | ||
| 2 | ;;; Commentary: | ||
| 3 | ;;; Code: | ||
| 4 | (require 'ox-latex) | ||
| 5 | (require 'ox-extra) | ||
| 6 | (require 'oc-bibtex) | ||
| 7 | |||
| 8 | (org-babel-do-load-languages | ||
| 9 | 'org-babel-load-languages | ||
| 10 | '((latex . t) | ||
| 11 | (sql . t))) | ||
| 12 | |||
| 13 | (ox-extras-activate '(ignore-headlines)) | ||
| 14 | |||
| 15 | (setq org-latex-src-block-backend 'minted) | ||
| 16 | (add-to-list 'org-latex-packages-alist '("newfloat" "minted")) | ||
| 17 | |||
| 18 | (cl-defun cmmm/org-latex-src-block--minted | ||
| 19 | (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys) | ||
| 20 | "Transcode a SRC-BLOCK element from Org to LaTeX, using minted. | ||
| 21 | LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES | ||
| 22 | and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." | ||
| 23 | (let* ((caption-str (org-latex--caption/label-string src-block info)) | ||
| 24 | (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement)) | ||
| 25 | (plist-get info :latex-default-figure-position))) | ||
| 26 | (multicolumn-p (string= "multicolumn" float)) | ||
| 27 | (float-env | ||
| 28 | (cond | ||
| 29 | ((string= float "nil") | ||
| 30 | (cons | ||
| 31 | (concat "\\begin{center}" (if caption-above-p (concat "\n" caption-str) "")) | ||
| 32 | (concat (if caption-above-p "" (concat "\n" caption-str)) "\n\\end{center}" ))) | ||
| 33 | ((or caption multicolumn-p) | ||
| 34 | (cons | ||
| 35 | (concat "\\begin{listing" (when multicolumn-p "*") | ||
| 36 | "}[" placement "]\n" | ||
| 37 | (if caption-above-p caption-str "")) | ||
| 38 | (concat "\n" (if caption-above-p "" caption-str) | ||
| 39 | "\\end{listing" (when multicolumn-p "*") "}"))) | ||
| 40 | ((string= "t" float) | ||
| 41 | (cons | ||
| 42 | (concat "\\begin{listing}[" placement "]\n") | ||
| 43 | "\n\\end{listing}")))) | ||
| 44 | (options (plist-get info :latex-minted-options)) | ||
| 45 | (body | ||
| 46 | (format | ||
| 47 | "\\begin{minted}[%s]{%s}\n%s\\end{minted}" | ||
| 48 | ;; Options. | ||
| 49 | (concat | ||
| 50 | (org-latex--make-option-string | ||
| 51 | (if (or (not num-start) (assoc "linenos" options)) | ||
| 52 | options | ||
| 53 | (append | ||
| 54 | `(("linenos") | ||
| 55 | ("firstnumber" ,(number-to-string (1+ num-start)))) | ||
| 56 | options))) | ||
| 57 | (let ((local-options (plist-get attributes :options))) | ||
| 58 | (and local-options (concat "," local-options)))) | ||
| 59 | ;; Language. | ||
| 60 | (or (cadr (assq (intern lang) | ||
| 61 | (plist-get info :latex-minted-langs))) | ||
| 62 | (downcase lang)) | ||
| 63 | ;; Source code. | ||
| 64 | (let* ((code-info (org-export-unravel-code src-block)) | ||
| 65 | (max-width | ||
| 66 | (apply 'max | ||
| 67 | (mapcar 'string-width | ||
| 68 | (org-split-string (car code-info) | ||
| 69 | "\n"))))) | ||
| 70 | (org-export-format-code | ||
| 71 | (car code-info) | ||
| 72 | (lambda (loc _num ref) | ||
| 73 | (concat | ||
| 74 | loc | ||
| 75 | (when ref | ||
| 76 | ;; Ensure references are flushed to the right, | ||
| 77 | ;; separated with 6 spaces from the widest line | ||
| 78 | ;; of code. | ||
| 79 | (concat (make-string (+ (- max-width (length loc)) 6) | ||
| 80 | ?\s) | ||
| 81 | (format "(%s)" ref))))) | ||
| 82 | nil (and retain-labels (cdr code-info))))))) | ||
| 83 | (concat (car float-env) body (cdr float-env)))) | ||
| 84 | (advice-add 'org-latex-src-block--minted :override 'cmmm/org-latex-src-block--minted) | ||
| 85 | |||
| 86 | (setq org-latex-bib-compiler "biber") | ||
| 87 | |||
| 88 | (setq org-latex-remove-logfiles nil) | ||
| 89 | |||
| 90 | (setq org-latex-caption-above '(table src-block special-block)) | ||
| 91 | |||
| 92 | (setq org-latex-pdf-process '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f" | ||
| 93 | "%bib %b" | ||
| 94 | "%latex -shell-escape -interaction nonstopmode -output-directory %o %f")) | ||
| 95 | (setq org-latex-classes '(("spbstu-report" "\\documentclass[12pt]{spbstu-report}" | ||
| 96 | ("\\section{%s}" . "\\section*{%s}") | ||
| 97 | ("\\subsection{%s}" . "\\subsection*{%s}") | ||
| 98 | ("\\subsubsection{%s}" . "\\subsubsection*{%s}") | ||
| 99 | ("\\paragraph{%s}" . "\\paragraph*{%s}") | ||
| 100 | ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))) | ||
| 101 | |||
| 102 | ;;; ox-init.el ends here | ||
