Skip to content

Instantly share code, notes, and snippets.

@dayer4b
Last active June 21, 2017 14:29
Show Gist options
  • Save dayer4b/a5935fc1f34511964ff0 to your computer and use it in GitHub Desktop.
Save dayer4b/a5935fc1f34511964ff0 to your computer and use it in GitHub Desktop.
easy markdown previews / renders in ubuntu 14.04 (or Mac)
# this goes in your .bashrc (or maybe .bash_profile on a Mac)
function readmarkdown() {
TMPFILE=`mktemp`.pdf
pandoc "$@" -o $TMPFILE
evince $TMPFILE
rm $TMPFILE
}
# OR, for fancy formatting you can use --listings (this requires the latex-xcolor package)
function readmarkdown() {
TMPFILE=`mktemp`.pdf
pandoc "$@" --listings -H /path/to/listings-setup.tex -o $TMPFILE
# for Ubuntu
evince $TMPFILE
rm $TMPFILE
# for Mac
open $TMPFILE
# the rm $TMPFILE breaks things on Mac, so don't do it!
}
# once things are set up, this is how you use it:
readmarkdown README.md
#!/bin/bash
brew install pandoc
# install BasicTex.pkg from here http://www.ctan.org/pkg/mactex-basic
# then restart your BASH session so you can run the following command
sudo tlmgr install collection-fontsrecommended
# setup the listings latex file, setup the BASH function in your bashrc
# these packages can be pretty big, so I'd recommended not installing the recommended packages...
sudo apt-get install pandoc --no-install-recommends
sudo apt-get install texlive-latex-base --no-install-recommends
sudo apt-get install texlive-fonts-recommended --no-install-recommends
sudo apt-get install texlive-latex-recommended --no-install-recommends
# here's a one-liner that should work
sudo apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-latex-recommended --no-install-recommends
# an additional package can help with custom formatting (and is ~ 600kB)
sudo apt-get install latex-xcolor
% Contents of listings-setup.tex
\usepackage{xcolor}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\lstset{
basicstyle=\ttfamily,
numbers=left,
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,
numberstyle=\color[RGB]{150,150,150}\footnotesize,
stepnumber=1,
numbersep=4pt,
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,
}
@dayer4b
Copy link
Author

dayer4b commented Feb 6, 2015

I prefer this over the popular "markdown editors" because the best markdown editor is really just a text editor. Live preview is distracting. However, rendering a well-formatted document can be useful sometimes!

@dayer4b
Copy link
Author

dayer4b commented May 6, 2015

credit goes to JLDiaz at the TeX StackExchange site for producing an awesome style for the PDF

http://tex.stackexchange.com/questions/179926/pandoc-markdown-to-pdf-without-cutting-off-code-block-lines-that-are-too-long

@dayer4b
Copy link
Author

dayer4b commented Jan 24, 2017

I use a Mac for work these days, so I added a new file with an example on how to install prerequisites for Mac OS X 10.11.6:

https://gist.github.com/dayer4b/a5935fc1f34511964ff0#file-install-prerequisites-on-mac-sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment