On Tue, Jan 10 2023, Nick Dokos <ndo...@gmail.com> wrote: > Leo Butler <leo.but...@umanitoba.ca> writes: > >>> >>> So: if you insert >>> >>> :PROPERTIES: >>> :EXPORT_FILE_NAME: lecture-1.pdf >>> :END: >>> >> >> Aha! Thank you very much. I had forgotten about using property >> drawers. It would be a simple matter to create a filter to insert that >> property drawer under the heading that contains point. >> > > IIUC, you really don't need to insert things dynamically: you can add > an appropriate property drawer after every top-level heading once and > for all.
Yes, you are correct. And, in fact, the naïve way to insert the property dynamically (using ~org-export-before-processing-hook~) does not work: #+name: does-not-work #+begin_src emacs-lisp :exports none (defun ltb-org-insert-export-file-name (backend) (save-excursion (goto-char (point-min)) (while (search-forward-regexp "^[*] Lecture \\([0-9]+\\)" nil t) (forward-line 1) (let ((num (match-string 1))) (unless (looking-at "^:PROPERTIES:") (let ((pty (format ":PROPERTIES:\n:EXPORT_FILE_NAME: lecture-%s.pdf\n:END:\n" num))) (insert pty) (message (buffer-substring-no-properties (point-min) (point-max))))))))) (add-hook 'org-export-before-processing-hook 'ltb-org-insert-export-file-name) #+end_src The property drawer is ignored, presumably because org has already scanned the file and determined the filename. I guess one would need to reach inside the document structure and alter the filename there, but I don't have that knowledge. Suggestions are welcome. Leo