Next: Other C-x * Commands, Previous: Standalone Operation, Up: Using Calc [Contents][Index]

#### 1.5.6 Embedded Mode (Overview)

Embedded mode is a way to use Calc directly from inside an editing buffer. Suppose you have a formula written as part of a document like this:

    The derivative of

                                       ln(ln(x))

    is

and you wish to have Calc compute and format the derivative for you and store this derivative in the buffer automatically. To do this with Embedded mode, first copy the formula down to where you want the result to be, leaving a blank line before and after the formula:

    The derivative of

                                       ln(ln(x))

    is

                                       ln(ln(x))

Now, move the cursor onto this new formula and press `C-x * e`. Calc will read the formula (using the surrounding blank lines to tell how much text to read), then push this formula (invisibly) onto the Calc stack. The cursor will stay on the formula in the editing buffer, but the line with the formula will now appear as it would on the Calc stack (in this case, it will be left-aligned) and the buffer’s mode line will change to look like the Calc mode line (with mode indicators like ‘`12 Deg`’ and so on). Even though you are still in your editing buffer, the keyboard now acts like the Calc keyboard, and any new result you get is copied from the stack back into the buffer. To take the derivative, you would type `a d x RET`.

    The derivative of

                                       ln(ln(x))

    is

    1 / x ln(x)

(Note that by default, Calc gives division lower precedence than multiplication, so that ‘`1 / x ln(x)`’ is equivalent to ‘`1 / (x ln(x))`’.)

To make this look nicer, you might want to press `d =` to center the formula, and even `d B` to use Big display mode.

    The derivative of

                                       ln(ln(x))

    is
    % [calc-mode: justify: center]
    % [calc-mode: language: big]

                                           1
                                        -------
                                        x ln(x)

Calc has added annotations to the file to help it remember the modes that were used for this formula. They are formatted like comments in the TeX typesetting language, just in case you are using TeX or LaTeX. (In this example TeX is not being used, so you might want to move these comments up to the top of the file or otherwise put them out of the way.)

As an extra flourish, we can add an equation number using a righthand label: Type `d } (1) RET`.

    % [calc-mode: justify: center]
    % [calc-mode: language: big]
    % [calc-mode: right-label: " (1)"]

                                           1
                                        -------                      (1)
                                        ln(x) x

To leave Embedded mode, type `C-x * e` again. The mode line and keyboard will revert to the way they were before.

The related command `C-x * w` operates on a single word, which generally means a single number, inside text. It searches for an expression which “looks” like a number containing the point. Here’s an example of its use (before you try this, remove the Calc annotations or use a new buffer so that the extra settings in the annotations don’t take effect):

    A slope of one-third corresponds to an angle of 1 degrees.

Place the cursor on the ‘`1`’, then type `C-x * w` to enable Embedded mode on that number. Now type `3 /` (to get one-third), and `I T` (the Inverse Tangent converts a slope into an angle), then `C-x * w` again to exit Embedded mode.

    A slope of one-third corresponds to an angle of 18.4349488229 degrees.

See Embedded Mode, for full details.

Next: Other C-x * Commands, Previous: Standalone Operation, Up: Using Calc [Contents][Index]