Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created April 19, 2023 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luckylittle/ebb46b2f4663df7c1dc0fc257ee1ef89 to your computer and use it in GitHub Desktop.
Save luckylittle/ebb46b2f4663df7c1dc0fc257ee1ef89 to your computer and use it in GitHub Desktop.
Beautiful PDF generator out of Markdown powered by podman
#!/bin/zsh
########################################
########################################
## ##
## Author: lmaly@redhat.com ##
## Takes Markdown file `in.md` and ##
## converts it into a LaTeX PDF !! ##
## ##
########################################
########################################
# Create a listings setup for code blocks
cat <<EOF > listings-setup.tex
\usepackage{xcolor}
\lstset{
basicstyle=\ttfamily,
keywordstyle=\color[rgb]{0.13,0.29,0.53}\bfseries,
stringstyle=\color[rgb]{0.31,0.60,0.02},
commentstyle=\color[rgb]{0.56,0.35,0.01}\itshape,
backgroundcolor=\color[RGB]{248,248,248},
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
captionpos=b,
breaklines=true,
breakatwhitespace=true,
breakautoindent=true,
escapeinside={\%*}{*)},
linewidth=\textwidth,
basewidth=0.5em,
}
EOF
# Create a Containerfile
cat <<EOF > Containerfile
FROM registry.redhat.io/rhel7:7.9-983.1679306060
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y pandoc pandoc-citeproc texlive
COPY in.md /tmp/
COPY listings-setup.tex /tmp/
RUN pandoc -f markdown_github --listings -H /tmp/listings-setup.tex -V geometry:margin=0.3in -o /tmp/out.pdf /tmp/in.md
EOF
# Build a container
podman build -t pandoc-citeproc -f Containerfile .
# Run the container
podman run --name pandoc-citeproc pandoc-citeproc
# Copy the out.pdf from inside the container
podman cp pandoc-citeproc:/tmp/out.pdf .
# Cleanup
podman rm pandoc-citeproc
podman rmi localhost/pandoc-citeproc
rm -vf listings-setup.tex Containerfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment