emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Lawrence Mitchell <wence@gmx.li>
To: emacs-orgmode@gnu.org
Cc: Achim Gratz <Stromeko@nexgo.de>
Subject: Re: [Feature Request] Cross headings in tables
Date: Wed, 02 Feb 2011 12:30:12 +0000	[thread overview]
Message-ID: <m3fws6d3fv.fsf@e4300lm.epcc.ed.ac.uk> (raw)
In-Reply-To: 87d3nwzo22.fsf@Rainer.invalid

Achim Gratz wrote:

[...]

> The first header is still determined like it always was.  Headers inside
> table need to get a special "hline", the choice of "~" for this was
> dictated by most of the other characters already being used for various
> markup inside or outside tables.  When I say "halfway there", I mean
> that the export is working and the lines are recognized as hlines
> everywhere I could find (there may still be some regexpressions floating
> around that don't).  However, aligning tables will replace the wigglies
> with plain dashes since I have not yet found a way to inject the correct
> character for the currently hardcoded "-".  The HTML export for the
> above table looks like this:

[...]

> If somebody has an idea how to make the table alignment work, please
> lend me a hand.  Experimental patch is attached, comments are
> welcome.

How about the following two patches on top.  The first fixes
table alignment, the second fixes LaTeX export of these tables.


From c555b7e15b617538490210a041bd4af45e51d752 Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <wence@gmx.li>
Date: Wed, 2 Feb 2011 12:20:12 +0000
Subject: [PATCH 1/2] Correctly realign tables with internal headers
To: emacs-orgmode@gnu.org

* lisp/org-table.el (org-table-align): Deal with internal headers
(specified by ?~) when realigning.
---
 lisp/org-table.el |   38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 9437ae1..498a6fc 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -632,7 +632,7 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
 	 lines (new "") lengths l typenums ty fields maxfields i
 	 column
 	 (indent "") cnt frac
-	 rfmt hfmt
+	 rfmt hfmt tfmt
 	 (spaces '(1 . 1))
 	 (sp1 (car spaces))
 	 (sp2 (cdr spaces))
@@ -640,6 +640,8 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
 		 (make-string sp2 ?\ ) "%%%s%ds" (make-string sp1 ?\ ) "|"))
 	 (hfmt1 (concat
 		 (make-string sp2 ?-) "%s" (make-string sp1 ?-) "+"))
+	 (tfmt1 (concat
+		 (make-string sp2 ?~) "%s" (make-string sp1 ?~) "+"))
 	 emptystrings links dates emph raise narrow
 	 falign falign1 fmax f1 len c e space)
     (untabify beg end)
@@ -680,17 +682,19 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
     ;; Mark the hlines by setting the corresponding element to nil
     ;; At the same time, we remove trailing space.
     (setq lines (mapcar (lambda (l)
-			  (if (string-match "^ *|[-~]" l)
-			      nil
-			    (if (string-match "[ \t]+$" l)
-				(substring l 0 (match-beginning 0))
-			      l)))
+			  (cond ((string-match "^ *|[-]" l)
+				 'dash)
+				((string-match "^ *|[~]" l)
+				 'tilde)
+				((string-match "[ \t]+$" l)
+				 (substring l 0 (match-beginning 0)))
+				(t l)))
 			lines))
     ;; Get the data fields by splitting the lines.
     (setq fields (mapcar
 		  (lambda (l)
 		      (org-split-string l " *| *"))
-		  (delq nil (copy-sequence lines))))
+		  (delq 'dash (delq 'tilde (copy-sequence lines)))))
     ;; How many fields in the longest line?
     (condition-case nil
 	(setq maxfields (apply 'max (mapcar 'length fields)))
@@ -770,19 +774,25 @@ When nil, simply write \"#ERROR\" in corrupted fields.")
 				    (concat (car c) space))))))))
 
     ;; Compute the formats needed for output of the table
-    (setq rfmt (concat indent "|") hfmt (concat indent "|"))
+    (setq rfmt (concat indent "|") hfmt (concat indent "|")
+	  tfmt (concat indent "|"))
     (while (setq l (pop lengths))
       (setq ty (if (pop typenums) "" "-")) ; number types flushright
       (setq rfmt (concat rfmt (format rfmt1 ty l))
-	    hfmt (concat hfmt (format hfmt1 (make-string l ?-)))))
+	    hfmt (concat hfmt (format hfmt1 (make-string l ?-)))
+	    tfmt (concat tfmt (format tfmt1 (make-string l ?~)))))
     (setq rfmt (concat rfmt "\n")
-	  hfmt (concat (substring hfmt 0 -1) "|\n"))
-
+	  hfmt (concat (substring hfmt 0 -1) "|\n")
+	  tfmt (concat (substring tfmt 0 -1) "|\n"))
     (setq new (mapconcat
 	       (lambda (l)
-		 (if l (apply 'format rfmt
-			      (append (pop fields) emptystrings))
-		   hfmt))
+		 (cond ((eq l 'dash)
+			hfmt)
+		       ((eq l 'tilde)
+			tfmt)
+		       (t
+			(apply 'format rfmt
+			       (append (pop fields) emptystrings)))))
 	       lines ""))
     (if (equal (char-before) ?\n)
 	;; This hack is for org-indent, to force redisplay of the


From 306605c2f49710a80d47553cb9bdf318dadf4db7 Mon Sep 17 00:00:00 2001
From: Lawrence Mitchell <wence@gmx.li>
Date: Wed, 2 Feb 2011 12:21:13 +0000
Subject: [PATCH 2/2] Correctly export internal table headers during LaTeX export
To: emacs-orgmode@gnu.org

* lisp/org-latex.el (org-export-latex-tables): Allow for tildes in
table format (indicating internal headers).
(org-export-latex-content): Export tables before special characters to
deal with new tilde header style.
---
 lisp/org-latex.el |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 9290c35..61dced4 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -1389,6 +1389,9 @@ links, keywords, lists, tables, fixed-width"
    (unless (memq 'emphasis exclude-list)
      (when (plist-get org-export-latex-options-plist :emphasize)
        (org-export-latex-fontify)))
+   (unless (memq 'tables exclude-list)
+     (org-export-latex-tables
+      (plist-get org-export-latex-options-plist :tables)))
    (unless (memq 'sub-superscript exclude-list)
      (org-export-latex-special-chars
       (plist-get org-export-latex-options-plist :sub-superscript)))
@@ -1398,9 +1401,6 @@ links, keywords, lists, tables, fixed-width"
      (org-export-latex-keywords))
    (unless (memq 'lists exclude-list)
      (org-export-latex-lists))
-   (unless (memq 'tables exclude-list)
-     (org-export-latex-tables
-      (plist-get org-export-latex-options-plist :tables)))
    (unless (memq 'fixed-width exclude-list)
      (org-export-latex-fixed-width
       (plist-get org-export-latex-options-plist :fixed-width)))
@@ -1804,7 +1804,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
             ;; make a formatting string to reflect alignment
             (setq olines lines)
             (while (and (not line-fmt) (setq line (pop olines)))
-              (unless (string-match "^[ \t]*|-" line)
+              (unless (string-match "^[ \t]*|[-~]" line)
                 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
                 (setq fnum (make-vector (length fields) 0))
                 (setq line-fmt
@@ -1839,7 +1839,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
             (setq lines
                   (mapcar
                    (lambda(elem)
-                     (or (and (string-match "[ \t]*|-+" elem) 'hline)
+                     (or (and (string-match "[ \t]*|[-~]+" elem) 'hline)
                          (org-split-string (org-trim elem) "|")))
                    lines))
             (when insert
-- 
1.7.4.rc2.18.gb20e9

  reply	other threads:[~2011-02-02 14:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-04 17:46 Quoting formula "cookies" in table? Achim Gratz
2010-10-05  1:25 ` Carsten Dominik
2010-10-05 17:10   ` Achim Gratz
2010-10-05 17:24     ` Carsten Dominik
2010-10-06 17:37       ` Achim Gratz
2010-10-05 17:54 ` [Feature Request] Cross headings in tables Achim Gratz
2011-01-16 18:44   ` Achim Gratz
2011-02-02 12:30     ` Lawrence Mitchell [this message]
2011-02-02 20:49       ` Achim Gratz
2011-02-08 21:52         ` Achim Gratz
2011-03-20  9:16           ` Achim Gratz
2011-05-29 18:18           ` [Orgmode] " Carsten Dominik
2011-05-30 21:02             ` Achim Gratz
2011-05-31  7:21               ` Carsten Dominik
2011-05-31  8:07                 ` Lawrence Mitchell
2011-05-31 18:01                 ` Achim Gratz
2011-05-31 18:44                   ` Jambunathan K
2011-06-02 16:12                   ` Carsten Dominik
2011-06-07 19:42                 ` Achim Gratz
2013-02-16 19:21                   ` Achim Gratz
2013-02-17  8:35                     ` Nicolas Goaziou
2013-02-17 19:41                       ` Achim Gratz
2013-02-17 21:06                         ` Achim Gratz
2013-02-22 12:31                       ` Carsten Dominik
2013-02-22 20:33                         ` Achim Gratz
2013-02-22 20:59                           ` Carsten Dominik
2013-02-23  8:10                           ` Bastien
2013-02-23 12:26                       ` Achim Gratz

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=m3fws6d3fv.fsf@e4300lm.epcc.ed.ac.uk \
    --to=wence@gmx.li \
    --cc=Stromeko@nexgo.de \
    --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).