[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: setting export_file_name during export
From: |
Leo Butler |
Subject: |
Re: setting export_file_name during export |
Date: |
Tue, 10 Jan 2023 20:01:13 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
On Tue, Jan 10 2023, Nick Dokos <ndokos@gmail.com> wrote:
> Leo Butler <Leo.Butler@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