emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Reproducing a table
@ 2017-03-13 17:13 Jarmo Hurri
  2017-03-14  7:35 ` Christian Moe
  0 siblings, 1 reply; 4+ messages in thread
From: Jarmo Hurri @ 2017-03-13 17:13 UTC (permalink / raw)
  To: emacs-orgmode


Greetings (again).

What is the smartest way to reproduce a table without defining the table
as an Org source block (constraint explained below).

I can do the following, but it doesn't seem very sane (need to use elisp
or some other language just to funnel the table).

# -----------------------------------------------------------------
* define table
  #+name: my-table
  | row 1 |     1 |     2 |
  | row 2 |     3 |     4 |
  |-------+-------+-------|
  |       | col 1 | col 2 |
* reproduce entire table
  I need to be able to reproduce the entire table in my document
  #+BEGIN_SRC elisp :var data=my-table :hlines yes
  (print data)
  #+END_SRC

  #+RESULTS:
  | row 1 |     1 |     2 |
  | row 2 |     3 |     4 |
  |-------+-------+-------|
  |       | col 1 | col 2 |
* reproduce only data
  I also need to be able to pass only the data to functions
  #+BEGIN_SRC elisp :var data=my-table[0:1,1:2]
  (print data)
  #+END_SRC

  #+RESULTS:
  | 1 | 2 |
  | 3 | 4 |
# -----------------------------------------------------------------

The reason I can _not_ define the table as an Org source block is the
second example. I need to pass parts of the table as data to functions,
and constructs like my-table()[0:1,1:2] don't work. (At least I have not
been able to get them to work.)

Jarmo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reproducing a table
  2017-03-13 17:13 Reproducing a table Jarmo Hurri
@ 2017-03-14  7:35 ` Christian Moe
  2017-03-14 10:27   ` Jarmo Hurri
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Moe @ 2017-03-14  7:35 UTC (permalink / raw)
  To: Jarmo Hurri; +Cc: emacs-orgmode


You can simplify it even further to

#+begin_src elisp :var data=my-table :hlines yes
  data  
#+end_src

which is sane enough for me.

To get simpler than that, I think you need #+INCLUDE and a separate
file.

I can't tell from the example why you need to define it in one place and
reproduce it in another, though, instead of just giving it a name right
where you want it to appear. (One situation where it would be helpful,
obviously, is if you want the same table to appear in multiple documents
that you export from the same .org file.)

Yours,
Christian


Jarmo Hurri writes:

> Greetings (again).
>
> What is the smartest way to reproduce a table without defining the table
> as an Org source block (constraint explained below).
>
> I can do the following, but it doesn't seem very sane (need to use elisp
> or some other language just to funnel the table).
>
> # -----------------------------------------------------------------
> * define table
>   #+name: my-table
>   | row 1 |     1 |     2 |
>   | row 2 |     3 |     4 |
>   |-------+-------+-------|
>   |       | col 1 | col 2 |
> * reproduce entire table
>   I need to be able to reproduce the entire table in my document
>   #+BEGIN_SRC elisp :var data=my-table :hlines yes
>   (print data)
>   #+END_SRC
>
>   #+RESULTS:
>   | row 1 |     1 |     2 |
>   | row 2 |     3 |     4 |
>   |-------+-------+-------|
>   |       | col 1 | col 2 |
> * reproduce only data
>   I also need to be able to pass only the data to functions
>   #+BEGIN_SRC elisp :var data=my-table[0:1,1:2]
>   (print data)
>   #+END_SRC
>
>   #+RESULTS:
>   | 1 | 2 |
>   | 3 | 4 |
> # -----------------------------------------------------------------
>
> The reason I can _not_ define the table as an Org source block is the
> second example. I need to pass parts of the table as data to functions,
> and constructs like my-table()[0:1,1:2] don't work. (At least I have not
> been able to get them to work.)
>
> Jarmo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reproducing a table
  2017-03-14  7:35 ` Christian Moe
@ 2017-03-14 10:27   ` Jarmo Hurri
  2017-03-14 15:38     ` Christian Moe
  0 siblings, 1 reply; 4+ messages in thread
From: Jarmo Hurri @ 2017-03-14 10:27 UTC (permalink / raw)
  To: emacs-orgmode

Christian Moe <mail@christianmoe.com> writes:

Greetings.

> You can simplify it even further to
>
> #+begin_src elisp :var data=my-table :hlines yes
>   data  
> #+end_src
>
> which is sane enough for me.
>
> To get simpler than that, I think you need #+INCLUDE and a separate
> file.

I think that would be the best approach.

> I can't tell from the example why you need to define it in one place
> and reproduce it in another, though, instead of just giving it a name
> right where you want it to appear.

The table contains a bivariate probability distribution, which I need to
reproduce at multiple locations in a document, and from which I need to
calculate a few things (which is why I need to pass the data part to
functions).

This is part of a process of fixing an old Org file which no longer
exports into LaTeX PDF. In some earlier version of Org the following
used to work:

  #+name: my-table
  | row 1 |     1 |     2 |
  | row 2 |     3 |     4 |
  |-------+-------+-------|
  |       | col 1 | col 2 |

  #+call: my-table() :hlines yes

That is, in the past the table name used to sort of define a function
which could then be called to reproduce the table. But this produced
errors in the current version, so I started to figure out ways to
achieve the same end result.

Thanks!

Jarmo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Reproducing a table
  2017-03-14 10:27   ` Jarmo Hurri
@ 2017-03-14 15:38     ` Christian Moe
  0 siblings, 0 replies; 4+ messages in thread
From: Christian Moe @ 2017-03-14 15:38 UTC (permalink / raw)
  To: Jarmo Hurri; +Cc: emacs-orgmode


Jarmo Hurri writes:

> In some earlier version of Org the following
> used to work:
>
>   #+name: my-table
>   | row 1 |     1 |     2 |
>   | row 2 |     3 |     4 |
>   |-------+-------+-------|
>   |       | col 1 | col 2 |
>
>   #+call: my-table() :hlines yes
>
> That is, in the past the table name used to sort of define a function
> which could then be called to reproduce the table. But this produced
> errors in the current version, so I started to figure out ways to
> achieve the same end result.

I see! I had no idea that this was possible, but it does indeed work for
me (I'm still on version 8.3.4).

Yours,
Christian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-14 15:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-13 17:13 Reproducing a table Jarmo Hurri
2017-03-14  7:35 ` Christian Moe
2017-03-14 10:27   ` Jarmo Hurri
2017-03-14 15:38     ` Christian Moe

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).