Org-mode

It is a powerful Emacs mode for note taking and for personal information management.

Export

This talk comes back on the org-publish features with a hack for having HTML templates and pages building from the metadata.

Org-THTML is one of the most interesting HTML template system for Org mode that I am aware of.

Export engines

Weblog seems a interesting project that goes beyond the publishing features of org-mode.

Firn is a static site generator for org files.

Bibliography

Org-ref

I am looking for a way to export the reference in HTML. I found an interesting start on the kitchin research group website, but their proposition is outdated. Also it requires some improvements in terms of:

  • support for any backend,
  • bibliography supported entry types.

      (setq org-ref-bibliography-entry-format
            '(("article" . "<li><a name=\"\%k\"></a>%a, %t, <i>%j</i>, <b>%v(%n)</b>, %p (%y). <a href=\"%U\">link</a>. <a href=\"https://doi.org/%D\">doi</a>.</li>")
              ("techreport" . "<li><a name=\"\%k\"></a>%a, %t, <i>%j</i>, <b>%v(%n)</b>, %p (%y). <a href=\"%U\">link</a>. <a href=\"https://doi.org/%D\">doi</a>.</li>")
              ("incollection" . "<li><a name=\"\%k\"></a>%a, %t, <i>%j</i>, <b>%v(%n)</b>, %p (%y). <a href=\"%U\">link</a>. <a href=\"https://doi.org/%D\">doi</a>.</li>")
              ("book" . "<li><a name=\"\%k\"></a>%a, %t, %u (%y).</li>")))
    
    
    (defun org-ref-unsrt-latex-processor () nil)
    (defun org-ref-unsrt-html-processor ()
      "Citation processor function for the unsrt style with html output."
      (let (links
            unique-keys numbered-keys
            replacements
            bibliography-link
            bibliographystyle-link
            bibliography)
        ;; step 1 - get the citation links
        (setq links (loop for link in (org-element-map
                                          (org-element-parse-buffer) 'link 'identity)
                          if (-contains?
                              org-ref-cite-types
                              (org-element-property :type link))
                          collect link))
    
        ;; list of unique numbered keys. '((key number))
        (setq unique-keys (loop for i from 1
                                for key in (org-ref-get-bibtex-keys)
                                collect (list key (number-to-string i))))
    
    
        ;; (start end replacement-text)
        (setq replacements
              (loop for link in links
                    collect
                    (let ((path (org-element-property :path link)))
                      (loop for (key number) in unique-keys
                            do
                            (setq
                             path
                             (replace-regexp-in-string
                              key (format "<a href=\"#%s\">%s</a>" key number)
                              path)))
                      (list (org-element-property :begin link)
                            (org-element-property :end link)
                            (format "@@html:<sup>%s</sup>@@" path)))))
    
        ;; construct the bibliography string
        (setq bibliography
              (concat "#+BEGIN_EXPORT html
    <h1>Bibliography</h1><ol>"
                      (mapconcat
                       'identity
                       (loop for (key number) in unique-keys
                             collect
                             (let* ((result (org-ref-get-bibtex-key-and-file key))
                                    (bibfile (cdr result))
                                    (entry (save-excursion
                                             (with-temp-buffer
                                               (insert-file-contents bibfile)
                                               (bibtex-set-dialect
                                                (parsebib-find-bibtex-dialect) t)
                                               (bibtex-search-entry key)
                                               (bibtex-parse-entry t)))))
                               ;; remove escaped & in the strings
                               (replace-regexp-in-string "\\\\&" "&"
                                               (org-ref-reftex-format-citation
                                                entry
                                                (cdr (assoc (cdr (assoc "=type=" entry))
                                                            org-ref-bibliography-entry-format))))))
                       "")
                      "</ol>
    #+END_EXPORT"))
    
        ;; now, we need to replace each citation. We do that in reverse order so the
        ;; positions do not change.
        (loop for (start end replacement) in (reverse replacements)
              do
              (setf (buffer-substring start end) replacement))
    
        ;; Eliminate bibliography style links
        (loop for link in (org-element-map
                              (org-element-parse-buffer) 'link 'identity)
              if (string= "bibliographystyle"
                          (org-element-property :type link))
              do
              (setf (buffer-substring (org-element-property :begin link)
                                      (org-element-property :end link))
                    ""))
    
        ;; replace the bibliography link with the bibliography text
        (setq bibliography-link (loop for link in (org-element-map
                                                      (org-element-parse-buffer) 'link 'identity)
                                      if (string= "bibliography"
                                                  (org-element-property :type link))
                                      collect link))
        (if (> (length bibliography-link) 1)
            (error "Only one bibliography link allowed"))
    
        (setq bibliography-link (car bibliography-link))
        (setf (buffer-substring (org-element-property :begin bibliography-link)
                                (org-element-property :end bibliography-link))
              bibliography)))
    
    
    (defun org-ref-citation-processor (backend)
      "Figure out what to call and call it"
      (let (bibliographystyle)
        (setq
         bibliographystyle
         (org-element-property
          :path (car
                 (loop for link in
                       (org-element-map
                           (org-element-parse-buffer) 'link 'identity)
                       if (string= "bibliographystyle"
                                   (org-element-property :type link))
                       collect link))))
        (funcall (intern (format "org-ref-%s-%s-processor" bibliographystyle backend)))))
    
    (add-hook 'org-export-before-parsing-hook 'org-ref-citation-processor)
    

Ivy BibTeX

Ivy BibTeX is a package that allows to manage and search in your BibTeX bibliography. I mostly use it to insert citation and open pdf.

HTML export

I found an explanation how to customize the HTML export.

Issues

TeX encoding in BibTeX

The TeX encoding of accent characters in BibTeX causes some unexpected results when calling bibtex-completion-insert-reference. If you use Zotero with Betterbibtex, a solution is to disable the TeX encoding for BibTeX export.

Literal Programming

How to handle JSON results nicely

echo '{"name": "john"}' | jq .
{
  "name": "john"
}

Python

Caches to Caches article about literal programming in org-mode.

Others

Thunderbird

cbthunderlink allows to link thunderbird email with org-mode. More information here.

Mobile

Orgro an application to view org files.

Parser

Orgize is org file parser in Rust.

This post accepts webmentions. Do you have the URL to your post?

Otherwise, send your comment on my service.

Or interact from the fediverse with your username:

fediverse logo Share on the Fediverse