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