Try this
;; Don't skip `comment' or `comment-block' elements
(advice-add 'org-export--skip-p :around
(defun my-org-export--skip-p (orig-fun &rest args)
(pcase-let ((`(,datum ,options ,selected ,excluded) args))
(cond
((memq (org-element-type datum) '(comment comment-block))
;; Don't skip
(ignore))
(t
(apply orig-fun args))))))
;; A generic transcoder for `comment' and `comment-block' elements
;; which works with `html', `odt' and `latex' backends.
(defun org-*-comment (comment contents info)
(with-temp-buffer
(insert (org-element-property :value comment))
(when-let ((mode-fn (alist-get org-export-current-backend
'((html . nxml-mode)
(odt . nxml-mode)
(latex . latex-mode)))))
(funcall mode-fn)
(comment-region (point-min) (point-max))
(buffer-substring-no-properties (point-min) (point-max)))))
;; Teach the backends about the above transcoder
(cl-loop for backend in '(html latex odt)
for transcoders = (org-export-backend-transcoders
(org-export-get-backend backend))
do (cl-loop for els in '(comment comment-block)
do (setf (org-export-backend-transcoders
(org-export-get-backend backend))
(append
(list (cons 'comment 'org-*-comment)
(cons 'comment-block 'org-*-comment))
transcoders))))
- Create
somefile.org
with following content
# why do we use the method
#+begin_comment
... and this method
#+end_comment
We use the method because it is great!
- If you do
C-c C-e C-b l L
, you get
% why do we use the method
% ... and this method
We use the method because it is great!
- If you do
C-c C-e C-b h H
, you get
<!-- why do we use the method -->
<!-- ... and this method -->
<p>
We use the method because it is great!
</p>
org-export--prune-tree
is called and long before the LaTeX exporter itself (or any other backend for that matter) lays hands on the tree: by that time there are no comments left. You'd have to changeorg-export--prune-tree
to pass the comments through to the backend and then change the backend to teach it what to do with them. I don't think either is particularly difficult, but it would require some time, lisp knowledge and familiarity with the code.#+LATEX_HEADER: \usepackage{comment}
to your Org file and then delimit multiline comments with#+LATEX: \begin{comment}
and#+LATEX: \end{comment}
- a slight generalization of your single-line comment method. Structure templates or some other template expansion package can make this method more tolerable.org-export-before-processing-hook
.