* Updating CONSTANTS in LaTeX mode @ 2010-12-11 15:05 Seweryn 2010-12-11 17:03 ` Carsten Dominik 0 siblings, 1 reply; 5+ messages in thread From: Seweryn @ 2010-12-11 15:05 UTC (permalink / raw) To: emacs-orgmode Hello, Is it possible to have locally defined CONSTANTS in .tex buffer? What is the command to update the list of known CONSTANTS since $pi works but I cannot insert $x to the list of CONSTANTS. See example below \begin{comment} #+CONSTANTS: x=458.0 #+ORGTBL: SEND test1 orgtbl-to-latex :splice t :lend "" | 3.1415927 | #ERROR | #+TBLFM: @1$1=$pi::@1$2=$x % $ \end{comment} I would appreciate a hint. Thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Updating CONSTANTS in LaTeX mode 2010-12-11 15:05 Updating CONSTANTS in LaTeX mode Seweryn @ 2010-12-11 17:03 ` Carsten Dominik 2010-12-11 17:07 ` Carsten Dominik 0 siblings, 1 reply; 5+ messages in thread From: Carsten Dominik @ 2010-12-11 17:03 UTC (permalink / raw) To: Seweryn; +Cc: emacs-orgmode On Dec 11, 2010, at 4:05 PM, Seweryn wrote: > Hello, > > Is it possible to have locally defined CONSTANTS in .tex buffer? > What is the > command to update the list of known CONSTANTS since $pi works but I > cannot > insert $x to the list of CONSTANTS. See example below > > \begin{comment} > #+CONSTANTS: x=458.0 > #+ORGTBL: SEND test1 orgtbl-to-latex :splice t :lend "" > | 3.1415927 | #ERROR | > #+TBLFM: @1$1=$pi::@1$2=$x > % $ > \end{comment} > > I would appreciate a hint. This works for me. Put you must do `C-c C-c' in the CONSTANTS line to make changes known to Org-mode. Or kill the buffer and revisit the file, that will also make CONSTANTS known. HTH - Carsten ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Updating CONSTANTS in LaTeX mode 2010-12-11 17:03 ` Carsten Dominik @ 2010-12-11 17:07 ` Carsten Dominik 2010-12-11 22:06 ` Seweryn 0 siblings, 1 reply; 5+ messages in thread From: Carsten Dominik @ 2010-12-11 17:07 UTC (permalink / raw) To: Carsten Dominik; +Cc: Seweryn, emacs-orgmode On Dec 11, 2010, at 6:03 PM, Carsten Dominik wrote: > > On Dec 11, 2010, at 4:05 PM, Seweryn wrote: > >> Hello, >> >> Is it possible to have locally defined CONSTANTS in .tex buffer? >> What is the >> command to update the list of known CONSTANTS since $pi works but I >> cannot >> insert $x to the list of CONSTANTS. See example below >> >> \begin{comment} >> #+CONSTANTS: x=458.0 >> #+ORGTBL: SEND test1 orgtbl-to-latex :splice t :lend "" >> | 3.1415927 | #ERROR | >> #+TBLFM: @1$1=$pi::@1$2=$x >> % $ >> \end{comment} >> >> I would appreciate a hint. > > This works for me. Put you must do `C-c C-c' in the CONSTANTS line > to make changes known to Org-mode. Or kill the buffer and revisit > the file, > that will also make CONSTANTS known. > I am sorry, I did not read this carefully. No, this is currently not possible in tex and other non-org-mode files. - Carsten ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Updating CONSTANTS in LaTeX mode 2010-12-11 17:07 ` Carsten Dominik @ 2010-12-11 22:06 ` Seweryn 2010-12-12 12:26 ` Carsten Dominik 0 siblings, 1 reply; 5+ messages in thread From: Seweryn @ 2010-12-11 22:06 UTC (permalink / raw) To: emacs-orgmode Carsten Dominik <carsten.dominik <at> gmail.com> writes: > > > On Dec 11, 2010, at 6:03 PM, Carsten Dominik wrote: > > > > > On Dec 11, 2010, at 4:05 PM, Seweryn wrote: > > > >> Hello, > >> > >> Is it possible to have locally defined CONSTANTS in .tex buffer? > >> What is the > >> command to update the list of known CONSTANTS since $pi works but I > >> cannot > >> insert $x to the list of CONSTANTS. See example below > >> > >> \begin{comment} > >> #+CONSTANTS: x=458.0 > >> #+ORGTBL: SEND test1 orgtbl-to-latex :splice t :lend "" > >> | 3.1415927 | #ERROR | > >> #+TBLFM: @1$1=$pi::@1$2=$x > >> % $ > >> \end{comment} > >> > >> I would appreciate a hint. > > > > This works for me. Put you must do `C-c C-c' in the CONSTANTS line > > to make changes known to Org-mode. Or kill the buffer and revisit > > the file, > > that will also make CONSTANTS known. > > > > I am sorry, I did not read this carefully. No, this is currently > not possible in tex and other non-org-mode files. > For sure, there is a better way to implement it, but for now I modified orgtbl- ctrl-c-ctrl-c function to update org-table-formula-constants-local. This variable is updated when hitting C-c C-c when being on #+TBLFM line. (defun orgtbl-ctrl-c-ctrl-c (arg) "If the cursor is inside a table, realign the table. If it is a table to be sent away to a receiver, do it. With prefix arg, also recompute table." (interactive "P") (let ((pos (point)) action consts-str consts cst) (save-excursion (beginning-of-line 1) (setq action (cond ((looking-at "[ \t]*#\\+ORGTBL:.*\n[ \t]*|") (match- end 0)) ((looking-at "[ \t]*|") pos) ((looking-at "[ \t]*#\\+TBLFM:") 'recalc)))) (cond ((integerp action) (goto-char action) (org-table-maybe-eval-formula) (if arg (call-interactively 'org-table-recalculate) (org-table-maybe-recalculate-line)) (call-interactively 'org-table-align) (when (orgtbl-send-table 'maybe) (run-hooks 'orgtbl-after-send-table-hook))) ((eq action 'recalc) (save-excursion (goto-char (point-min)) (while (re-search-forward "#\\+CONSTANTS: \\(.*\\)" nil t) (setq const-str (substring-no-properties (match-string 1))) (setq consts (append consts (org-split-string const-str "[ \t]+"))) (when consts (let (e) (while (setq e (pop consts)) (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) (push (cons (match-string 1 e) (match-string 2 e)) cst))) (setq org-table-formula-constants-local cst))))) (save-excursion (beginning-of-line 1) (skip-chars-backward " \r\n\t") (if (org-at-table-p) (org-call-with-arg 'org-table-recalculate t)))) (t (let (orgtbl-mode) (call-interactively (key-binding "\C-c\C-c"))))))) Cheers, Seweryn ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re: Updating CONSTANTS in LaTeX mode 2010-12-11 22:06 ` Seweryn @ 2010-12-12 12:26 ` Carsten Dominik 0 siblings, 0 replies; 5+ messages in thread From: Carsten Dominik @ 2010-12-12 12:26 UTC (permalink / raw) To: Seweryn; +Cc: emacs-orgmode Hi Seweryn, nice patch, thanks, I have included it with very minor modifications (mainly anchoring the match to the left margin with spaces). Thanks! - Carsten On Dec 11, 2010, at 11:06 PM, Seweryn wrote: > Carsten Dominik <carsten.dominik <at> gmail.com> writes: > >> >> >> On Dec 11, 2010, at 6:03 PM, Carsten Dominik wrote: >> >>> >>> On Dec 11, 2010, at 4:05 PM, Seweryn wrote: >>> >>>> Hello, >>>> >>>> Is it possible to have locally defined CONSTANTS in .tex buffer? >>>> What is the >>>> command to update the list of known CONSTANTS since $pi works but I >>>> cannot >>>> insert $x to the list of CONSTANTS. See example below >>>> >>>> \begin{comment} >>>> #+CONSTANTS: x=458.0 >>>> #+ORGTBL: SEND test1 orgtbl-to-latex :splice t :lend "" >>>> | 3.1415927 | #ERROR | >>>> #+TBLFM: @1$1=$pi::@1$2=$x >>>> % $ >>>> \end{comment} >>>> >>>> I would appreciate a hint. >>> >>> This works for me. Put you must do `C-c C-c' in the CONSTANTS line >>> to make changes known to Org-mode. Or kill the buffer and revisit >>> the file, >>> that will also make CONSTANTS known. >>> >> >> I am sorry, I did not read this carefully. No, this is currently >> not possible in tex and other non-org-mode files. >> > > For sure, there is a better way to implement it, but for now I > modified orgtbl- > ctrl-c-ctrl-c function to update org-table-formula-constants-local. > This > variable is updated when hitting C-c C-c when being on #+TBLFM line. > > (defun orgtbl-ctrl-c-ctrl-c (arg) > "If the cursor is inside a table, realign the table. > If it is a table to be sent away to a receiver, do it. > With prefix arg, also recompute table." > (interactive "P") > (let ((pos (point)) action consts-str consts cst) > (save-excursion > (beginning-of-line 1) > (setq action (cond ((looking-at "[ \t]*#\\+ORGTBL:.*\n[ \t]*|") > (match- > end 0)) > ((looking-at "[ \t]*|") pos) > ((looking-at "[ \t]*#\\+TBLFM:") 'recalc)))) > (cond > ((integerp action) > (goto-char action) > (org-table-maybe-eval-formula) > (if arg > (call-interactively 'org-table-recalculate) > (org-table-maybe-recalculate-line)) > (call-interactively 'org-table-align) > (when (orgtbl-send-table 'maybe) > (run-hooks 'orgtbl-after-send-table-hook))) > ((eq action 'recalc) > (save-excursion > (goto-char (point-min)) > (while (re-search-forward "#\\+CONSTANTS: \\(.*\\)" nil t) > (setq const-str (substring-no-properties (match-string 1))) > (setq consts (append consts (org-split-string const-str "[ \t]+"))) > (when consts > (let (e) > (while (setq e (pop consts)) > (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) > (push (cons (match-string 1 e) (match-string 2 e)) cst))) > (setq org-table-formula-constants-local cst))))) > (save-excursion > (beginning-of-line 1) > (skip-chars-backward " \r\n\t") > (if (org-at-table-p) > (org-call-with-arg 'org-table-recalculate t)))) > (t (let (orgtbl-mode) > (call-interactively (key-binding "\C-c\C-c"))))))) > > Cheers, > Seweryn > > > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-12-12 12:26 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-12-11 15:05 Updating CONSTANTS in LaTeX mode Seweryn 2010-12-11 17:03 ` Carsten Dominik 2010-12-11 17:07 ` Carsten Dominik 2010-12-11 22:06 ` Seweryn 2010-12-12 12:26 ` Carsten Dominik
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).