|
| 1 | +;;; org-export.el --- Org texinfo customizations |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | +;; Stuff to make org and texinfo work better together. |
| 5 | + |
| 6 | +;; This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | +;; License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | + |
| 10 | +;;; Code: |
| 11 | + |
| 12 | +(require 'cl-lib) |
| 13 | +(require 'ox) |
| 14 | +(require 'ox-md) |
| 15 | +(require 'ox-texinfo) |
| 16 | +(require 'ox-latex) |
| 17 | +(require 'ox-koma-letter nil t) |
| 18 | + |
| 19 | +(setq org-export-allow-bind-keywords t ; allows the use og #+BIND in org files |
| 20 | + org-export-date-timestamp-format "%Y-%m-%d" |
| 21 | + org-footnote-auto-label t ; generate numbered footnotes like [fn:1] |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +;;;; TEXINFO |
| 26 | +;;; |
| 27 | + |
| 28 | +;;; use strike-through to markup vars in texinfo |
| 29 | +(add-to-list 'org-texinfo-text-markup-alist '(strike-through . "@var{%s}")) |
| 30 | + |
| 31 | +(defun org-texinfo-ref-open (path) |
| 32 | + "Open the reference. |
| 33 | +
|
| 34 | +PATH is the reference headline." |
| 35 | + (let ((headline (org-find-exact-headline-in-buffer path (current-buffer) t))) |
| 36 | + (if headline |
| 37 | + (goto-char headline) |
| 38 | + ;; try to find anchor |
| 39 | + (let ((anchor (save-excursion |
| 40 | + (save-restriction |
| 41 | + (widen) |
| 42 | + (goto-char (point-min)) |
| 43 | + (search-forward (format "@anchor{%s}" path) nil t) |
| 44 | + (when (match-string 0) |
| 45 | + (point)))))) |
| 46 | + (when anchor |
| 47 | + (goto-char anchor)))))) |
| 48 | + |
| 49 | +(defun org-texinfo-reference-export (ref-type path description backend) |
| 50 | + "Format the texinfo reference. |
| 51 | +Argument REF-TYPE The reference type. |
| 52 | +Argument PATH Path to reference. |
| 53 | +Argument DESCRIPTION Reference Description. |
| 54 | +Argument BACKEND Org export backend." |
| 55 | + (when (eql backend 'texinfo) |
| 56 | + (format "@%s{%s}" |
| 57 | + ref-type |
| 58 | + (if description |
| 59 | + (format "%s,,%s" path description) |
| 60 | + path)))) |
| 61 | + |
| 62 | +(defun org-texinfo-xref-export (path desc backend) |
| 63 | + "Export xref with PATH DESC for BACKEND." |
| 64 | + (org-texinfo-reference-export "xref" path desc backend)) |
| 65 | + |
| 66 | +(org-link-set-parameters "texixref" |
| 67 | + :follow 'org-texinfo-ref-open |
| 68 | + :export 'org-texinfo-xref-export) |
| 69 | + |
| 70 | +(defun org-texinfo-ref-export (path desc backend) |
| 71 | + "Export ref with PATH DESC for BACKEND." |
| 72 | + (org-texinfo-reference-export "ref" path desc backend)) |
| 73 | + |
| 74 | +(org-link-set-parameters "texiref" |
| 75 | + :follow 'org-texinfo-ref-open |
| 76 | + :export 'org-texinfo-ref-export) |
| 77 | + |
| 78 | +(defun org-texinfo-pxref-export (path desc backend) |
| 79 | + "Export pxref with PATH DESC for BACKEND." |
| 80 | + (org-texinfo-reference-export "pxref" path desc backend)) |
| 81 | + |
| 82 | +(org-link-set-parameters "texipxref" |
| 83 | + :follow 'org-texinfo-ref-open |
| 84 | + :export 'org-texinfo-pxref-export) |
| 85 | + |
| 86 | +;;;; LATEX |
| 87 | +;;; |
| 88 | + |
| 89 | +;;; extend latex "log" files |
| 90 | +(setq org-latex-logfiles-extensions |
| 91 | + '("aux" "bcf" "blg" "fdb_latexmk" "fls" "figlist" "glg" "glo" "gls" "idx" "ist" |
| 92 | + "log" "nav" "out" "ptc" "run.xml" "snm" "toc" "vrb" "xdv" "bbl" "ilg" "ind" |
| 93 | + "lof" "lot" "lol" "xwm")) |
| 94 | + |
| 95 | +;;; misc. |
| 96 | +(defun toggle-org-latex-hyperref-colorlinks (&optional force-colorlinks) |
| 97 | + "Toggel colorlinks=true in LaTeX hyperref setup. |
| 98 | +
|
| 99 | +This is great for printing the document in grayscale. |
| 100 | +
|
| 101 | +With prefix argumnet or if FORCE-COLORLINKS is non-nil set |
| 102 | +hypersetup to include colorlinks=true." |
| 103 | + (interactive "P") |
| 104 | + (let ((prefix "\\hypersetup{\n pdftitle={%t},\n pdfcreator={%c}, \n pdflang={%L},\n colorlinks=") |
| 105 | + (suffix "}\n") |
| 106 | + (colorlinksp (string-match "colorlinks=true" org-latex-hyperref-template))) |
| 107 | + (setq org-latex-hyperref-template |
| 108 | + (concat prefix |
| 109 | + (if (or force-colorlinks |
| 110 | + (not colorlinksp)) |
| 111 | + "true" |
| 112 | + "false") |
| 113 | + suffix)))) |
| 114 | + |
| 115 | +;;; latex settings |
| 116 | +(setq org-latex-prefer-user-labels t |
| 117 | + org-latex-hyperref-template (toggle-org-latex-hyperref-colorlinks t) |
| 118 | + org-latex-compiler "xelatex" |
| 119 | + org-latex-pdf-process '("%latex -interaction nonstopmode %f" |
| 120 | + "%bib %b" |
| 121 | + "makeindex %b" |
| 122 | + "PATH=\"/usr/bin:$PATH\" makeglossaries %b" ; use system perl for makeglossaries |
| 123 | + "%latex -interaction nonstopmode %f" |
| 124 | + "%latex -interaction nonstopmode %f")) |
| 125 | + |
| 126 | +;;; org export filters |
| 127 | +(defvar org-export-latex-add-link-footnotes nil |
| 128 | + "If non-nil links will be added as footnotes if exported to latex.") |
| 129 | + |
| 130 | +(defun org-export-latex-link-footnote (text backend info) |
| 131 | + "Create a footnote in latex for each link. |
| 132 | +
|
| 133 | +So when printed the information isn't lost. |
| 134 | +Argument TEXT is the link's text. |
| 135 | +Argument BACKEND is the use export backend. |
| 136 | +Argument INFO - I have no idea what this does." |
| 137 | + (when (and org-export-latex-add-link-footnotes |
| 138 | + (org-export-derived-backend-p backend 'latex) |
| 139 | + (string-match "\\\\href{\\(.*\\)}{\\(.*\\)}" text)) |
| 140 | + (when (cl-some (lambda (type) |
| 141 | + (string-prefix-p type (match-string 1 text))) |
| 142 | + '("http" "https" "ftp" "mailto" "doi")) |
| 143 | + (format "%s \\footnote{\\url{%s}} " text (match-string 1 text))))) |
| 144 | +(add-to-list 'org-export-filter-link-functions #'org-export-latex-link-footnote) |
| 145 | + |
| 146 | +;;; org-babel |
| 147 | +(org-babel-do-load-languages |
| 148 | + 'org-babel-load-languages |
| 149 | + '((emacs-lisp .t) |
| 150 | + (shell . t))) |
| 151 | + |
| 152 | +(provide 'org-export) |
| 153 | + |
| 154 | +;;; org-export.el ends here |
0 commit comments