From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Ulrich G. Wortmann" Subject: Re: Bug: org export table.el [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.1/lisp/org/)] Date: Mon, 3 Dec 2018 10:02:25 -0500 Message-ID: References: <87a7ly3jg0.fsf@nicolasgoaziou.fr> <87woozwo1d.fsf@nicolasgoaziou.fr> <874lbyqpji.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000007e646b057c1f70a0" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTpkE-00052Y-SR for emacs-orgmode@gnu.org; Mon, 03 Dec 2018 10:02:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTpk7-0003Dd-C4 for emacs-orgmode@gnu.org; Mon, 03 Dec 2018 10:02:46 -0500 Received: from mail-pl1-f177.google.com ([209.85.214.177]:35262) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTpk6-0003CH-KG for emacs-orgmode@gnu.org; Mon, 03 Dec 2018 10:02:39 -0500 Received: by mail-pl1-f177.google.com with SMTP id p8so6619617plo.2 for ; Mon, 03 Dec 2018 07:02:38 -0800 (PST) In-Reply-To: <874lbyqpji.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --0000000000007e646b057c1f70a0 Content-Type: text/plain; charset="UTF-8" I made a few more tweaks. The function now recognizes modifiers as to which float environment to use, and where to place the float on the page. E.g. #+ATTR_LATEX: :environment longtable #+ATTR_LATEX: :placment [t] I also had a quick look at the html export code to see whether I can add the caption text to the html export, but that is beyond my understanding of lisp. Below the code for org-latex--table.el-table Cheers Uli (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)) )))))) On Fri, 30 Nov 2018 at 15:27 Nicolas Goaziou wrote: > Hello, > > "Ulrich G. Wortmann" writes: > > > > I know nothing about lisp, but I think I understand enough of the > structure > > to propose the following changes: > > > > In my testfile, this preserves the current behavior if no #+CAPTION is > > present. However, if the #+CAPTION is not empty, the table will be > > exported as float with the proper caption and label. The code needs > > probably some cleanup, but I don't understand enough lisp to know what's > > save to drop. > > > > Hope this can be merged > > Thank you. I applied something similar in "next" branch (i.e., Org 9.3). > > Regards, > > -- > Nicolas Goaziou > -- Ulrich Wortmann 416 978 7084 Associate Chair Undergraduate Affairs Department of Earth Sciences University of Toronto 22 Russel St., Toronto, ON, Canada, M5S 3B1 --0000000000007e646b057c1f70a0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

I made a few more tweaks. The function now = recognizes modifiers as to which float environment to use, and where to pla= ce the float on the page. E.g.

#+ATTR_LATEX: :envir= onment longtable
#+ATTR_LATEX: :placment [t]

=
I also had a quick look at the html export code to see whether I can a= dd the caption text to the html export, but that is beyond my understanding= of lisp.

Below the code for=C2=A0org-latex--table= .el-table=C2=A0

Cheers

Ul= i=C2=A0



(defun org-latex--t= able.el-table (table info)
=C2=A0 "Return appropriate LaTeX = code for a table.el table.

TABLE is the table type= element to transcode.=C2=A0 INFO is a plist
used as a communicat= ion channel.

This function assumes TABLE has `tabl= e.el' as its `:type'
property."
=C2=A0 (le= t* ((caption (org-latex--caption/label-string table info))
(attr (org-export-read-attribute :attr_l= atex table))
;; Determin= e alignment string.
(ali= gnment (org-latex--align-string table info))
;; Determine environment for the table: longtable, tab= ular...
;;(table-env (or= (plist-get attr :environment)
<= /span> ;; (plist-get info :latex-de= fault-table-environment)))
;; If table is a float, determine environment: table, table*
<= span style=3D"white-space:pre"> ;; or sidewaystable.
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (table-env (or (plist-get attr :environment= )
(plist-get info :late= x-default-table-environment)))
<= /span> (float-env (unless (member t= able-env '("longtable" "longtabu"))
=C2=A0 =C2=A0 =C2=A0 (let ((float (plis= t-get attr :float)))
(c= ond
((and (not float) = (plist-member attr :float)) nil)
= ((or (string=3D float "sidewaystable")
=C2=A0 =C2=A0 =C2=A0 (string=3D float = "sideways")) "sidewaystable")
((string=3D float "multicolumn") &quo= t;table*")
((or f= loat
=C2=A0 =C2=A0 =C2= =A0 (org-element-property :caption table)
=C2=A0 =C2=A0 =C2=A0 (org-string-nw-p (plist-get attr :c= aption)))
=C2=A0 "= table")))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
(placement
=C2=A0 (or (plist-get attr :placement)
=C2=A0 =C2=A0 =C2=A0 (format "[%= s]" (plist-get info :latex-default-figure-position))))
;; (centerp (if (plist-member attr :cen= ter) (plist-get attr :center)
;; =C2=A0 =C2=A0 (plist-get in= fo :latex-tables-centered)))
(caption-above-p (org-latex--caption-above-p table info)))
= =C2=A0 (require 'table)
=C2=A0 ;; Ensure "*org-export-ta= ble*" buffer is empty.
=C2=A0 (with-current-buffer (get-buff= er-create "*org-export-table*")
=C2=A0 =C2=A0 (erase-bu= ffer))
=C2=A0 (let ((output (with-temp-buffer
=C2=A0 (insert (org-element-property :value= table))
=C2=A0 (goto-ch= ar 1)
=C2=A0 (re-search-= forward "^[ \t]*|[^|]" nil t)
=C2=A0 (table-generate-source 'latex "*org-export-= table*")
=C2=A0 (wi= th-current-buffer "*org-export-table*"
=C2=A0 =C2=A0 (org-trim (buffer-string))))))
=
=C2=A0 =C2=A0 (kill-buffer (get-buffer "*org-export-table*")= )
=C2=A0 =C2=A0 ;; Remove left out comments.
=C2=A0 =C2= =A0 (while (string-match "^%.*\n" output)
=C2=A0 =C2=A0= =C2=A0 (setq output (replace-match "" t t output)))
= =C2=A0 =C2=A0 (let ((attr (org-export-read-attribute :attr_latex table)))
=C2=A0 =C2=A0 =C2=A0 (when (plist-get attr :rmlines)
;; When the "rmlines" attrib= ute is provided, remove all hlines
;; but the the one separating heading from the table body.
<= div> (let ((n 0) (pos 0))
= =C2=A0 (while (and (< (length ou= tput) pos)
=C2=A0 =C2=A0= =C2=A0 (setq pos (string-match "^\\\\hline\n?" output pos)))
=C2=A0 =C2=A0 (cl-incf n)
=C2=A0 =C2=A0 (unless (=3D = n 2) (setq output (replace-match "" nil nil output))))))
=C2=A0 =C2=A0 =C2=A0 (let ((centerp (if (plist-member attr :center) (plis= t-get attr :center)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0(plist-get info :latex-tables-centered))))
(if (not centerp) output
=C2=A0 (if (string=3D ""= ; caption)
=C2=A0 =C2=A0 = =C2=A0 (format (concat "\\begin{center}\n"
=C2=A0 =C2=A0 =C2=A0 "%s\n"
<= div> =C2=A0 =C2=A0 =C2=A0 "\\= end{center}\n") output)
=C2=A0 =C2=A0 (format (concat "\\begin{"table-env"}"= ; placement"\n"
=C2=A0 =C2=A0 caption
=C2=A0 =C2=A0 "\\centering\n"
=C2=A0 =C2=A0 "%s\n"
=C2=A0 =C2=A0 "\\end{"table-env"}= \n") output))
=C2=A0= ))))))


On Fri, 30 Nov 2018 at 15:27 = Nicolas Goaziou <mail@nicolasg= oaziou.fr> wrote:
Hello,
"Ulrich G. Wortmann" <uli.wortmann@utoronto.ca> writes:
>
> I know nothing about lisp, but I think I understand enough of the stru= cture
> to propose the following changes:
>
> In my testfile, this preserves the current behavior if no #+CAPTION is=
> present. However, if the=C2=A0 #+CAPTION is not empty, the table will = be
> exported as float with the proper caption and label. The code needs > probably some cleanup, but I don't understand enough lisp to know = what's
> save to drop.
>
> Hope this can be merged

Thank you. I applied something similar in "next" branch (i.e., Or= g 9.3).

Regards,

--
Nicolas Goaziou
--

Ulrich Wortman= n=C2=A0416 978 7084

Associate Chair Undergra= duate=C2=A0Affairs

Department of Earth Sciences

University of Toronto
22 Russel St., Toronto, ON, Canada, M5S 3B1

--0000000000007e646b057c1f70a0--