Go to the previous, next section.

Embedded Mode

Embedded Mode in Calc provides an alternative to copying numbers and formulas back and forth between editing buffers and the Calc stack. In Embedded Mode, your editing buffer becomes temporarily linked to the stack and this copying is taken care of automatically.

Basic Embedded Mode

To enter Embedded mode, position the Emacs point (cursor) on a formula in any buffer and press M-# e (calc-embedded). Note that M-# e is not to be used in the Calc stack buffer like most Calc commands, but rather in regular editing buffers that are visiting your own files.

Calc normally scans backward and forward in the buffer for the nearest opening and closing formula delimiters. The simplest delimiters are blank lines. Other delimiters that Embedded Mode understands are:

  1. The TeX and LaTeX math delimiters `$ $', `$$ $$', `\[ \]', and `\( \)';
  2. Lines beginning with `\begin' and `\end';
  3. Lines beginning with `@' (Texinfo delimiters).
  4. Lines beginning with `.EQ' and `.EN' (eqn delimiters);
  5. Lines containing a single `%' or `.\"' symbol and nothing else.

See section Customizing Embedded Mode, to see how to make Calc recognize your own favorite delimiters. Delimiters like `$ $' can appear on their own separate lines or in-line with the formula.

If you give a positive or negative numeric prefix argument, Calc instead uses the current point as one end of the formula, and moves forward or backward (respectively) by that many lines to find the other end. Explicit delimiters are not necessary in this case.

With a prefix argument of zero, Calc uses the current region (delimited by point and mark) instead of formula delimiters.

With a prefix argument of C-u only, Calc scans for the first non-numeric character (i.e., the first character that is not a digit, sign, decimal point, or upper- or lower-case `e') forward and backward to delimit the formula. M-# w (calc-embedded-word) is equivalent to C-u M-# e.

When you enable Embedded mode for a formula, Calc reads the text between the delimiters and tries to interpret it as a Calc formula. It's best if the current Calc language mode is correct for the formula, but Calc can generally identify TeX formulas and Big-style formulas even if the language mode is wrong. If Calc can't make sense of the formula, it beeps and refuses to enter Embedded mode. But if the current language is wrong, Calc can sometimes parse the formula successfully (but incorrectly); for example, the C expression `atan(a[1])' can be parsed in Normal language mode, but the atan won't correspond to the built-in arctan function, and the `a[1]' will be interpreted as `a' times the vector `[1]'!

If you press M-# e or M-# w to activate an embedded formula which is blank, say with the cursor on the space between the two delimiters `$ $', Calc will immediately prompt for an algebraic entry.

Only one formula in one buffer can be enabled at a time. If you move to another area of the current buffer and give Calc commands, Calc turns Embedded mode off for the old formula and then tries to restart Embedded mode at the new position. Other buffers are not affected by Embedded mode.

When Embedded mode begins, Calc pushes the current formula onto the stack. No Calc stack window is created; however, Calc copies the top-of-stack position into the original buffer at all times. You can create a Calc window by hand with M-# o if you find you need to see the entire stack.

For example, typing M-# e while somewhere in the formula `n>2' in the following line enables Embedded mode on that inequality:

We define $F_n = F_(n-1)+F_(n-2)$ for all $n>2$.

The formula n>2 will be pushed onto the Calc stack, and the top of stack will be copied back into the editing buffer. This means that spaces will appear around the `>' symbol to match Calc's usual display style:

We define $F_n = F_(n-1)+F_(n-2)$ for all $n > 2$.

No spaces have appeared around the `+' sign because it's in a different formula, one which we have not yet touched wiefine $F_n = F_(n-1)+F_(n-2)$ for all $n>2$.

The formula n>2 will be pushed onto the Calc stack, and the top of stack will be copied back into the editing buffer. This means that spaces will appear around the `>' symbol to match Calc's usual display style:

We define $F_n = F_(n-1)+F_(n-2)$ for all $n > 2$.

No spaces have appeared around the `+' sign because it's in a different formula, one which we have not yet touched wi