Revisions made by tamc up to 15:06 Wed 27 Jul 2005
Note, if you wish to edit or undo these revisions, please follow the links from here. You cannot do it from here, becuase someone may have edited the page more recently and because you may need a password to edit the page.
15:06 Wed 27 Jul 2005
45. pbcopy.puts "\\multicolumn{#{columns}}{r}{{Continued\ldots}} \\"- 45. pbcopy.puts "\\multicolumn{#{columns}}{r}{{Continued\\ldots}} \\"
07:47 Tue 26 Jul 2005
37. pbpaste = IO.popen('pbcopy','w+')- 37. pbcopy = IO.popen('pbcopy','w+')
39. pbpaste.puts "\\begin{center}"40. pbpaste.puts "\\begin{longtable}{#{'l '*columns}}"41. pbpaste.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'42. pbpaste.puts "\\endfirsthead"43. pbpaste.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'44. pbpaste.puts "\\endhead"45. pbpaste.puts "\\multicolumn{#{columns}}{r}{{Continued\ldots}} \\"46. pbpaste.puts "\\endfoot"47. pbpaste.puts "\\hline"48. pbpaste.puts "\\endlastfoot"49. pbpaste.puts- 39. pbcopy.puts "\\begin{center}"
- 40. pbcopy.puts "\\begin{longtable}{#{'l '*columns}}"
- 41. pbcopy.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
- 42. pbcopy.puts "\\endfirsthead"
- 43. pbcopy.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
- 44. pbcopy.puts "\\endhead"
- 45. pbcopy.puts "\\multicolumn{#{columns}}{r}{{Continued\ldots}} \\"
- 46. pbcopy.puts "\\endfoot"
- 47. pbcopy.puts "\\hline"
- 48. pbcopy.puts "\\endlastfoot"
- 49. pbcopy.puts
51. pbpaste.puts row.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'- 51. pbcopy.puts row.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
53. pbpaste.puts54. pbpaste.puts "\\end{longtable}"55. pbpaste.puts "\\end{center}"56. pbpaste.close_write57. puts pbpaste.gets || "Ok. In clipboard"- 53. pbcopy.puts
- 54. pbcopy.puts "\\end{longtable}"
- 55. pbcopy.puts "\\end{center}"
- 56. pbcopy.close_write
- 57. puts pbcopy.gets || "Ok. In clipboard"
07:42 Tue 26 Jul 2005
- 0. h1. Excel to Latex table convertor
- 1.
- 2. This is a quick script I hacked up to help doing tables in latex. Written for OSX 10.4 and your latex must use the longtable package.
- 3.
- 4. To use:
- 5. # Copy the excel table you want to convert
- 6. # Run this code (excel2latex.rb), it will place the latex in the clipboard
- 7. # Paste into your latex document
- 8.
- 9. <pre>
- 10. <code>
- 11. #!/usr/bin/ruby
- 12. # (c) 2005 Tom Counsell tom@counsell.org
- 13. # Licenced under the GPL
- 14. #
- 15. # Converts excel tables into latex tables
- 16. #
- 17. # Requires Mac OSX 10.4, although could be adapted for other platoforms
- 18. #
- 19. # To use, copy the excel table you want to convert to the clipboard
- 20. # Run this code
- 21. # The latex code will be in the clipboard ready to paste
- 22. #
- 23. # Let me know of any bugfixes or suggestions
- 24.
- 25. require 'csv'
- 26.
- 27. def escape_latex( string )
- 28. string.gsub( %r{([&$#%])} ) { '\\' + $1 }
- 29. end
- 30.
- 31. text = `pbpaste`
- 32. lines = text.split("\r")
- 33. lines = lines.map { |line| line.split("\t") }
- 34. columns = lines.map { |line| line.size }.max
- 35. header = lines.shift
- 36.
- 37. pbpaste = IO.popen('pbcopy','w+')
- 38.
- 39. pbpaste.puts "\\begin{center}"
- 40. pbpaste.puts "\\begin{longtable}{#{'l '*columns}}"
- 41. pbpaste.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
- 42. pbpaste.puts "\\endfirsthead"
- 43. pbpaste.puts header.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
- 44. pbpaste.puts "\\endhead"
- 45. pbpaste.puts "\\multicolumn{#{columns}}{r}{{Continued\ldots}} \\"
- 46. pbpaste.puts "\\endfoot"
- 47. pbpaste.puts "\\hline"
- 48. pbpaste.puts "\\endlastfoot"
- 49. pbpaste.puts
- 50. lines.each do |row|
- 51. pbpaste.puts row.map{ |entry| escape_latex entry }.join(' & ')+' \\\\'
- 52. end
- 53. pbpaste.puts
- 54. pbpaste.puts "\\end{longtable}"
- 55. pbpaste.puts "\\end{center}"
- 56. pbpaste.close_write
- 57. puts pbpaste.gets || "Ok. In clipboard"
- 58. </code>
- 59. </pre>