Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.9 KiB

5 years ago
  1. ;;; org-re-reveal-ref.el --- Citations and bibliography for org-re-reveal -*- lexical-binding: t; -*-
  2. ;; -*- Mode: Emacs-Lisp -*-
  3. ;; -*- coding: utf-8 -*-
  4. ;; Copyright (C) 2018-2019 Jens Lechtenbörger
  5. ;; SPDX-License-Identifier: GPL-3.0-or-later
  6. ;; Author: Jens Lechtenbörger
  7. ;; URL: https://gitlab.com/oer/org-re-reveal-ref
  8. ;; Version: 0.10.0
  9. ;; Package-Requires: ((emacs "24.4") (org-ref "1.1.1") (org-re-reveal "0.9.3"))
  10. ;; Keywords: hypermedia, tools, slideshow, presentation, bibliography
  11. ;;; License:
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License as
  14. ;; published by the Free Software Foundation; either version 3, or
  15. ;; (at your option) any later version.
  16. ;; This program is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. ;; General Public License for more details.
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.
  22. ;; If not, see http://www.gnu.org/licenses/ or write to the
  23. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. ;; Boston, MA 02110-1301, USA.
  25. ;;; Commentary:
  26. ;; This package extends `org-re-reveal' with support for a
  27. ;; bibliography slide based on package `org-ref'. Thus, `cite'
  28. ;; commands of `org-ref' are translated into hyperlinks to the
  29. ;; bibliography slide upon export by `org-re-reveal'. Also, export to
  30. ;; PDF via LaTeX and export to HTML with Org's usual export
  31. ;; functionality work.
  32. ;;
  33. ;; * Install
  34. ;; 0. Install reveal.js: https://revealjs.com/
  35. ;; 1. Install org-re-reveal and org-re-reveal-ref, either from MELPA
  36. ;; or GitLab:
  37. ;; - https://gitlab.com/oer/org-re-reveal/
  38. ;; - https://gitlab.com/oer/org-re-reveal-ref/
  39. ;; (a) Place their directories into your load path or install from MELPA
  40. ;; (https://melpa.org/#/getting-started).
  41. ;; (b) Load package manually ("M-x load-library" followed by
  42. ;; "org-re-reveal-ref") or place "(require 'org-re-reveal-ref)" into
  43. ;; your ~/.emacs and restart.
  44. ;; 2. Load an Org file and export it to HTML.
  45. ;; (a) Make sure that reveal.js is available in your current directory
  46. ;; (e.g., as sub-directory or symbolic link).
  47. ;; (b) Load "README.org" (coming with org-re-reveal-ref).
  48. ;; (c) Export to HTML: Key bindings depend upon version of org-re-reveal.
  49. ;; Starting with version 1.0.0, press "C-c C-e v v" (write HTML file)
  50. ;; or "C-c C-e v b" (write HTML file and open in browser)
  51. ;;
  52. ;; * Customizable options
  53. ;; Customizable variables are `org-re-reveal-ref-bib' and
  54. ;; `org-re-reveal-ref-class'.
  55. ;; The value of `org-re-reveal-ref-bib' is used to generate hyperlinks
  56. ;; to the bibliography. You must use its value as CUSTOM_ID on your
  57. ;; bibliography slide.
  58. ;; The value of `org-re-reveal-ref-class' is assigned as class
  59. ;; attribute of hyperlinks to the bibliography slide.
  60. ;; Furthermore, the following variables of `org-ref' are changed by
  61. ;; this package:
  62. ;; - `org-ref-bib-html' is set to the empty string
  63. ;; - `org-ref-bib-html-sorted' is set to t
  64. ;; - `org-ref-printbibliography-cmd' is configured not to produce a
  65. ;; heading (as the bibliography slide has a heading already)
  66. ;; - `org-ref-ref-html' is configured to link to the bibliography
  67. ;;; Code:
  68. (require 'org-ref)
  69. (require 'org-re-reveal)
  70. (defcustom org-re-reveal-ref-bib "bibliography"
  71. "Specify name for link targets generated from citations.
  72. Use that name as CUSTOM_ID for your bibliography slide."
  73. :group 'org-export-re-reveal
  74. :type 'string)
  75. (defcustom org-re-reveal-ref-class "org-ref-reference"
  76. "Specify class of hyperlinks generated from citations.
  77. Set to empty string if no class should be assigned."
  78. :group 'org-export-re-reveal
  79. :type 'string)
  80. (defun org-re-reveal-ref-filter-bib-para (text backend info)
  81. "Replace incorrect p tags around bibliography.
  82. This function is added to `org-export-filter-paragraph-functions',
  83. where TEXT is the paragraph, BACKEND is checked for `re-reveal' or
  84. `html', and INFO is unused."
  85. (ignore info) ; Silence byte compiler
  86. (when (and (or (org-export-derived-backend-p backend 're-reveal)
  87. (org-export-derived-backend-p backend 'html))
  88. (string-match-p "<p>[ \n]*<ul" text))
  89. (replace-regexp-in-string
  90. "<p>[ \n]*<ul" "<ul"
  91. (replace-regexp-in-string "</p>\n" "" text))))
  92. (add-to-list 'org-export-filter-paragraph-functions
  93. #'org-re-reveal-ref-filter-bib-para)
  94. (setq org-ref-bib-html ""
  95. org-ref-bib-html-sorted t
  96. org-ref-printbibliography-cmd "\\printbibliography[heading=none]"
  97. org-ref-ref-html (concat
  98. "<a"
  99. (if (< 0 (length org-re-reveal-ref-class))
  100. (format " class=\"%s\"" org-re-reveal-ref-class)
  101. "")
  102. " href=\"#"
  103. org-re-reveal--href-fragment-prefix
  104. org-re-reveal-ref-bib
  105. "\">[%s]</a>"))
  106. (provide 'org-re-reveal-ref)
  107. ;;; org-re-reveal-ref.el ends here