Function: org-latex-table-row

org-latex-table-row is a byte-compiled function defined in ox-latex.el.gz.

Signature

(org-latex-table-row TABLE-ROW CONTENTS INFO)

Documentation

Transcode a TABLE-ROW element from Org to LaTeX.

CONTENTS is the contents of the row. INFO is a plist used as a communication channel.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-latex.el.gz
;;;; Table Row

(defun org-latex-table-row (table-row contents info)
  "Transcode a TABLE-ROW element from Org to LaTeX.
CONTENTS is the contents of the row.  INFO is a plist used as
a communication channel."
  (let* ((attr (org-export-read-attribute :attr_latex
					  (org-element-parent table-row)))
	 (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
		      (plist-get info :latex-tables-booktabs)))
	 (longtablep
	  (member (or (plist-get attr :environment)
		      (plist-get info :latex-default-table-environment))
		  '("longtable" "longtabu"))))
    (if (eq (org-element-property :type table-row) 'rule)
	(cond
	 ((not booktabsp) "\\hline")
	 ((not (org-export-get-previous-element table-row info)) "\\toprule")
	 ((not (org-export-get-next-element table-row info)) "\\bottomrule")
	 ((and longtablep
	       (org-export-table-row-ends-header-p
		(org-export-get-previous-element table-row info) info))
	  "")
	 (t "\\midrule"))
      ;; Memorize table header in case it is multiline. We need this
      ;; information to define contents before "\\endhead" in longtable environments.
      (when (org-export-table-row-in-header-p table-row info)
        (let ((table-head-cache (plist-get info :org-latex-table-head-cache)))
          (unless (hash-table-p table-head-cache)
            (setq table-head-cache (make-hash-table :test #'eq))
            (plist-put info :org-latex-table-head-cache table-head-cache))
          (if-let* ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
              (puthash (org-element-parent table-row) (concat head-contents "\\\\\n" contents)
                       table-head-cache)
            (puthash (org-element-parent table-row) contents table-head-cache))))
      ;; Return LaTeX string as the transcoder.
      (concat
       ;; When BOOKTABS are activated enforce top-rule even when no
       ;; hline was specifically marked.
       (and booktabsp (not (org-export-get-previous-element table-row info))
	    "\\toprule\n")
       contents "\\\\\n"
       (cond
	;; Special case for long tables.  Define header and footers.
	((and longtablep (org-export-table-row-ends-header-p table-row info))
	 (let ((columns (cdr (org-export-table-dimensions
			      (org-element-lineage table-row 'table) info))))
	   (format "%s
\\endfirsthead
\\multicolumn{%d}{l}{%s} \\\\
%s
%s \\\\\n
%s
\\endhead
%s\\multicolumn{%d}{r}{%s} \\\\
\\endfoot
\\endlastfoot"
		   (if booktabsp "\\midrule" "\\hline")
		   columns
		   (org-latex--translate "Continued from previous page" info)
		   (cond
		    ((not (org-export-table-row-starts-header-p table-row info))
		     "")
		    (booktabsp "\\toprule\n")
		    (t "\\hline\n"))
		   (gethash (org-element-parent table-row) (plist-get info :org-latex-table-head-cache))
		   (if booktabsp "\\midrule" "\\hline")
		   (if booktabsp "\\midrule" "\\hline")
		   columns
		   (org-latex--translate "Continued on next page" info))))
	;; When BOOKTABS are activated enforce bottom rule even when
	;; no hline was specifically marked.
	((and booktabsp (not (org-export-get-next-element table-row info)))
	 "\\bottomrule"))))))