Next: Assignments in Embedded Mode, Previous: Basic Embedded Mode, Up: Embedded Mode [Contents][Index]
When Embedded mode “activates” a formula, i.e., when it examines the formula for the first time since the buffer was created or loaded, Calc tries to sense the language in which the formula was written. If the formula contains any LaTeX-like ‘\’ sequences, it is parsed (i.e., read) in LaTeX mode. If the formula appears to be written in multi-line Big mode, it is parsed in Big mode. Otherwise, it is parsed according to the current language mode.
Note that Calc does not change the current language mode according the formula it reads in. Even though it can read a LaTeX formula when not in LaTeX mode, it will immediately rewrite this formula using whatever language mode is in effect.
Calc’s parser is unable to read certain kinds of formulas. For
example, with v ] (calc-matrix-brackets
) you can
specify matrix display styles which the parser is unable to
recognize as matrices. The d p (calc-show-plain
)
command turns on a mode in which a “plain” version of a
formula is placed in front of the fully-formatted version.
When Calc reads a formula that has such a plain version in
front, it reads the plain version and ignores the formatted
version.
Plain formulas are preceded and followed by ‘%%%’ signs by default. This notation has the advantage that the ‘%’ character begins a comment in TeX and LaTeX, so if your formula is embedded in a TeX or LaTeX document its plain version will be invisible in the final printed copy. Certain major modes have different delimiters to ensure that the “plain” version will be in a comment for those modes, also. See Customizing Embedded Mode to see how to change the “plain” formula delimiters.
There are several notations which Calc’s parser for “big”
formatted formulas can’t yet recognize. In particular, it can’t
read the large symbols for sum
, prod
, and integ
,
and it can’t handle ‘=>’ with the righthand argument omitted.
Also, Calc won’t recognize special formats you have defined with
the Z C command (see User-Defined Compositions). In
these cases it is important to use “plain” mode to make sure
Calc will be able to read your formula later.
Another example where “plain” mode is important is if you have specified a float mode with few digits of precision. Normally any digits that are computed but not displayed will simply be lost when you save and re-load your embedded buffer, but “plain” mode allows you to make sure that the complete number is present in the file as well as the rounded-down number.
Embedded buffers remember active formulas for as long as they exist in Emacs memory. Suppose you have an embedded formula which is ‘pi’ to the normal 12 decimal places, and then type C-u 5 d n to display only five decimal places. If you then type d n, all 12 places reappear because the full number is still there on the Calc stack. More surprisingly, even if you exit Embedded mode and later re-enter it for that formula, typing d n will restore all 12 places because each buffer remembers all its active formulas. However, if you save the buffer in a file and reload it in a new Emacs session, all non-displayed digits will have been lost unless you used “plain” mode.
In some applications of Embedded mode, you will want to have a sequence of copies of a formula that show its evolution as you work on it. For example, you might want to have a sequence like this in your file (elaborating here on the example from the “Getting Started” chapter):
The derivative of ln(ln(x)) is (the derivative of ln(ln(x))) whose value at x = 2 is (the value) and at x = 3 is (the value)
The C-x * d (calc-embedded-duplicate
) command is a
handy way to make sequences like this. If you type C-x * d,
the formula under the cursor (which may or may not have Embedded
mode enabled for it at the time) is copied immediately below and
Embedded mode is then enabled for that copy.
For this example, you would start with just
The derivative of ln(ln(x))
and press C-x * d with the cursor on this formula. The result is
The derivative of ln(ln(x)) ln(ln(x))
with the second copy of the formula enabled in Embedded mode. You can now press a d x RET to take the derivative, and C-x * d C-x * d to make two more copies of the derivative. To complete the computations, type 3 s l x RET to evaluate the last formula, then move up to the second-to-last formula and type 2 s l x RET.
Finally, you would want to press C-x * e to exit Embedded mode, then go up and insert the necessary text in between the various formulas and numbers.
The C-x * f (calc-embedded-new-formula
) command
creates a new embedded formula at the current point. It inserts
some default delimiters, which are usually just blank lines,
and then does an algebraic entry to get the formula (which is
then enabled for Embedded mode). This is just shorthand for
typing the delimiters yourself, positioning the cursor between
the new delimiters, and pressing C-x * e. The key sequence
C-x * ' is equivalent to C-x * f.
The C-x * n (calc-embedded-next
) and C-x * p
(calc-embedded-previous
) commands move the cursor to the
next or previous active embedded formula in the buffer. They
can take positive or negative prefix arguments to move by several
formulas. Note that these commands do not actually examine the
text of the buffer looking for formulas; they only see formulas
which have previously been activated in Embedded mode. In fact,
C-x * n and C-x * p are a useful way to tell which
embedded formulas are currently active. Also, note that these
commands do not enable Embedded mode on the next or previous
formula, they just move the cursor.
The C-x * ` (calc-embedded-edit
) command edits the
embedded formula at the current point as if by ` (calc-edit
).
Embedded mode does not have to be enabled for this to work. Press
C-c C-c to finish the edit, or C-x k to cancel.
Next: Assignments in Embedded Mode, Previous: Basic Embedded Mode, Up: Embedded Mode [Contents][Index]