;;; ox-init --- Initialization script for async org exprort session ;;; Commentary: ;;; Code: (require 'ox-latex) (require 'ox-extra) (require 'oc-bibtex) (org-babel-do-load-languages 'org-babel-load-languages '((latex . t) (sql . t))) (ox-extras-activate '(ignore-headlines)) (setq org-latex-src-block-backend 'minted) (add-to-list 'org-latex-packages-alist '("newfloat" "minted")) (cl-defun cmmm/org-latex-src-block--minted (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using minted. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." (let* ((caption-str (org-latex--caption/label-string src-block info)) (placement (or (org-unbracket-string "[" "]" (plist-get attributes :placement)) (plist-get info :latex-default-figure-position))) (multicolumn-p (string= "multicolumn" float)) (float-env (cond ((string= float "nil") (cons (concat "\\begin{center}" (if caption-above-p (concat "\n" caption-str) "")) (concat (if caption-above-p "" (concat "\n" caption-str)) "\n\\end{center}" ))) ((or caption multicolumn-p) (cons (concat "\\begin{listing" (when multicolumn-p "*") "}[" placement "]\n" (if caption-above-p caption-str "")) (concat "\n" (if caption-above-p "" caption-str) "\\end{listing" (when multicolumn-p "*") "}"))) ((string= "t" float) (cons (concat "\\begin{listing}[" placement "]\n") "\n\\end{listing}")))) (options (plist-get info :latex-minted-options)) (body (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}" ;; Options. (concat (org-latex--make-option-string (if (or (not num-start) (assoc "linenos" options)) options (append `(("linenos") ("firstnumber" ,(number-to-string (1+ num-start)))) options))) (let ((local-options (plist-get attributes :options))) (and local-options (concat "," local-options)))) ;; Language. (or (cadr (assq (intern lang) (plist-get info :latex-minted-langs))) (downcase lang)) ;; Source code. (let* ((code-info (org-export-unravel-code src-block)) (max-width (apply 'max (mapcar 'string-width (org-split-string (car code-info) "\n"))))) (org-export-format-code (car code-info) (lambda (loc _num ref) (concat loc (when ref ;; Ensure references are flushed to the right, ;; separated with 6 spaces from the widest line ;; of code. (concat (make-string (+ (- max-width (length loc)) 6) ?\s) (format "(%s)" ref))))) nil (and retain-labels (cdr code-info))))))) (concat (car float-env) body (cdr float-env)))) (advice-add 'org-latex-src-block--minted :override 'cmmm/org-latex-src-block--minted) (setq org-latex-bib-compiler "biber") (setq org-latex-remove-logfiles nil) (setq org-latex-caption-above '(table src-block special-block)) (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}")))) ;;; ox-init.el ends here