diff options
author | Christoph Helma <helma@in-silico.ch> | 2019-06-05 17:28:10 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2019-06-05 17:28:10 +0200 |
commit | 9a217185e791d6abbe46549cd4e87c1d1a643c05 (patch) | |
tree | 1968aebd8a38acd7784e58d478e0f6c3fb08ab76 /paper/lua-filters/short-captions/short-captions.lua | |
parent | feb1f82356da50a1ebf63b1eda434c388ab009e1 (diff) |
first manuscript version
Diffstat (limited to 'paper/lua-filters/short-captions/short-captions.lua')
-rw-r--r-- | paper/lua-filters/short-captions/short-captions.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/paper/lua-filters/short-captions/short-captions.lua b/paper/lua-filters/short-captions/short-captions.lua new file mode 100644 index 0000000..9aaf309 --- /dev/null +++ b/paper/lua-filters/short-captions/short-captions.lua @@ -0,0 +1,37 @@ +if FORMAT ~= "latex" then + return +end + +local function latex(str) + return pandoc.RawInline('latex', str) +end + +function figure_image (elem) + local image = elem.content and elem.content[1] + return (image.t == 'Image' and image.title == 'fig:') + and image + or nil +end + +function Para (para) + local img = figure_image(para) + if not img or not img.caption or not img.attributes['short-caption'] then + return nil + end + + local short_caption = pandoc.Span( + pandoc.read(img.attributes['short-caption']).blocks[1].c + ) + local hypertarget = "{%%\n" + local label = "\n" + if img.identifier ~= img.title then + hypertarget = string.format("\\hypertarget{%s}{%%\n",img.identifier) + label = string.format("\n\\label{%s}",img.identifier) + end + return pandoc.Para { + latex(hypertarget .. "\\begin{figure}\n\\centering\n"), + img, + latex("\n\\caption["), short_caption, latex("]"), pandoc.Span(img.caption), + latex(label .."\n\\end{figure}\n}\n") + } +end |