emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org table: emphasizing calculated cell
@ 2021-08-26  5:47 Jarmo Hurri
  2021-08-26  7:51 ` Norwid Behrnd
  0 siblings, 1 reply; 8+ messages in thread
From: Jarmo Hurri @ 2021-08-26  5:47 UTC (permalink / raw)
  To: emacs-orgmode


Greetings.

In the table below, the text in the first column of the last row is
emphasized. What is (an easy way) to emphasize the calculated value in
the second column of the last row?

| quantity | value |
|----------+-------|
| A        |     1 |
| B        |     3 |
|----------+-------|
| *C*      |  0.33 |
#+TBLFM: @4$2=@-2/@-1;%.2f

All the best,

Jarmo



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

* Re: Org table: emphasizing calculated cell
  2021-08-26  5:47 Org table: emphasizing calculated cell Jarmo Hurri
@ 2021-08-26  7:51 ` Norwid Behrnd
  2021-08-27  4:07   ` Jarmo Hurri
  0 siblings, 1 reply; 8+ messages in thread
From: Norwid Behrnd @ 2021-08-26  7:51 UTC (permalink / raw)
  To: Jarmo Hurri; +Cc: emacs-orgmode

Jarmo,

try extending the format of the table formula with asterisks, i.e.

```
| quantity |  value |
|----------+--------|
| A        |      1 |
| B        |      3 |
|----------+--------|
| *C*      | *0.33* |
#+TBLFM:  @4$2=@-2/@-1; *%.2f*
```

Subsequently, issue the call ```C-c *``` for an update while the
cursor is within the table.  This approach works well enough for me
(equally for emphasis with enclosing forward slashes, or underscores)
in Emacs' native display (backed by elpa-org 9.4.0) as well as for a
subsequent export into .html and display (e.g., in Firefox), or .tex.


Norwid


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

* Re: Org table: emphasizing calculated cell
  2021-08-26  7:51 ` Norwid Behrnd
@ 2021-08-27  4:07   ` Jarmo Hurri
  2021-08-27  8:12     ` Norwid Behrnd
  2021-08-27 20:08     ` Nick Dokos
  0 siblings, 2 replies; 8+ messages in thread
From: Jarmo Hurri @ 2021-08-27  4:07 UTC (permalink / raw)
  To: emacs-orgmode


Greetings Norwid.

Norwid Behrnd <nbehrnd@yahoo.com> writes:

> try extending the format of the table formula with asterisks, i.e.
>
> ```
> | quantity |  value |
> |----------+--------|
> | A        |      1 |
> | B        |      3 |
> |----------+--------|
> | *C*      | *0.33* |
>
> #+TBLFM:  @4$2=@-2/@-1; *%.2f*
> ```
>
> Subsequently, issue the call ```C-c *``` for an update while the
> cursor is within the table.  This approach works well enough for me
> (equally for emphasis with enclosing forward slashes, or underscores)
> in Emacs' native display (backed by elpa-org 9.4.0) as well as for a
> subsequent export into .html and display (e.g., in Firefox), or .tex.

Excellent, this is a working solution for the basic case. Much
appreciated!

This solution seems to change the contents of a cell, not only its
formatting. So the following, where I try to increase the value of "C"
by one, leads to an error:

```
| quantity | value  |
|----------+--------|
| A        | 1      |
| B        | 3      |
|----------+--------|
| *C*      | *0.33* |
| D        | #ERROR |
#+TBLFM: @4$2=@-2/@-1; *%.2f*::@5$2=@-1+1
```

I wonder if there is a way around this effect?

Jarmo



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

* Re: Org table: emphasizing calculated cell
  2021-08-27  4:07   ` Jarmo Hurri
@ 2021-08-27  8:12     ` Norwid Behrnd
  2021-08-28  4:42       ` Jarmo Hurri
  2021-08-27 20:08     ` Nick Dokos
  1 sibling, 1 reply; 8+ messages in thread
From: Norwid Behrnd @ 2021-08-27  8:12 UTC (permalink / raw)
  To: Jarmo Hurri; +Cc: emacs-orgmode

Dear Jarmo,

your observation is new to me because I only used the approach

```
#+TBLFM:  @4$2=@-2/@-1; *%.2f*
```

at the end of a table e.g., about the grand total of an addition
(there are other/better ways to achieve this).

The instruction however computes the ratio, and formats twice the
result; once for the number of decimals displayed (which is not the
adjustable precision of computation), followed by the addition
asterisks orgmode subsequently interprets to use bold glyphs.  So
eventually you concatenate characters, i.e. the content of the cell
no longer is of type integer, nor a real/floating number. Since an
addition in line of

```
A + 3.14 = ...
```

is not defined, Emacs reports an error.

My insight in Emacs calc still is too small to know how to to trim
character strings (i.e., remove of the asterisks) and convert a
string of characters like ```3.14``` into a floating number.  So
there might be better solutions than the following.

Let's use your idea to use /multiple table formulae/.  Contrasting to
your attempt, I don't mind to go the extra mile and to run a cheap
computation twice for a result already in hand.  As a MWE 

```
| quantity  |  value |
| A         |      1 |
| B         |      3 |
| ratio A/B | *0.33* |
| ratio + 1 |   1.33 |
#+TBLFM: @4$2 = @2/@3; *%.2f* :: @5$2 = @2/@3 + 1; %.2f
```

where the table is populated/updated by ```C-u C-c *```.

-8><---
Side note:  It is possible to experiment with multiple table formulae
on multiple lines, e.g. to use here

```
#+TBLFM: @4$2 = @2/@3; *%.2f*
#+TBLFM: @5$2 = @2/@3 + 1; %.2f
```

instead.  This may be fine at the level to join the nuts and bolts,
to populate (and update) the table TBLFM by TBLFM with an individual
```C-c C-c``` while the cursor is in the corresponding definition.
The example below however suggests ```C-u C-c *``` considers only the
first TBLFM and skips the other:

```
cave!  incomplete update by C-u C-c *

| quantity  |  value |
| A         |     20 |
| B         |      3 |
| ratio A/B | *6.67* |
| ratio + 1 |   1.33 |
#+TBLFM: @4$2 = @2/@3; *%.2f*
#+TBLFM: @5$2 = @2/@3 + 1; %.2f
```

Norwid


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

* Re: Org table: emphasizing calculated cell
  2021-08-27  4:07   ` Jarmo Hurri
  2021-08-27  8:12     ` Norwid Behrnd
@ 2021-08-27 20:08     ` Nick Dokos
  2021-08-27 22:05       ` Samuel Wales
  2021-08-28  4:33       ` Jarmo Hurri
  1 sibling, 2 replies; 8+ messages in thread
From: Nick Dokos @ 2021-08-27 20:08 UTC (permalink / raw)
  To: emacs-orgmode

Jarmo Hurri <jarmo.hurri@iki.fi> writes:

> Greetings Norwid.
>
> Norwid Behrnd <nbehrnd@yahoo.com> writes:
>
>> try extending the format of the table formula with asterisks, i.e.
>>
>> ```
>> | quantity |  value |
>> |----------+--------|
>> | A        |      1 |
>> | B        |      3 |
>> |----------+--------|
>> | *C*      | *0.33* |
>>
>> #+TBLFM:  @4$2=@-2/@-1; *%.2f*
>> ```
>>
>> Subsequently, issue the call ```C-c *``` for an update while the
>> cursor is within the table.  This approach works well enough for me
>> (equally for emphasis with enclosing forward slashes, or underscores)
>> in Emacs' native display (backed by elpa-org 9.4.0) as well as for a
>> subsequent export into .html and display (e.g., in Firefox), or .tex.
>
> Excellent, this is a working solution for the basic case. Much
> appreciated!
>
> This solution seems to change the contents of a cell, not only its
> formatting. So the following, where I try to increase the value of "C"
> by one, leads to an error:
>
> ```
> | quantity | value  |
> |----------+--------|
> | A        | 1      |
> | B        | 3      |
> |----------+--------|
> | *C*      | *0.33* |
> | D        | #ERROR |
>
> #+TBLFM: @4$2=@-2/@-1; *%.2f*::@5$2=@-1+1
> ```
>
> I wonder if there is a way around this effect?
>

The error here is that `*0.33*' is no longer a string that can be converted to a number,
so the calculator barfs.

TUrn on formula debugging with `C-c {' and try evaluating it.

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler



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

* Re: Org table: emphasizing calculated cell
  2021-08-27 20:08     ` Nick Dokos
@ 2021-08-27 22:05       ` Samuel Wales
  2021-08-28  4:33       ` Jarmo Hurri
  1 sibling, 0 replies; 8+ messages in thread
From: Samuel Wales @ 2021-08-27 22:05 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

out of curiosity, do common spreadsheets implement the feature of
distinguishing calculated results from entered values?  i find myself
wanting that too, but don't know if that desire is unusual.


On 8/27/21, Nick Dokos <ndokos@gmail.com> wrote:
> Jarmo Hurri <jarmo.hurri@iki.fi> writes:
>
>> Greetings Norwid.
>>
>> Norwid Behrnd <nbehrnd@yahoo.com> writes:
>>
>>> try extending the format of the table formula with asterisks, i.e.
>>>
>>> ```
>>> | quantity |  value |
>>> |----------+--------|
>>> | A        |      1 |
>>> | B        |      3 |
>>> |----------+--------|
>>> | *C*      | *0.33* |
>>>
>>> #+TBLFM:  @4$2=@-2/@-1; *%.2f*
>>> ```
>>>
>>> Subsequently, issue the call ```C-c *``` for an update while the
>>> cursor is within the table.  This approach works well enough for me
>>> (equally for emphasis with enclosing forward slashes, or underscores)
>>> in Emacs' native display (backed by elpa-org 9.4.0) as well as for a
>>> subsequent export into .html and display (e.g., in Firefox), or .tex.
>>
>> Excellent, this is a working solution for the basic case. Much
>> appreciated!
>>
>> This solution seems to change the contents of a cell, not only its
>> formatting. So the following, where I try to increase the value of "C"
>> by one, leads to an error:
>>
>> ```
>> | quantity | value  |
>> |----------+--------|
>> | A        | 1      |
>> | B        | 3      |
>> |----------+--------|
>> | *C*      | *0.33* |
>> | D        | #ERROR |
>>
>> #+TBLFM: @4$2=@-2/@-1; *%.2f*::@5$2=@-1+1
>> ```
>>
>> I wonder if there is a way around this effect?
>>
>
> The error here is that `*0.33*' is no longer a string that can be converted
> to a number,
> so the calculator barfs.
>
> TUrn on formula debugging with `C-c {' and try evaluating it.
>
> --
> Nick
>
> "There are only two hard problems in computer science: cache
> invalidation, naming things, and off-by-one errors." -Martin Fowler
>
>
>


-- 
The Kafka Pandemic

Please learn what misopathy is.
https://thekafkapandemic.blogspot.com/2013/10/why-some-diseases-are-wronged.html


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

* Re: Org table: emphasizing calculated cell
  2021-08-27 20:08     ` Nick Dokos
  2021-08-27 22:05       ` Samuel Wales
@ 2021-08-28  4:33       ` Jarmo Hurri
  1 sibling, 0 replies; 8+ messages in thread
From: Jarmo Hurri @ 2021-08-28  4:33 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <ndokos@gmail.com> writes:

> Jarmo Hurri <jarmo.hurri@iki.fi> writes:
>> This solution seems to change the contents of a cell, not only its
>> formatting. So the following, where I try to increase the value of "C"
>> by one, leads to an error:
>>
>> ```
>> | quantity | value  |
>> |----------+--------|
>> | A        | 1      |
>> | B        | 3      |
>> |----------+--------|
>> | *C*      | *0.33* |
>> | D        | #ERROR |
>>
>> #+TBLFM: @4$2=@-2/@-1; *%.2f*::@5$2=@-1+1
>> ```
>>
>> I wonder if there is a way around this effect?
>
> The error here is that `*0.33*' is no longer a string that can be
> converted to a number, so the calculator barfs.

Yes, that is obvious. The underlying question is whether it is possible
to cleanly separate presentation from contents. Here they are mixed.

All the best,

Jarmo



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

* Re: Org table: emphasizing calculated cell
  2021-08-27  8:12     ` Norwid Behrnd
@ 2021-08-28  4:42       ` Jarmo Hurri
  0 siblings, 0 replies; 8+ messages in thread
From: Jarmo Hurri @ 2021-08-28  4:42 UTC (permalink / raw)
  To: emacs-orgmode


Greetings Norwid.

Norwid Behrnd <nbehrnd@yahoo.com> writes:

> Let's use your idea to use /multiple table formulae/.  Contrasting to
> your attempt, I don't mind to go the extra mile and to run a cheap
> computation twice for a result already in hand.  As a MWE 
>
> ```
> | quantity  |  value |
> | A         |      1 |
> | B         |      3 |
> | ratio A/B | *0.33* |
> | ratio + 1 |   1.33 |
>
> #+TBLFM: @4$2 = @2/@3; *%.2f* :: @5$2 = @2/@3 + 1; %.2f
> ```

Thanks, that is indeed a working approach. As you suspected, I would go
an extra mile or ten to avoid repeating formulae. ;)

Have fun and stay safe,

Jarmo



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

end of thread, other threads:[~2021-08-28  4:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26  5:47 Org table: emphasizing calculated cell Jarmo Hurri
2021-08-26  7:51 ` Norwid Behrnd
2021-08-27  4:07   ` Jarmo Hurri
2021-08-27  8:12     ` Norwid Behrnd
2021-08-28  4:42       ` Jarmo Hurri
2021-08-27 20:08     ` Nick Dokos
2021-08-27 22:05       ` Samuel Wales
2021-08-28  4:33       ` Jarmo Hurri

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).