emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Ulrich G. Wortmann" <uli.wortmann@utoronto.ca>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <CAKoZnLrXoC8XBfUgX5iN062qi-jDaOaMhJ_wAa_qgUeH3Tg6nw@mail.gmail.com> (raw)
In-Reply-To: <874lbyqpji.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 4322 bytes --]

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 <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> "Ulrich G. Wortmann" <uli.wortmann@utoronto.ca> 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

[-- Attachment #2: Type: text/html, Size: 8490 bytes --]

  reply	other threads:[~2018-12-03 15:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-23 19:45 Bug: org export table.el [9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.1/lisp/org/)] Ulrich G. Wortmann
2018-11-24  9:37 ` Nicolas Goaziou
2018-11-26 16:21   ` Ulrich G. Wortmann
2018-11-26 16:30   ` Ulrich G. Wortmann
2018-11-26 21:02     ` Nicolas Goaziou
2018-11-28 17:10       ` Ulrich G. Wortmann
2018-11-30 20:27         ` Nicolas Goaziou
2018-12-03 15:02           ` Ulrich G. Wortmann [this message]
2018-12-03 17:15             ` Nicolas Goaziou
2018-12-04 20:14               ` Ulrich G. Wortmann
2018-12-06 13:35                 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKoZnLrXoC8XBfUgX5iN062qi-jDaOaMhJ_wAa_qgUeH3Tg6nw@mail.gmail.com \
    --to=uli.wortmann@utoronto.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).