From mboxrd@z Thu Jan 1 00:00:00 1970 From: Seweryn Subject: Re: Updating CONSTANTS in LaTeX mode Date: Sat, 11 Dec 2010 22:06:55 +0000 (UTC) Message-ID: References: <7A1269C4-244F-4C24-815F-EB9EEB8B0C30@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=51000 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PRXax-0006s3-Kp for emacs-orgmode@gnu.org; Sat, 11 Dec 2010 17:07:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PRXaw-0008KW-HR for emacs-orgmode@gnu.org; Sat, 11 Dec 2010 17:07:11 -0500 Received: from lo.gmane.org ([80.91.229.12]:55529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PRXaw-0008K6-6B for emacs-orgmode@gnu.org; Sat, 11 Dec 2010 17:07:10 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PRXau-0007nf-Sb for emacs-orgmode@gnu.org; Sat, 11 Dec 2010 23:07:08 +0100 Received: from 94.163.185.182 ([94.163.185.182]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Dec 2010 23:07:08 +0100 Received: from sewkokot by 94.163.185.182 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 11 Dec 2010 23:07:08 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Carsten Dominik 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