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