emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tip] Export some footnotes as pdf annotations (LaTeX) or comments (odt)


From: Juan Manuel Macías
Subject: [tip] Export some footnotes as pdf annotations (LaTeX) or comments (odt)
Date: Fri, 22 Oct 2021 15:01:24 +0000

Hi,

Sometimes I need to export an Org document with certain "meta-comments",
so I wrote this export filter to export those footnotes that start with
the string "!annot" to:

- [LaTeX] PDF annotations (requires the pdfcomment LaTeX package),

- [odt] Comments.

#+BIND: org-export-filter-footnote-reference-functions 
(my-custom-filters/export-footnote-as-annotation)
#+begin_src emacs-lisp :exports results :results none
  (defun my-custom-filters/export-footnote-as-annotation (text backend info)
    (interactive)
    (cond ((and (org-export-derived-backend-p backend 'latex)
                (string-match-p "!annot" text))
           (replace-regexp-in-string "\\\\footnote{\s*!annot\s*"
                                     
"\\\\pdfcomment[icon=Note,opacity=0.4,color=gray,date]{"
                                     text))
          ((and (org-export-derived-backend-p backend 'odt)
                (string-match-p "!annot" text))
           (with-temp-buffer
             (insert text)
             (let* ((from (save-excursion
                            (goto-char (point-min))
                            (re-search-forward "!annot" nil t)
                            (point)))
                    (to (save-excursion
                          (goto-char from)
                          (re-search-forward "</text:p>" nil t)
                          (- (point) 9)))
                    (contents (buffer-substring-no-properties from to)))
               (delete-region (point-min) (point-max))
               (insert (concat
                        "<office:annotation 
loext:resolved=\"false\"><dc:creator>"
                        (car (plist-get info :author))
                        "</dc:creator><dc:date>"
                        ;; date in iso format
                        (org-odt--format-timestamp (plist-get info :date) nil t)
                        "</dc:date><text:p text:style-name=\"P5\"><text:span 
text:style-name=\"T1\">"
                        contents
                        "</text:span></text:p></office:annotation> "))
               (setq text (buffer-string)))))))
#+end_src

Example:

Lorem[fn:1] ipsum dolor sit amet,

[fn:1] !annot This note will be exported as an annotation...

And this other filter does not export the notes that start with the
string "!noannot" (although it could be merged with the previous
filter):

#+BIND: org-export-filter-footnote-reference-functions 
(my-custom-filters/disable-footnote-as-annotation)
#+begin_src emacs-lisp :exports results :results none
  (defun my-custom-filters/disable-footnote-as-annotation (text backend info)
    (interactive)
    (cond ((and (org-export-derived-backend-p backend 'latex)
                (string-match-p "!noannot" text))
           (replace-regexp-in-string ".+"
                                     ""
                                     text))
          ((and (org-export-derived-backend-p backend 'odt)
                (string-match-p "!noannot" text))
           (replace-regexp-in-string ".+"
                                     ""
                                     text))))
#+end_src

Best regards,

Juan Manuel

--
--
------------------------------------------------------
Juan Manuel Macías --

https://juanmanuelmacias.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]