From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: James Powell <powellj@pdx.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Bug: redundant and undocumented #label is required to link to a table [9.4.4 (9.4.4-dist @ /home/powellj/elisp/org-9.4.4/lisp/)]
Date: Mon, 19 Apr 2021 21:31:23 +0200 [thread overview]
Message-ID: <878s5eax6c.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <b5a3b02b-03d6-2e04-fc6f-6b793504c197@pdx.edu> (James Powell's message of "Mon, 19 Apr 2021 11:48:12 -0700")
James Powell <powellj@pdx.edu> writes:
> If I put #+name before the table, the link does indeed work, but now
> the table is reproduced twice in the latex output and also C-c C-c in
> the code block writes a new table into the file instead of updating
> the current table.
>
> Before C-c C-c in the code block, this org snippet produces the table
> twice in the latex output:
> <<begin>>
>
> #+begin_src R :exports both
> library(tidyverse)
> x <- tribble(~a, ~b, 1, 3)
> x
> #+end_src
>
> #+NAME: t1
> #+CAPTION: Org Table
>
> #+RESULTS: t1
> | 1 | 3 |
>
>
> I want to refer to Table [[t1]].
> <<end>>
OK. My explanation was a bit short. Let me expound it a bit.
There are two important keywords in this situation: #+name and
#+results. The former is used to reference a specific element in
a document. The latter is used to know what source code block produced
an element. #+results keywords are automatically generated by Org
whereas #+name keywords are always written by the user.
When you see "#+results: t1" above a table in the previous example, you
and Org know a source block named (with #+name) "t1" generated this
table. Example:
#+name: some name
#+begin_src R :exports both
library(tidyverse)
x <- tribble(~a, ~b, 1, 3)
x
#+end_src
generates
#+results: some name
| 1 | 3 |
If you then write "tribble(~a, ~b, 1, 4)" in the source block,
evaluating it again will replace the table because Org knows what table
you are generating:
#+results: some name
| 1 | 4 |
Note that since the table itself doesn't have any "#+name", you cannot
reference it with an internal link yet.
Had you seen "#+results:" instead, you would have known that an unnamed
source block, located right above the table, had created the table.
Example:
#+begin_src R :exports both
library(tidyverse)
x <- tribble(~a, ~b, 1, 3)
x
#+end_src
#+results:
| 1 | 3 |
> After C-c C-c in the code block, the table appears twice in the org mode
> file:
Let's analyze your document, which I paste here for easier reading:
#+begin_src R :exports both
library(tidyverse)
x <- tribble(~a, ~b, 1, 3)
x
#+end_src
#+NAME: t1
#+CAPTION: Org Table
#+RESULTS: t1
| 1 | 3 |
Your source block is now unnamed. Upon evaluating it, Org looks for some
generated structure right below it. Unfortunately, the table below
claims (per #+results keyword) to come from a source block named "t1".
Consequently, it cannot be the output of the code block Org is currently
evaluating, and Org deduces no previous output has been created so far
by the code block: it inserts a new table in the document.
Moreover, an element, here the table, cannot realistically have both
#+name and #+results set to the same value, as it raises a chicken and
egg problem. It is not really an error though.
So, the correct document would be the following:
#+name: t1
#+begin_src R :exports both
library(tidyverse)
x <- tribble(~a, ~b, 1, 3)
x
#+end_src
#+caption: Org Table
#+results: t1
| 1 | 3 |
With it, evaluating (with C-c C-c) the source code block will not create
a new table, because references are appropriately set.
If you later want to refer to the table, you can write, e.g.,
#+name: t1
#+begin_src R :exports both
library(tidyverse)
x <- tribble(~a, ~b, 1, 3)
x
#+end_src
#+name: t1_output
#+caption: Org Table
#+results: t1
| 1 | 3 |
so [[t1_output]] links jump to the table.
HTH,
--
Nicolas Goaziou
prev parent reply other threads:[~2021-04-19 20:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-19 17:18 Bug: redundant and undocumented #label is required to link to a table [9.4.4 (9.4.4-dist @ /home/powellj/elisp/org-9.4.4/lisp/)] James Powell
2021-04-19 17:45 ` Nicolas Goaziou
2021-04-19 18:48 ` James Powell
2021-04-19 19:31 ` Nicolas Goaziou [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878s5eax6c.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=powellj@pdx.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).