blob: dec45ee0ae433a10ae4cf27750685bd4620ec208 (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
;;; ox-init.el --- Initialization script for async org exprort session
;;; Commentary:
;;; Code:
(org-babel-do-load-languages
'org-babel-load-languages
'((org . t)
(plantuml . t)))
(require 'ox-extra)
(ox-extras-activate '(ignore-headlines))
(setq org-latex-src-block-backend 'minted)
(require 'oc-bibtex)
(setq org-latex-bib-compiler "biber")
(setq org-latex-remove-logfiles nil)
(setq org-export-default-language "ru")
(setq org-latex-default-packages-alist nil)
(setq org-latex-tables-booktabs t)
(setq org-latex-caption-above '(table))
(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}"))))
;; TODO(cmmm): add \addlinespace between rows which don't have 'rule
;; TODO(cmmm): wrap head columns in something like:
;; \multicolumn{1}{c}{\bold head1}
(defun cmmm-org-latex-table-row (table-row contents info)
"Transcode a TABLE-ROW element from Org to LaTeX.
CONTENTS is the contents of the row. INFO is a plist used as
a communication channel."
(let* ((attr (org-export-read-attribute :attr_latex
(org-element-parent table-row)))
(booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
(plist-get info :latex-tables-booktabs)))
(longtablep
(member (or (plist-get attr :environment)
(plist-get info :latex-default-table-environment))
;; adding xltabular is the only change
'("longtable" "longtabu" "xltabular"))))
(if (eq (org-element-property :type table-row) 'rule)
(cond
((not booktabsp) "\\hline")
((not (org-export-get-previous-element table-row info)) "\\toprule")
((not (org-export-get-next-element table-row info)) "\\bottomrule")
((and longtablep
(org-export-table-row-ends-header-p
(org-export-get-previous-element table-row info) info))
"")
(t "\\midrule"))
;; Memorize table header in case it is multiline. We need this
;; information to define contents before "\\endhead" in longtable environments.
(when (org-export-table-row-in-header-p table-row info)
(let ((table-head-cache (plist-get info :org-latex-table-head-cache)))
(unless (hash-table-p table-head-cache)
(setq table-head-cache (make-hash-table :test #'eq))
(plist-put info :org-latex-table-head-cache table-head-cache))
(if-let* ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
(puthash (org-element-parent table-row) (concat head-contents "\\\\\n" contents)
table-head-cache)
(puthash (org-element-parent table-row) contents table-head-cache))))
;; Return LaTeX string as the transcoder.
(concat
;; When BOOKTABS are activated enforce top-rule even when no
;; hline was specifically marked.
(and booktabsp (not (org-export-get-previous-element table-row info))
"\\toprule\n")
contents "\\\\\n"
(cond
;; Special case for long tables. Define header and footers.
((and longtablep (org-export-table-row-ends-header-p table-row info))
(let ((columns (cdr (org-export-table-dimensions
(org-element-lineage table-row 'table) info))))
(format "%s
\\endfirsthead
\\multicolumn{%d}{l}{%s} \\\\
%s
%s \\\\\n
%s
\\endhead
%s\\multicolumn{%d}{r}{%s} \\\\
\\endfoot
\\endlastfoot"
(if booktabsp "\\midrule" "\\hline")
columns
(org-latex--translate "Continued from previous page" info)
(cond
((not (org-export-table-row-starts-header-p table-row info))
"")
(booktabsp "\\toprule\n")
(t "\\hline\n"))
(gethash (org-element-parent table-row) (plist-get info :org-latex-table-head-cache))
(if booktabsp "\\midrule" "\\hline")
(if booktabsp "\\midrule" "\\hline")
columns
(org-latex--translate "Continued on next page" info))))
;; When BOOKTABS are activated enforce bottom rule even when
;; no hline was specifically marked.
((and booktabsp (not (org-export-get-next-element table-row info)))
"\\bottomrule"))))))
(advice-add 'org-latex-table-row :override 'cmmm-org-latex-table-row)
(defun cmmm-org-export-translate (s encoding info)
"Translate string S according to language specification.
ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1'
and `:utf-8'. INFO is a plist used as a communication channel.
Translation depends on `:language' property. Return the
translated string. If no translation is found, try to fall back
to `:default' encoding. If it fails, return S."
(let* ((lang (plist-get info :language))
(translations (cdr (assoc lang
(cdr (assoc s org-export-dictionary))))))
(or (plist-get translations encoding)
(plist-get translations :default)
(plist-get translations :utf-8)
s)))
(advice-add 'org-export-translate :override 'cmmm-org-export-translate)
;;; ox-init.el ends here
|