diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el index 3cddc9d3e..9d33e276b 100644 --- a/contrib/lisp/org-e-latex.el +++ b/contrib/lisp/org-e-latex.el @@ -1932,16 +1932,77 @@ contextual information." ;;;; Table +;; +;; `org-e-latex-table' is the entry point for table transcoding. It +;; takes care of tables with a "verbatim" attribute. Otherwise, it +;; delegates the job to either `org-e-latex-table--table.el-table' or +;; `org-e-latex-table--org-table' functions, depending of the type of +;; the table. +;; +;; `org-e-latex-table--align-string' is a subroutine used to build +;; alignment string for Org tables. -(defun org-e-latex-table--format-string (table info) - "Return an appropriate format string for TABLE. +(defun org-e-latex-table (table contents info) + "Transcode a TABLE element from Org to LaTeX. +CONTENTS is nil. INFO is a plist holding contextual information." + (cond + ;; Case 1: verbatim table. + ((or org-e-latex-tables-verbatim + (let ((attr (mapconcat 'identity + (org-element-property :attr_latex table) + " "))) + (and attr (string-match "\\" attr)))) + (format "\\begin{verbatim}\n%s\n\\end{verbatim}" + ;; Re-create table, without affiliated keywords. + (org-trim + (org-element-interpret-data + `(table nil ,@(org-element-contents table)))))) + ;; Case 2: table.el table. Convert it using appropriate tools. + ((eq (org-element-property :type table) 'table.el) + (org-e-latex-table--table.el-table table contents info)) + ;; Case 3: Standard table. + (t (org-e-latex-table--org-table table contents info)))) -TABLE-INFO is the plist containing format info about the table, -as returned by `org-export-table-format-info'. INFO is a plist -used as a communication channel. +(defun org-e-latex-table--align-string (table info) + "Return an appropriate LaTeX alignment string. +TABLE is the considered table. INFO is a plist used as +a communication channel." + (let ((attr (mapconcat 'identity + (org-element-property :attr_latex table) + " "))) + (if (string-match "\\" attr)))) - (format "\\begin{verbatim}\n%s\n\\end{verbatim}" - ;; Re-create table, without affiliated keywords. - (org-trim - (org-element-interpret-data - `(org-data nil (table nil ,@(org-element-contents table))))))) - ;; Case 2: table.el table. Convert it using appropriate tools. - ((eq (org-element-property :type table) 'table.el) - (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))) - ;; When the "rmlines" attribute is provided, remove all hlines - ;; but the the one separating heading from the table body. - (let ((attr (mapconcat 'identity - (org-element-property :attr_latex table) - " "))) - (when (and attr (string-match "\\" attr)) - (let ((n 0) (pos 0)) - (while (and (< (length output) pos) - (setq pos (string-match "^\\\\hline\n?" output pos))) - (incf n) - (unless (= n 2) - (setq output (replace-match "" nil nil output))))))) - (if (not org-e-latex-tables-centered) output - (format "\\begin{center}\n%s\n\\end{center}" output)))) - ;; Case 3: Standard table. - (t (format (org-e-latex-table--format-string table info) contents)))) +TABLE is the table type element to transcode. CONTENTS is its +contents, as a string. INFO is a plist used as a communication +channel. + +This function assumes TABLE has `table.el' as its `:type' +attribute." + (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))) + ;; When the "rmlines" attribute is provided, remove all hlines but + ;; the the one separating heading from the table body. + (let ((attr (mapconcat 'identity + (org-element-property :attr_latex table) + " "))) + (when (and attr (string-match "\\" attr)) + (let ((n 0) (pos 0)) + (while (and (< (length output) pos) + (setq pos (string-match "^\\\\hline\n?" output pos))) + (incf n) + (unless (= n 2) + (setq output (replace-match "" nil nil output))))))) + (if (not org-e-latex-tables-centered) output + (format "\\begin{center}\n%s\n\\end{center}" output)))) ;;;; Table Cell