emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Lixin Chin <lixinchin@gmail.com>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: 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	[thread overview]
Message-ID: <20161109125040.00004325@gmail.com> (raw)
In-Reply-To: <alpine.OSX.2.20.1611070838490.675@charles-berrys-macbook.local>

On Mon, 7 Nov 2016 08:44:47 -0800
"Charles C. Berry" <ccberry@ucsd.edu> 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	other threads:[~2016-11-09  4:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03  3:47 Bug: Unable to nest headings within export blocks [9.0 (9.0-elpa @ c:/Data/Documents/emacs.d/elpa/org-20161102/)] Lixin Chin
2016-11-03  5:20 ` Lixin Chin
2016-11-05  7:41 ` Nicolas Goaziou
2016-11-07  2:47   ` Lixin Chin
2016-11-07 16:44     ` Charles C. Berry
2016-11-09  4:51       ` Lixin Chin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161109125040.00004325@gmail.com \
    --to=lixinchin@gmail.com \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).