summaryrefslogtreecommitdiff
path: root/mdtopdf
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2026-08-26 21:15:36 +0500
committerAnton Bobov <anton@bobov.name>2026-08-26 21:15:36 +0500
commita834a7adf6cbf1e352dd3715d7d1e2d4867f6059 (patch)
tree79afb6b723d4d3714d8135db2e9a85e21d9cd016 /mdtopdf
parent4e505b4244fc466cfc88183abfe110d77ccfc3ca (diff)
mdtopdf: Add script to convert markdown to PDF
Diffstat (limited to 'mdtopdf')
-rwxr-xr-xmdtopdf43
1 files changed, 43 insertions, 0 deletions
diff --git a/mdtopdf b/mdtopdf
new file mode 100755
index 0000000..cbfcf08
--- /dev/null
+++ b/mdtopdf
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# @describe Convert markdown file to PDF
+# @meta require-tools pandoc
+# @arg inputfile+ markdown file
+# @option --font[?`_choice_font_fn`] font (default Arial)
+# @option --from[?`_choice_from_fn`] from format
+# @option --pdf-engine[typst|xelatex] PDF engine
+
+# Specification: https://github.com/sigoden/argc/blob/main/docs/specification.md
+
+_choice_font_fn() {
+ fc-list : family
+}
+
+_choice_from_fn() {
+ pandoc --list-input-formats
+}
+
+find_pdf_engine() {
+ for engine in typst xelatex; do
+ if command -v "$engine" &>/dev/null; then
+ echo "$engine"
+ exit
+ fi
+ done
+ exit 2
+}
+
+main() {
+ local engine
+ local from
+ engine=${argc_pdf_engine:-$(find_pdf_engine)}
+ from=${argc_from:-markdown}
+ for infile in "${argc_inputfile[@]?}"; do
+ outfile="${infile%.*}.pdf"
+ pandoc --from="$from" --pdf-engine="$engine" -V mainfont="${argc_font:-Arial}" "$infile" -o "$outfile"
+ done
+}
+
+eval "$(argc --argc-eval "$0" "$@")"