Code to create PDF's from TaskPaper files

This code does the following,

  1. Converts a TaskPaper file into a Markdown file using the Ruby TaskPaper Library.
  2. Converts the Markdown file into XeLaTex using MMD templates
  3. Runs XeLaTex on the source files creating a PDF file.
  4. Creates a back up of the PDF based on date and moves the files into a particular directory.
  5. Prints the handout(s)
  6. And finally it clears the aux and temporary files.

Just a quick warning. I sanitized the code to not include some personal information. That means that there may be some errors in the paths, or file names. Make sure to check that if you want to just modify this code and run it.

If you are interested in the MMD templates, send me a direct message and I can help you with that.

If you need help with the Ruby Library and how to create you own Markdown output, I think that it would be better to ask in this forum and create another topic for the question. I modified the library so long ago that I think it would take me as long to figure it out myself as it would take for you to do that too.

#!/usr/bin/ruby

# TaskPaperConverter
#version = "1.2.0" # 2018-06-01
#
# This script converts TaskPaper files to PDF.
# Output is via a template file.
#
# Made by Victor Gutierrez based on Matt Gemmel's code
#
github_url = "http://github.com/mattgemmell/TaskPaperRuby"
#
# Requirements: [optional/recommended] Less CSS. See README.

time = Time.new
documentsPath = "/Users/user/location_of_my_source/Code/"
require_relative 'src/taskpaperdocument'
require_relative 'src/taskpaper+prayer'

taskpaper_input_filename = "/Users/user/Dropbox/Apps/TaskPaper/Documents/test/toPrint.taskpaper"
markdown_output_filename = "/Users/user/location_of_my_source/Code/test.md"


# Ensure we have an input file to work with
if !File.exist?(taskpaper_input_filename)
	puts "Couldn't find input file \"#{taskpaper_input_filename}\". ¯\\_(ツ)_/¯"
	exit
end

# Load TaskPaper file
document = TaskPaperDocument.new(taskpaper_input_filename)

# Produce Markdown output from document
# This is a result of some modifications I made to the Ruby Library. This will not 
# work for you unless you create your own or use the code already provided by Matt.
document_md = document.to_mydoc

# Write Markdown file
File.open(markdown_output_filename, 'w') do |outfile|
  outfile.puts document_md
end

# This is what I use to create names, and the copy and move commands necessary to do all I want.
handoutName = documentsPath + "'Document Backup Example - " + time.strftime("%b %d, %Y") + ".pdf'"
copyCommand = "cp " + documentsPath + "r.pdf " + handoutName
openCommand = "open " + handoutName
printCommand = "lpr " + handoutName
moveCommand = "mv " + handoutName + "/Users/user/location_of_my_source/Code/PDF/" + "'" + time.strftime("%Y") + "/" + time.strftime("%m") + " - " + time.strftime("%B") + "'"
cleartemp = "rm " + taskpaper_input_filename


# Okay. This is where the scripts makes use of MMD (Multimarkdown) and their templates. 
# Even though this script previously created a Markdown file, I make use of a MMD
# template to produce the handout I want.
#
# I call this file in this example "hand_out_template.md" 
#
# This is what the template has.
#
#LaTeX Config:	test-handout
#Base Header Level:	3
#
#{{test.md}}
#

system ('mmd2tex ' + documentsPath + 'hand_out_template.md')
system ('mv ' + documentsPath + 'handout.tex ' + documentsPath + 'r.tex')
system ('xelatex -interaction=nonstopmode ' + documentsPath + 'r.tex')
system ('xelatex -interaction=nonstopmode ' + documentsPath + 'r.tex')
system (copyCommand)
system ('rm ' + documentsPath + 'r.*')
# system (openCommand)
system (printCommand)

# This is just in case you want to print everything from the command line. 
# This allows you to have a bigger margin and a bigger font when using a Mac. 
# At least that is the feeling I have. :) 
puts "How many copies do you want to print?"
x = gets.chomp.to_i
until x <= 0
  system (printCommand)
  x -= 1
end

# c = gets.chomp
# printFinalCommand = "lpr -# " + c + " " + handoutName
# system (printFinalCommand)

system (moveCommand)
system (cleartemp)
1 Like