2

I'm aware of #+OPTIONS: tags:nil to have tags not be exported. I'd like them exported to LaTeX exports, but not ASCII exports. Is there a way to have options only apply to certain exports? Is there some other method to have ASCII export drop tags?

2

You can achieve what you want by advising the commands that serve as entry points for the different export back-ends offered by org-mode. For example, to tell org-mode to skip tags when exporting to ASCII, you can advise the command for exporting to ASCII (org-ascii-export-to-ascii) as follows:

(defadvice org-ascii-export-to-ascii
    (around turn-off-tags (&optional async subtreep visible-only
                                     body-only ext-plist) activate compile)
  (let ((org-export-with-tags nil))
    ad-do-it))

Note that Emacs 24.4 introduces a new advice system which might replace the old system at some point in the future. Here is a modified version of the code above that makes use of the new advice system (use this version if you are already on Emacs 24.4 and want to future-proof your configuration):

(defun turn-off-tags
    (orig &optional async subtreep visible-only body-only ext-plist)
  (let ((org-export-with-tags nil))
    (funcall orig async subtreep visible-only body-only ext-plist)))

(advice-add 'org-ascii-export-to-ascii :around #'turn-off-tags)

Generalizing the solution

The general naming scheme for export commands that produce files is org-<backend>-export-to-<backend>:

  • org-ascii-export-to-ascii
  • org-html-export-to-html
  • org-latex-export-to-latex
  • ...

Here is a skeleton that you can use to set as many <backend>-specific options as you like:

(defadvice org-<backend>-export-to-<backend>
    (around org-<backend>-set-export-options
            (&optional async subtreep visible-only body-only ext-plist)
            activate compile)
  (let ((<variable> <value>)
        (<variable> <value>)
        (<variable> <value>))
    ad-do-it))

Ported to the new advice system:

(defun org-<backend>-set-export-options
    (orig &optional async subtreep visible-only body-only ext-plist)
  (let ((<variable> <value>)
        (<variable> <value>)
        (<variable> <value>))
    (funcall orig async subtreep visible-only body-only ext-plist)))

(advice-add 'org-<backend>-export-to-<backend>
            :around #'org-<backend>-set-export-options)
  • @mankoff Did you get a chance to try out this solution? Let me know if you have any follow-up questions. – itsjeyd Jan 23 '15 at 7:12
1

Recall macros are expanded before the document is parsed. This might get you started.

#+MACRO: tags-on-latex (eval (format "#+OPTIONS: tags:%s" (if (org-export-derived-backend-p org-export-current-backend 'latex) "t" "nil")))
{{{tags-on-latex}}}
* h                                                                     :tag:

For more fine-grained control (say html) just add more backend to the &rest part of org-export-derived-backend-p.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.