diff options
Diffstat (limited to 'doc/ox-init.el')
| -rw-r--r-- | doc/ox-init.el | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/doc/ox-init.el b/doc/ox-init.el new file mode 100644 index 0000000..47ef892 --- /dev/null +++ b/doc/ox-init.el | |||
| @@ -0,0 +1,132 @@ | |||
| 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 | (setq org-latex-classes '(("spbstu-report" "\\documentclass[12pt]{spbstu-report}" | ||
| 30 | ("\\section{%s}" . "\\section*{%s}") | ||
| 31 | ("\\subsection{%s}" . "\\subsection*{%s}") | ||
| 32 | ("\\subsubsection{%s}" . "\\subsubsection*{%s}") | ||
| 33 | ("\\paragraph{%s}" . "\\paragraph*{%s}") | ||
| 34 | ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))) | ||
| 35 | |||
| 36 | ;; TODO(cmmm): add \addlinespace between rows which don't have 'rule | ||
| 37 | ;; TODO(cmmm): wrap head columns in something like: | ||
| 38 | ;; \multicolumn{1}{c}{\bold head1} | ||
| 39 | (defun cmmm-org-latex-table-row (table-row contents info) | ||
| 40 | "Transcode a TABLE-ROW element from Org to LaTeX. | ||
| 41 | CONTENTS is the contents of the row. INFO is a plist used as | ||
| 42 | a communication channel." | ||
| 43 | (let* ((attr (org-export-read-attribute :attr_latex | ||
| 44 | (org-element-parent table-row))) | ||
| 45 | (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs) | ||
| 46 | (plist-get info :latex-tables-booktabs))) | ||
| 47 | (longtablep | ||
| 48 | (member (or (plist-get attr :environment) | ||
| 49 | (plist-get info :latex-default-table-environment)) | ||
| 50 | ;; adding xltabular is the only change | ||
| 51 | '("longtable" "longtabu" "xltabular")))) | ||
| 52 | (if (eq (org-element-property :type table-row) 'rule) | ||
| 53 | (cond | ||
| 54 | ((not booktabsp) "\\hline") | ||
| 55 | ((not (org-export-get-previous-element table-row info)) "\\toprule") | ||
| 56 | ((not (org-export-get-next-element table-row info)) "\\bottomrule") | ||
| 57 | ((and longtablep | ||
| 58 | (org-export-table-row-ends-header-p | ||
| 59 | (org-export-get-previous-element table-row info) info)) | ||
| 60 | "") | ||
| 61 | (t "\\midrule")) | ||
| 62 | ;; Memorize table header in case it is multiline. We need this | ||
| 63 | ;; information to define contents before "\\endhead" in longtable environments. | ||
| 64 | (when (org-export-table-row-in-header-p table-row info) | ||
| 65 | (let ((table-head-cache (plist-get info :org-latex-table-head-cache))) | ||
| 66 | (unless (hash-table-p table-head-cache) | ||
| 67 | (setq table-head-cache (make-hash-table :test #'eq)) | ||
| 68 | (plist-put info :org-latex-table-head-cache table-head-cache)) | ||
| 69 | (if-let* ((head-contents (gethash (org-element-parent table-row) table-head-cache))) | ||
| 70 | (puthash (org-element-parent table-row) (concat head-contents "\\\\\n" contents) | ||
| 71 | table-head-cache) | ||
| 72 | (puthash (org-element-parent table-row) contents table-head-cache)))) | ||
| 73 | ;; Return LaTeX string as the transcoder. | ||
| 74 | (concat | ||
| 75 | ;; When BOOKTABS are activated enforce top-rule even when no | ||
| 76 | ;; hline was specifically marked. | ||
| 77 | (and booktabsp (not (org-export-get-previous-element table-row info)) | ||
| 78 | "\\toprule\n") | ||
| 79 | contents "\\\\\n" | ||
| 80 | (cond | ||
| 81 | ;; Special case for long tables. Define header and footers. | ||
| 82 | ((and longtablep (org-export-table-row-ends-header-p table-row info)) | ||
| 83 | (let ((columns (cdr (org-export-table-dimensions | ||
| 84 | (org-element-lineage table-row 'table) info)))) | ||
| 85 | (format "%s | ||
| 86 | \\endfirsthead | ||
| 87 | \\multicolumn{%d}{l}{%s} \\\\ | ||
| 88 | %s | ||
| 89 | %s \\\\\n | ||
| 90 | %s | ||
| 91 | \\endhead | ||
| 92 | %s\\multicolumn{%d}{r}{%s} \\\\ | ||
| 93 | \\endfoot | ||
| 94 | \\endlastfoot" | ||
| 95 | (if booktabsp "\\midrule" "\\hline") | ||
| 96 | columns | ||
| 97 | (org-latex--translate "Continued from previous page" info) | ||
| 98 | (cond | ||
| 99 | ((not (org-export-table-row-starts-header-p table-row info)) | ||
| 100 | "") | ||
| 101 | (booktabsp "\\toprule\n") | ||
| 102 | (t "\\hline\n")) | ||
| 103 | (gethash (org-element-parent table-row) (plist-get info :org-latex-table-head-cache)) | ||
| 104 | (if booktabsp "\\midrule" "\\hline") | ||
| 105 | (if booktabsp "\\midrule" "\\hline") | ||
| 106 | columns | ||
| 107 | (org-latex--translate "Continued on next page" info)))) | ||
| 108 | ;; When BOOKTABS are activated enforce bottom rule even when | ||
| 109 | ;; no hline was specifically marked. | ||
| 110 | ((and booktabsp (not (org-export-get-next-element table-row info))) | ||
| 111 | "\\bottomrule")))))) | ||
| 112 | (advice-add 'org-latex-table-row :override 'cmmm-org-latex-table-row) | ||
| 113 | |||
| 114 | (defun cmmm-org-export-translate (s encoding info) | ||
| 115 | "Translate string S according to language specification. | ||
| 116 | |||
| 117 | ENCODING is a symbol among `:ascii', `:html', `:latex', `:latin1' | ||
| 118 | and `:utf-8'. INFO is a plist used as a communication channel. | ||
| 119 | |||
| 120 | Translation depends on `:language' property. Return the | ||
| 121 | translated string. If no translation is found, try to fall back | ||
| 122 | to `:default' encoding. If it fails, return S." | ||
| 123 | (let* ((lang (plist-get info :language)) | ||
| 124 | (translations (cdr (assoc lang | ||
| 125 | (cdr (assoc s org-export-dictionary)))))) | ||
| 126 | (or (plist-get translations encoding) | ||
| 127 | (plist-get translations :default) | ||
| 128 | (plist-get translations :utf-8) | ||
| 129 | s))) | ||
| 130 | (advice-add 'org-export-translate :override 'cmmm-org-export-translate) | ||
| 131 | |||
| 132 | ;;; ox-init.el ends here | ||
