aboutsummaryrefslogtreecommitdiff
path: root/doc/diploma/ox-init.el
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 22:28:13 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-11 22:47:34 +0000
commitcb070b2d3f2b6e241e3be1b7e0eeb90fc755255f (patch)
treec7d90c0abe9533c87d51b5196871846855efa1ba /doc/diploma/ox-init.el
downloadthesis-cb070b2d3f2b6e241e3be1b7e0eeb90fc755255f.tar.gz
publishHEADmaster
Diffstat (limited to 'doc/diploma/ox-init.el')
-rw-r--r--doc/diploma/ox-init.el145
1 files changed, 145 insertions, 0 deletions
diff --git a/doc/diploma/ox-init.el b/doc/diploma/ox-init.el
new file mode 100644
index 0000000..7139e8d
--- /dev/null
+++ b/doc/diploma/ox-init.el
@@ -0,0 +1,145 @@
1;;; ox-init.el --- Initialization script for async org exprort session
2;;; Commentary:
3;;; Code:
4
5;; (org-babel-do-load-languages
6;; 'org-babel-load-languages
7;; '((latex . t)))
8
9(add-to-list 'load-path "/home/cmmm/.config/emacs/elpaca/builds/org")
10(add-to-list 'load-path "/home/cmmm/.config/emacs/elpaca/builds/org-contrib")
11
12(setenv "TEXINPUTS" "./:./gost/:")
13
14(setq org-latex-remove-logfiles nil)
15
16(setq org-export-default-language "ru")
17
18(setq org-latex-default-packages-alist nil)
19
20(setq org-latex-toc-include-unnumbered t)
21
22(setq org-latex-tables-booktabs t)
23
24(setq org-latex-caption-above '(table))
25
26;; (setq org-latex-pdf-process '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"))
27(setq org-latex-pdf-process '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
28 "%bib %b"
29 "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"))
30
31(setq org-latex-classes '(("spbstu-report" "\\documentclass[14pt]{spbstu-report}"
32 ("\\section{%s}" . "\\section*{%s}")
33 ("\\subsection{%s}" . "\\subsection*{%s}")
34 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
35 ("\\paragraph{%s}" . "\\paragraph*{%s}")
36 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
37
38(require 'ox-extra)
39(ox-extras-activate '(ignore-headlines))
40;; (setq org-export-exclude-tags nil)
41
42;; (setq org-latex-src-block-backend 'minted)
43(setq org-latex-src-block-backend 'listings)
44(setq org-latex-listings-options '(("numbers" "left")))
45
46(require 'oc-bibtex)
47(setq org-latex-bib-compiler "biber")
48
49;; TODO(cmmm): add \addlinespace between rows which don't have 'rule
50;; TODO(cmmm): wrap head columns in something like:
51;; \multicolumn{1}{c}{\bold head1}
52(defun cmmm-org-latex-table-row (table-row contents info)
53 "Transcode a TABLE-ROW element from Org to LaTeX.
54CONTENTS is the contents of the row. INFO is a plist used as
55a communication channel."
56 (let* ((attr (org-export-read-attribute :attr_latex
57 (org-element-parent table-row)))
58 (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
59 (plist-get info :latex-tables-booktabs)))
60 (longtablep
61 (member (or (plist-get attr :environment)
62 (plist-get info :latex-default-table-environment))
63 ;; adding xltabular is the only change
64 '("longtable" "longtabu" "xltabular"))))
65 (if (eq (org-element-property :type table-row) 'rule)
66 (cond
67 ((not booktabsp) "\\hline")
68 ((not (org-export-get-previous-element table-row info)) "\\toprule")
69 ((not (org-export-get-next-element table-row info)) "\\bottomrule")
70 ((and longtablep
71 (org-export-table-row-ends-header-p
72 (org-export-get-previous-element table-row info) info))
73 "")
74 (t "\\midrule"))
75 ;; Memorize table header in case it is multiline. We need this
76 ;; information to define contents before "\\endhead" in longtable environments.
77 (when (org-export-table-row-in-header-p table-row info)
78 (let ((table-head-cache (plist-get info :org-latex-table-head-cache)))
79 (unless (hash-table-p table-head-cache)
80 (setq table-head-cache (make-hash-table :test #'eq))
81 (plist-put info :org-latex-table-head-cache table-head-cache))
82 (if-let* ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
83 (puthash (org-element-parent table-row) (concat head-contents "\\\\\n" contents)
84 table-head-cache)
85 (puthash (org-element-parent table-row) contents table-head-cache))))
86 ;; Return LaTeX string as the transcoder.
87 (concat
88 ;; When BOOKTABS are activated enforce top-rule even when no
89 ;; hline was specifically marked.
90 (and booktabsp (not (org-export-get-previous-element table-row info))
91 "\\toprule\n")
92 contents "\\\\\n"
93 (cond
94 ;; Special case for long tables. Define header and footers.
95 ((and longtablep (org-export-table-row-ends-header-p table-row info))
96 (let ((columns (cdr (org-export-table-dimensions
97 (org-element-lineage table-row 'table) info))))
98 (format "%s
99\\endfirsthead
100\\multicolumn{%d}{l}{%s} \\\\
101%s
102%s \\\\\n
103%s
104\\endhead
105%s\\multicolumn{%d}{r}{%s} \\\\
106\\endfoot
107\\endlastfoot"
108 (if booktabsp "\\midrule" "\\hline")
109 columns
110 (org-latex--translate "Continued from previous page" info)
111 (cond
112 ((not (org-export-table-row-starts-header-p table-row info))
113 "")
114 (booktabsp "\\toprule\n")
115 (t "\\hline\n"))
116 (gethash (org-element-parent table-row) (plist-get info :org-latex-table-head-cache))
117 (if booktabsp "\\midrule" "\\hline")
118 (if booktabsp "\\midrule" "\\hline")
119 columns
120 (org-latex--translate "Continued on next page" info))))
121 ;; When BOOKTABS are activated enforce bottom rule even when
122 ;; no hline was specifically marked.
123 ((and booktabsp (not (org-export-get-next-element table-row info)))
124 "\\bottomrule"))))))
125(advice-add 'org-latex-table-row :override 'cmmm-org-latex-table-row)
126
127(defun cmmm-org-export-translate (s encoding info)
128 "Translate string S according to language specification.
129
130ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
131and `:utf-8'. INFO is a plist used as a communication channel.
132
133Translation depends on `:language' property. Return the
134translated string. If no translation is found, try to fall back
135to `:default' encoding. If it fails, return S."
136 (let* ((lang (plist-get info :language))
137 (translations (cdr (assoc lang
138 (cdr (assoc s org-export-dictionary))))))
139 (or (plist-get translations encoding)
140 (plist-get translations :default)
141 (plist-get translations :utf-8)
142 s)))
143(advice-add 'org-export-translate :override 'cmmm-org-export-translate)
144
145;;; ox-init.el ends here