From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: Question about the math mode table exporting for latex and html Date: Sat, 18 Jan 2014 21:40:25 +0100 Message-ID: <87ioth6n2e.fsf@gmx.us> References: <87ha9gi0o1.fsf@pku.edu.cn> <8761pw6o3e.fsf@gmx.us> <8738kzd9w5.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4cd9-0003rc-Dl for emacs-orgmode@gnu.org; Sat, 18 Jan 2014 15:36:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4cd2-0001J3-Ng for emacs-orgmode@gnu.org; Sat, 18 Jan 2014 15:36:35 -0500 Received: from mout.gmx.net ([212.227.15.19]:61566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4cd2-0001Ix-Cq for emacs-orgmode@gnu.org; Sat, 18 Jan 2014 15:36:28 -0500 Received: from W530 ([109.201.154.184]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0M5MIN-1V7rmA3AFj-00zV6p for ; Sat, 18 Jan 2014 21:36:27 +0100 In-Reply-To: <8738kzd9w5.fsf@gmail.com> (Nicolas Goaziou's message of "Tue, 07 Jan 2014 17:39:06 +0100") 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, >> Perhaps something like the following would be OK? Nicholas? >> >> #+ATTR_HTML: :mode latex >> #+ATTR_LATEX: :mode math :environment pmatrix :math-prefix \mathbf{H}=3D >> | \vdots | 0 | \vdots | >> | \vdots | H | \vdots | >> | \vdots | 0 | \vdots | >> >> This would tell ox-html.el to transcode the table via ox-latex-tabel >> and feed the string via org-html-format-latex (assuming latex-frag is >> a string).=20=20 > > FWIW, I think it's worth trying. I'm Cc'ing Rick Frankel for his > opinion. > >> Of course ox-html could also check out ATTR_LATEX but this >> would lead to a spurious solution since LaTeX =E2=89=A0 HTML IMO. > > I agree. > >> Nicholas, if you want I can look into this. > > Certainly. Thank you. I have attached a rough proof-of-concept that will export the above table correctly with mathjax. But I guess it will also have to handle it correctly in the case of static png images. I'm not sure how to handle captions. I guess the most natural way is to let org-latex-table handle is. Let me know if something like this is OK in which case I can polish it up and add documentation. =E2=80=93Rasmus --=20 . . . It begins of course with The Internet. A Net of Peers. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-latex-html-output-tables-as-latex.patch >From 036c06fc9f577b3d17e9caf7db366267bb4d28de Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sat, 18 Jan 2014 20:48:28 +0100 Subject: [PATCH] latex-html output tables as latex --- lisp/ox-html.el | 105 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 8ea9e65..80ce53c 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -3286,54 +3286,65 @@ contextual information." (table.el (org-html-table--table.el-table table info)) ;; Case 2: Standard table. (t - (let* ((label (org-element-property :name table)) - (caption (org-export-get-caption table)) - (number (org-export-get-ordinal - table info nil 'org-html--has-caption-p)) - (attributes - (org-html--make-attribute-string - (org-combine-plists - (and label (list :id (org-export-solidify-link-text label))) - (and (not (org-html-html5-p info)) - (plist-get info :html-table-attributes)) - (org-export-read-attribute :attr_html table)))) - (alignspec - (if (and (boundp 'org-html-format-table-no-css) - org-html-format-table-no-css) - "align=\"%s\"" "class=\"%s\"")) - (table-column-specs - (function - (lambda (table info) - (mapconcat - (lambda (table-cell) - (let ((alignment (org-export-table-cell-alignment - table-cell info))) - (concat - ;; Begin a colgroup? - (when (org-export-table-cell-starts-colgroup-p - table-cell info) - "\n") - ;; Add a column. Also specify it's alignment. - (format "\n%s" - (org-html-close-tag - "col" (concat " " (format alignspec alignment)) info)) - ;; End a colgroup? - (when (org-export-table-cell-ends-colgroup-p - table-cell info) - "\n")))) - (org-html-table-first-row-data-cells table info) "\n"))))) - (format "\n%s\n%s\n%s" - (if (equal attributes "") "" (concat " " attributes)) - (if (not caption) "" - (format (if org-html-table-caption-above - "%s" - "%s") + (let ((mode (member :mode (org-export-read-attribute :attr_html table)))) + (cond + ((member-ignore-case "latex" mode) + (org-html-table--as-latex table contents info)) + (t + (let* ((label (org-element-property :name table)) + (caption (org-export-get-caption table)) + (number (org-export-get-ordinal + table info nil 'org-html--has-caption-p)) + (attributes + (org-html--make-attribute-string + (org-combine-plists + (and label (list :id (org-export-solidify-link-text label))) + (and (not (org-html-html5-p info)) + (plist-get info :html-table-attributes)) + (org-export-read-attribute :attr_html table)))) + (alignspec + (if (and (boundp 'org-html-format-table-no-css) + org-html-format-table-no-css) + "align=\"%s\"" "class=\"%s\"")) + (table-column-specs + (function + (lambda (table info) + (mapconcat + (lambda (table-cell) + (let ((alignment (org-export-table-cell-alignment + table-cell info))) (concat - "" - (format (org-html--translate "Table %d:" info) number) - " " (org-export-data caption info)))) - (funcall table-column-specs table info) - contents))))) + ;; Begin a colgroup? + (when (org-export-table-cell-starts-colgroup-p + table-cell info) + "\n") + ;; Add a column. Also specify it's alignment. + (format "\n%s" + (org-html-close-tag + "col" (concat " " (format alignspec alignment)) info)) + ;; End a colgroup? + (when (org-export-table-cell-ends-colgroup-p + table-cell info) + "\n")))) + (org-html-table-first-row-data-cells table info) "\n"))))) + (t (format "\n%s\n%s\n%s" + (if (equal attributes "") "" (concat " " attributes)) + (if (not caption) "" + (format (if org-html-table-caption-above + "%s" + "%s") + (concat + "" + (format (org-html--translate "Table %d:" info) number) + " " (org-export-data caption info)))) + (funcall table-column-specs table info) + contents))))))))) + +(defun org-html-table--as-latex (table contents info) + "Transcode TABLE into LaTeX code. +Suitable for transcoding Org tables into math matrices. " + (require 'ox-latex) + (org-latex-table table contents info)) ;;;; Target -- 1.8.5.3 --=-=-=--