Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created September 22, 2012 08:41
Show Gist options
  • Select an option

  • Save mizzy/3765569 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/3765569 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8; -*-
require 'rubygems'
require 'pathname'
require 'github/markdown'
Dir['*.md'].each do |md|
target = Pathname.new(md)
header = <<-HEADER
\\documentclass[a4paper]{report}
\\usepackage{hyperref}
\\usepackage{ctable}
\\setcounter{chapter}{1}
\\begin{document}
HEADER
footer = <<-FOOTER
\\end{document}
FOOTER
html_file = target.sub(/\.md\z/, '.html')
tex_file = target.sub(/\.md\z/, '.tex')
dvi_file = target.sub(/\.md\z/, '.dvi')
html = GitHub::Markdown.render(File.open(md).read)
open(html_file, 'wb' ) {|f| f.write html }
tex = `pandoc --to=latex #{html_file}`
open(tex_file, 'wb' ) {|f| f.write header + tex + footer }
`platex -kanji=utf-8 #{tex_file}`
`dvipdfmx #{dvi_file}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment