1

I read a blog, which mentioned using orgtbl-mode to write a matrix quickly in org table format and then translated it into the LaTeX format. The post mentioned that due to the close relation between LaTeX and orgmode, many features there likely work for orgmode.

However, I couldn't get orgtbl-mode or the table conversion to work within LaTeX fragments/enviroments in org-mode itself. For example, in a org file, I added the following LaTeX fragment with an org style table.

\begin{equation}
\begin{bmatrix}

| 1 | 2 |
|   | 1 |

\end{bmatrix}

\end{equation}

As said in the blog, I hit C-c C-c, trying to convert it to LaTeX format. But org-mode reports that

org-ctrl-c-ctrl-c: ‘C-c C-c’ can do nothing useful here

Well, maybe orgtbl-mode isn't useful indeed in an org-mode file. Then, I tried to edit this fragment in its own environment by hitting C-c C-'. And a separate buffer shows up with ...[LaTeX enviroment]. Then I tried a few things including hitting C-c C-' in the new buffer and executing M-x orgtbl-send-table, and enabling the lazytab mode in the blog, to no avail.

C-c C-c triggered some latex command. And M-x orgtbl-send-table on the table causes:

orgtbl-send-table: Don’t know how to transform this table

I've seen python keybindings work in org file when the separate python environment is launched with C-c C-'. I was wondering if the same can be done for orgtbl-mode in the LaTeX environment from C-c C-'.

Hence the question:

Is it possible to use orgtbl-mode to convert LaTeX tables inside an org file?

(This is with Emacs 29.1, Ubuntu 22.04 LTS)

1
  • Do you mean: "Is it possible to use orgtbl-mode to convert Org mode tables to LaTeX tables inside an Org file?" ?
    – NickD
    Commented Nov 23, 2023 at 19:04

1 Answer 1

2

I assume what you are trying to do is a radio table: define a table under an #+ORGTBL: keyword that can be translated into LaTeX and inserted where the placeholders BEGIN RECEIVE ORGTBL <table name> ... and END RECEIVE ORGTBL <table name> indicate.

For example, in a LaTeX mode buffer, you enable this capability (and also the capabilities of editing the source table as if you were in an Org mode buffer) by turning on orgtbl-mode. Then C-c C-c on the #+ORGTBL: SEND ... line translates the table and inserts it between the placeholders. The idea is that you keep the table "hidden" from whatever processor (latex, pdflatex, xelatex, lualatex) will munge the LaTeX file by e.g. putting it in a block comment.[1]

In an Org mode buffer, you cannot turn on orgtbl-mode: if you do M-x orgtbl-mode, it will actually do nothing except produce the message Orgtbl mode is not useful in Org mode, command ignored. It is true that orgtbl-mode is mostly useless in an Org mode file: Org mode already provides all of the capabilities of editing tables e.g. so it does not need orgtbl-mode to let you do that. What orgtbl-mode does in other buffers is to set up a keymap that will allow you access to all the functions that are needed to edit/navigate/realign/etc the table as IF you were in an Org mode buffer. But the orgtbl-mode keymap also has a binding for C-c C-c which does the special processing for sending a radio table to its destination as described above: plain vanilla Org mode does not.

But so what? Plain vanilla Org mode still knows about all the commands and functions that orgtbl-mode uses. So you can still call the appropriate orgtbl-mode command from an Org mode file, even though you cannot activate the minor mode. All you have to do is find out which command that is: if you open a LaTeX buffer, enable orgbl-mode and ask what C-c C-c is bound to (i.e. C-h c C-c C-c) you'll find out that it is bound to a command called orgtbl-ctrl-c-ctrl-c. So all you have to do in an Org mode buffer to send a radio table wherever you want is to invoke that command: M-x orgtbl-ctrl-c-ctrl-c - that's all. That's the only thing that orgtbl-mode provides to other major modes that Org mode does not have: a convenient key binding to orgtbl-ctrl-c-ctrl-c.

Here is a complete example Org mode file:

* Test with latex fragment getting radio table from this same file

Here's a latex fragment:


\begin{equation}

% BEGIN RECEIVE ORGTBL matrix
% END RECEIVE ORGTBL matrix

\end{equation}

that is going to receive the radio table below:


#+ORGTBL: SEND matrix orgtbl-to-latex :tstart "\\begin{matrix}" :tend "\\end{matrix}"
| a | b | c |
| d | e | f |

With point on the #+ORGTBL: SEND ... line, do M-x orgtbl-ctrl-ctrl-c and you will get this:


* Test with latex fragment getting radio table from this same file

Here's a latex fragment:


\begin{equation}

% BEGIN RECEIVE ORGTBL matrix
\begin{matrix}
a & b & c\\[0pt]
d & e & f\\[0pt]
\end{matrix}
% END RECEIVE ORGTBL matrix

\end{equation}

that is going to receive the radio table below:


#+ORGTBL: SEND matrix orgtbl-to-latex :tstart "\\begin{matrix}" :tend "\\end{matrix}"
| a | b | c |
| d | e | f |

Note that we "hide" the placeholders in the LaTeX fragment by commenting them out with %, the LaTeX commend marker.

You can of course either bind orgtbl-ctrl-c-ctrl-c to some key in the Org mode keymap, or modify the Org mode command that is invoked by C-c C-c (the command's name is org-ctrl-c-ctrl-c) to recognize that it is being called on an #+ORGTBL: SEND line and then does the appropriate action.


Footnotes:

[1] Although LaTeX doesn't provide block comments so another strategy is needed. Check the section of the manual I linked above (as well as the LaTeX example in the next section).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.