Commit 678c7323 authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Use new citeproc, luatex and lua filter for divs

parent 3d3398bd
--[[
take a table of key-value-pairs/attributes and create a string with
`{foo}={bar}, ` for each of them to be used as arguments in the \begin command
--]]
local function attributes_to_string(attributes)
local result = ""
for k,v in pairs(attributes) do
result = result .. string.format("{%s}={%s}, ", k, v)
end
return result
end
-- if the identifier is not empty, wrap it
local function identifier_to_string(identifier)
if identifier ~= "" then
return string.format("[%s]", identifier)
else
return ""
end
end
-- convert divs to LaTeX environments
function Div(div)
local result = {}
-- for each class insert a \begin{foo} command
for i = 1, #(div.classes) do
table.insert(result,
pandoc.RawBlock("latex", string.format
( "\\begin{%s}[%s]{%s}"
, div.classes[i]
, div.identifier
, attributes_to_string(div.attributes)
)
)
)
end
-- insert the original content of the div
for _,block in ipairs(div.content) do
table.insert(result, block)
end
-- for each class insert a \end{foo} command, in reverse order
for i = #(div.classes), 1, -1 do
table.insert(result,
pandoc.RawBlock("latex", string.format("\\end{%s}", div.classes[i]))
)
end
return result
end
inputs = $(shell ls src/*.md) # $(wildcard src/*.md) outputs in the wrong order
pandoc = pandoc $(inputs) -f markdown -t latex \
--template template.tex --top-level-division=chapter --filter pandoc-div.hs \
--filter pandoc-crossref --filter pandoc-citeproc --csl style.csl --bibliography literature.yaml -M link-citations:true
--template template.tex --top-level-division=chapter --lua-filter div-to-env.lua \
--metadata-file metadata.yaml \
--filter pandoc-crossref --citeproc --csl style.csl --bibliography literature.yaml -M link-citations:true
thesis.pdf: $(inputs) res/* template.tex macros.tex literature.yaml style.csl pandoc-div.hs
$(pandoc) --pdf-engine=xelatex -o $@
thesis.pdf: $(inputs) metadata.yaml res/* template.tex macros.tex literature.yaml style.csl div-to-env.lua
$(pandoc) --pdf-engine=lualatex -o $@
thesis.tex: $(inputs) res/* template.tex macros.tex literature.yaml style.csl pandoc-div.hs
thesis.tex: $(inputs) metadata.yaml res/* template.tex macros.tex literature.yaml style.csl div-to-env.lua
$(pandoc) -o $@
clean:
......
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Text.Printf
import Text.Pandoc.JSON
import Data.Text as T
main :: IO ()
main = toJSONFilter divToEnv
-- | Converts a pandoc Div into a LaTeX environment.
divToEnv :: Block -> [Block]
divToEnv (Div (_ , [] , _ ) content) = content -- Ignore divs without class
divToEnv (Div (identifier, cl:cls, kvpairs) content)
= RawBlock (Format "tex") (T.pack $ printf "\\begin{%s}%s{%s}"
cl
(if identifier /= "" then "[" <> identifier <> "]" else "")
(intercalate "," $ (\(key, value) -> T.pack $ printf "{%s}={%s}" key value) <$> kvpairs))
: divToEnv (Div (identifier, cls, kvpairs) content)
++ [RawBlock (Format "tex") (T.pack $ printf "\\end{%s}" cl)]
divToEnv block = [block] -- All non-div blocks stay the same
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment