Skip to content

Instantly share code, notes, and snippets.

View tarleb's full-sized avatar
🌱
Growing some software

Albert Krewinkel tarleb

🌱
Growing some software
View GitHub Profile
@tarleb
tarleb / pandoc-schema.json
Last active January 26, 2023 03:26
Schema for pandoc json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"Attr": {
"type": "array",
"items": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}},
{
"type": "array",
@tarleb
tarleb / latex-short-captions.lua
Last active June 14, 2019 22:43
Filter to turn figure titles into short captions in LaTeX
-- don't do anything unless we target latex
if FORMAT ~= "latex" then
return {}
end
local List = require'pandoc.List'
local function latex(str)
return List:new{pandoc.RawInline('latex', str)}
end
@tarleb
tarleb / section-refs.lua
Created January 4, 2018 20:09
Ugly, proof of concept filter to create section refs.
dkjson = require 'dkjson'
List = require 'pandoc.List'
utils = require 'pandoc.utils'
CitationOrig = pandoc.Citation
-- monkey-patch citation creation
pandoc.Citation = function(id, mode, prefix, suffix, note_num, hash)
local res = CitationOrig(id, mode, prefix, suffix, note_num, hash)
setmetatable(
-- jsonld.lua
--
-- Copyright (c) 2017-2018 Albert Krewinkel, Robert Winkler
--
-- This program is free software; you can redistribute it and/or modify it
-- under the terms of the GNU public license version 2 or later.
-- See the LICENSE file for details.
-- USAGE:
-- The filters cito.lua and scholarly-metadata.lua must be run before this filter.
@tarleb
tarleb / include.lua
Last active May 1, 2023 14:12
Filter to include Markdown files via code blocks
--- Pandoc Lua filter to include other Markdown files
---
--- Usage: Use a special code block with class `include` to
--- include Markdown files. Each code line is treated as the
--- filename of a Markdown file, parsed as Markdown, and
--- included. Metadata from include files is discarded.
---
--- Example:
---
--- ``` {.include}
@tarleb
tarleb / sidenote.lua
Last active October 30, 2021 12:50
Reimplementation of pandoc-sitenote by @jez as Lua filter
local counter = 0
function make_label(nonu)
local label_class = 'margin-toggle' .. (nonu and '' or ' sidenote-number')
local label_sym = nonu and '⊕' or ''
local label_html = string.format(
'<label for="sn-%d" class="%s">%s</label>',
counter,
label_class,
label_sym
function Inlines (inlns)
-- switch period/cite elements
for i=1,#inlns-1 do
local period, cite = inlns[i], inlns[i+1]
if period.t == 'Str' and period.text == '.' and cite.t == 'Cite' then
inlns[i], inlns[i+1] = cite, period
end
end
return inlns
end
@tarleb
tarleb / ORCIDid.tex
Last active May 11, 2020 12:04
ORCID id logo with TikZ
\documentclass{article}
\usepackage{tikz}
\usepackage{calc}
\newlength{\ORCIDidheight}
\newlength{\ORCIDidunit}
\definecolor{ORCIDgreen}{HTML}{A6CE39}
\newcommand{\ORCIDid}{%
% Scale icon to match current line height
\settoheight{\ORCIDidheight}{AXg}%
@tarleb
tarleb / highlight-author.lua
Created May 22, 2020 06:28
Filter to highlight some authors in the bibliography
local List = require 'pandoc.List'
local utils = require 'pandoc.utils'
local stringify = utils.stringify
function highlighter(given_name_pattern, family_name_pattern)
local highlight_author = function (author)
local given = author.given and stringify(author.given)
local family = author.family and stringify(author.family)
if given and given:match(given_name_pattern) and
family and family:match(family_name_pattern) then
local yaml_template = "---\nDUMMY: %s\n---"
function evaluate (str)
local tag, value = str:match('^:(%a*):(.*)')
if tag == 'lua' then
return load(
'return ' .. value,
"evaluating " .. value
)()
elseif tag == 'json' then