* Allow Currency Symbols and Grouping Commas in Table Numbers @ 2022-05-26 19:40 Daniel E. Doherty 2022-05-27 8:22 ` Ihor Radchenko 0 siblings, 1 reply; 10+ messages in thread From: Daniel E. Doherty @ 2022-05-26 19:40 UTC (permalink / raw) To: emacs-orgmode I often use org table to perform calculations and export those tables to LaTeX documents. One thing I always wished I could do with org tables is get it to allow numbers to be decorated with currency symbols, the dollar, euro, yen, etc., as well as grouping commas so that the tables are more suitable for presentation. I can see from the code that there is a function, org-table--number-for-summing, that converts text into numbers for summing, and it would seem it could strip out leading or trailing currency symbols as well as grouping commas before submitting numbers to calc for calculation. Consider this a feature request. I think it would be a very popular enhancement to org. Regards, -- ==================================================== Daniel E. Doherty Law Offices of Daniel E. Doherty 7300 W. 110th Street, Suite 930 Overland Park, KS 66210 913.338.7182 (Phone) 913.338.7164 (FAX) ded@ddoherty.net ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-26 19:40 Allow Currency Symbols and Grouping Commas in Table Numbers Daniel E. Doherty @ 2022-05-27 8:22 ` Ihor Radchenko 2022-05-27 11:00 ` Eric S Fraga 2022-05-27 13:49 ` Daniel E. Doherty 0 siblings, 2 replies; 10+ messages in thread From: Ihor Radchenko @ 2022-05-27 8:22 UTC (permalink / raw) To: Daniel E. Doherty; +Cc: emacs-orgmode "Daniel E. Doherty" <ded@ddoherty.net> writes: > I often use org table to perform calculations and export those tables > to LaTeX documents. > > One thing I always wished I could do with org tables is get it to > allow numbers to be decorated with currency symbols, the dollar, euro, > yen, etc., as well as grouping commas so that the tables are more > suitable for presentation. You can, for example, do | 1 USD | 2 USD | 4 USD | 7 USD | #+tblfm: $4=vsum($1..$3) Emacs calc is able to work with arbitrary ascii symbols or even units. However, calc does not appear work with unicode. If Emacs calc were to support unicode, it would automatically work in Org. Also, you can enable latex in calc via (setq org-calc-default-modes '(calc-internal-prec 12 calc-float-format (float 8) calc-angle-mode deg calc-prefer-frac nil calc-symbolic-mode nil calc-language latex ;; <--- this is new compared to default calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm)) calc-display-working-message t)) Then, the following will work | \dollar1 | \dollar2 | \dollar3 | 6 \dollar | #+tblfm: $4=vsum($1..$3) Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 8:22 ` Ihor Radchenko @ 2022-05-27 11:00 ` Eric S Fraga 2022-05-27 11:17 ` Ihor Radchenko 2022-05-27 13:49 ` Daniel E. Doherty 1 sibling, 1 reply; 10+ messages in thread From: Eric S Fraga @ 2022-05-27 11:00 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Daniel E. Doherty, emacs-orgmode On Friday, 27 May 2022 at 16:22, Ihor Radchenko wrote: > However, calc does not appear work with unicode. Are you sure? This works just fine for me with embedded Calc: --8<---------------cut here---------------start------------->8--- n := 100 a := 0 b := 1.0 δx := (b - a) / n => 0.01 i := 15 xi := a + δx i => 0.15 --8<---------------cut here---------------end--------------->8--- Note use of δ. I use Greek characters all the time in my Calc formulas. If it works in embedded Calc, it should work with the rest of Calc? -- : Eric S Fraga, with org release_9.5.3-511-g8e69ad in Emacs 29.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 11:00 ` Eric S Fraga @ 2022-05-27 11:17 ` Ihor Radchenko 2022-05-27 12:02 ` Eric S Fraga 0 siblings, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2022-05-27 11:17 UTC (permalink / raw) To: Eric S Fraga; +Cc: Daniel E. Doherty, emacs-orgmode Eric S Fraga <e.fraga@ucl.ac.uk> writes: > On Friday, 27 May 2022 at 16:22, Ihor Radchenko wrote: >> However, calc does not appear work with unicode. > > Are you sure? This works just fine for me with embedded Calc: > ... > δx := (b - a) / n => 0.01 > ... > Note use of δ. I use Greek characters all the time in my Calc formulas. > > If it works in embedded Calc, it should work with the rest of Calc? You are right. However, non-letter symbols do not work. Try, € or ☺. I tried the following: 1. M-x calc 2. ' C-x 8 <RET> small greek delta <RET> + 1 <RET> 3. Works 4. ' C-x 8 <RET> EURO SIGN <RET> + 1 <RET> 5. Error Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 11:17 ` Ihor Radchenko @ 2022-05-27 12:02 ` Eric S Fraga 0 siblings, 0 replies; 10+ messages in thread From: Eric S Fraga @ 2022-05-27 12:02 UTC (permalink / raw) To: Ihor Radchenko; +Cc: Daniel E. Doherty, emacs-orgmode On Friday, 27 May 2022 at 19:17, Ihor Radchenko wrote: > You are right. However, non-letter symbols do not work. Try, € or ☺️. Interesting. Seems rather strange but definitely the case. :-( I guess I've only ever used Greek symbols if not ASCII. -- : Eric S Fraga, with org release_9.5.3-511-g8e69ad in Emacs 29.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 8:22 ` Ihor Radchenko 2022-05-27 11:00 ` Eric S Fraga @ 2022-05-27 13:49 ` Daniel E. Doherty 2022-05-27 14:49 ` Ihor Radchenko 1 sibling, 1 reply; 10+ messages in thread From: Daniel E. Doherty @ 2022-05-27 13:49 UTC (permalink / raw) To: emacs-orgmode On Fri, May 27 2022, Ihor Radchenko wrote: Ihor, thanks for your thoughts, but this does not solve my problem. Here is an sample org table that exemplifies the problem: ================================================== #+begin_SRC emacs-lisp (setq org-calc-default-modes '(calc-internal-prec 12 calc-float-format (float 8) calc-angle-mode deg calc-prefer-frac nil calc-symbolic-mode nil calc-language latex ;; <--- this is new compared to default calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm)) calc-display-working-message t)) #+end_SRC #+RESULTS: | calc-internal-prec | 12 | calc-float-format | (float 8) | calc-angle-mode | deg | calc-prefer-frac | nil | calc-symbolic-mode | nil | calc-language | latex | calc-date-format | (YYYY - MM - DD Www ( hh : mm)) | calc-display-working-message | t | | Description | Amount | |--------------+-----------------| | Mortage | $125,000.26 | | Credit Cards | 6,325.00 | | Auto Loan | 14,853.00 | |--------------+-----------------| | Total | :=vsum(@I..@II) | #+TBLFM: @5$2=vsum(@I..@II) -> Error: Invalid field specifier "$125" | Description | Amount | |--------------+-----------| | Mortage | 125000.26 | | Credit Cards | 6325.00 | | Auto Loan | 14853.00 | |--------------+-----------| | Total | 146178.26 | #+TBLFM: @5$2=vsum(@I..@II) | Description | Amount | |--------------+------------| | Mortage | 125,000.26 | | Credit Cards | 6,325.00 | | Auto Loan | 14,853.00 | |--------------+------------| | Total | 1323.26 | #+TBLFM: @5$2=vsum(@I..@II) Note that the total is wrong. | Description | Amount | |--------------+----------------------------| | Mortage | \dollar 125000.26 | | Credit Cards | 6325.00 | | Auto Loan | 14853.00 | |--------------+----------------------------| | Total | 125000.26 \dollar + 21178. | #+TBLFM: @5$2=vsum(@I..@II) Total is still wrong. ============================================ > > You can, for example, do > > | 1 USD | 2 USD | 4 USD | 7 USD | > > #+tblfm: $4=vsum($1..$3) > > Emacs calc is able to work with arbitrary ascii symbols or even units. > However, calc does not appear work with unicode. If Emacs calc were to > support unicode, it would automatically work in Org. > > Also, you can > > enable latex in calc via > (setq org-calc-default-modes > '(calc-internal-prec 12 > calc-float-format (float 8) > calc-angle-mode deg > calc-prefer-frac nil > calc-symbolic-mode nil > calc-language latex ;; <--- this is new compared to default > calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm)) > calc-display-working-message t)) > But it requires the \dollar on every entry. The convention if financial table is to include the currency symbol only on the first item. > Then, the following will work > > | \dollar1 | \dollar2 | \dollar3 | 6 \dollar | > > #+tblfm: $4=vsum($1..$3) Whatever calc is able to handle, calc is not getting the entries interpreted as numbers, or at least not the numbers that a human would understand. My elisp skills are limited, but it seems that org mode could, as a matter of course, strip commas and currency symbols from the numbers before delivering them to calc, and, if the user wants add back the grouping commas and currency symbol with a format specifier in the result. Also, it would be better if the regular expression for recognizing numbers allowed grouping commas and currency symbols to be included by default so that financial-type numbers get right-aligned by default. > > Best, > Ihor -- ==================================================== Daniel E. Doherty Law Offices of Daniel E. Doherty 7300 W. 110th Street, Suite 930 Overland Park, KS 66210 913.338.7182 (Phone) 913.338.7164 (FAX) ded@ddoherty.net ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 13:49 ` Daniel E. Doherty @ 2022-05-27 14:49 ` Ihor Radchenko 2022-05-31 14:19 ` Daniel E. Doherty 0 siblings, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2022-05-27 14:49 UTC (permalink / raw) To: Daniel E. Doherty; +Cc: emacs-orgmode "Daniel E. Doherty" <ded@ddoherty.net> writes: > | Description | Amount | > |--------------+------------| > | Mortage | 125,000.26 | > | Credit Cards | 6,325.00 | > | Auto Loan | 14,853.00 | > |--------------+------------| > | Total | 1323.26 | > #+TBLFM: @5$2=vsum(@I..@II) > > Note that the total is wrong. Well. This is also a caveat from calc, unfortunately. 7.7.2 Grouping Digits Please note that grouped numbers will not generally be parsed correctly if re-read in textual form, say by the use of ‘C-x * y’ and ‘C-x * g’. (*Note Kill and Yank::, for details on these commands.) One exception is the ‘\,’ separator, which doesn’t interfere with parsing because it is ignored by TeX language mode. So, you can instead do | Description | Amount | |--------------+-------------| | Mortage | 125\,000.26 | | Credit Cards | 6\,325.00 | | Auto Loan | 14\,853.00 | |--------------+-------------| | Total | 146178.26 | #+TBLFM: @5$2=vsum(@I..@II) Or with #+begin_SRC emacs-lisp (setq org-calc-default-modes '( calc-internal-prec 12 calc-float-format (float 8) calc-angle-mode deg calc-prefer-frac nil calc-symbolic-mode nil calc-language latex ;; <--- this is new compared to default, enable latex symbols calc-group-digits t ;; <--- group digits in the results calc-group-char "\\," calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm)) calc-display-working-message t)) #+end_SRC | Description | Amount | |--------------+-------------| | Mortage | 125\,000.26 | | Credit Cards | 6\,325.00 | | Auto Loan | 14\,853.00 | |--------------+-------------| | Total | 146\,178.26 | #+TBLFM: @5$2=vsum(@I..@II) > | Description | Amount | > |--------------+----------------------------| > | Mortage | \dollar 125000.26 | > | Credit Cards | 6325.00 | > | Auto Loan | 14853.00 | > |--------------+----------------------------| > | Total | 125000.26 \dollar + 21178. | > #+TBLFM: @5$2=vsum(@I..@II) > > Total is still wrong. You need | Description | Amount | |--------------+----------------------------| | Mortage | \dollar 125000.26 | | Credit Cards | \dollar 6325.00 | | Auto Loan | \dollar 14853.00 | |--------------+----------------------------| | Total | 146178.26 \dollar | #+TBLFM: @5$2=vsum(@I..@II) Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-27 14:49 ` Ihor Radchenko @ 2022-05-31 14:19 ` Daniel E. Doherty 2022-06-02 4:57 ` Ihor Radchenko 0 siblings, 1 reply; 10+ messages in thread From: Daniel E. Doherty @ 2022-05-31 14:19 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode Ihor, Again, thanks for your thoughts. All, however, ruin the look of the tables. Could you, perhaps, point me to where in the vast org code, strings are converted to numbers in preparation for sending to calc? I could then play with overriding the function and come up with a work-around. Regards, On Fri, May 27 2022, Ihor Radchenko wrote: > "Daniel E. Doherty" <ded@ddoherty.net> writes: > >> | Description | Amount | >> |--------------+------------| >> | Mortage | 125,000.26 | >> | Credit Cards | 6,325.00 | >> | Auto Loan | 14,853.00 | >> |--------------+------------| >> | Total | 1323.26 | >> #+TBLFM: @5$2=vsum(@I..@II) >> >> Note that the total is wrong. > > Well. This is also a caveat from calc, unfortunately. > > 7.7.2 Grouping Digits > Please note that grouped numbers will not generally be parsed > correctly if re-read in textual form, say by the use of ‘C-x * y’ and > ‘C-x * g’. (*Note Kill and Yank::, for details on these commands.) One > exception is the ‘\,’ separator, which doesn’t interfere with parsing > because it is ignored by TeX language mode. > > So, you can instead do > > | Description | Amount | > |--------------+-------------| > | Mortage | 125\,000.26 | > | Credit Cards | 6\,325.00 | > | Auto Loan | 14\,853.00 | > |--------------+-------------| > | Total | 146178.26 | > > #+TBLFM: @5$2=vsum(@I..@II) > > Or with > > #+begin_SRC emacs-lisp > (setq org-calc-default-modes > '( calc-internal-prec 12 > calc-float-format (float 8) > calc-angle-mode deg > calc-prefer-frac nil > calc-symbolic-mode nil > calc-language latex ;; <--- this is new compared to default, enable latex symbols > calc-group-digits t ;; <--- group digits in the results > calc-group-char "\\," > calc-date-format (YYYY "-" MM "-" DD " " Www (" " hh ":" mm)) > calc-display-working-message t)) > #+end_SRC > > > | Description | Amount | > |--------------+-------------| > | Mortage | 125\,000.26 | > | Credit Cards | 6\,325.00 | > | Auto Loan | 14\,853.00 | > |--------------+-------------| > | Total | 146\,178.26 | > > #+TBLFM: @5$2=vsum(@I..@II) > >> | Description | Amount | >> |--------------+----------------------------| >> | Mortage | \dollar 125000.26 | >> | Credit Cards | 6325.00 | >> | Auto Loan | 14853.00 | >> |--------------+----------------------------| >> | Total | 125000.26 \dollar + 21178. | >> #+TBLFM: @5$2=vsum(@I..@II) >> >> Total is still wrong. > > You need > > | Description | Amount | > |--------------+----------------------------| > | Mortage | \dollar 125000.26 | > | Credit Cards | \dollar 6325.00 | > | Auto Loan | \dollar 14853.00 | > |--------------+----------------------------| > | Total | 146178.26 \dollar | > > #+TBLFM: @5$2=vsum(@I..@II) > > Best, > Ihor -- ==================================================== Daniel E. Doherty Law Offices of Daniel E. Doherty 7300 W. 110th Street, Suite 930 Overland Park, KS 66210 913.338.7182 (Phone) 913.338.7164 (FAX) ded@ddoherty.net ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-05-31 14:19 ` Daniel E. Doherty @ 2022-06-02 4:57 ` Ihor Radchenko 2022-06-03 20:37 ` Daniel E. Doherty 0 siblings, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2022-06-02 4:57 UTC (permalink / raw) To: Daniel E. Doherty; +Cc: emacs-orgmode "Daniel E. Doherty" <ded@ddoherty.net> writes: > Again, thanks for your thoughts. All, however, ruin the look of the > tables. Could you, perhaps, point me to where in the vast org code, > strings are converted to numbers in preparation for sending to calc? org-table-eval-formula could be a good starting point to look into. Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Allow Currency Symbols and Grouping Commas in Table Numbers 2022-06-02 4:57 ` Ihor Radchenko @ 2022-06-03 20:37 ` Daniel E. Doherty 0 siblings, 0 replies; 10+ messages in thread From: Daniel E. Doherty @ 2022-06-03 20:37 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode Thanks, I'll take a look at it. Cheers, On Thu, Jun 02 2022, Ihor Radchenko wrote: > "Daniel E. Doherty" <ded@ddoherty.net> writes: > >> Again, thanks for your thoughts. All, however, ruin the look of the >> tables. Could you, perhaps, point me to where in the vast org code, >> strings are converted to numbers in preparation for sending to calc? > > org-table-eval-formula could be a good starting point to look into. > > Best, > Ihor -- ==================================================== Daniel E. Doherty Law Offices of Daniel E. Doherty 7300 W. 110th Street, Suite 930 Overland Park, KS 66210 913.338.7182 (Phone) 913.338.7164 (FAX) ded@ddoherty.net ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-06-03 20:39 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-05-26 19:40 Allow Currency Symbols and Grouping Commas in Table Numbers Daniel E. Doherty 2022-05-27 8:22 ` Ihor Radchenko 2022-05-27 11:00 ` Eric S Fraga 2022-05-27 11:17 ` Ihor Radchenko 2022-05-27 12:02 ` Eric S Fraga 2022-05-27 13:49 ` Daniel E. Doherty 2022-05-27 14:49 ` Ihor Radchenko 2022-05-31 14:19 ` Daniel E. Doherty 2022-06-02 4:57 ` Ihor Radchenko 2022-06-03 20:37 ` Daniel E. Doherty
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).