aboutsummaryrefslogtreecommitdiff
path: root/doc/ox-init.el
blob: 3d60dc6c957e55b179e550a96e87cd0149547745 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
;;; ox-init --- Initialization script for async org exprort session
;;; Commentary:
;;; Code:
(require 'ox-latex)
(require 'ox-extra)
(require 'oc-bibtex)

(org-babel-do-load-languages
 'org-babel-load-languages
 '((latex . t)
   (sql . t)))

(ox-extras-activate '(ignore-headlines))

(setq org-latex-src-block-backend 'minted)
(add-to-list 'org-latex-packages-alist '("newfloat" "minted"))

(cl-defun cmmm/org-latex-src-block--minted
    (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys)
  "Transcode a SRC-BLOCK element from Org to LaTeX, using minted.
LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES
and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
  (let* ((caption-str (org-latex--caption/label-string src-block info))
         (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement))
                        (plist-get info :latex-default-figure-position)))
         (multicolumn-p (string= "multicolumn" float))
         (float-env
          (cond
           ((string= float "nil")
            (cons
             (concat "\\begin{center}" (if caption-above-p (concat "\n" caption-str) ""))
             (concat (if caption-above-p "" (concat "\n" caption-str)) "\n\\end{center}" )))
           ((or caption multicolumn-p)
            (cons
             (concat "\\begin{listing" (when multicolumn-p "*")
                     "}[" placement "]\n"
                     (if caption-above-p caption-str ""))
             (concat "\n" (if caption-above-p "" caption-str)
                     "\\end{listing" (when multicolumn-p "*") "}")))
           ((string= "t" float)
            (cons
             (concat "\\begin{listing}[" placement "]\n")
             "\n\\end{listing}"))))
         (options (plist-get info :latex-minted-options))
         (body
          (format
           "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
           ;; Options.
           (concat
            (org-latex--make-option-string
             (if (or (not num-start) (assoc "linenos" options))
                 options
               (append
                `(("linenos")
                  ("firstnumber" ,(number-to-string (1+ num-start))))
                options)))
            (let ((local-options (plist-get attributes :options)))
              (and local-options (concat "," local-options))))
           ;; Language.
           (or (cadr (assq (intern lang)
                           (plist-get info :latex-minted-langs)))
               (downcase lang))
           ;; Source code.
           (let* ((code-info (org-export-unravel-code src-block))
                  (max-width
                   (apply 'max
                          (mapcar 'string-width
                                  (org-split-string (car code-info)
                                                    "\n")))))
             (org-export-format-code
              (car code-info)
              (lambda (loc _num ref)
                (concat
                 loc
                 (when ref
                   ;; Ensure references are flushed to the right,
                   ;; separated with 6 spaces from the widest line
                   ;; of code.
                   (concat (make-string (+ (- max-width (length loc)) 6)
                                        ?\s)
                           (format "(%s)" ref)))))
              nil (and retain-labels (cdr code-info)))))))
    (concat (car float-env) body (cdr float-env))))
(advice-add 'org-latex-src-block--minted :override 'cmmm/org-latex-src-block--minted)

(setq org-latex-bib-compiler "biber")

(setq org-latex-remove-logfiles nil)

(setq org-latex-caption-above '(table src-block special-block))

(setq org-latex-pdf-process '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
                              "%bib %b"
                              "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"))
(setq org-latex-classes '(("spbstu-report" "\\documentclass[12pt]{spbstu-report}"
                           ("\\section{%s}" . "\\section*{%s}")
                           ("\\subsection{%s}" . "\\subsection*{%s}")
                           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                           ("\\paragraph{%s}" . "\\paragraph*{%s}")
                           ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))

;;; ox-init.el ends here