Skip to content

Instantly share code, notes, and snippets.

@skoppula
Created December 21, 2015 22:14
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 skoppula/4328826182d2c72ad6ac to your computer and use it in GitHub Desktop.
Save skoppula/4328826182d2c72ad6ac to your computer and use it in GitHub Desktop.
Mirror of Markdown/Latex integration from linguisticmystic.com
# Entirely from http://linguisticmystic.com/2015/03/04/how-to-write-a-dissertation-in-latex-using-markdown/
# Captures the date for later use
date=`date +"%m-%d-%y"`
# Archives a copy of the plaintext by date, leaving a trail of prior drafts outside Dropbox
cp ~/Dropbox/plaintext/prospectus.md ~/Documents/prospectus/build/backups/prospectus-$date.txt
# Run Pandoc to turn the markdown file with the bulk of the document into a .TeX file
pandoc -f markdown --latex-engine=xelatex -R -i ~/Dropbox/plaintext/prospectus.md -o ~/Documents/prospectus/build/pandocked.tex
# Remove some of the junk that Markdown adds when converting to TeX.
sed -i .bak 's/\[<+->\]//g' ~/Documents/prospectus/build/pandocked.tex
sed -i .bak 's/\\def\\labelenumi{\\arabic{enumi}.}//g' ~/Documents/prospectus/build/pandocked.tex
sed -i .bak 's/\\itemsep1pt\\parskip0pt\\parsep0pt//g' ~/Documents/prospectus/build/pandocked.tex
# Concatenate the header file (with the preambles, TOC, etc), the pandoc-created TeX file, and the footer file (with the bibliography) into a single buildable TeX file
cat ~/Documents/prospectus/build/header.tex ~/Documents/prospectus/build/pandocked.tex ~/Documents/prospectus/build/footer.tex > ~/Documents/prospectus/build/StylerProspectus.tex
# Move into the build folder, which keeps the TeX junk and included files out of the main folder
cd ~/Documents/prospectus/build
# Build the TeX once without stopping for errors (as the hyperref plugin throws errors on the first run)
/usr/texbin/xelatex -output-driver="/usr/texbin/xdvipdfmx" -interaction=nonstopmode -synctex=1 StylerProspectus
# Render the bibliography based on the prior file
/usr/texbin/bibtex StylerProspectus
# Render the file twice more, to ensure that the bibliographical references are included and that the TOC reflects everything accurately
/usr/texbin/xelatex -output-driver="/usr/texbin/xdvipdfmx" -synctex=1 StylerProspectus
/usr/texbin/xelatex -output-driver="/usr/texbin/xdvipdfmx" -synctex=1 StylerProspectus
# Open the PDF generated in my PDF reader of choice
open /Applications/Skim.app StylerProspectus.pdf
# Copy the PDF and final TeX out of the build folder for accessibility
cp StylerProspectus.pdf ~/Documents/prospectus/StylerProspectus.pdf
cp StylerProspectus.tex ~/Documents/prospectus/StylerProspectus.tex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment