local vars = {}
local additionalChars = {".", ",", "!", ":", ";"}
function fileExists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
local function countWords()
local rawText = pandoc.pipe("pdftotext", {"output.pdf", "-"}, "")
return pandoc.pipe("wc", {"-w"}, rawText)
local function getVars(meta)
for k, v in pairs(meta) do
if v.t == 'MetaInlines' then
local var_key = "$" .. k .. "$"
local var_value = table.unpack(v)["c"]
vars[var_key] = var_value
for _, char in pairs(additionalChars) do
vars[var_key .. char] = var_value .. char
vars[char .. var_key] = char .. var_value
return {
{
Meta = function(meta)
getVars(meta)
if fileExists("output.pdf") then
meta["wordcount"] = countWords()
meta["secondpass"] = true
return meta
end,
},
Str = function (el)
if vars[el.text] then
return pandoc.Span(vars[el.text])
else
return el
}