Next: , Previous: GNU Free Documentation License, Up: Top

Appendix C Customizing Calc

The usual prefix for Calc is the key sequence C-x *. If you wish to use a different prefix, you can put

     (global-set-key "NEWPREFIX" 'calc-dispatch)

in your .emacs file. (See Customizing Key Bindings, for more information on binding keys.) A convenient way to start Calc is with C-x * *; to make it equally convenient for users who use a different prefix, the prefix can be followed by =, &, #, \, /, + or - as well as * to start Calc, and so in many cases the last character of the prefix can simply be typed twice.

Calc is controlled by many variables, most of which can be reset from within Calc. Some variables are less involved with actual calculation and can be set outside of Calc using Emacs's customization facilities. These variables are listed below. Typing M-x customize-variable RET variable-name RET will bring up a buffer in which the variable's value can be redefined. Typing M-x customize-group RET calc RET will bring up a buffer which contains all of Calc's customizable variables. (These variables can also be reset by putting the appropriate lines in your .emacs file; See Init File.)

Some of the customizable variables are regular expressions. A regular expression is basically a pattern that Calc can search for. See Regular Expression Search to see how regular expressions work.

— Variable: calc-settings-file

The variable calc-settings-file holds the file name in which commands like m m and Z P store “permanent” definitions. If calc-settings-file is not your user init file (typically ~/.emacs) and if the variable calc-loaded-settings-file is nil, then Calc will automatically load your settings file (if it exists) the first time Calc is invoked.

The default value for this variable is "~/.emacs.d/calc.el" unless the file ~/.calc.el exists, in which case the default value will be "~/.calc.el".

— Variable: calc-gnuplot-name

See Graphics.
The variable calc-gnuplot-name should be the name of the GNUPLOT program (a string). If you have GNUPLOT installed on your system but Calc is unable to find it, you may need to set this variable. You may also need to set some Lisp variables to show Calc how to run GNUPLOT on your system, see Graphical Devices . The default value of calc-gnuplot-name is "gnuplot".

— Variable: calc-gnuplot-plot-command
— Variable: calc-gnuplot-print-command

See Graphical Devices.
The variables calc-gnuplot-plot-command and calc-gnuplot-print-command represent system commands to display and print the output of GNUPLOT, respectively. These may be nil if no command is necessary, or strings which can include ‘%s’ to signify the name of the file to be displayed or printed. Or, these variables may contain Lisp expressions which are evaluated to display or print the output.

The default value of calc-gnuplot-plot-command is nil, and the default value of calc-gnuplot-print-command is "lp %s".

— Variable: calc-language-alist

See Basic Embedded Mode.
The variable calc-language-alist controls the languages that Calc will associate with major modes. When Calc embedded mode is enabled, it will try to use the current major mode to determine what language should be used. (This can be overridden using Calc's mode changing commands, See Mode Settings in Embedded Mode.) The variable calc-language-alist consists of a list of pairs of the form (MAJOR-MODE . LANGUAGE); for example, (latex-mode . latex) is one such pair. If Calc embedded is activated in a buffer whose major mode is MAJOR-MODE, it will set itself to use the language LANGUAGE.

The default value of calc-language-alist is

             ((latex-mode . latex)
              (tex-mode   . tex)
              (plain-tex-mode . tex)
              (context-mode . tex)
              (nroff-mode . eqn)
              (pascal-mode . pascal)
              (c-mode . c)
              (c++-mode . c)
              (fortran-mode . fortran)
              (f90-mode . fortran))
— Variable: calc-embedded-announce-formula
— Variable: calc-embedded-announce-formula-alist

See Customizing Embedded Mode.
The variable calc-embedded-announce-formula helps determine what formulas C-x * a will activate in a buffer. It is a regular expression, and when activating embedded formulas with C-x * a, it will tell Calc that what follows is a formula to be activated. (Calc also uses other patterns to find formulas, such as ‘=>’ and ‘:=’.)

The default pattern is "%Embed\n\\(% .*\n\\)*", which checks for ‘%Embed’ followed by any number of lines beginning with ‘%’ and a space.

The variable calc-embedded-announce-formula-alist is used to set calc-embedded-announce-formula to different regular expressions depending on the major mode of the editing buffer. It consists of a list of pairs of the form (MAJOR-MODE . REGEXP), and its default value is

             ((c++-mode     . "//Embed\n\\(// .*\n\\)*")
              (c-mode       . "/\\*Embed\\*/\n\\(/\\* .*\\*/\n\\)*")
              (f90-mode     . "!Embed\n\\(! .*\n\\)*")
              (fortran-mode . "C Embed\n\\(C .*\n\\)*")
              (html-helper-mode . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
              (html-mode    . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
              (nroff-mode   . "\\\\\"Embed\n\\(\\\\\" .*\n\\)*")
              (pascal-mode  . "{Embed}\n\\({.*}\n\\)*")
              (sgml-mode    . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
              (xml-mode     . "<!-- Embed -->\n\\(<!-- .* -->\n\\)*")
              (texinfo-mode . "@c Embed\n\\(@c .*\n\\)*"))

Any major modes added to calc-embedded-announce-formula-alist should also be added to calc-embedded-open-close-plain-alist and calc-embedded-open-close-mode-alist.

— Variable: calc-embedded-open-formula
— Variable: calc-embedded-close-formula
— Variable: calc-embedded-open-close-formula-alist

See Customizing Embedded Mode.
The variables calc-embedded-open-formula and calc-embedded-close-formula control the region that Calc will activate as a formula when Embedded mode is entered with C-x * e. They are regular expressions; Calc normally scans backward and forward in the buffer for the nearest text matching these regular expressions to be the “formula delimiters”.

The simplest delimiters are blank lines. Other delimiters that Embedded mode understands by default are:

  1. The TeX and LaTeX math delimiters ‘$ $’, ‘$$ $$’, ‘\[ \]’, and ‘\( \)’;
  2. Lines beginning with ‘\begin’ and ‘\end’ (except matrix delimiters);
  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.

The variable calc-embedded-open-close-formula-alist is used to set calc-embedded-open-formula and calc-embedded-close-formula to different regular expressions depending on the major mode of the editing buffer. It consists of a list of lists of the form (MAJOR-MODE OPEN-FORMULA-REGEXP CLOSE-FORMULA-REGEXP), and its default value is nil.

— Variable: calc-embedded-word-regexp
— Variable: calc-embedded-word-regexp-alist

See Customizing Embedded Mode.
The variable calc-embedded-word-regexp determines the expression that Calc will activate when Embedded mode is entered with C-x * w. It is a regular expressions.

The default value of calc-embedded-word-regexp is "[-+]?[0-9]+\\(\\.[0-9]+\\)?\\([eE][-+]?[0-9]+\\)?".

The variable calc-embedded-word-regexp-alist is used to set calc-embedded-word-regexp to a different regular expression depending on the major mode of the editing buffer. It consists of a list of lists of the form (MAJOR-MODE WORD-REGEXP), and its default value is nil.

— Variable: calc-embedded-open-plain
— Variable: calc-embedded-close-plain
— Variable: calc-embedded-open-close-plain-alist

See Customizing Embedded Mode.
The variables calc-embedded-open-plain and calc-embedded-open-plain are used to delimit “plain” formulas. Note that these are actual strings, not regular expressions, because Calc must be able to write these string into a buffer as well as to recognize them.

The default string for calc-embedded-open-plain is "%%% ", note the trailing space. The default string for calc-embedded-close-plain is " %%%\n", without the trailing newline here, the first line of a Big mode formula that followed might be shifted over with respect to the other lines.

The variable calc-embedded-open-close-plain-alist is used to set calc-embedded-open-plain and calc-embedded-close-plain to different strings depending on the major mode of the editing buffer. It consists of a list of lists of the form (MAJOR-MODE OPEN-PLAIN-STRING CLOSE-PLAIN-STRING), and its default value is

             ((c++-mode     "// %% "   " %%\n")
              (c-mode       "/* %% "   " %% */\n")
              (f90-mode     "! %% "    " %%\n")
              (fortran-mode "C %% "    " %%\n")
              (html-helper-mode "<!-- %% " " %% -->\n")
              (html-mode "<!-- %% " " %% -->\n")
              (nroff-mode   "\\\" %% " " %%\n")
              (pascal-mode  "{%% "    " %%}\n")
              (sgml-mode     "<!-- %% " " %% -->\n")
              (xml-mode     "<!-- %% " " %% -->\n")
              (texinfo-mode "@c %% "   " %%\n"))

Any major modes added to calc-embedded-open-close-plain-alist should also be added to calc-embedded-announce-formula-alist and calc-embedded-open-close-mode-alist.

— Variable: calc-embedded-open-new-formula
— Variable: calc-embedded-close-new-formula
— Variable: calc-embedded-open-close-new-formula-alist

See Customizing Embedded Mode.
The variables calc-embedded-open-new-formula and calc-embedded-close-new-formula are strings which are inserted before and after a new formula when you type C-x * f.

The default value of calc-embedded-open-new-formula is "\n\n". If this string begins with a newline character and the C-x * f is typed at the beginning of a line, C-x * f will skip this first newline to avoid introducing unnecessary blank lines in the file. The default value of calc-embedded-close-new-formula is also "\n\n". The final newline is omitted by C-x * f if typed at the end of a line. (It follows that if C-x * f is typed on a blank line, both a leading opening newline and a trailing closing newline are omitted.)

The variable calc-embedded-open-close-new-formula-alist is used to set calc-embedded-open-new-formula and calc-embedded-close-new-formula to different strings depending on the major mode of the editing buffer. It consists of a list of lists of the form (MAJOR-MODE OPEN-NEW-FORMULA-STRING CLOSE-NEW-FORMULA-STRING), and its default value is nil.

— Variable: calc-embedded-open-mode
— Variable: calc-embedded-close-mode
— Variable: calc-embedded-open-close-mode-alist

See Customizing Embedded Mode.
The variables calc-embedded-open-mode and calc-embedded-close-mode are strings which Calc will place before and after any mode annotations that it inserts. Calc never scans for these strings; Calc always looks for the annotation itself, so it is not necessary to add them to user-written annotations.

The default value of calc-embedded-open-mode is "% " and the default value of calc-embedded-close-mode is "\n". If you change the value of calc-embedded-close-mode, it is a good idea still to end with a newline so that mode annotations will appear on lines by themselves.

The variable calc-embedded-open-close-mode-alist is used to set calc-embedded-open-mode and calc-embedded-close-mode to different strings expressions depending on the major mode of the editing buffer. It consists of a list of lists of the form (MAJOR-MODE OPEN-MODE-STRING CLOSE-MODE-STRING), and its default value is

             ((c++-mode     "// "   "\n")
              (c-mode       "/* "   " */\n")
              (f90-mode     "! "    "\n")
              (fortran-mode "C "    "\n")
              (html-helper-mode "<!-- " " -->\n")
              (html-mode    "<!-- " " -->\n")
              (nroff-mode   "\\\" " "\n")
              (pascal-mode  "{ "    " }\n")
              (sgml-mode    "<!-- " " -->\n")
              (xml-mode     "<!-- " " -->\n")
              (texinfo-mode "@c "   "\n"))

Any major modes added to calc-embedded-open-close-mode-alist should also be added to calc-embedded-announce-formula-alist and calc-embedded-open-close-plain-alist.

— Variable: calc-lu-power-reference
— Variable: calc-lu-field-reference

See Logarithmic Units.
The variables calc-lu-power-reference and calc-lu-field-reference are unit expressions (written as strings) which Calc will use as reference quantities for logarithmic units.

The default value of calc-lu-power-reference is "mW" and the default value of calc-lu-field-reference is "20 uPa".

— Variable: calc-note-threshold

See Musical Notes.
The variable calc-note-threshold is a number (written as a string) which determines how close (in cents) a frequency needs to be to a note to be recognized as that note.

The default value of calc-note-threshold is 1.

— Variable: calc-highlight-selections-with-faces
— Variable: calc-selected-face
— Variable: calc-nonselected-face

See Displaying Selections.
The variable calc-highlight-selections-with-faces determines how selected sub-formulas are distinguished. If calc-highlight-selections-with-faces is nil, then a selected sub-formula is distinguished either by changing every character not part of the sub-formula with a dot or by changing every character in the sub-formula with a ‘#’ sign. If calc-highlight-selections-with-faces is t, then a selected sub-formula is distinguished either by displaying the non-selected portion of the formula with calc-nonselected-face or by displaying the selected sub-formula with calc-nonselected-face.

— Variable: calc-multiplication-has-precedence

The variable calc-multiplication-has-precedence determines whether multiplication has precedence over division in algebraic formulas in normal language modes. If calc-multiplication-has-precedence is non-nil, then multiplication has precedence (and, for certain obscure reasons, is right associative), and so for example ‘a/b*c’ will be interpreted as ‘a/(b*c)’. If calc-multiplication-has-precedence is nil, then multiplication has the same precedence as division (and, like division, is left associative), and so for example ‘a/b*c’ will be interpreted as ‘(a/b)*c’. The default value of calc-multiplication-has-precedence is t.

— Variable: calc-ensure-consistent-units

When converting units, the variable calc-ensure-consistent-units determines whether or not the target units need to be consistent with the original units. If calc-ensure-consistent-units is nil, then the target units don't need to have the same dimensions as the original units; for example, converting ‘100 ft/s’ to ‘m’ will produce ‘30.48 m/s’. If calc-ensure-consistent-units is non-nil, then the target units need to have the same dimensions as the original units; for example, converting ‘100 ft/s’ to ‘m’ will result in an error, since ‘ft/s’ and ‘m’ have different dimensions. The default value of calc-ensure-consistent-units is nil.

— Variable: calc-undo-length

The variable calc-undo-length determines the number of undo steps that Calc will keep track of when calc-quit is called. If calc-undo-length is a non-negative integer, then this is the number of undo steps that will be preserved; if calc-undo-length has any other value, then all undo steps will be preserved. The default value of calc-undo-length is ‘100’.