emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Bug: Unable to nest headings within export blocks [9.0 (9.0-elpa


From: Lixin Chin
Subject: Re: [O] Bug: Unable to nest headings within export blocks [9.0 (9.0-elpa @ c:/Data/Documents/emacs.d/elpa/org-20161102/)]
Date: Wed, 9 Nov 2016 12:51:24 +0800

On Mon, 7 Nov 2016 08:44:47 -0800
"Charles C. Berry" <address@hidden> wrote:

> Run this:
> 
> #+BEGIN_SRC emacs-lisp :eval never-export :exports none
>    (require 'ob-org)
>    (defun eval-if-html ()
>      (if (not (eq org-export-current-backend 'html)) "never"))
> #+END_SRC
> 
> 
> Then export this with the html backend:
> 
> #+OPTIONS: toc:nil
> 
> #+BEGIN_SRC org :eval (eval-if-html) :exports results :results replace
>    ,* HTML only heading
>    Text which should appear in HTML exports, but not \LaTeX{}.
> #+END_SRC
> 
> and you will get this:
> 
> <div id="outline-container-org1e9ad24" class="outline-2">
> <h2 id="org1e9ad24"><span class="section-number-2">1</span> HTML only 
> heading</h2>
> <div class="outline-text-2" id="text-1">
> <p>
> Text which should appear in HTML exports, but not \LaTeX{}.
> </p>
> </div>
> </div>
> 
> With other backends you get nothing.
> 
> HTH,
> 
> Chuck

Thank you very much, that works perfectly!

For future reference, I tweaked the source code block to allow
specifying multiple export backends, and to avoid generating results
when evaluating using C-c C-c:

#+BEGIN_SRC emacs-lisp :eval never-export :exports none :results silent
  (require 'cl-extra)
  (defun eval-if-export (backend)
    "For use within org-mode source blocks :eval argument. Causes
  the block to be evaluated if the current export backend matches
  any of the backends in BACKEND. (e.g., (eval-if-export '(latex
  html)))."
    (unless (cl-some (lambda (back) (eq org-export-current-backend
back))
                      backend)
      "never"))
#+END_SRC

Then using:
#+BEGIN_SRC org :eval (eval-if-export '(html)) :exports
results :results replace
  ,* HTML only heading
  Text which should appear in HTML exports, but not \LaTeX{}.
#+END_SRC

The syntax isn't as elegant as #+BEGIN_EXPORT <backend> ...
#+END_EXPORT, but it works nicely enough.

Thanks,
Lixin



reply via email to

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