Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- def escape(str)
- esc_str = str.gsub(/\t/," & ") + "\\\\"
- esc_str.gsub(/(\d)E([+-]?)(\d{1,2})/) do |m|
- "#{$1} \\$\\times 10^{#{$2 =="-" ? "-" : ""}#{$3.to_i}}\\$"
- end
- end
- require 'pp'
- data=STDIN.read.split("\n")
- first_line = data.shift
- count=first_line.scan(/\t/).length+1;
- result=["\\begin{tabular}{#{"c" * count}}"];
- hl = "\\hline"
- result << hl << escape(first_line) << hl
- result += data.map{|line| escape(line)}
- result << hl << "\\end{tabular}"
- puts result.join("\n")
Add Comment
Please, Sign In to add comment