Hello,

Rasmus <ras...@gmx.us> writes:

> I'm doing some stuff where the natural output of my tables are
> matrices.  I found a decent translation  function here ¹.  However,
> I'm not very successful in making org use it. 

Using the new exporter, something like should replace any table using
default environment (i.e. no special attribute) and without horizontal
rules with bmatrix environment. It should also insert it in math mode
automatically.

Untested.

#+begin_src emacs-lisp
(defun my-latex-table-to-matrix (table backend info)
  (when (and (memq backend '(e-latex e-beamer))
             (not (string-match "^\\\\[A-Za-z]+$" table))
             (not (string-match "\\begin{\\(table*\\|sidewaystable\\)}" table)))
    (let ((default-env (format "\\\\\\(begin\\|end\\){\\(%s\\)}.*"
                               org-e-latex-default-table-environment)))
      (when (string-match default-env table)
        (concat "\\[\n"
                (org-trim
                 (replace-regexp-in-string
                  "\\\\\\(begin\\|end\\){\\(center\\)}" ""
                  (replace-regexp-in-string
                   default-env "\\\\\\1{bmatrix}" table)))
                "\n\\]")))))

(add-to-list 'org-export-filter-table-functions 'my-latex-table-to-matrix)
#+end_src


Regards,

-- 
Nicolas Goaziou

Reply via email to