Last active
June 14, 2019 22:43
-
-
Save tarleb/a57366474bbeef4c4c388adc19e85a41 to your computer and use it in GitHub Desktop.
Revisions
-
tarleb revised this gist
Jan 20, 2018 . 1 changed file with 24 additions and 31 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,48 +3,41 @@ if FORMAT ~= "latex" then return {} end local List = require'pandoc.List' local function latex(str) return List:new{pandoc.RawInline('latex', str)} end local function is_titled_figure(para) return #para.content == 1 and para.content[1].t == "Image" and para.content[1].title end local function read_inlines(txt) return pandoc.read(txt).blocks[1].content end local function make_caption(long_caption, short_caption) return latex'\\caption[' .. short_caption .. latex']{' .. long_caption .. latex'}\n' end local function figure_with_short_caption(para) if not is_titled_figure(para) then return nil end local img = para.content[1] local title_inlines = read_inlines(img.title:gsub('^fig:', '')) return pandoc.Plain( latex'\\begin{figure}\n\\centering\n' .. {img} .. latex'\n' .. make_caption(img.caption, title_inlines) .. latex'\\end{figure}' ) end return {{Para = figure_with_short_caption}} -
tarleb created this gist
Nov 22, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ -- don't do anything unless we target latex if FORMAT ~= "latex" then return {} end function latex(str) return pandoc.RawInline('latex', str) end -- Append `list2` to `list1` by modifying `list1`. function append(list1, list2) local n1 = #list1 for i = 1, #list2 do list1[n1 + i] = list2[i] end return list1 end function make_caption(long_caption, short_caption) local caption = {latex '\\caption['} append(caption, short_caption) table.insert(caption, latex ']{') append(caption, long_caption) table.insert(caption, latex '}\n') return caption end function is_titled_figure(para) return #para.content == 1 and para.content[1].t == "Image" and para.content[1].title end local latex_figure_start = latex '\\begin{figure}\n\\centering\n' local latex_figure_end = latex '\\end{figure}' function Para(para) if not is_titled_figure(para) then return nil end local img = para.content[1] img.title = img.title:gsub('^fig:', '') local title_inlines = pandoc.read(img.title).blocks[1].content local figure = {latex_figure_start} append(figure, {img, latex '\n'}) append(figure, make_caption(img.caption, title_inlines)) append(figure, {latex_figure_end}) return pandoc.Plain(figure) end