From 2499640c7149f34f5bed38fc93c586b78d514140 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Tue, 10 Nov 2026 08:42:14 +0300 Subject: publish --- doc/ox-init.el | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 doc/ox-init.el (limited to 'doc/ox-init.el') diff --git a/doc/ox-init.el b/doc/ox-init.el new file mode 100644 index 0000000..4ffe061 --- /dev/null +++ b/doc/ox-init.el @@ -0,0 +1,133 @@ +;;; ox-init.el --- Initialization script for async org exprort session +;;; Commentary: +;;; Code: +;; (org-babel-do-load-languages +;; 'org-babel-load-languages +;; '((latex . 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 -- cgit v1.3.1