emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Export tables as matrices (change tbl-export function on the fly


From: Nicolas Goaziou
Subject: Re: [O] Export tables as matrices (change tbl-export function on the fly)
Date: Sun, 18 Nov 2012 14:20:51 +0100

Rasmus <address@hidden> writes:

>> I meant: what is the exact problem with my code (with examples and
>> expected output if possible)? It shouldn't be hard to fix.
>
> They are not caught by the regexp.  And I wasn't able to find a regexp
> which could correctly identify all cases.  I have a sample in the
> footnote ¹ 

That's because you use "booktabs" by default. It creates horizontal
rules, and the filter hence doesn't apply.

> Sounds good to me.  However, should $'s be stripped?  Say I have an
> org-table which I'm indecisive about.  In one sell I might have a
> \frac{·}{·} in a cell; so in a normal table export I'd have to insert
> $'s, but in :math-mode I wouldn't.  It could thus be expensive to go
> from :math mode to nil math mode.  Hence, stripping $ might be
> appropriate

Since e-latex back-end doesn't strip anything in regular LaTeX snippets
or environments, it should be the same here. Switching to math mode
won't happen automatically, so the user can act appropriately.

>> Then, the :environment keyword can be set to "tabular", "longtable",
>> "tabularx", "tabulary", "bmatrix", "pmatrix", "vmatrix", "kbordermatrix"
>> or "qbordermatrix". "bordermatrix", "array"... It would default to
>> `org-e-latex-default-table-environment' (default to "tabular").
>
> and Bmatrix ({matrix}) and Vmatrix ( ||matrix||) and matrix (no
> decoration).

:environment value is a string. It can be set to anything.

> Array needs per column configuration. 

That's not a problem, Org handles alignment per column already:

    | <c> | <c> |
    | a   | b   |
    | c   | d   |

Also, every math environment but "array" ignores column separators.

>> What is the variable ALIGN? You mean :align keyword? Do matrix
>> environments accept alignment? Also I haven't heard about starred
>> version of these. What do they do?
>
> They allow you to align a matrix to [rlc] (and maybe others?)  They
> are defined in mathtools.
>
> Here's an example (unrelated to tables):
>
> #+BEGIN_SRC latex
> \documentclass{article}
> \usepackage{amsmath,mathtools}
> \begin{document}
> $\max_{x}f(x)\quad\text{s.t. 
> }\left\{\begin{matrix*}[r]g(x)\geq0\\h(x)+h(y)\geq
>     k\end{matrix*}\right.$
> \end{document}
> #+END_SRC

Then the backend can add the alignment as an optional argument in math
mode only when the name of the environment ends with a star and the
alignment string is one character long.

>> From the syntax perspective, I see no difference between bordered
>> matrices and the others: they just use a different environment, which
>> can be provided through :environment keyword. Am I missing something?
>
> No.  But they are typically macros.  Note the use of cr which
> sometimes needs to be used in the bordermatrix (from TeX).  It's not
> the case in kbordermatrix (which I use) and presumably qbordermatrix.
>
> #+BEGIN_SRC latex
> \documentclass{article}
> \begin{document}
> $\bordermatrix{&a&b&c\cr a&1&0&0\cr b&0&1&0\cr c&0&0&1}$
> \end{document}
> #+END_SRC

To circumvent the problem, org-e-latex.el can use a defconst to store
table/matrix environments requiring "\cr" instead of "\\" at the end of
each row. It will, as a starter, only contain "bordermatrix".

Any name to suggest for it?

>>>      - Potentially: an :inline exists s.t. if inline is t the
>>>        matrix is typeset inline [i.e. with \(\)].  Perhaps, it
>>>        should be smart and use the small verison of
>>>        org-export-latex-tables-matrix-default-type.  I.e. if
>>>        bmatrix use bsmallmatrix.  This could be set via
>>>        org-export-latex-tables-matrix-inline-small.
>>
>> Do all matrix environments accept a small counterpart?
>
>  amsmath provides: 
>     smallmatrix from which all variants be generated using
>     appropriated \left "bracket" \right "bracket"
>  mathtools provides:
>      smallmatrix*
>      psmallmatrix 
>      psmallmatrix*
>      bsmallmatrix 
>      bsmallmatrix*
>      Bsmallmatrix 
>      Bsmallmatrix*
>      vsmallmatrix 
>      vsmallmatrix*
>      Vsmallmatrix 
>      Vsmallmatrix*
>      smallmatrix*
>
> so I think it covers all variants except "small bordermatrix" and
> "small arrary".

Ok. Then the sanest approach is to allow :math-mode to be set to nil,
t or `inline'. When `inline', as you suggest, it replaces \[...\] with
\(...\) and ignores any label. But it still uses whatever environment is
provided in :environment, that is, it won't make any guess about which
one to use.

Also, instead of using a single `org-e-latex-default-table-environment',
its value can be a plist like the following:

   (:table-mode "tabular" :math-mode "bmatrix" :inline-math-mode "smallmatrix")

What do you think about it?


Regards,

-- 
Nicolas Goaziou



reply via email to

[Prev in Thread] Current Thread [Next in Thread]