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 / org-header-beautification.lua
Last active August 16, 2020 20:30
No-id org headers
-- Licensed, at your choice, under the MIT or GPL-2-or-later license
local header_ids = {}
local function collect_id (header)
if header.identifier and header.identifier ~= "" then
header_ids[header.identifier] = header.content
header.identifier = ""
return header
end
end
@tarleb
tarleb / lua-manual-cleanup.lua
Last active March 21, 2023 07:43
Lua filter to clean-up the Lua manual markup
-- There is no glyph for pi in the default font, but there is one in the
-- math font.
function Emph (e)
local s = e.content[1]
if #e.content == 1 and s.tag == 'Str' and s.text == 'π' then
return pandoc.RawInline('tex', '$\\pi$')
end
end
-- No glyph available for `≤` in the monospaced font.
\documentclass{minimal}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newlength{\OAheight}
\newcommand{\OA}[1]{% symbol height
\setlength{\OAheight}{#1}%
\raisebox{-0.40\OAheight}{\resizebox{\OAheight}{!}{%
\definecolor{OA}{HTML}{f68212}
\begin{tikzpicture}[x=1pt,y=1pt]
@tarleb
tarleb / noexport-subtrees.lua
Last active October 21, 2024 12:46
Emulating org-mode's :noexport: behavior for Markdown.
--[[
Remove all subtrees whose headlines contain class `noexport`.
License: MIT
Copyright: © Albert Krewinkel
]]
-- pandoc.utils.make_sections exists since pandoc 2.8
PANDOC_VERSION:must_be_at_least {2,8}
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
@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
@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}%
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 / 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
@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}