* Help with fixing an org-mode multicolumn implementation - LaTeX special characters
@ 2016-02-21 10:28 mcg
2016-02-22 15:48 ` Aaron Ecay
0 siblings, 1 reply; 3+ messages in thread
From: mcg @ 2016-02-21 10:28 UTC (permalink / raw)
To: emacs-orgmode
I found a very nice implementation of LaTeX multicolumn functionality in
this thread:
https://lists.gnu.org/archive/html/emacs-orgmode/2013-02/msg00736.html
("using export filters to emulate multi-column table cells?")
#+begin_src emacs-lisp :exports none
(defun my-latex-multicolumn-filter (row backend info)
(when (org-export-derived-backend-p backend 'latex)
(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 "[[: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))
(add-to-list 'org-export-filter-table-row-functions
'my-latex-multicolumn-filter)
#+end_src
#+LATEX_HEADER: \usepackage{multirow}
You have to put the number of columns to span and a r / l / c option for
column alignment (<2colc>) and the column contents afterwards. Nice!
#+CAPTION: Example table
| Characters not working | <2colc> Characters working: ! " § . ,
* + ? % | |
|-------------------------------+-----------------------------------------------+------------------|
| ^ % _ { } $ | The header above is
merged | over two columns |
| /italics/ *bold* _underline_
| | |
| any, \LaTeX special character
| | |
| or expression requiring \
| | |
However, using any of the characters of the left column of my example
table in the merged <2colc> column, I get:
"setq: Invalid use of `\' in replacement text"
Questions:
- How to escape the special characters in the left column properly to be
able to use them? (tried everything I could think of)
or
- How to modify the code above so that it allows for such characters.
- If anyone likes the implementation and is more capable than I am, then
the same for multirow would be really nice...
Comment: whoever read some of my questions recently will notice that I
excessively use org-mode as a LaTeX frontend. I am aware that this is
not what it is supposed to be in the first place - but it works so
perfect 99 % of the time, so I cannot keep from asking...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with fixing an org-mode multicolumn implementation - LaTeX special characters
2016-02-21 10:28 Help with fixing an org-mode multicolumn implementation - LaTeX special characters mcg
@ 2016-02-22 15:48 ` Aaron Ecay
2016-02-25 11:33 ` mcg
0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2016-02-22 15:48 UTC (permalink / raw)
To: mcg, emacs-orgmode
Hi mcg,
2016ko otsailak 21an, mcg-ek idatzi zuen:
>
> I found a very nice implementation of LaTeX multicolumn functionality in
> this thread:
> https://lists.gnu.org/archive/html/emacs-orgmode/2013-02/msg00736.html
[...]
> However, using any of the characters of the left column of my example
> table in the merged <2colc> column, I get:
> "setq: Invalid use of `\' in replacement text"
I think the function should be written (untested):
(defun my-latex-multicolumn-filter (row backend info)
(when (org-export-derived-backend-p backend 'latex)
(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 "[[: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 t row 1))
(while (and (> columns 1) (string-match "&" row start))
(setq row (replace-match "" nil nil row))
(decf columns))))
row))
The change is setting the third argument (‘literal’) to ‘replace-match’
to t, and deleting an extra backslash in the "\\multicolumn..." string.
>
>
> Questions:
> - How to escape the special characters in the left column properly to be
> able to use them? (tried everything I could think of)
> or
> - How to modify the code above so that it allows for such characters.
>
> - If anyone likes the implementation and is more capable than I am, then
> the same for multirow would be really nice...
Unfortunately I think that’s more complicated, since it would necessitate
examining/modifying the whole table in one go, rather than operating one
row at a time.
--
Aaron Ecay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with fixing an org-mode multicolumn implementation - LaTeX special characters
2016-02-22 15:48 ` Aaron Ecay
@ 2016-02-25 11:33 ` mcg
0 siblings, 0 replies; 3+ messages in thread
From: mcg @ 2016-02-25 11:33 UTC (permalink / raw)
To: emacs-orgmode
Hello Aaron,
[I noticed I did not answer to the list; just writing again to add it to
the list]
this fix works perfect! Thank you very much.
Never mind about multirow...
Michael
On 22/02/16 16:48, Aaron Ecay wrote:
> Hi mcg,
>
> 2016ko otsailak 21an, mcg-ek idatzi zuen:
>> I found a very nice implementation of LaTeX multicolumn functionality in
>> this thread:
>> https://lists.gnu.org/archive/html/emacs-orgmode/2013-02/msg00736.html
> [...]
>
>> However, using any of the characters of the left column of my example
>> table in the merged <2colc> column, I get:
>> "setq: Invalid use of `\' in replacement text"
> I think the function should be written (untested):
>
> (defun my-latex-multicolumn-filter (row backend info)
> (when (org-export-derived-backend-p backend 'latex)
> (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 "[[: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 t row 1))
> (while (and (> columns 1) (string-match "&" row start))
> (setq row (replace-match "" nil nil row))
> (decf columns))))
> row))
>
> The change is setting the third argument (‘literal’) to ‘replace-match’
> to t, and deleting an extra backslash in the "\\multicolumn..." string.
>
>>
>> Questions:
>> - How to escape the special characters in the left column properly to be
>> able to use them? (tried everything I could think of)
>> or
>> - How to modify the code above so that it allows for such characters.
>>
>> - If anyone likes the implementation and is more capable than I am, then
>> the same for multirow would be really nice...
> Unfortunately I think that’s more complicated, since it would necessitate
> examining/modifying the whole table in one go, rather than operating one
> row at a time.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-25 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 10:28 Help with fixing an org-mode multicolumn implementation - LaTeX special characters mcg
2016-02-22 15:48 ` Aaron Ecay
2016-02-25 11:33 ` mcg
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.