summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/ctable/doit
blob: 91b71e02b156b675aa4f2ae36e087187e44d80c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env ruby
require 'optparse'
require 'erb'
require 'rubygems'
require 'rio'
require 'session'

# doit - make all or some example picture sets.

# Usage: doit      # make them all
#        doit nnx  # make nnx.pdf and snnx.pdf
#
# pictures are numbered 01, 02, etc.
# nn[a-z] has code to typeset a \ctable; for nn[k-z] page layout will be shown
# for each nn[a-z] two pdfs are generated:
#      nn[a-z].pdf for the ctable picture
# and snn[a-z].pdf for the source code verbatim.
# The number of digits (nn) is set with DIGS
# The prefix (s) for source verbatims and (empty) for result files is set by PRE
# Windows users should replace NULL with perhaps "c:/temp/null"

MYNAME = File.basename($0)
  DIGS = 2
   ALL = Dir["[0-9]"*DIGS+"[a-z]"].sort
  NULL = '/dev/null'
   PRE = ['s','']

# clean up directory
# all = false: keep pdf's
# all = true: remove pdf's, too
def clean(all=false)
  ALL.map{|x| PRE.map{|y| y+x }}.flatten.each do |f|
    exts = %w{aux tex log chk fls out}
    exts << 'pdf' if all
    exts.each do |e|
      fe = "#{f}.#{e}"
      File.delete(fe) if File.exist?(fe)
    end
  end
  exit(0)
end

# call the system shell with command
# exit on error
def sys(command)
  sh = Session::Bash.new
  o,e = sh.execute(command)
  unless sh.exit_status == 0
    puts "error running: #{command}",
         "  exit_status: #{sh.exit_status}",
         "       output: #{o}",
         "        error: #{e}"

    exit(sh.exit_status)
  end
end

@quiet = false
ARGV.options do |opt|
  opt.banner = "Create example images\n"
  opt.banner << "No arguments: create them all\n"
  opt.banner << "Example: ./#{MYNAME} 03? # creates 03a.pdf, 03b.pdf, s03a.pdf, and s03b.pdf"
  opt.separator ""
  opt.on('-h','--help','print this help and exit')       do puts opt.help; exit end
  opt.on("-c","--clean","Clean up, but keep pdf files")  do clean end
  opt.on("-C","--Clean","Clean up, including pdf files") do clean(true) end
  opt.on("-q","--quiet","Be silent")                     do @quiet = true end
  opt.parse!
end
set = ARGV.empty? ? ALL : ARGV
tex = DATA.readlines("\n\n") # tex[0] -> source verbatim, tex[1] -> result
sh = Session::Shell.new
set.each do |j|
  puts j unless @quiet
  0.upto(1) do |i|
    f = "#{PRE[i]}#{j}"
    r = rio(f+'.tex') < ERB.new(tex[i]).result(binding)
    sys("pdflatex --interaction=nonstopmode #{r.path}")
    sys("pdfcrop #{f}.pdf #{f}.pdf")
  end
end
# $Id: doit,v 1.6 2009-09-15 11:28:26 wybo Exp $
__END__
\documentclass{article}
\usepackage[a4paper,margin=20mm,noheadfoot]{geometry}
\pagestyle{empty}
\begin{document}\ttfamily
\fontsize{10}{12 pt}\selectfont
\begin{verbatim}<%= open(j).readlines.delete_if {|x| x =~ /\$Id|remove for source/ } %>\end{verbatim}
\end{document}

\documentclass[twoside]{article}
<% if j =~ /[k-z]$/ %>
\usepackage[papersize={65mm,40mm},showframe,margin=5mm,noheadfoot]{geometry}
<% end %>
\usepackage{ctable}
\usepackage{txfonts}
\pagestyle{empty}
\parindent0pt
\begin{document}
<%= open(j).readlines.delete_if {|x| x =~ /\$Id/ } %>
\end{document}