(defun org-latex--table.el-table (table info)
"Return appropriate LaTeX code for a table.el table.
TABLE is the table type element to transcode. INFO is a plist
used as a communication channel.
This function assumes TABLE has `table.el' as its `:type'
property."
(let* ((caption (org-latex--caption/label-string table info))
(attr (org-export-read-attribute :attr_latex table))
;; Determine alignment string.
(alignment (org-latex--align-string table info))
;; Determine environment for the table: longtable, tabular...
;;(table-env (or (plist-get attr :environment)
;; (plist-get info :latex-default-table-environment)))
;; If table is a float, determine environment: table, table*
;; or sidewaystable.
(table-env (or (plist-get attr :environment)
(plist-get info :latex-default-table-environment)))
(float-env (unless (member table-env '("longtable" "longtabu"))
(let ((float (plist-get attr :float)))
(cond
((and (not float) (plist-member attr :float)) nil)
((or (string= float "sidewaystable")
(string= float "sideways")) "sidewaystable")
((string= float "multicolumn") "table*")
((or float
(org-element-property :caption table)
(org-string-nw-p (plist-get attr :caption)))
"table")))))
(placement
(or (plist-get attr :placement)
(format "[%s]" (plist-get info :latex-default-figure-position))))
;; (centerp (if (plist-member attr :center) (plist-get attr :center)
;; (plist-get info :latex-tables-centered)))
(caption-above-p (org-latex--caption-above-p table info)))
(require 'table)
;; Ensure "*org-export-table*" buffer is empty.
(with-current-buffer (get-buffer-create "*org-export-table*")
(erase-buffer))
(let ((output (with-temp-buffer
(insert (org-element-property :value table))
(goto-char 1)
(re-search-forward "^[ \t]*|[^|]" nil t)
(table-generate-source 'latex "*org-export-table*")
(with-current-buffer "*org-export-table*"
(org-trim (buffer-string))))))
(kill-buffer (get-buffer "*org-export-table*"))
;; Remove left out comments.
(while (string-match "^%.*\n" output)
(setq output (replace-match "" t t output)))
(let ((attr (org-export-read-attribute :attr_latex table)))
(when (plist-get attr :rmlines)
;; When the "rmlines" attribute is provided, remove all hlines
;; but the the one separating heading from the table body.
(let ((n 0) (pos 0))
(while (and (< (length output) pos)
(setq pos (string-match "^\\\\hline\n?" output pos)))
(cl-incf n)
(unless (= n 2) (setq output (replace-match "" nil nil output))))))
(let ((centerp (if (plist-member attr :center) (plist-get attr :center)
(plist-get info :latex-tables-centered))))
(if (not centerp) output
(if (string= "" caption)
(format (concat "\\begin{center}\n"
"%s\n"
"\\end{center}\n") output)
(format (concat "\\begin{"table-env"}" placement"\n"
caption
"\\centering\n"
"%s\n"
"\\end{"table-env"}\n") output))
))))))