Go forward to Assignments in Embedded Mode. Go backward to Basic Embedded Mode. Go up to Embedded Mode.

More About Embedded Mode
========================

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 TeX-like `\' sequences, it is parsed (i.e.,
read) in TeX 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 to
what it finds.  Even though it can read a TeX formula when not in TeX
mode, it will immediately rewrite this formula using whatever language
mode is in effect.  You must then type `d T' to switch Calc
permanently into TeX mode if that is what you desire.


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, so if your formula is embedded in a TeX document its
plain version will be invisible in the final printed copy.  *Note
Customizing Embedded Mode::, to see how to change the "plain" formula
delimiters, say to something that "eqn" or some other formatter will
treat as a comment.

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 (*Note 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 `M-# d' (`calc-embedded-duplicate') command is a handy way to make
sequences like this.  If you type `M-# 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 `M-# 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 `M-# d M-# 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 `M-# e' to exit Embedded mode, then
go up and insert the necessary text in between the various formulas
and numbers.


The `M-# 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 `M-#
e'.  The key sequence `M-# '' is equivalent to `M-# f'.

The `M-# n' (`calc-embedded-next') and `M-# 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, `M-# n' and `M-#
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.  (By the way,
`M-# n' is not as awkward to type as it may seem, because `M-#'
ignores Shift and Meta on the second keystroke: `M-# M-N' can be typed
by holding down Shift and Meta and alternately typing two keys.)

The `M-# `' (`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 `M-# M-#' to finish
the edit, or `M-# x' to cancel.