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