emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* running some elisp code when exporting a given file
@ 2013-09-05  7:58 Alan Schmitt
  2013-09-05 10:07 ` Myles English
  2013-09-05 10:13 ` Nicolas Goaziou
  0 siblings, 2 replies; 6+ messages in thread
From: Alan Schmitt @ 2013-09-05  7:58 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I would like to inline a css when exporting a file to html, but I don't
know how to tell org-mode to set the variable org-html-head from within
the file.

Here is what I tried: I added the following block at the beginning of my
file:

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC emacs-lisp :exports none
  (set (make-local-variable 'org-html-head) (concat
                             "<style type=\"text/css\">\n"
                             "<!--/*--><![CDATA[/*><!--*/\n"
                             (with-temp-buffer
                               (insert-file-contents "style.css")
                               (buffer-string))
                             "/*]]>*/-->\n"
                             "</style>\n"))
#+END_SRC
--8<---------------cut here---------------end--------------->8---

It does not seem to be evaluated, however.

Is there a way to have arbitrary code stored in the file being exported
being evaluated before an export?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running some elisp code when exporting a given file
  2013-09-05  7:58 running some elisp code when exporting a given file Alan Schmitt
@ 2013-09-05 10:07 ` Myles English
  2013-09-05 12:39   ` Alan Schmitt
  2013-09-05 10:13 ` Nicolas Goaziou
  1 sibling, 1 reply; 6+ messages in thread
From: Myles English @ 2013-09-05 10:07 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode


Hi Alan,

Alan Schmitt writes:

> Is there a way to have arbitrary code stored in the file being exported
> being evaluated before an export?

I think you can use org-export-before-processing-hook for this.

"""
12.13 Advanced configuration
============================

Hooks
-----

Two hooks are run during the first steps of the export process.  The
first one, 'org-export-before-processing-hook' is called before
expanding macros, Babel code and include keywords in the buffer.  The
second one, 'org-export-before-parsing-hook', as its name suggests,
happens just before parsing the buffer.  Their main use is for heavy
duties, that is duties involving structural modifications of the
document.  For example, one may want to remove every headline in the
buffer during export.
"""

Myles

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running some elisp code when exporting a given file
  2013-09-05  7:58 running some elisp code when exporting a given file Alan Schmitt
  2013-09-05 10:07 ` Myles English
@ 2013-09-05 10:13 ` Nicolas Goaziou
  2013-09-05 12:39   ` Alan Schmitt
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2013-09-05 10:13 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Hello,

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> I would like to inline a css when exporting a file to html, but I don't
> know how to tell org-mode to set the variable org-html-head from within
> the file.
>
> Here is what I tried: I added the following block at the beginning of my
> file:
>
> #+BEGIN_SRC emacs-lisp :exports none
>   (set (make-local-variable 'org-html-head) (concat
>                              "<style type=\"text/css\">\n"
>                              "<!--/*--><![CDATA[/*><!--*/\n"
>                              (with-temp-buffer
>                                (insert-file-contents "style.css")
>                                (buffer-string))
>                              "/*]]>*/-->\n"
>                              "</style>\n"))
> #+END_SRC
>
> It does not seem to be evaluated, however.
>
> Is there a way to have arbitrary code stored in the file being exported
> being evaluated before an export?

I think this has to do with ":exports none", which means that code will
not be evaluated during export. You may want to try setting the
attribute to some other value, and put the block in a :noexport: entry.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running some elisp code when exporting a given file
  2013-09-05 10:07 ` Myles English
@ 2013-09-05 12:39   ` Alan Schmitt
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Schmitt @ 2013-09-05 12:39 UTC (permalink / raw)
  To: Myles English; +Cc: emacs-orgmode

mylesenglish@gmail.com writes:

> Hi Alan,
>
> Alan Schmitt writes:
>
>> Is there a way to have arbitrary code stored in the file being exported
>> being evaluated before an export?
>
> I think you can use org-export-before-processing-hook for this.

Thank you for the suggestion. My question would then be: how do I set
the hook from within the file being exported? (And the answer is: apply
Nicolas's suggestion, it worked.)

Alan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running some elisp code when exporting a given file
  2013-09-05 10:13 ` Nicolas Goaziou
@ 2013-09-05 12:39   ` Alan Schmitt
  2013-09-06 17:41     ` Eric Schulte
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Schmitt @ 2013-09-05 12:39 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

n.goaziou@gmail.com writes:

> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I would like to inline a css when exporting a file to html, but I don't
>> know how to tell org-mode to set the variable org-html-head from within
>> the file.
>>
>> Here is what I tried: I added the following block at the beginning of my
>> file:
>>
>> #+BEGIN_SRC emacs-lisp :exports none
>>   (set (make-local-variable 'org-html-head) (concat
>>                              "<style type=\"text/css\">\n"
>>                              "<!--/*--><![CDATA[/*><!--*/\n"
>>                              (with-temp-buffer
>>                                (insert-file-contents "style.css")
>>                                (buffer-string))
>>                              "/*]]>*/-->\n"
>>                              "</style>\n"))
>> #+END_SRC
>>
>> It does not seem to be evaluated, however.
>>
>> Is there a way to have arbitrary code stored in the file being exported
>> being evaluated before an export?
>
> I think this has to do with ":exports none", which means that code will
> not be evaluated during export. You may want to try setting the
> attribute to some other value, and put the block in a :noexport: entry.

Thanks a lot, this was it.

Alan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: running some elisp code when exporting a given file
  2013-09-05 12:39   ` Alan Schmitt
@ 2013-09-06 17:41     ` Eric Schulte
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2013-09-06 17:41 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode, Nicolas Goaziou

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> n.goaziou@gmail.com writes:
>
>> Hello,
>>
>> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>>
>>> I would like to inline a css when exporting a file to html, but I don't
>>> know how to tell org-mode to set the variable org-html-head from within
>>> the file.
>>>
>>> Here is what I tried: I added the following block at the beginning of my
>>> file:
>>>
>>> #+BEGIN_SRC emacs-lisp :exports none
>>>   (set (make-local-variable 'org-html-head) (concat
>>>                              "<style type=\"text/css\">\n"
>>>                              "<!--/*--><![CDATA[/*><!--*/\n"
>>>                              (with-temp-buffer
>>>                                (insert-file-contents "style.css")
>>>                                (buffer-string))
>>>                              "/*]]>*/-->\n"
>>>                              "</style>\n"))
>>> #+END_SRC
>>>
>>> It does not seem to be evaluated, however.
>>>
>>> Is there a way to have arbitrary code stored in the file being exported
>>> being evaluated before an export?
>>
>> I think this has to do with ":exports none", which means that code will
>> not be evaluated during export. You may want to try setting the
>> attribute to some other value, and put the block in a :noexport: entry.
>
> Thanks a lot, this was it.
>

Just for completeness, another option may be the following set of header
arguments.

    #+begin_src emacs-lisp :exports results :results none
      ;; code executed for side effects
    #+end_src

Cheers,

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-06 17:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-05  7:58 running some elisp code when exporting a given file Alan Schmitt
2013-09-05 10:07 ` Myles English
2013-09-05 12:39   ` Alan Schmitt
2013-09-05 10:13 ` Nicolas Goaziou
2013-09-05 12:39   ` Alan Schmitt
2013-09-06 17:41     ` Eric Schulte

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).