Created
April 16, 2021 09:43
-
-
Save Ddedalus/ddb8199624d2a13fbb7d8e3daeca7cfd to your computer and use it in GitHub Desktop.
Preview quiver diagrams in pandoc HTML and LaTeX
This file contains 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 characters
-- Install: save the file in $(pandoc data dir)/filters | |
-- pandoc --filter quiver.lua | |
-- call this filter before any cross-referencing filters like xnos or crossref | |
-- Markdown syntax: | |
-- :::{.quiver #eq:label} | |
-- <paste LateX Output from q.uiver.app <including the link> | |
-- ::: | |
-- Reference with -@eq:label for just the number without eq. prefix. | |
function Div(div) | |
if div.classes[1] == 'quiver' then | |
local content = div.content[1].content | |
if (content[3].text:match "https://q%.uiver%.app/.+") then | |
link = content[3].text | |
if FORMAT:match 'html' then | |
return pandoc.Div({pandoc.Div( | |
{pandoc.RawBlock(FORMAT, | |
'<iframe class="quiver-embed" src="' .. link .. | |
'&embed" width="488" height="332" border: none"></iframe>')}, | |
{class='quiver', style='display: flex; justify-content: center;'}), | |
pandoc.Para({pandoc.Math('DisplayMath', ''), | |
pandoc.Str('{#' .. div.identifier .. '}')}), | |
} | |
) | |
elseif FORMAT:match 'latex' then | |
local math = content[5].text:gsub("%$%$", "") | |
return pandoc.Para({ | |
pandoc.Math('DisplayMath', math), | |
pandoc.Str('{#' .. div.identifier .. '}'), | |
}) | |
else | |
print("WARNING unknown quiver format:" .. FORMAT) | |
return div | |
end | |
else | |
print("WARNING: Quiver div without a quiver link!") | |
return div | |
end | |
else | |
return div | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment