Org Abstract Block Export
biggs opened this issue ยท 5 comments
Is it possible to allow export of the abstract block, i.e.
#+BEGIN_ABSTRACT
as a pandoc_metadata 'abstract'? This would allow export of an abstract before the TOC in latex documents, which currently requires a long:
#+PANDOC_METADATA "abstract: very long line"
Yes, this is possible, but requires some trickery. A simple way is to use a Lua filter: Put the following into a file and name it abstract-div-to-meta.lua
. The file should either be in the same folder as your .org document, or in $HOME/.pandoc/filters/
; the latter makes sense if you plan to re-use this technique with other documents.
-- file: abstract-div-to-meta.lua
local abstract = {}
function Div (div)
if div.classes:includes 'ABSTRACT' then
abstract = div.content
return {}
end
end
function Meta (meta)
meta.abstract = pandoc.MetaBlocks(abstract)
return meta
end
Now tell pandoc to use this by altering the variable org-pandoc-options
. E.g., M-x (setq org-pandoc-options '((standalone . t) (lua-filter . "abstract-div-to-meta.lua")))
. Your ABSTRACT block should now be converted into pandoc metadata on every export.
Thanks for the quick response, this does indeed seem to be the way to do it. However I'm currently getting an error with the LUA script:
Error occured.
Error running filter abstract-div-to-meta.lua:
Error while running filter function: abstract-div-to-meta.lua:5: attempt to call a nil value (method 'includes')
Just to clarify, it runs without an abstract block, but not with one.
OK, I found a way to achieve more or less the desired functionality, using instead a top-level Abstract header:
https://github.com/pandoc/lua-filters/tree/master/abstract-to-meta
Thanks.
Happy the other filter works for you.
The error is puzzling, includes
exists since pandoc 2.0.4. Are you using an older version?
Ah - that does appear to be the issue, 2.0.2. Thanks!