*using a simple numerical variable in an org text ocument@ 2013-07-25 21:36 Matt Price2013-07-25 21:55 ` Thorsten Jolitz ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Matt Price @ 2013-07-25 21:36 UTC (permalink / raw) To: Org Mode Hi, I'm making a very simple org-document -- a packing list for a trip. It has entries like - 4 mugs - for sleeping bags - 4 thermarest pads I'd like to replace the numbers there by a variable -- so if I make a list for 4 people, the number displayed will be '4'; but if the list is for 2 people, the number displayed will be 2. Better would be if I could also do simple arithmetic manipulations (x * 6 dinners for a week...). I there a really simple way to do this? if it's not really easy, it won't really seem worth it, but if it is really easy, I will use it a lot... Thanks guys! Matt ^ permalink raw reply [flat|nested] 7+ messages in thread

*Re: using a simple numerical variable in an org text ocument2013-07-25 21:36 using a simple numerical variable in an org text ocument Matt Price@ 2013-07-25 21:55 ` Thorsten Jolitz2013-07-25 23:39 ` Thorsten Jolitz 2013-07-26 7:43 ` Sebastien Vauban 2 siblings, 0 replies; 7+ messages in thread From: Thorsten Jolitz @ 2013-07-25 21:55 UTC (permalink / raw) To: emacs-orgmode Matt Price <moptop99@gmail.com> writes: > Hi, > > I'm making a very simple org-document -- a packing list for a trip. > It has entries like > > - 4 mugs > - for sleeping bags > - 4 thermarest pads > > > I'd like to replace the numbers there by a variable -- so if I make a > list for 4 people, the number displayed will be '4'; but if the list > is for 2 people, the number displayed will be 2. Better would be if I > could also do simple arithmetic manipulations (x * 6 dinners for a > week...). I there a really simple way to do this? if it's not really > easy, it won't really seem worth it, but if it is really easy, I will > use it a lot... Use a table with a named reference, e.g. stored as subtree property. See [[http://orgmode.org/org.html#The-spreadsheet][Spreadsheets]]. ,-------------------------------- | * My Trip | :PROPERTIES: | :people: 4 | :END: | | | item | factor | total | | |------------+--------+-------| | | toothbrush | 1 | 4 | | | socks | 4 | 16 | | #+TBLFM: $3=$2*$PROP_people `-------------------------------- -- cheers, Thorsten ^ permalink raw reply [flat|nested] 7+ messages in thread

*Re: using a simple numerical variable in an org text ocument2013-07-25 21:36 using a simple numerical variable in an org text ocument Matt Price 2013-07-25 21:55 ` Thorsten Jolitz@ 2013-07-25 23:39 ` Thorsten Jolitz2013-07-26 1:16 ` Jonathan Leech-Pepin 2013-07-26 7:43 ` Sebastien Vauban 2 siblings, 1 reply; 7+ messages in thread From: Thorsten Jolitz @ 2013-07-25 23:39 UTC (permalink / raw) To: emacs-orgmode Matt Price <moptop99@gmail.com> writes: > Hi, > > I'm making a very simple org-document -- a packing list for a trip. > It has entries like > > - 4 mugs > - for sleeping bags > - 4 thermarest pads > > > I'd like to replace the numbers there by a variable -- so if I make a > list for 4 people, the number displayed will be '4'; but if the list > is for 2 people, the number displayed will be 2. Better would be if I > could also do simple arithmetic manipulations (x * 6 dinners for a > week...). I there a really simple way to do this? if it's not really > easy, it won't really seem worth it, but if it is really easy, I will > use it a lot... Or, if you insist on checkboxes (private conversation), you might put this function in your .emacs and run it to replace all numbers (that are either factors or totals) with num * people (when people >= 0) or with num / people (when people > 0). #+begin_src emacs-lisp (defun tj/calc-total-items (people) "Replace factor cookies with factor * people totals." (interactive "NPeople: ") (save-excursion (save-restriction (save-match-data (goto-char (point-min)) (widen) (while (not (eobp)) (and (org-at-item-checkbox-p) (looking-at (concat "\\(^[[:space:]]*-[[:space:]]" "\\[[-X\s]\\][[:space:]]\\)" "\\([[:digit:]]+\\)\\([[:space:]]+\\)")) (let* ((num (string-to-number (match-string-no-properties 2))) (total (if (>= people 0) (* num people) (/ num (abs people))))) (replace-match (format "%s" total) nil nil nil 2))) (forward-line)))))) #+end_src #+results: : tj/calc-total-items Use either as ,---------------------------------- | M-x tj/calc-total-items RET 7 RET `---------------------------------- or ,---------------------------------- | C-7 M-x tj/calc-total-items RET `---------------------------------- in your org-buffer. When there are e.g. 7 people, this checkbox list - [ ] 1 toothbrushes - [ ] 4 socks turns into - [ ] 7 toothbrushes - [ ] 28 socks after applying the above command in this buffer, and the change is reversed when applying ,---------------------------------- | M-x tj/calc-total-items RET -7 RET `---------------------------------- or ,---------------------------------- | C--7 M-x tj/calc-total-items RET `---------------------------------- afterwards. Note that you must stick to the format ,-------------------------- | - [ ] <<digit>> text .... `-------------------------- for this to work. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 7+ messages in thread

*Re: using a simple numerical variable in an org text ocument2013-07-25 23:39 ` Thorsten Jolitz@ 2013-07-26 1:16 ` Jonathan Leech-Pepin0 siblings, 0 replies; 7+ messages in thread From: Jonathan Leech-Pepin @ 2013-07-26 1:16 UTC (permalink / raw) To: Thorsten Jolitz;+Cc:emacs-orgmode Hi, Thorsten Jolitz writes: > Matt Price <moptop99@gmail.com> writes: > >> Hi, >> >> I'm making a very simple org-document -- a packing list for a trip. >> It has entries like >> >> - 4 mugs >> - for sleeping bags >> - 4 thermarest pads >> >> >> I'd like to replace the numbers there by a variable -- so if I make a >> list for 4 people, the number displayed will be '4'; but if the list >> is for 2 people, the number displayed will be 2. Better would be if I >> could also do simple arithmetic manipulations (x * 6 dinners for a >> week...). I there a really simple way to do this? if it's not really >> easy, it won't really seem worth it, but if it is really easy, I will >> use it a lot... > > Or, if you insist on checkboxes (private conversation), you might put this > function in your .emacs and run it to replace all numbers (that are either > factors or totals) with num * people (when people >= 0) or with num / people > (when people > 0). > If you want to use checkboxes, couldn't you use a babel code block and then =call= it on each entry? #+begin_src org ,#+MACRO: count call_Sample(x=$1)[:results raw] ,* Test :PROPERTIES: :var: people=5 :END: - [ ] call_Sample(x=2)[:results raw] socks - [ ] call_Sample(x=1)[:results raw] toothbrushes - [ ] {{{count(3)}}} shoes ,#+name: Sample ,#+header: :var x=1 :results raw ,#+begin_src emacs-lisp (* x people) ,#+end_src ,#+RESULTS: Sample 5 #+end_src You can then wrap it in a macro to avoid having to write out quite as much per line (as the last entry demonstrates. Then just adjust the value of the =:var:= property to match how many people, and your export will provide the correct values > #+begin_src emacs-lisp > (defun tj/calc-total-items (people) > "Replace factor cookies with factor * people totals." > (interactive "NPeople: ") > (save-excursion > (save-restriction > (save-match-data > (goto-char (point-min)) > (widen) > (while (not (eobp)) > (and (org-at-item-checkbox-p) > (looking-at > (concat > "\\(^[[:space:]]*-[[:space:]]" > "\\[[-X\s]\\][[:space:]]\\)" > "\\([[:digit:]]+\\)\\([[:space:]]+\\)")) > (let* ((num > (string-to-number > (match-string-no-properties 2))) > (total > (if (>= people 0) > (* num people) > (/ num (abs people))))) > (replace-match > (format "%s" total) nil nil nil 2))) > (forward-line)))))) > #+end_src > > #+results: > : tj/calc-total-items > > > Use either as > > ,---------------------------------- > | M-x tj/calc-total-items RET 7 RET > `---------------------------------- > > or > > ,---------------------------------- > | C-7 M-x tj/calc-total-items RET > `---------------------------------- > > in your org-buffer. > > When there are e.g. 7 people, this checkbox list > > - [ ] 1 toothbrushes > - [ ] 4 socks > > turns into > > - [ ] 7 toothbrushes > - [ ] 28 socks > > after applying the above command in this buffer, and the change is > reversed when applying > > ,---------------------------------- > | M-x tj/calc-total-items RET -7 RET > `---------------------------------- > > or > > ,---------------------------------- > | C--7 M-x tj/calc-total-items RET > `---------------------------------- > > afterwards. Note that you must stick to the format > > ,-------------------------- > | - [ ] <<digit>> text .... > `-------------------------- > > for this to work. Regards, -- Jonathan ^ permalink raw reply [flat|nested] 7+ messages in thread

*2013-07-25 21:36 using a simple numerical variable in an org text ocument Matt Price 2013-07-25 21:55 ` Thorsten Jolitz 2013-07-25 23:39 ` Thorsten JolitzRe: using a simple numerical variable in an org text ocument@ 2013-07-26 7:43 ` Sebastien Vauban2013-07-27 18:19 ` Dieter Wilhelm 2 siblings, 1 reply; 7+ messages in thread From: Sebastien Vauban @ 2013-07-26 7:43 UTC (permalink / raw) To: emacs-orgmode-mXXj517/zsQ Matt Price wrote: > I'm making a very simple org-document -- a packing list for a trip. > It has entries like > > - 4 mugs > - for sleeping bags > - 4 thermarest pads > > > I'd like to replace the numbers there by a variable -- so if I make a > list for 4 people, the number displayed will be '4'; but if the list > is for 2 people, the number displayed will be 2. Better would be if I > could also do simple arithmetic manipulations (x * 6 dinners for a > week...). I there a really simple way to do this? if it's not really > easy, it won't really seem worth it, but if it is really easy, I will > use it a lot... As macros are expanded before Babel code is evaluated, I would try #+scr_calc{...} with MACRO constants in the formula (untested). Best regards, Seb -- Sebastien Vauban ^ permalink raw reply [flat|nested] 7+ messages in thread

*Re: using a simple numerical variable in an org text ocument2013-07-26 7:43 ` Sebastien Vauban@ 2013-07-27 18:19 ` Dieter Wilhelm2013-08-14 5:54 ` Sebastien Vauban 0 siblings, 1 reply; 7+ messages in thread From: Dieter Wilhelm @ 2013-07-27 18:19 UTC (permalink / raw) To: Sebastien Vauban;+Cc:emacs-orgmode "Sebastien Vauban" <sva-news@mygooglest.com> writes: > Matt Price wrote: >> I'm making a very simple org-document -- a packing list for a trip. >> It has entries like >> - 4 mugs >> - for sleeping bags >> - 4 thermarest pads >> I'd like to replace the numbers there by a variable -- so if I make a >> list for 4 people, the number displayed will be '4'; but if the list >> is for 2 people, the number displayed will be 2. Better would be if I >> could also do simple arithmetic manipulations (x * 6 dinners for a >> week...). I there a really simple way to do this? if it's not really >> easy, it won't really seem worth it, but if it is really easy, I will >> use it a lot... > As macros are expanded before Babel code is evaluated, I would > try #+scr_calc{...} with MACRO constants in the formula (untested). Hi Seb(astien), it seems that you're working with calc source blocks! :-) I'd like to leverage calc in org-mode (I'm thinking of unit conversions, etc.: Mathematica for free men) but I'm not getting it. I assume that in an #+src_calc block the mode of operation of calc is algebraic, isn't it? #+BEGIN_SRC calc 2 + 2 sqrt(8) # above is working, by the way, does a calc block have a comment sign? 2 cm calc-convert-units(mm) #+END_SRC #+RESULTS: : calc - convert - units(mm) Above attempt is not working. Is it also possible to use the RPN? Like in this fictive block: #+BEGIN_SRC calc :mode rpn 2 2 + 2 'mm 8 'cm + 'in u c #+END_SRC And the *Calc Trail* buffer seems not to reflect any operations, despite Calc showing the block results in its calculator buffer! Thanks Dieter > Best regards, > Seb -- Best wishes H. Dieter Wilhelm Darmstadt Germany ^ permalink raw reply [flat|nested] 7+ messages in thread

*Re: using a simple numerical variable in an org text ocument2013-07-27 18:19 ` Dieter Wilhelm@ 2013-08-14 5:54 ` Sebastien Vauban0 siblings, 0 replies; 7+ messages in thread From: Sebastien Vauban @ 2013-08-14 5:54 UTC (permalink / raw) To: emacs-orgmode-mXXj517/zsQ Hi Dieter, Dieter Wilhelm wrote: > "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes: >> As macros are expanded before Babel code is evaluated, I would >> try #+scr_calc{...} with MACRO constants in the formula (untested). > > it seems that you're working with calc source blocks! :-) I'd like to > leverage calc in org-mode (I'm thinking of unit conversions, etc.: > Mathematica for free men) but I'm not getting it. I assume that in an > #+src_calc block the mode of operation of calc is algebraic, isn't it? > > #+BEGIN_SRC calc > 2 + 2 > sqrt(8) > # above is working, by the way, does a calc block have a comment sign? > 2 cm > calc-convert-units(mm) > #+END_SRC > > #+RESULTS: > : calc - convert - units(mm) > > Above attempt is not working. Is it also possible to use the RPN? Like > in this fictive block: > > #+BEGIN_SRC calc :mode rpn > 2 2 + > 2 'mm 8 'cm + 'in u c > #+END_SRC > > And the *Calc Trail* buffer seems not to reflect any operations, despite > Calc showing the block results in its calculator buffer! Sorry to come back to this with a huge delay, but in fact I don't have any experience with Calc mode at all! I can't answer your questions without digging the manuals. The only thing I make use of is inline Calc for simple computations, to avoid making mistakes in prices (fictitious example): --8<---------------cut here---------------start------------->8--- The work will last 20 days and cost src_calc[:results raw]{20 * 498} USD at the base rate. --8<---------------cut here---------------end--------------->8--- Best regards, Seb -- Sebastien Vauban ^ permalink raw reply [flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-08-14 5:54 UTC | newest]Thread overview:7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-07-25 21:36 using a simple numerical variable in an org text ocument Matt Price 2013-07-25 21:55 ` Thorsten Jolitz 2013-07-25 23:39 ` Thorsten Jolitz 2013-07-26 1:16 ` Jonathan Leech-Pepin 2013-07-26 7:43 ` Sebastien Vauban 2013-07-27 18:19 ` Dieter Wilhelm 2013-08-14 5:54 ` Sebastien Vauban

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