From: Vikas Rawal <vikaslists@agrarianresearch.org>
To: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: multicolumn cells in latex export
Date: Sat, 5 Nov 2016 13:27:21 +0530 [thread overview]
Message-ID: <1F648E1B-FFC1-4F1A-A29C-69030E4A5084@agrarianresearch.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 3354 bytes --]
Two years ago, Eric Schulte had shared some most useful code snippets (https://lists.gnu.org/archive/html/emacs-orgmode/2014-08/msg00113.html <https://lists.gnu.org/archive/html/emacs-orgmode/2014-08/msg00113.html>). This included an export filter (code pasted below) that provided a very useful way of introducing multicolumn cells in latex export.
I have been using this since then without any trouble. But today I tried using it to centre-align column headings in the top row by using <1colc>. While it works for other columns, it does not work on the last column.
The last column gets exported as
\multicolumn{1}{c}{Australia (2015)\\
}\hline
rather than as
\multicolumn{1}{c}{Australia (2015)}\\
\hline
Can anyone help debug what is wrong with this code?
Vikas
---------------
;;; Multi-column Table Cells
;;
;; Export table cells with multiple columns using Latex-like syntax.
;; For example in the following the "<3colc>Backends" cell spans 3
;; columns with it's text centered.
;;
;; | | <3colc>Backends | | |
;; | | LaTeX | HTML | Text |
;; |-----------+-----------------+-------+-------|
;; | extension | .tex | .html | .txt |
;;
;; The `org-export-multicolumn-filter-latex' function is taken from
;; the following.
;; http://thread.gmane.org/gmane.emacs.orgmode/66332/match=latex+table+multicolumn+cell
(defun org-export-multicolumn-filter (row backend info)
(cond
((org-export-derived-backend-p backend 'latex)
(org-export-multicolumn-filter-latex row backend info))
((org-export-derived-backend-p backend 'html)
(org-export-multicolumn-filter-html row backend info))))
(defun org-export-multicolumn-filter-latex (row backend info)
(while (string-match
"\\(<\\([0-9]+\\)col\\([lrc]\\)?>[[:blank:]]*\\([^&]+\\)\\)" row)
(let ((columns (string-to-number (match-string 2 row)))
(start (match-end 0))
(contents (replace-regexp-in-string
"\\\\" "\\\\\\\\"
(replace-regexp-in-string "[[:blank:]]*$" ""
(match-string 4 row))))
(algn (or (match-string 3 row) "l")))
(setq row (replace-match
(format "\\\\multicolumn{%d}{%s}{%s}" columns algn contents)
nil nil row 1))
(while (and (> columns 1) (string-match "&" row start))
(setq row (replace-match "" nil nil row))
(decf columns))))
row)
(defun org-export-multicolumn-filter-html (row backend info)
(while (string-match "class=\".*\" *><\\([0-9]+\\)col\\([lrc]\\)?>" row)
(let ((columns (string-to-number (match-string 1 row)))
(start (match-end 0))
(algn (case (intern (or (match-string 2 row) "l"))
(c "center")
(r "right")
(l "left"))))
(setq row (replace-match
(format " class=\"%s\" colspan=\"%s\">" algn columns)
nil nil row))
(while (and (> columns 1)
(string-match "<th .*> </th>" row start))
(setq row (replace-match "" nil nil row))
(decf columns))))
row)
(add-to-list 'org-export-filter-table-row-functions
'org-export-multicolumn-filter)
[-- Attachment #2: Type: text/html, Size: 6524 bytes --]
reply other threads:[~2016-11-05 7:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1F648E1B-FFC1-4F1A-A29C-69030E4A5084@agrarianresearch.org \
--to=vikaslists@agrarianresearch.org \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.