Guest User

Untitled

a guest
Feb 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. def escape(str)
  3. esc_str = str.gsub(/\t/," & ") + "\\\\"
  4. esc_str.gsub(/(\d)E([+-]?)(\d{1,2})/) do |m|
  5. "#{$1} \\$\\times 10^{#{$2 =="-" ? "-" : ""}#{$3.to_i}}\\$"
  6. end
  7. end
  8. require 'pp'
  9. data=STDIN.read.split("\n")
  10. first_line = data.shift
  11. count=first_line.scan(/\t/).length+1;
  12. result=["\\begin{tabular}{#{"c" * count}}"];
  13. hl = "\\hline"
  14. result << hl << escape(first_line) << hl
  15. result += data.map{|line| escape(line)}
  16. result << hl << "\\end{tabular}"
  17. puts result.join("\n")
Add Comment
Please, Sign In to add comment