Export Denote notes with Org Mode
Org Mode has a built-in configurable export engine. You can prevent duplicate identifiers when exporting manually for each exported file or by advising the Org export function.
The denote-org package (by Protesilaos) also provides commands to convert ‘denote:’ links to their ‘file:’ equivalent, in case this is a required pre-processing step for export purposes.
Manually configure Org export
Insert ‘
#+export_file_name: FILENAME’ in the front matter before exporting to force a filename called whatever the value of ‘FILENAME’ is. The ‘FILENAME’ does not specify the file type extension, such as ‘.pdf’. This is up to the export engine. For example, a Denote note with a complete file name of ‘20230515T085612--example__keyword.org’ and a front matter entry of ‘#+export_file_name: hello’ will be exported as ‘hello.pdf’.The advantage of this manual method is that it gives the user full control over the resulting file name. The disadvantage is that it depends on the user’s behaviour. Forgetting to add a new name can lead to duplicate identifiers, as already noted in the introduction to this section (Export Denote notes).
Automatically store Org exports in another folder
It is possible to automatically place all exports in another folder by making Org’s function
org-export-output-file-namecreate the target directory if needed and move the exported file there. Remember that advising Elisp code must be handled with care, as it might break the original function in subtle ways.emacs-lisp(defvar my-org-export-output-directory-prefix "./export_" "Prefix of directory used for org-mode export. The single dot means that the directory is created on the same level as the one where the Org file that performs the exporting is. Use two dots to place the directory on a level above the current one. If this directory is part of `denote-directory', make sure it is not read by Denote. See `denote-excluded-directories-regexp'. This way there will be no known duplicate Denote identifiers produced by the Org export mechanism.") (defun my-org-export-create-directory (fn extension &rest args) "Move Org export file to its appropriate directory. Append the file type EXTENSION of the exported file to `my-org-export-output-directory-prefix' and, if absent, create a directory named accordingly. Install this as advice around `org-export-output-file-name'. The EXTENSION is supplied by that function. ARGS are its remaining arguments." (let ((export-dir (format "%s%s" my-org-export-output-directory-prefix extension))) (unless (file-directory-p export-dir) (make-directory export-dir))) (apply fn extension args)) (advice-add #'org-export-output-file-name :around #'my-org-export-create-directory)The target export directory should not be a subdirectory of
denote-directory, as that will result in duplicate identifiers. Exclude it with thedenote-excluded-directories-regexpuser option (Exclude certain directories from all operations).[ NOTE: I (Protesilaos) am not a LaTeX user and cannot test the following. ]
Using a different directory will require some additional configuration when exporting using LaTeX. The export folder cannot be inside the path of the
denote-directoryto prevent Denote from recognising it as an attachment: https://emacs.stackexchange.com/questions/45751/org-export-to-different-directory.Org Mode Publishing
Org Mode also has a publishing tool for exporting a collection of files. Some user might apply this approach to convert their note collection to a public or private website.
The
org-publish-project-alistvariable drives the publishing process, including the publishing directory.The publishing directory should not be a subdirectory of
denote-directory, as that will result in duplicate identifiers. Exclude it with thedenote-excluded-directories-regexpuser option (Exclude certain directories from all operations).