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