Skip to content

Commit

Permalink
Merge pull request progit#125 from dr-itz/master
Browse files Browse the repository at this point in the history
fix makepdf for Windows
  • Loading branch information
schacon committed Dec 8, 2011
2 parents 9feba1d + b9614f5 commit 712f9a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
15 changes: 15 additions & 0 deletions latex/README
Expand Up @@ -10,3 +10,18 @@ pandoc and XeTeX as dependencies.
* `template.tex`: this is the main LaTeX file which determines the style of the
PDF version of the book. Its contents is run through the ERB templating
language to include language-specific customisations from config.yml.


For Windows
===========

Windows build is tested with Pandoc 1.8 and MixTeX 2.9. Install MixTeX with all
font options. Only `en` has been tested so far. To make it work, it needs some
tweaks.

* `pandoc` and `xelatex` binaries must be on the PATH
* Change the default fonts in `config.yml` to something that exists in Windows.
Example for working fonts:
font: Latin Modern Roman
mono: Courier
bold: "{*}"
26 changes: 14 additions & 12 deletions latex/makepdf
@@ -1,12 +1,10 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'fileutils'
require 'open3'
require 'erb'
require 'yaml'

include FileUtils, Open3
alias :pipe :popen3
include FileUtils

$here = File.expand_path(File.dirname(__FILE__))
$root = File.join($here, '..')
Expand Down Expand Up @@ -37,8 +35,12 @@ USAGE
end

def command_exists?(command)
ENV['PATH'].split(/:/).map do |path|
File.executable?("#{path}/#{command}")
if File.executable?(command) then
return command
end
ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
cmd = "#{path}/#{command}"
File.executable?(cmd) || File.executable?("#{cmd}.exe") || File.executable?("#{cmd}.cmd")
end.inject{|a, b| a || b}
end

Expand Down Expand Up @@ -133,10 +135,10 @@ figures do
end.join("\n\n")

print "\tParsing markdown... "
latex = pipe('pandoc -p --no-wrap -f markdown -t latex') do |stdin, stdout|
stdin.write(pre_pandoc(markdown, config))
stdin.close
post_pandoc(stdout.read, config)
latex = IO.popen('pandoc -p --no-wrap -f markdown -t latex', 'w+') do |pipe|
pipe.write(pre_pandoc(markdown, config))
pipe.close_write
post_pandoc(pipe.read, config)
end
puts "done"

Expand All @@ -154,15 +156,15 @@ figures do
cd($root)
3.times do |i|
print "\t\tPass #{i + 1}... "
pipe("xelatex -output-directory='#{dir}' '#{dir}/main.tex' 2>&1") do |_, stdout|
IO.popen("xelatex -output-directory=\"#{dir}\" \"#{dir}/main.tex\" 2>&1") do |pipe|
unless $DEBUG
if ~ /^!\s/
puts "failed with:\n\t\t\t#{$_.strip}"
puts "\tConsider running this again with --debug."
abort = true
end while stdout.gets and not abort
end while pipe.gets and not abort
else
STDERR.print while stdout.gets rescue abort = true
STDERR.print while pipe.gets rescue abort = true
end
end
break if abort
Expand Down

0 comments on commit 712f9a4

Please sign in to comment.