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 / 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}
\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 / 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.
@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
local List = require 'pandoc.List'
local meta
function merge_meta(m1, m2)
local result = m1
for k, v in pairs(m2) do
if result[k] == nil then
result[k] = v
end
@tarleb
tarleb / latex-logo.lua
Last active April 8, 2021 10:33
Lua filter to render TeX and LaTeX as logos like the \TeX and \LaTeX{} macros do.
-- Render TeX and LaTeX like the `\TeX` and `\LaTeX{}` macros do.
-- Copyright © 2020 Albert Krewinkel <albert+pandoc@zeitkraut.de>
-- License: MIT License
-- Style inspired by https://tess.oconnor.cx/2007/08/tex-poshlet
local style = pandoc.RawBlock('html', [[
<style>
.tex-logo sub, .latex-logo sub {
font-size: 100%;
margin-left: -0.1667em;
@tarleb
tarleb / image-extension.lua
Last active December 20, 2020 18:23
Add file extension to images
local known_exts = pandoc.List{".png", ".jpg", "jpeg"}
if FORMAT:match 'tex' then
known_exts = pandoc.List {
".pdf", ".png", ".jpg", ".mps", ".jpeg", ".jbig2", ".jb2"
}
elseif FORMAT:match 'html' then
known_exts = pandoc.List {
".svg", ".png", ".jpg", ".jpeg", ".webp", ".gif"
}
end
@tarleb
tarleb / custom-markdown.lua
Last active November 3, 2024 06:18
Custom Lua writer, using the `layout` module to produce nicely layed-out Markdown.
-- This is a sample custom writer for pandoc, using Layout to
-- produce nicely wrapped output.
local layout = pandoc.layout
local text = pandoc.text
local type = pandoc.utils.type
local l = layout.literal
-- Table to store footnotes, so they can be included at the end.
@tarleb
tarleb / toc.lua
Created February 10, 2022 19:55
Adaptable Lua filter to generate a Table of Contents
-- Generate a Table of Contents.
--
-- This is an adaption of the Haskell code used in pandoc. This script
-- is intended to be adapted to specific requirements before use. E.g.,
-- it can be modified to add additional elements as TOC items, to add
-- more info to each line in the TOC, or to control whether the heading
-- number is included in the link.
local PANDOC_WRITER_OPTIONS = PANDOC_WRITER_OPTIONS
_ENV = pandoc
@tarleb
tarleb / interactive.lua
Last active September 29, 2024 21:18
Helper function for interactive Lua filters
function interactive (it, env)
local has_readline, RL = pcall(require, 'readline')
if not has_readline then
RL = {
readline = function (prompt)
io.stdout:write(prompt)
return io.read()
end
}