I tend to use markdown almost unconsciously when taking notes or expressing thoughts or ideas in a text editor. But on several occasions I’ve had the need to share what I’ve written with a non technical person and handing off markdown to them seems a bit so-so. So after a few of these incidences I settled the matter and decided to investigate if there was an easy way to just generate a pdf file from markdown from the command-line in MacOSX. A quick tour on google and you’ll find this excellent gist that describes more or less how to get it working. The problem was that everything didn’t quite work for me (I later found out that a fix was written in the comment but I didn’t know at the time). These are the two things that I had to do differently:
- When it says that you should do
brew tap phinze/cask
I simply ignored this step and went directly tobrew cask install mactex
- When it’s time to create a symlink the gist instructs us to do
sudo ln -s /usr/texbin/pdflatex /usr/local/bin/
but instead I had to doln -s /Library/TeX/Root/bin/x86_64-darwin/pdflatex /usr/local/bin/pdflatex
Here are the instructions in its entirety:
$ brew update
$ brew install pandoc
$ brew install ghc cabal-install
$ cabal install pandoc
$ brew cask install mactex
$ ln -s /Library/TeX/Root/bin/x86_64-darwin/pdflatex /usr/local/bin/pdflatex
Now you should be able to run pandoc
from the command-line and generate pdfs like this:
$ pandoc -o out.pdf osx-pdf-from-markdown.markdown
Great! But I’m not using pandoc regularly so in order to make it a little easier to remember I wrote a small bash script that I’ve named md2pdf
:
#!/bin/bash
if [ -z "${1}" ]; then
echo "You need to specify the markdown file"
exit 0
fi
# If second argument is undefined then name the output file the same as the input file
# expect that use a "pdf" file extension
if [ -z "${2}" ]; then
# Get the filename (and path) without the extension
filename_without_ext=`rev <<< "${1}" | cut -d"." -f2- | rev`
pdf_filename="${filename_without_ext}.pdf"
else
pdf_filename="${2}"
fi
pandoc -o "${pdf_filename}" "${1}"
After some chmod +x md2pdf
and having copied it to /usr/local/bin
this allows me to simply write:
$ md2pdf some.md
and it'll generate a file called some.pdf
. It's also possible to specify another directory or filename if you like:
$ md2pdf some.md ~/pdfs/important.pdf
That's it!
15 thoughts on “Markdown to PDF in MacOSX”
You don’t need lines 3 and 4; those relate to the Haskell/Cabal method of installing pandoc and are redundant since brew pandoc works fine.
Thanks for the instructions!
That’s a nice tutorial, thanks. Personally I settled for MacDown as my markdown editor which allows me to simply hit cmd+p.
Thanky ou for this article, very useful script! But I think it suffices to install pandoc via brew. Also, an important option to add to the pandoc command in case you write anything possibly containing special characters: `–pdf-engine=xelatex`
Your article helped me a lot, is there any more related content? Thanks!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Markdown to PDF in MacOSX – Coding all the things
igoizrnsjb http://www.g1p9p558pzc7w2we7y3bo84m9052je4rs.org/
[url=http://www.g1p9p558pzc7w2we7y3bo84m9052je4rs.org/]uigoizrnsjb[/url]
aigoizrnsjb
Foot Valve For Water
Plastic Water Line Connectors
affordable gucci earrings cheap CL SMALL TOTE
rep gucci eyeglasses cheap CL TOTE BAG
affordable gucci for cheap CL TOTE BAG
rep gucci for sale cheap CL SHOPPING BAG
Industrial Water Pump
tbgfrisbee.no
Peripheral Pump
In Line Pump
Foot Valve Pipe
Plastic Valves
cheap gucci flip flops cheap CL LARGE TOTE
Self-priming Peripheral Pump
Half Inch Pvc Ball Valve
JET Water Pump
cheap adidas employee stor UGG, Women's Brooklyn Waterproof Chelsea Boot – Black 'on sale now' under $120 e-commerce discounts
Acid-Resistance Rubber Sheets
kinnikubaka.com
Stepper Motor Weight
cheap what are yeezys UGG, Women's Brisbane Lace up Platform Boot – Black 'hot offers this week' under $100 affordable deals
Underwater Motor
Asbestos Rubber Sheet With Wire Net Strengthening
Underwater ROV Motor
Asbestos Rubber Sheets
affordable adidas outlet store kittery maine UGG, Women's Classic Mini Bailey Zip Boot – Black 'special pricing' under $130 best offers on items
affordable what are yeezy shoes UGG, Men's Burleigh Waterproof Casual Boot – Stout 'hurry up' under $110 free shipping on all purchases
Asbestos Latex Sheet
Flange Insulation Gaskets Kits
China Pm Stepper Motor
affordable yeezy sizes UGG, Men's Neumel Weather Waterproof Chukka Boot – Black 'great savings' under $90 lowest price
China Slider Stepper Motor
gucci replica store REP-Gucci Bags 20GUC0115
High Pressure Zinc Die Casting Parts
Swiss Milling
Mechanical Machine Parts
Car Modification Parts
CNC Machining
Cnc Parts Manufacturer
toyotavinh.vn
True Precision Machining
gucci replica store REP-Gucci Bags 208B570060
CNC Machining Assembly
gucci duplicate shoes REP-Gucci Bags 20GUC0125
5 Axis Impeller Machining
gucci duplicate shoes REP-Gucci Bags 20GUC0126
gucci duplicate shoes REP-Gucci Bags 208B570051
CNC Machining Cylinder Parts
E9TJWI4QyWA
9LhvZylxTiL
Alcohol Disinfectant
Wholesale Modern Design Ceramic Base Orange Table Lamp
Hot-selling Cement Industrial Smoky Mushroom Table Lamp
affordable yeezy 700 rep adidas Yeezy YEEZY 450 “Sulfur” sneakers
affordable cigarette dunks adidas Ultraboost 1.0 “Black Gum Camo Sole” sneakers
cheap m batch dunks adidas Samba Millenium “Black” sneakers
Nordic Cordless Desk Lamp Bedroom Led European Table Lamp
cheap louis vuitton shoes reps adidas Forum Low “White” sneakers
affordable jordan 4 off white reps adidas x Pharrell Williams Human Race NMD “Friends & Family – Shock Pink” sneakers
Manual Defibrillator
Modern Nordic LED Light Fixtures Middle-Sized Table Lamp
Portable Defibrillator
Decorative Dining Room Custom Led Atmosphere Table Lamp
Suction Unit
http://www.szklarski.pl
Portable Oxygen Tank
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.