Update snippets/md-to-pdf.md
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Convert Markdown files to PDF Pandoc & Typst
|
||||
So sometimes I have a md file that I just really quickly want to
|
||||
convert to a PDF file. I usually always have typst and pandoc installed
|
||||
on my system, so I've just created a small script which I have in `/usr/local/bin/md-to-pdf.sh` ish.
|
||||
Just a no brainer, write something super fast in md, spit it out as a pdf.
|
||||
Good yes.
|
||||
|
||||
*Dependencies*:
|
||||
- pandoc as converter
|
||||
- typst as pdf creation engine
|
||||
- tested on fedora and ubuntu
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
printf 'usage: %s <input.md>\n' "${0##*/}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input=$1
|
||||
|
||||
if [[ ! -f $input ]]; then
|
||||
printf 'error: not a file: %s\n' "$input" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for cmd in pandoc typst; do
|
||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||
printf 'error: %s not found in PATH\n' "$cmd" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
dir=$(dirname -- "$input")
|
||||
base=$(basename -- "$input")
|
||||
stem=${base%.*}
|
||||
output="$dir/$stem.pdf"
|
||||
|
||||
pandoc "$input" \
|
||||
--from=gfm \
|
||||
--to=pdf \
|
||||
--pdf-engine=typst \
|
||||
--output="$output" \
|
||||
-V papersize=a4 \
|
||||
-V fontsize=10pt \
|
||||
-V mainfont="Noto Sans" \
|
||||
|
||||
printf '%s\n' "$output"
|
||||
```
|
||||
Reference in New Issue
Block a user