home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume24 / gnucalc / part50 < prev    next >
Encoding:
Text File  |  1991-11-02  |  55.5 KB  |  1,177 lines

  1. Newsgroups: comp.sources.misc
  2. From: daveg@synaptics.com (David Gillespie)
  3. Subject:  v24i098:  gnucalc - GNU Emacs Calculator, v2.00, Part50/56
  4. Message-ID: <1991Nov3.001038.19733@sparky.imd.sterling.com>
  5. X-Md4-Signature: e60c59206a809d145d3903e295fc8077
  6. Date: Sun, 3 Nov 1991 00:10:38 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: daveg@synaptics.com (David Gillespie)
  10. Posting-number: Volume 24, Issue 98
  11. Archive-name: gnucalc/part50
  12. Environment: Emacs
  13. Supersedes: gmcalc: Volume 13, Issue 27-45
  14.  
  15. #!/bin/sh
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file calc.texinfo continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 50; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping calc.texinfo'
  33. else
  34. echo 'x - continuing file calc.texinfo'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
  36. going to be replaced right away anyhow), or by using the @kbd{s =}
  37. (@code{calc-evalto}) command, which takes @var{a} from the stack
  38. and replaces it with @samp{@var{a} => @var{b}}.
  39. X
  40. Calc keeps track of all @samp{=>} operators on the stack, and
  41. recomputes them whenever anything changes that might affect their
  42. values, i.e., a mode setting or variable value.  This occurs only
  43. if the @samp{=>} operator is at the top level of the formula, or
  44. if it is part of a top-level vector.  In other words, pushing
  45. @samp{2 + (a => 17)} will change the 17 to the actual value of
  46. @samp{a} when you enter the formula, but the result will not be
  47. dynamically updated when @samp{a} is changed later because the
  48. @samp{=>} operator is buried inside a sum.  However, a vector
  49. of @samp{=>} operators will be recomputed, since it is convenient
  50. to push a vector like @samp{[a =>, b =>, c =>]} on the stack to
  51. make a concise display of all the variables in your problem.
  52. (Another way to do this would be to use @samp{[a, b, c] =>},
  53. which provides a slightly different format of display.  You
  54. can use whichever you find easiest to read.)
  55. X
  56. @kindex m C
  57. @pindex calc-auto-recompute
  58. The @kbd{m C} (@code{calc-auto-recompute}) command allows you to
  59. turn this automatic recomputation on or off.  If you turn
  60. recomputation off, you must explicitly recompute an @samp{=>}
  61. operator on the stack in one of the usual ways, such as by
  62. pressing @kbd{=}.  Turning recomputation off temporarily can save
  63. a lot of time if you will be changing several modes or variables
  64. before you look at the @samp{=>} entries again.
  65. X
  66. Most commands are not especially useful with @samp{=>} operators
  67. as arguments.  For example, given @samp{x + 2 => 17}, it won't
  68. work to type @kbd{1 +} to get @samp{x + 3 => 18}.  If you want
  69. to operate on the lefthand side of the @samp{=>} operator on
  70. the top of the stack, type @kbd{j 1} (that's the digit ``one'')
  71. to select the lefthand side, execute your commands, then type
  72. @kbd{j u} to unselect.
  73. X
  74. All current modes apply when an @samp{=>} operator is computed,
  75. including the current simplification mode.  Recall that the
  76. formula @samp{x + y + x} is not handled by Calc's default
  77. simplifications, but the @kbd{a s} command will reduce it to
  78. the simpler form @samp{y + 2 x}.  You can also type @kbd{m A}
  79. to enable an algebraic-simplification mode in which the
  80. equivalent of @kbd{a s} is used on all of Calc's results.
  81. If you enter @samp{x + y + x =>} normally, the result will
  82. be @samp{x + y + x => x + y + x}.  If you change to
  83. algebraic-simplification mode, the result will be
  84. @samp{x + y + x => y + 2 x}.  However, just pressing @kbd{a s}
  85. once will have no effect on @samp{x + y + x => x + y + x},
  86. because the righthand side depends only on the lefthand side
  87. and the current mode settings, and the lefthand side is not
  88. affected by commands like @kbd{a s}.
  89. X
  90. The ``let'' command (@kbd{s l}) has an interesting interaction
  91. with the @samp{=>} operator.  The @kbd{s l} command evaluates the
  92. second-to-top stack entry with the top stack entry supplying
  93. a temporary value for a given variable.  As you might expect,
  94. if that stack entry is an @samp{=>} operator its righthand
  95. side will temporarily show this value for the variable.  In
  96. fact, all @samp{=>}s on the stack will be updated if they refer
  97. to that variable.  But this change is temporary in the sense
  98. that the next command that causes Calc to look at those stack
  99. entries will make them revert to the old variable value.
  100. X
  101. @group
  102. @smallexample
  103. 2:  a => a             2:  a => 17         2:  a => a
  104. 1:  a + 1 => a + 1     1:  a + 1 => 18     1:  a + 1 => a + 1
  105. X    .                      .                   .
  106. X
  107. X                           17 s l a RET        p 8 RET
  108. @end smallexample
  109. @end group
  110. X
  111. Here the @kbd{p 8} command changes the current precision,
  112. thus causing the @samp{=>} forms to be recomputed after the
  113. influence of the ``let'' is gone.  The @kbd{d SPC} command
  114. (@code{calc-refresh}) is a handy way to force the @samp{=>}
  115. operators on the stack to be recomputed without any other
  116. side effects.
  117. X
  118. @kindex s :
  119. @pindex calc-assign
  120. @tindex assign
  121. @tindex :=
  122. Embedded Mode also uses @samp{=>} operators.  In embedded mode,
  123. the lefthand side of an @samp{=>} operator can refer to variables
  124. assigned elsewhere in the file by @samp{:=} operators.  The
  125. assignment operator @samp{a := 17} does not actually do anything
  126. by itself.  But Embedded Mode recognizes it and marks it as a sort
  127. of file-local definition of the variable.  You can enter @samp{:=}
  128. operators in algebraic mode, or by using the @kbd{s :}
  129. (@code{calc-assign}) [@code{assign}] command which takes a variable
  130. and value from the stack and replaces them with an assignment.
  131. X
  132. @xref{TeX Language Mode}, for the way @samp{=>} appears in
  133. @TeX{} language output.  The @dfn{eqn} mode gives similar
  134. treatment to @samp{=>}.
  135. X
  136. @node Graphics, Kill and Yank, Store and Recall, Top
  137. @chapter Graphics
  138. X
  139. @noindent
  140. The commands for graphing data begin with the @kbd{g} prefix key.  Calc
  141. uses GNUPLOT 2.0 or 3.0 to do graphics.  These commands will only work
  142. if GNUPLOT is available on your system.  (While GNUPLOT sounds like
  143. a relative of GNU Emacs, it is actually completely unrelated.
  144. However, it is free software and can be obtained from the Free
  145. Software Foundation's machine @samp{prep.ai.mit.edu}.)
  146. X
  147. @vindex calc-gnuplot-name
  148. If you have GNUPLOT installed on your system but Calc is unable to
  149. find it, you may need to set the @code{calc-gnuplot-name} variable
  150. in your @file{.emacs} file.  You may also need to set some Lisp
  151. variables to show Calc how to run GNUPLOT on your system; these
  152. are described under @kbd{g D} and @kbd{g O} below.  If you are
  153. using the X window system, Calc will configure GNUPLOT for you
  154. automatically.  If you have GNUPLOT 3.0 and you are not using X,
  155. Calc will configure GNUPLOT to display graphs using simple character
  156. graphics that will work on any terminal.
  157. X
  158. @menu
  159. * Basic Graphics::
  160. * Three Dimensional Graphics::
  161. * Managing Curves::
  162. * Graphics Options::
  163. * Devices::
  164. @end menu
  165. X
  166. @node Basic Graphics, Three Dimensional Graphics, Graphics, Graphics
  167. @section Basic Graphics
  168. X
  169. @noindent
  170. @kindex g f
  171. @pindex calc-graph-fast
  172. The easiest graphics command is @kbd{g f} (@code{calc-graph-fast}).
  173. This command takes two vectors of equal length from the stack.
  174. The vector at the top of the stack represents the ``y'' values of
  175. the various data points.  The vector in the second-to-top position
  176. represents the corresponding ``x'' values.  This command runs
  177. GNUPLOT (if it has not already been started by previous graphing
  178. commands) and displays the set of data points.  The points will
  179. be connected by lines, and there will also be some kind of symbol
  180. to indicate the points themselves.
  181. X
  182. The ``x'' entry may instead be an interval form, in which case suitable
  183. ``x'' values are interpolated between the minimum and maximum values of
  184. the interval (whether the interval is open or closed is ignored).
  185. X
  186. The ``x'' entry may also be a number, in which case Calc uses the
  187. sequence of ``x'' values @cite{x}, @cite{x+1}, @cite{x+2}, etc.
  188. (Generally the number 0 or 1 would be used for @cite{x} in this case.)
  189. X
  190. The ``y'' entry may be any formula instead of a vector.  Calc effectively
  191. uses @kbd{N} (@code{calc-eval-num}) to evaluate variables in the formula;
  192. the result of this must be a formula in a single (unassigned) variable.
  193. The formula is plotted with this variable taking on the various ``x''
  194. values.  Graphs of formulas by default use lines without symbols at the
  195. computed data points.  Note that if neither ``x'' nor ``y'' is a vector,
  196. Calc guesses at a reasonable number of data points to use.  See the
  197. @kbd{g N} command below.  (The ``x'' values must be either a vector
  198. or an interval if ``y'' is a formula.)
  199. X
  200. @tindex xy
  201. If ``y'' is (or evaluates to) a formula of the form
  202. @samp{xy(@var{x}, @var{y})} then the result is a
  203. parametric plot.  The two arguments of the fictitious @code{xy} function
  204. are used as the ``x'' and ``y'' coordinates of the curve, respectively.
  205. In this case the ``x'' vector or interval you specified is not directly
  206. visible in the graph.  For example, if ``x'' is the interval @samp{[0..360]}
  207. and ``y'' is the formula @samp{xy(sin(t), cos(t))}, the resulting graph
  208. will be a circle.@refill
  209. X
  210. Also, ``x'' and ``y'' may each be variable names, in which case Calc
  211. looks for suitable vectors, intervals, or formulas stored in those
  212. variables.
  213. X
  214. The ``x'' and ``y'' values for the data points (as pulled from the vectors,
  215. calculated from the formulas, or interpolated from the intervals) should
  216. be real numbers (integers, fractions, or floats).  If either the ``x''
  217. value or the ``y'' value of a given data point is not a real number, that
  218. data point will be omitted from the graph.  The points on either side
  219. of the invalid point will @emph{not} be connected by a line.
  220. X
  221. See the documentation for @kbd{g a} below for a description of the way
  222. numeric prefix arguments affect @kbd{g f}.
  223. X
  224. @cindex @code{PlotRejects} variable
  225. @vindex PlotRejects
  226. If you store an empty vector in the variable @code{PlotRejects}
  227. (i.e., @kbd{[ ] s t PlotRejects}), Calc will append information to
  228. this vector for every data point which was rejected because its
  229. ``x'' or ``y'' values were not real numbers.  The result will be
  230. a matrix where each row holds the curve number, data point number,
  231. ``x'' value, and ``y'' value for a rejected data point.
  232. @xref{Evaluates-To Operator}, for a handy way to keep tabs on the
  233. current value of @code{PlotRejects}.  @xref{Operations on Variables},
  234. for the @kbd{s R} command which is another easy way to examine
  235. @code{PlotRejects}.
  236. X
  237. @kindex g c
  238. @pindex calc-graph-clear
  239. To clear the graphics display, type @kbd{g c} (@code{calc-graph-clear}).
  240. If the GNUPLOT output device is an X window, the window will go away.
  241. Effects on other kinds of output devices will vary.  You don't need
  242. to use @kbd{g c} if you don't want to---if you give another @kbd{g f}
  243. or @kbd{g p} command later on, it will reuse the existing graphics
  244. window if there is one.
  245. X
  246. @node Three Dimensional Graphics, Managing Curves, Basic Graphics, Graphics
  247. @section Three Dimensional Graphics
  248. X
  249. @kindex g F
  250. @pindex calc-graph-fast-3d
  251. The @kbd{g F} (@code{calc-graph-fast-3d}) command makes a three-dimensional
  252. graph.  It works only if you have GNUPLOT 3.0 or later; with GNUPLOT 2.0,
  253. you will see a GNUPLOT error message if you try this command.
  254. X
  255. The @kbd{g F} command takes three values from the stack, called ``x'',
  256. ``y'', and ``z'', respectively.  As was the case for 2D graphs, there
  257. are several options for these values.
  258. X
  259. In the first case, ``x'' and ``y'' are each vectors (not necessarily of
  260. the same length); either or both may instead be interval forms.  The
  261. ``z'' value must be a matrix with the same number of rows as elements
  262. in ``x'', and the same number of columns as elements in ``y''.  The
  263. result is a surface plot where @c{$z_{ij}$}
  264. @cite{z_ij} is the height of the point
  265. at coordinate @cite{(x_i, y_j)} on the surface.  The 3D graph will
  266. be displayed from a certain default viewpoint; you can change this
  267. viewpoint by adding a @samp{set view} to the @samp{*Gnuplot Commands*}
  268. buffer as described later.  See the GNUPLOT documentation for a
  269. description of the @samp{set view} command.
  270. X
  271. Each point in the matrix will be displayed as a dot in the graph,
  272. and these points will be connected by a grid of lines (@dfn{isolines}).
  273. X
  274. In the second case, ``x'', ``y'', and ``z'' are all vectors of equal
  275. length.  The resulting graph displays a 3D line instead of a surface,
  276. where the coordinates of points along the line are successive triplets
  277. of values from the input vectors.
  278. X
  279. In the third case, ``x'' and ``y'' are vectors or interval forms, and
  280. ``z'' is any formula involving two variables (not counting variables
  281. with assigned values).  These variables are sorted into alphabetical
  282. order; the first takes on values from ``x'' and the second takes on
  283. values from ``y'' to form a matrix of results that are graphed as a
  284. 3D surface.
  285. X
  286. If the ``z'' formula evaluates to a call to the fictitious function
  287. @samp{xyz(@var{x}, @var{y}, @var{z})}, then the result is a
  288. ``parametric surface.''  In this case, the axes of the graph are
  289. taken from the @var{x} and @var{y} values in these calls, and the
  290. ``x'' and ``y'' values from the input vectors or intervals are used
  291. only to generate inputs to the formula.  For example, plotting
  292. @samp{[0..360], [0..180], xyz(sin(x)*sin(y), cos(x)*sin(y), cos(y))}
  293. will draw a sphere.  (Since the default resolution for 3D plots is
  294. 5 steps in each of ``x'' and ``y'', this will draw a very crude
  295. sphere.  You could use the @kbd{g N} command, described below, to
  296. increase this resolution, or specify the ``x'' and ``y'' values as
  297. vectors with more than 5 components.)
  298. X
  299. It is also possible to have a function in a regular @kbd{g f} plot
  300. evaluate to an @code{xyz} call.  Since @kbd{g f} plots a line, not
  301. a surface, the result will be 3D parametric line.  For example,
  302. @samp{[[0..720], xyz(sin(x), cos(x), x)]} will plot two turns of a
  303. helix (a three-dimensional spiral).
  304. X
  305. As for @kbd{g f}, each of ``x'', ``y'', and ``z'' may instead be
  306. variables containing the relevant data.
  307. X
  308. @node Managing Curves, Graphics Options, Three Dimensional Graphics, Graphics
  309. @section Managing Curves
  310. X
  311. @noindent
  312. The @kbd{g f} command is really shorthand for the following commands:
  313. @kbd{C-u g d  g a  g p}.  Likewise, @kbd{g F} is shorthand for
  314. @kbd{C-u g d  g A  g p}.  You can gain more control over your graph
  315. by using these commands directly.
  316. X
  317. @kindex g a
  318. @pindex calc-graph-add
  319. The @kbd{g a} (@code{calc-graph-add}) command adds the ``curve''
  320. represented by the two values on the top of the stack to the current
  321. graph.  You can have any number of curves in the same graph.  When
  322. you give the @kbd{g p} command, all the curves will be drawn superimposed
  323. on the same axes.
  324. X
  325. The @kbd{g a} command (and many others that affect the current graph)
  326. will cause a special buffer, @samp{*Gnuplot Commands*}, to be displayed
  327. in another window.  This buffer is a template of the commands that will
  328. be sent to GNUPLOT when it is time to draw the graph.  The first
  329. @kbd{g a} command adds a @code{plot} command to this buffer.  Succeeding
  330. @kbd{g a} commands add extra curves onto that @code{plot} command.
  331. Other graph-related commands put other GNUPLOT commands into this
  332. buffer.  In normal usage you never need to work with this buffer
  333. directly, but you can if you wish.  The only constraint is that there
  334. must be only one @code{plot} command, and it must be the last command
  335. in the buffer.  If you want to save and later restore a complete graph
  336. configuration, you can use regular Emacs commands to save and restore
  337. the contents of the @samp{*Gnuplot Commands*} buffer.
  338. X
  339. @vindex PlotData1
  340. @vindex PlotData2
  341. If the values on the stack are not variable names, @kbd{g a} will invent
  342. variable names for them (of the form @samp{PlotData@var{n}}) and store
  343. the values in those variables.  The ``x'' and ``y'' variables are what
  344. go into the @code{plot} command in the template.  If you add a curve
  345. that uses a certain variable and then later change that variable, you
  346. can replot the graph without having to delete and re-add the curve.
  347. That's because the variable name, not the vector, interval or formula
  348. itself, is what was added by @kbd{g a}.
  349. X
  350. A numeric prefix argument on @kbd{g a} or @kbd{g f} changes the way
  351. stack entries are interpreted as curves.  With a positive prefix
  352. argument @cite{n}, the top @cite{n} stack entries are ``y'' values
  353. for @cite{n} different curves which share a common ``x'' value in
  354. the @cite{n+1}st stack entry.  (Thus @kbd{g a} with no prefix
  355. argument is equivalent to @kbd{C-u 1 g a}.)
  356. X
  357. A prefix of zero or plain @kbd{C-u} means to take two stack entries,
  358. ``x'' and ``y'' as usual, but to interpret ``y'' as a vector of
  359. ``y'' values for several curves that share a common ``x''.
  360. X
  361. A negative prefix argument tells Calc to read @cite{n} vectors from
  362. the stack; each vector @cite{[x, y]} describes an independent curve.
  363. This is the only form of @kbd{g a} that creates several curves at once
  364. that don't have common ``x'' values.  (Of course, the range of ``x''
  365. values covered by all the curves ought to be roughly the same if
  366. they are to look nice on the same graph.)
  367. X
  368. For example, to plot @c{$\sin n x$}
  369. @cite{sin(n x)} for integers @cite{n}
  370. from 1 to 5, you could use @kbd{v x} to create a vector of integers
  371. (@cite{n}), then @kbd{V M '} or @kbd{V M $} to map @samp{sin(n x)}
  372. across this vector.  The resulting vector of formulas is suitable
  373. for use as the ``y'' argument to a @kbd{C-u g a} or @kbd{C-u g f}
  374. command.
  375. X
  376. @kindex g A
  377. @pindex calc-graph-add-3d
  378. The @kbd{g A} (@code{calc-graph-add-3d}) command adds a 3D curve
  379. to the graph.  It is not legal to intermix 2D and 3D curves in a
  380. single graph.  This command takes three arguments, ``x'', ``y'',
  381. and ``z'', from the stack.  With a positive prefix @cite{n}, it
  382. takes @cite{n+2} arguments (common ``x'' and ``y'', plus @cite{n}
  383. separate ``z''s).  With a zero prefix, it takes three stack entries
  384. but the ``z'' entry is a vector of curve values.  With a negative
  385. prefix @cite{-n}, it takes @cite{n} vectors of the form @cite{[x, y, z]}.
  386. The @kbd{g A} command works by adding a @code{splot} (surface-plot)
  387. command to the @samp{*Gnuplot Commands*} buffer.
  388. X
  389. (Although @kbd{g a} adds a 2D @code{plot} command to the
  390. @samp{*Gnuplot Commands*} buffer, Calc changes this to @code{splot}
  391. before sending it to GNUPLOT if it notices that the data points are
  392. evaluating to @code{xyz} calls.  It will not work to mix 2D and 3D
  393. @kbd{g a} curves in a single graph, although Calc does not currently
  394. check for this.)
  395. X
  396. @kindex g d
  397. @pindex calc-graph-delete
  398. The @kbd{g d} (@code{calc-graph-delete}) command deletes the most
  399. recently added curve from the graph.  It has no effect if there are
  400. no curves in the graph.  With a numeric prefix argument of any kind,
  401. it deletes all of the curves from the graph.
  402. X
  403. @kindex g H
  404. @pindex calc-graph-hide
  405. The @kbd{g H} (@code{calc-graph-hide}) command ``hides'' or ``unhides''
  406. the most recently added curve.  A hidden curve will not appear in
  407. the actual plot, but information about it such its name and line and
  408. point styles will be retained.
  409. X
  410. @kindex g j
  411. @pindex calc-graph-juggle
  412. The @kbd{g j} (@code{calc-graph-juggle}) command moves the curve
  413. at the end of the list (the ``most recently added curve'') to the
  414. front of the list.  The next-most-recent curve is thus exposed for
  415. @kbd{g d} or similar commands to use.  With @kbd{g j} you can work
  416. with any curve in the graph even though curve-related commands only
  417. affect the last curve in the list.
  418. X
  419. @kindex g p
  420. @pindex calc-graph-plot
  421. The @kbd{g p} (@code{calc-graph-plot}) command uses GNUPLOT to draw
  422. the graph described in the @samp{*Gnuplot Commands*} buffer.  Any
  423. GNUPLOT parameters which are not defined by commands in this buffer
  424. are reset to their default values.  The variables named in the @code{plot}
  425. command are written to a temporary data file and the variable names
  426. are then replaced by the file name in the template.  The resulting
  427. plotting commands are fed to the GNUPLOT program.  See the documentation
  428. for the GNUPLOT program for more specific information.  All temporary
  429. files are removed when Emacs or GNUPLOT exits.
  430. X
  431. If you give a formula for ``y'', Calc will remember all the values that
  432. it calculates for the formula so that later plots can reuse these values.
  433. Calc throws out these saved values when you change any circumstances
  434. that may affect the data, such as switching from Degrees to Radians
  435. mode, or changing the value of a parameter in the formula.  You can
  436. force Calc to recompute the data from scratch by giving a negative
  437. numeric prefix argument to @kbd{g p}.
  438. X
  439. Calc uses a fairly rough step size when graphing formulas over intervals.
  440. This is to ensure quick response.  You can ``refine'' a plot by giving
  441. a positive numeric prefix argument to @kbd{g p}.  Calc goes through
  442. the data points it has computed and saved from previous plots of the
  443. function, and computes and inserts a new data point midway between
  444. each of the existing points.  You can refine a plot any number of times,
  445. but beware that amount of calculation involved doubles each time.
  446. X
  447. Calc does not remember computed values for 3D graphs.  This means the
  448. numerix prefix argument, if any, to @kbd{g p} is effectively ignored if
  449. the current graph is three-dimensional.
  450. X
  451. @kindex g P
  452. @pindex calc-graph-print
  453. The @kbd{g P} (@code{calc-graph-print}) command is like @kbd{g p},
  454. except that it sends the output to a printer instead of to the
  455. screen.  More precisely, @kbd{g p} looks for @samp{set terminal}
  456. or @samp{set output} commands in the @samp{*Gnuplot Commands*} buffer;
  457. lacking these it uses the default settings.  However, @kbd{g P}
  458. ignores @samp{set terminal} and @samp{set output} commands and
  459. uses a different set of default values.  All of these values are
  460. controlled by the @kbd{g D} and @kbd{g O} commands discussed below.
  461. Provided everything is set up properly, @kbd{g p} will plot to
  462. the screen unless you have specified otherwise and @kbd{g P} will
  463. always plot to the printer.
  464. X
  465. @node Graphics Options, Devices, Managing Curves, Graphics
  466. @section Graphics Options
  467. X
  468. @noindent
  469. @kindex g g
  470. @pindex calc-graph-grid
  471. The @kbd{g g} (@code{calc-graph-grid}) command turns the ``grid''
  472. on and off.  It is off by default; tick marks appear only at the
  473. edges of the graph.  With the grid turned on, dotted lines appear
  474. across the graph at each tick mark.  Note that this command only
  475. changes the setting in @samp{*Gnuplot Commands*}; to see the effects
  476. of the change you must give another @kbd{g p} command.
  477. X
  478. @kindex g b
  479. @pindex calc-graph-border
  480. The @kbd{g b} (@code{calc-graph-border}) command turns the border
  481. (the box that surrounds the graph) on and off.  It is on by default.
  482. This command will only work with GNUPLOT 3.0 and later versions.
  483. X
  484. @kindex g k
  485. @pindex calc-graph-key
  486. The @kbd{g k} (@code{calc-graph-key}) command turns the ``key''
  487. on and off.  The key is a chart in the corner of the graph that
  488. shows the correspondence between curves and line styles.  It is
  489. off by default, and is only really useful if you have several
  490. curves on the same graph.
  491. X
  492. @kindex g N
  493. @pindex calc-graph-num-points
  494. The @kbd{g N} (@code{calc-graph-num-points}) command allows you
  495. to select the number of data points in the graph.  This only affects
  496. curves where neither ``x'' nor ``y'' is specified as a vector.
  497. Enter a blank line to revert to the default value (initially 15).
  498. With a positive prefix argument this command changes or, if you enter
  499. a blank line, displays the default number of points used for all
  500. graphs created by @kbd{g a} that don't specify the resolution explicitly.
  501. With a negative prefix argument, this command changes or displays
  502. the default value (initially 5) used for 3D graphs created by @kbd{g A}.
  503. Note that a 3D setting of 5 means that a total of @cite{5^2 = 25} points
  504. will be computed for the surface.
  505. X
  506. Data points in the graph of a function are normally computed to a
  507. precision of five digits, regardless of the current precision at the
  508. time. This is usually more than adequate, but there are cases where
  509. it will not be.  For example, plotting @cite{1 + x} for @cite{x} in the
  510. interval @samp{[0 ..@: 1e-6]} will round all the data points down
  511. to 1.0!  Putting the command @samp{set precision @var{n}} in the
  512. @samp{*Gnuplot Commands*} buffer will cause the data to be computed
  513. at precision @var{n} instead of 5.  Since this is such a rare case,
  514. there is no keystroke-based command to set the precision.
  515. X
  516. @kindex g h
  517. @pindex calc-graph-header
  518. The @kbd{g h} (@code{calc-graph-header}) command sets the title
  519. for the graph.  This will show up centered above the graph.
  520. The default title is blank (no title).
  521. X
  522. @kindex g n
  523. @pindex calc-graph-name
  524. The @kbd{g n} (@code{calc-graph-name}) command sets the title of an
  525. individual curve.  Like the other curve-manipulating commands, it
  526. affects the most recently added curve, i.e., the last curve on the
  527. list in the @samp{*Gnuplot Commands*} buffer.  To set the title of
  528. the other curves you must first juggle them to the end of the list
  529. with @kbd{g j}, or edit the @samp{*Gnuplot Commands*} buffer by hand.
  530. Curve titles appear in the key; if the key is turned off they are
  531. not used.
  532. X
  533. @kindex g t
  534. @kindex g T
  535. @pindex calc-graph-title-x
  536. @pindex calc-graph-title-y
  537. The @kbd{g t} (@code{calc-graph-title-x}) and @kbd{g T}
  538. (@code{calc-graph-title-y}) commands set the titles on the ``x''
  539. and ``y'' axes, respectively.  These titles appear next to the
  540. tick marks on the left and bottom edges of the graph, respectively.
  541. Calc does not have commands to control the tick marks themselves,
  542. but you can edit them into the @samp{*Gnuplot Commands*} buffer if
  543. you wish.  See the GNUPLOT documentation for details.
  544. X
  545. @kindex g r
  546. @kindex g R
  547. @pindex calc-graph-range-x
  548. @pindex calc-graph-range-y
  549. The @kbd{g r} (@code{calc-graph-range-x}) and @kbd{g R}
  550. (@code{calc-graph-range-y}) commands set the range of values on the
  551. ``x'' and ``y'' axes, respectively.  You are prompted to enter a
  552. suitable range.  This should be either a pair of numbers of the
  553. form, @samp{@var{min}:@var{max}}, or a blank line to revert to the
  554. default behavior of setting the range based on the range of values
  555. in the data, or @samp{$} to take the range from the top of the stack.
  556. Ranges on the stack can be represented as either interval forms or
  557. vectors:  @samp{[@var{min} ..@: @var{max}]} or @samp{[@var{min}, @var{max}]}.
  558. X
  559. @kindex g l
  560. @kindex g L
  561. @pindex calc-graph-log-x
  562. @pindex calc-graph-log-y
  563. The @kbd{g l} (@code{calc-graph-log-x}) and @kbd{g L} (@code{calc-graph-log-y})
  564. commands allow you to set either or both of the axes of the graph to
  565. be logarithmic instead of linear.
  566. X
  567. @kindex g C-l
  568. @kindex g C-r
  569. @kindex g C-t
  570. @pindex calc-graph-log-z
  571. @pindex calc-graph-range-z
  572. @pindex calc-graph-title-z
  573. For 3D plots, @kbd{g C-t}, @kbd{g C-r}, and @kbd{g C-l} (those are
  574. letters with the Control key held down) are the corresponding commands
  575. for the Z axis.
  576. X
  577. @kindex g z
  578. @kindex g Z
  579. @pindex calc-graph-zero-x
  580. @pindex calc-graph-zero-y
  581. The @kbd{g z} (@code{calc-graph-zero-x}) and @kbd{g Z}
  582. (@code{calc-graph-zero-y}) commands control whether a dotted line is
  583. drawn to indicate the ``x'' and/or ``y'' zero axes.  (These are the same
  584. dotted lines that would be drawn there anyway if you used @kbd{g g} to
  585. turn the ``grid'' feature on.)  Zero-axis lines are on by default, and
  586. may be turned off only in GNUPLOT 3.0 and later versions.  They are
  587. not available for 3D plots.
  588. X
  589. @kindex g s
  590. @pindex calc-graph-line-style
  591. The @kbd{g s} (@code{calc-graph-line-style}) command turns the connecting
  592. lines on or off for the most recently added curve, and optionally selects
  593. the style of lines to be used for that curve.  Plain @kbd{g s} simply
  594. toggles the lines on and off.  With a numeric prefix argument, @kbd{g s}
  595. turns lines on and sets a particular line style.  Line style numbers
  596. start at one and their meanings vary depending on the output device.
  597. GNUPLOT guarantees that there will be at least six different line styles
  598. available for any device.
  599. X
  600. @kindex g S
  601. @pindex calc-graph-point-style
  602. The @kbd{g S} (@code{calc-graph-point-style}) command similarly turns
  603. the symbols at the data points on or off, or sets the point style.
  604. If you turn both lines and points off, the data points will show as
  605. tiny dots.
  606. X
  607. @cindex @code{LineStyles} variable
  608. @cindex @code{PointStyles} variable
  609. @vindex LineStyles
  610. @vindex PointStyles
  611. Another way to specify curve styles is with the @code{LineStyles} and
  612. @code{PointStyles} variables.  These variables initially have no stored
  613. values, but if you store a vector of integers in one of these variables,
  614. the @kbd{g a} and @kbd{g f} commands will use those style numbers
  615. instead of the defaults for new curves that are added to the graph.
  616. An entry should be a positive integer for a specific style, or 0 to
  617. let the style be chosen automatically, or -1 to turn off lines or points
  618. altogether.  If there are more curves than elements in the vector, the
  619. last few curves will continue to have the default styles.  Of course,
  620. you can later use @kbd{g s} and @kbd{g S} to change any of these styles.
  621. X
  622. For example, @kbd{'[2 -1 3] RET s t LineStyles} causes the first curve
  623. to have lines in style number 2, the second curve to have no connecting
  624. lines, and the third curve to have lines in style 3.  Point styles will
  625. still be assigned automatically, but you could store another vector in
  626. @code{PointStyles} to define them, too.
  627. X
  628. @node Devices, , Graphics Options, Graphics
  629. @section Graphical Devices
  630. X
  631. @noindent
  632. @kindex g D
  633. @pindex calc-graph-device
  634. The @kbd{g D} (@code{calc-graph-device}) command sets the device name
  635. (or ``terminal name'' in GNUPLOT lingo) to be used by @kbd{g p} commands
  636. on this graph.  It does not affect the permanent default device name.
  637. If you enter a blank name, the device name reverts to the default.
  638. Enter @samp{?} to see a list of supported devices.
  639. X
  640. With a positive numeric prefix argument, @kbd{g D} instead sets
  641. the default device name, used by all plots in the future which do
  642. not override it with a plain @kbd{g D} command.  If you enter a
  643. blank line this command shows you the current default.  The special
  644. name @code{default} signifies that Calc should choose @code{x11} if
  645. the X window system is in use (as indicated by the presence of a
  646. @code{DISPLAY} environment variable), or otherwise @code{dumb} under
  647. GNUPLOT 3.0 and later, or @code{postscript} under GNUPLOT 2.0.
  648. This is the initial default value.
  649. X
  650. The @code{dumb} device is an interface to ``dumb terminals,'' i.e.,
  651. terminals with no special graphics facilities.  It writes a crude
  652. picture of the graph composed of characters like @code{-} and @code{|}
  653. to a buffer called @samp{*Gnuplot Trail*}, which Calc then displays.
  654. The graph is made the same size as the Emacs screen, which on most
  655. dumb terminals will be 80x24 characters.  The graph is displayed in
  656. an Emacs ``recursive edit''; type @kbd{q} or @kbd{M-# M-#} to exit
  657. the recursive edit and return to Calc.  Note that the @code{dumb}
  658. device is present only in GNUPLOT 3.0 and later versions.
  659. X
  660. The word @code{dumb} may be followed by two numbers separated by
  661. spaces.  These are the desired width and height of the graph in
  662. characters.  Also, the device name @code{big} is like @code{dumb}
  663. but creates a graph four times the width and height of the Emacs
  664. screen.  You will then have to scroll around to view the entire
  665. graph.  In the @samp{*Gnuplot Trail*} buffer, @key{SPC}, @key{DEL},
  666. @kbd{<}, and @kbd{>} are defined to scroll by one screenful in each
  667. of the four directions.
  668. X
  669. With a negative numeric prefix argument, @kbd{g P} sets or displays
  670. the device name used by @kbd{g P} (@code{calc-graph-print}).  This
  671. is initially @code{postscript}.  If you don't have a PostScript
  672. printer, you may decide once again to use @code{dumb} to create a
  673. plot on any text-only printer.
  674. X
  675. @kindex g O
  676. @pindex calc-graph-output
  677. The @kbd{g O} (@code{calc-graph-output}) command sets the name of
  678. the output file used by GNUPLOT.  For some devices, notably @code{x11},
  679. there is no output file and this information is not used.  Many other
  680. ``devices'' are really file formats like @code{postscript}; in these
  681. cases the output in the desired format goes into the file you name
  682. with @kbd{g O}.  Type @kbd{g O stdout RET} to set GNUPLOT to write
  683. to its standard output stream, i.e., to @samp{*Gnuplot Trail*}.
  684. This is the default setting.
  685. X
  686. Another special output name is @code{tty}, which means that GNUPLOT
  687. is going to write graphics commands directly to its standard output,
  688. which you wish Emacs to pass through to your terminal.  Tektronix
  689. graphics terminals, among other devices, operate this way.  Calc does
  690. this by telling GNUPLOT to write to a temporary file, then running a
  691. sub-shell executing the command @samp{cat tempfile >/dev/tty}.  On
  692. typical Unix systems, this will copy the temporary file directly to
  693. the terminal, bypassing Emacs entirely.  You will have to type @kbd{C-l}
  694. to Emacs afterwards to refresh the screen.
  695. X
  696. Once again, @kbd{g O} with a positive or negative prefix argument
  697. sets the default or printer output file names, respectively.  In each
  698. case you can specify @code{auto}, which causes Calc to invent a temporary
  699. file name for each @kbd{g p} (or @kbd{g P}) command.  This temporary file
  700. will be deleted once it has been displayed or printed.  If the output file
  701. name is not @code{auto}, the file is not automatically deleted.
  702. X
  703. The default and printer devices and output files can be saved
  704. permanently by the @kbd{m m} (@code{calc-save-modes}) command.  The
  705. default number of data points (see @kbd{g N}) and the X geometry
  706. (see @kbd{g X}) are also saved.  Other graph information is @emph{not}
  707. saved; you can save a graph's configuration simply by saving the contents
  708. of the @samp{*Gnuplot Commands*} buffer.
  709. X
  710. @vindex calc-gnuplot-plot-command
  711. @vindex calc-gnuplot-default-device
  712. @vindex calc-gnuplot-default-output
  713. @vindex calc-gnuplot-print-command
  714. @vindex calc-gnuplot-print-device
  715. @vindex calc-gnuplot-print-output
  716. If you are installing Calc you may wish to configure the default and
  717. printer devices and output files for the whole system.  The relevant
  718. Lisp variables are @code{calc-gnuplot-default-device} and @code{-output},
  719. and @code{calc-gnuplot-print-device} and @code{-output}.  The output
  720. file names must be either strings as described above, or Lisp
  721. expressions which are evaluated on the fly to get the output file name.
  722. X
  723. Other important Lisp variables are @code{calc-gnuplot-plot-command} and
  724. @code{calc-gnuplot-print-command}, which give the system commands to
  725. display or print the output of GNUPLOT, respectively.  These may be
  726. @code{nil} if no command is necessary, or strings which can include
  727. @samp{%s} to signify the name of the file to be displayed or printed.
  728. Or, these variables may contain Lisp expressions which are evaluated
  729. to display or print the output.
  730. X
  731. @kindex g x
  732. @pindex calc-graph-display
  733. The @kbd{g x} (@code{calc-graph-display}) command lets you specify
  734. on which X window system display your graphs should be drawn.  Enter
  735. a blank line to see the current display name.  This command has no
  736. effect unless the current device is @samp{x11}.
  737. X
  738. @kindex g X
  739. @pindex calc-graph-geometry
  740. The @kbd{g X} (@code{calc-graph-geometry}) command is a similar
  741. command for specifying the position and size of the X window.
  742. The normal value is @samp{default}, which generally means your
  743. window manager will let you place the window interactively.
  744. Entering @samp{800x500+0+0} would create an 800-by-500 pixel
  745. window in the upper-left corner of the screen.
  746. X
  747. The buffer called @samp{*Gnuplot Trail*} holds a transcript of the
  748. session with GNUPLOT.  This shows the commands Calc has ``typed'' to
  749. GNUPLOT and the responses it has received.  Calc tries to notice when an
  750. error message has appeared here and display the buffer for you when
  751. this happens.  You can check this buffer yourself if you suspect
  752. something has gone wrong.
  753. X
  754. @kindex g C
  755. @pindex calc-graph-command
  756. The @kbd{g C} (@code{calc-graph-command}) command prompts you to
  757. enter any line of text, then simply sends that line to the current
  758. GNUPLOT process.  The @samp{*Gnuplot Trail*} buffer looks deceptively
  759. like a Shell buffer but you can't type commands in it yourself.
  760. Instead, you must use @kbd{g C} for this purpose.
  761. X
  762. @kindex g v
  763. @kindex g V
  764. @pindex calc-graph-view-commands
  765. @pindex calc-graph-view-trail
  766. The @kbd{g v} (@code{calc-graph-view-commands}) and @kbd{g V}
  767. (@code{calc-graph-view-trail}) commands display the @samp{*Gnuplot Commands*}
  768. and @samp{*Gnuplot Trail*} buffers, respectively, in another window.
  769. This happens automatically when Calc thinks there is something you
  770. will want to see in either of these buffers.  If you type @kbd{g v}
  771. or @kbd{g V} when the relevant buffer is already displayed, the
  772. buffer is hidden again.
  773. X
  774. One reason to use @kbd{g v} is to add your own commands to the
  775. @samp{*Gnuplot Commands*} buffer.  Press @kbd{g v}, then use
  776. @kbd{C-x o} to switch into that window.  For example, GNUPLOT has
  777. @samp{set label} and @samp{set arrow} commands that allow you to
  778. annotate your plots.  Since Calc doesn't understand these commands,
  779. you have to add them to the @samp{*Gnuplot Commands*} buffer
  780. yourself, then use @kbd{g p} to replot using these new commands.  Note
  781. that your commands must appear @emph{before} the @code{plot} command.
  782. To get help on any GNUPLOT feature, type, e.g., @kbd{g C help set label}.
  783. You may have to type @kbd{g C RET} a few times to clear the
  784. ``press return for more'' or ``subtopic of @dots{}'' requests.
  785. Note that Calc always sends commands (like @samp{set nolabel}) to
  786. reset all plotting parameters to the defaults before each plot, so
  787. to delete a label all you need to do is delete the @samp{set label}
  788. line you added (or comment it out with @samp{#}) and then replot
  789. with @kbd{g p}.
  790. X
  791. @kindex g q
  792. @pindex calc-graph-quit
  793. You can use @kbd{g q} (@code{calc-graph-quit}) to kill the GNUPLOT
  794. process that is running.  The next graphing command you give will
  795. start a fresh GNUPLOT process.  The word @samp{Graph} appears in
  796. the Calc window's mode line whenever a GNUPLOT process is currently
  797. running.  The GNUPLOT process is automatically killed when you
  798. exit Emacs if you haven't killed it manually by then.
  799. X
  800. @kindex g K
  801. @pindex calc-graph-kill
  802. The @kbd{g K} (@code{calc-graph-kill}) command is like @kbd{g q}
  803. except that it also views the @samp{*Gnuplot Trail*} buffer so that
  804. you can see the process being killed.  This is better if you are
  805. killing GNUPLOT because you think it has gotten stuck.
  806. X
  807. @node Kill and Yank, Keypad Mode, Graphics, Top
  808. @chapter Kill and Yank Functions
  809. X
  810. @noindent
  811. The commands in this chapter move information between the Calculator and
  812. other Emacs editing buffers.
  813. X
  814. In many cases Embedded Mode is an easier and more natural way to
  815. work with Calc from a regular editing buffer.  @xref{Embedded Mode}.
  816. X
  817. @menu
  818. * Killing From Stack::
  819. * Yanking Into Stack::
  820. * Grabbing From Buffers::
  821. * Yanking Into Buffers::
  822. * X Cut and Paste::
  823. * Editing Stack Entries::
  824. @end menu
  825. X
  826. @node Killing From Stack, Yanking Into Stack, Kill and Yank, Kill and Yank
  827. @section Killing from the Stack
  828. X
  829. @noindent
  830. @kindex C-k
  831. @pindex calc-kill
  832. @kindex M-k
  833. @pindex calc-copy-as-kill
  834. @kindex C-w
  835. @pindex calc-kill-region
  836. @kindex M-w
  837. @pindex calc-copy-region-as-kill
  838. @cindex Kill ring
  839. @dfn{Kill} commands are Emacs commands that insert text into the
  840. ``kill ring,'' from which it can later be ``yanked'' by a @kbd{C-y}
  841. command.  Three common kill commands in normal Emacs are @kbd{C-k}, which
  842. kills one line, @kbd{C-w}, which kills the region between mark and point,
  843. and @kbd{M-w}, which puts the region into the kill ring without actually
  844. deleting it.  All of these commands work in the Calculator, too.  Also,
  845. @kbd{M-k} has been provided to complete the set; it puts the current line
  846. into the kill ring without deleting anything.
  847. X
  848. The kill commands are unusual in that they pay attention to the location
  849. of the cursor in the Calculator buffer.  If the cursor is on or below the
  850. bottom line, the kill commands operate on the top of the stack.  Otherwise,
  851. they operate on whatever stack element the cursor is on.  Calc's kill
  852. commands always operate on whole stack entries.  (They act the same as their
  853. standard Emacs cousins except they ``round up'' the specified region to
  854. encompass full lines.)  The text is copied into the kill ring exactly as
  855. it appears on the screen, including line numbers if they are enabled.
  856. X
  857. A numeric prefix argument to @kbd{C-k} or @kbd{M-k} affects the number
  858. of lines killed.  A positive argument kills the current line and @cite{n-1}
  859. lines below it.  A negative argument kills the @cite{-n} lines above the
  860. current line.  Again this mirrors the behavior of the standard Emacs
  861. @kbd{C-k} command.  Although a whole line is always deleted, @kbd{C-k}
  862. with no argument copies only the number itself into the kill ring, whereas
  863. @kbd{C-k} with a prefix argument of 1 copies the number with its trailing
  864. newline.
  865. X
  866. @node Yanking Into Stack, Grabbing From Buffers, Killing From Stack, Kill and Yank
  867. @section Yanking into the Stack
  868. X
  869. @noindent
  870. @kindex C-y
  871. @pindex calc-yank
  872. The @kbd{C-y} command yanks the most recently killed text back into the
  873. Calculator.  It pushes this value onto the top of the stack regardless of
  874. the cursor position.  In general it re-parses the killed text as a number
  875. or formula (or list of these separated by commas or newlines).  However if
  876. the thing being yanked is something that was just killed from the Calculator
  877. itself, its full internal structure is yanked.  For example, if you have
  878. set the floating-point display mode to show only four significant digits,
  879. then killing and re-yanking 3.14159 (which displays as 3.142) will yank the
  880. full 3.14159, even though yanking it into any other buffer would yank the
  881. number in its displayed form, 3.142.  (Since the default display modes
  882. show all objects to their full precision, this feature normally makes no
  883. difference.)
  884. X
  885. @node Grabbing From Buffers, Yanking Into Buffers, Yanking Into Stack, Kill and Yank
  886. @section Grabbing from Other Buffers
  887. X
  888. @noindent
  889. @kindex M-# g
  890. @pindex calc-grab-region
  891. The @kbd{M-# g} (@code{calc-grab-region}) command takes the text between
  892. point and mark in the current buffer and attempts to parse it as a
  893. vector of values.  Basically, it wraps the text in vector brackets
  894. @samp{[ ]} unless the text already is enclosed in vector brackets,
  895. then reads the text as if it were an algebraic entry.  The contents
  896. of the vector may be numbers, formulas, or any other Calc objects.
  897. X
  898. A numeric prefix argument grabs the specified number of lines around
  899. point, ignoring the mark.  A positive prefix grabs from point to the
  900. @cite{n}th following newline (so that @kbd{M-1 M-# g} grabs from point
  901. to the end of the current line); a negative prefix grabs from points
  902. back to the @cite{n+1}st preceding newline.  In both cases, the text
  903. that is grabbed is exactly the same as the text that @kbd{C-k} would
  904. delete given that prefix argument.
  905. X
  906. A prefix of zero grabs the current line; point may be anywhere on the
  907. line.
  908. X
  909. A plain @kbd{C-u} prefix interprets the region between point and mark
  910. as a single number or formula rather than a vector.  For example,
  911. @kbd{M-# g} on the text @samp{2 a b} produces the vector of three
  912. values @samp{[2, a, b]}, but @kbd{C-u M-# g} on the same region
  913. reads a formula which is a product of three things:  @samp{2 a b}.
  914. X
  915. If a different language has been specified (@pxref{Language Modes}),
  916. the grabbed text will be interpreted according to that language.
  917. If the @kbd{M-# g} command works successfully, it does an automatic
  918. @kbd{M-# c} to enter the Calculator buffer.
  919. X
  920. @kindex M-# r
  921. @pindex calc-grab-rectangle
  922. The @kbd{M-# r} (@code{calc-grab-rectangle}) command takes the text between
  923. point and mark and attempts to parse it as a matrix.  If point and mark
  924. are both in the leftmost column, the lines in between are parsed in their
  925. entirety.  Otherwise, point and mark define the corners of a rectangle
  926. whose contents are parsed.
  927. X
  928. Each line of the grabbed area becomes a row of the matrix.  The result
  929. will actually be a vector of vectors, which Calc will treat as a matrix
  930. only if every row contains the same number of values.
  931. X
  932. If a line contains a portion surrounded by square brackets (or curly
  933. braces), that portion is interpreted as a vector which becomes a row
  934. of the matrix.  Any text surrounding the bracketed portion on the line
  935. is ignored.
  936. X
  937. Otherwise, the entire line is interpreted as a row vector as if it
  938. were surrounded by square brackets.  Leading line numbers (in the
  939. format used in the Calc stack buffer) are ignored.  If you wish to
  940. force this interpretation (even if the line contains bracketed
  941. portions), give a negative numeric prefix argument to the
  942. @kbd{M-# r} command.
  943. X
  944. If you give a numeric prefix argument of zero or plain @kbd{C-u}, each
  945. line is instead interpreted as a single formula which is converted into
  946. a one-element vector.  Thus the result of @kbd{C-u M-# r} will be a
  947. one-column matrix.  For example, suppose one line of the data is the
  948. expression @samp{2 a}.  A plain @kbd{M-# r} will interpret this as
  949. @samp{[2 a]}, which in turn is read as a two-element vector that forms
  950. one row of the matrix.  But a @kbd{C-u M-# r} will interpret this row
  951. as @samp{[2*a]}.
  952. X
  953. If you give a positive numeric prefix argument @var{n}, then each line
  954. will be split up into columns of width @var{n}; each column is parsed
  955. separately as a matrix element.  If a line contained @samp{2 +/- 3 4 +/- 5},
  956. then grabbing with a prefix argument of 8 would correctly split the
  957. line into two error forms.
  958. X
  959. @xref{Matrix Functions}, to see how to pull the matrix apart into its
  960. constituent rows and columns.  (If it is a @c{$1\times1$}
  961. @asis{1x1} matrix, just hit @kbd{v u}
  962. (@code{calc-unpack}) twice.)
  963. X
  964. @kindex M-# :
  965. @kindex M-# _
  966. @pindex calc-grab-sum-across
  967. @pindex calc-grab-sum-down
  968. @cindex Summing rows and columns of data
  969. The @kbd{M-# :} (@code{calc-grab-sum-down}) command is a handy way to
  970. grab a rectangle of data and sum its columns.  It is equivalent to
  971. typing @kbd{M-# r}, followed by @kbd{V R : +} (the vector reduction
  972. command that sums the columns of a matrix; @pxref{Reducing}).  The
  973. result of the command will be a vector of numbers, one for each column
  974. in the input data.  The @kbd{M-# _} (@code{calc-grab-sum-across}) command
  975. similarly grabs a rectangle and sums its rows by executing @kbd{V R _ +}.
  976. X
  977. For example, suppose we have a column of numbers in a file which we
  978. wish to sum.  Go to one corner of the column and press @kbd{C-@@} to
  979. set the mark; go to the other corner and type @kbd{M-# :}.  Since there
  980. is only one column, the result will be a vector of one number, the sum.
  981. (You can type @kbd{v u} to unpack this vector into a plain number if
  982. you want to do further arithmetic with it.)
  983. X
  984. To compute the product of the column of numbers, we would have to do
  985. it ``by hand'' since there's no special grab-and-multiply command.
  986. Use @kbd{M-# r} to grab the column of numbers into the calculator in
  987. the form of a column matrix.  The statistics command @kbd{u *} is a
  988. handy way to find the product of a vector or matrix of numbers.
  989. @xref{Statistical Operations}.  Another approach would be to use
  990. general-purpose vector commands, like @kbd{v t} to transpose the data
  991. into a row matrix, @kbd{v u} to unpack this into a simple vector
  992. (recall, a one-row matrix is a vector of a single vector), and
  993. @kbd{V R *} to compute the product of the vector.
  994. X
  995. @node Yanking Into Buffers, X Cut and Paste, Grabbing From Buffers, Kill and Yank
  996. @section Yanking into Other Buffers
  997. X
  998. @noindent
  999. @kindex y
  1000. @pindex calc-copy-to-buffer
  1001. The plain @kbd{y} (@code{calc-copy-to-buffer}) command inserts the number
  1002. at the top of the stack into the most recently used normal editing buffer.
  1003. (More specifically, this is the most recently used buffer which is displayed
  1004. in a window and whose name does not begin with @samp{*}.  If there is no
  1005. such buffer, this is the most recently used buffer except for Calculator
  1006. and Calc Trail buffers.)  The number is inserted exactly as it appears and
  1007. without a newline.  (If line-numbering is enabled, the line number is
  1008. normally not included.)  The number is @emph{not} removed from the stack.
  1009. X
  1010. With a prefix argument, @kbd{y} inserts several numbers, one per line.
  1011. A positive argument inserts the specified number of values from the top
  1012. of the stack.  A negative argument inserts the @cite{n}th value from the
  1013. top of the stack.  An argument of zero inserts the entire stack.  Note
  1014. that @kbd{y} with an argument of 1 is slightly different from @kbd{y}
  1015. with no argument; the former always copies full lines, whereas the
  1016. latter strips off the trailing newline.
  1017. X
  1018. With a lone @kbd{C-u} as a prefix argument, @kbd{y} @emph{replaces} the
  1019. region in the other buffer with the yanked text, then quits the
  1020. Calculator, leaving you in that buffer.  A typical use would be to use
  1021. @kbd{M-# g} to read a region of data into the Calculator, operate on the
  1022. data to produce a new matrix, then type @kbd{C-u y} to replace the
  1023. original data with the new data.  One might wish to alter the matrix
  1024. display style (@pxref{Vector and Matrix Formats}) or change the current
  1025. display language (@pxref{Language Modes}) before doing this.  Also, note
  1026. that this command replaces a linear region of text (as grabbed by
  1027. @kbd{M-# g}, not a rectangle (as grabbed by @kbd{M-# r}.@refill
  1028. X
  1029. If the editing buffer is in overwrite (as opposed to insert) mode,
  1030. and the @kbd{C-u} prefix was not used, then the yanked number will
  1031. overwrite the characters following point rather than being inserted
  1032. before those characters.  The usual conventions of overwrite mode
  1033. are observed; for example, characters will be inserted at the end of
  1034. a line rather than overflowing onto the next line.  Yanking a multi-line
  1035. object such as a matrix in overwrite mode overwrites the next @var{n}
  1036. lines in the buffer, lengthening or shortening each line as necessary.
  1037. Finally, if the thing being yanked is a simple integer or floating-point
  1038. number (like @samp{-1.2345e-3}) and the characters following point also
  1039. make up such a number, then Calc will replace that number with the new
  1040. number, lengthening or shortening as necessary.  The concept of
  1041. ``overwrite mode'' has thus been generalized from overwriting characters
  1042. to overwriting one complete number with another.
  1043. X
  1044. @kindex M-# y
  1045. The @kbd{M-# y} key sequence is equivalent to @kbd{y} except that
  1046. it can be typed anywhere, not just in Calc.  This provides an easy
  1047. way to guarantee that Calc knows which editing buffer you want to use!
  1048. X
  1049. @node X Cut and Paste, Editing Stack Entries, Yanking Into Buffers, Kill and Yank
  1050. @section X Cut and Paste
  1051. X
  1052. @noindent
  1053. If you are using Emacs with the X window system, there is an easier
  1054. way to move small amounts of data into and out of the calculator:
  1055. Use the mouse-oriented cut and paste facilities of X.
  1056. X
  1057. The default bindings for a three-button mouse cause the left button
  1058. to move the Emacs cursor to the given place, the right button to
  1059. select the text between the cursor and the clicked location, and
  1060. the middle button to yank the selection into the buffer at the
  1061. clicked location.  So, if you have a Calc window and an editing
  1062. window on your Emacs screen, you can use left-click/right-click
  1063. to select a number, vector, or formula from one window, then
  1064. middle-click to paste that value into the other window.  When you
  1065. paste text into the Calc window, Calc interprets it as an algebraic
  1066. entry.  It doesn't matter where you click in the Calc window; the
  1067. new value is always pushed onto the top of the stack.
  1068. X
  1069. The @code{xterm} program that is typically used for general-purpose
  1070. shell windows in X interprets the mouse buttons in the same way.
  1071. So you can use the mouse to move data between Calc and any other
  1072. Unix program.  One nice feature of @code{xterm} is that a double
  1073. left-click selects one word, and a triple left-click selects a
  1074. whole line.  So you can usually transfer a single number into Calc
  1075. just by double-clicking on it in the shell, then middle-clicking
  1076. in the Calc window.
  1077. X
  1078. @node Editing Stack Entries, , X Cut and Paste, Kill and Yank
  1079. @section Editing Stack Entries
  1080. X
  1081. @noindent
  1082. @kindex `
  1083. @pindex calc-edit
  1084. @pindex calc-edit-finish
  1085. @cindex Editing the stack with Emacs
  1086. The backquote, @kbd{`} (@code{calc-edit}) command creates a temporary
  1087. buffer (@samp{*Calc Edit*}) for editing the top-of-stack value using
  1088. regular Emacs commands.  With a numeric prefix argument, it edits the
  1089. specified number of stack entries at once.  (An argument of zero edits
  1090. the entire stack; a negative argument edits one specific stack entry.)
  1091. X
  1092. When you are done editing, press @kbd{M-# M-#} to finish and return
  1093. to Calc.  The @key{RET} and @key{LFD} keys also work to finish most
  1094. sorts of editing, though in some cases Calc leaves @key{RET} with its
  1095. usual meaning (``insert a newline'') if it's a situation where you
  1096. might want to insert new lines into the editing buffer.  The traditional
  1097. Emacs ``finish'' key sequence, @kbd{C-c C-c}, also works to finish
  1098. editing and may be easier to type, depending on your keyboard.
  1099. X
  1100. When you finish editing, the Calculator parses the lines of text in
  1101. the @samp{*Calc Edit*} buffer as numbers or formulas, replaces the
  1102. original stack elements in the original buffer with these new values,
  1103. then kills the @samp{*Calc Edit*} buffer.  The original Calculator buffer
  1104. continues to exist during editing, but for best results you should be
  1105. careful not to change it until you have finished the edit.  You can
  1106. also cancel the edit by pressing @kbd{M-# x}.
  1107. X
  1108. If you give a prefix argument to @kbd{M-# M-#} (or @kbd{C-c C-c}),
  1109. Calc will not kill the @samp{*Calc Edit*} buffer.  You can switch
  1110. back to that buffer and continue editing if you wish.  However, you
  1111. should understand that if you initiated the edit with @kbd{`}, the
  1112. @kbd{M-# M-#} operation will be programmed to replace the top of the
  1113. stack with the new edited value, and it will do this even if you have
  1114. rearranged the stack in the meanwhile.  This is not so much of a problem
  1115. with other editing commands, though, such as @kbd{s e}
  1116. (@code{calc-edit-variable}; @pxref{Operations on Variables}).
  1117. X
  1118. If the @code{calc-edit} command involves more than one stack entry,
  1119. each line of the @samp{*Calc Edit*} buffer is interpreted as a
  1120. separate formula.  Otherwise, the entire buffer is interpreted as
  1121. one formula, with line breaks ignored.  (You can use @kbd{C-o} or
  1122. @kbd{C-q C-j} to insert a newline in the buffer without pressing @key{RET}.)
  1123. X
  1124. The @kbd{`} key also works during numeric or algebraic entry.  The
  1125. text entered so far is moved to the @code{*Calc Edit*} buffer for
  1126. more extensive editing than is convenient in the minibuffer.
  1127. X
  1128. The @kbd{s e} (@code{calc-edit-variable}) command edits the stored
  1129. value of a variable.  @xref{Operations on Variables}.
  1130. X
  1131. @node Keypad Mode, Embedded Mode, Kill and Yank, Introduction
  1132. @chapter ``Keypad'' Mode
  1133. X
  1134. @noindent
  1135. @kindex M-# k
  1136. @pindex calc-keypad
  1137. The @kbd{M-# k} (@code{calc-keypad}) command starts the Calculator
  1138. and displays a picture of a Calculator-style keypad.  If you are using
  1139. the X window system, you can click on any of the ``keys'' in the
  1140. keypad using the left mouse button to operate the calculator.
  1141. The original window remains the selected window; in keypad mode
  1142. you can type in your file while simultaneously performing
  1143. calculations with the mouse.
  1144. X
  1145. @pindex full-calc-keypad
  1146. If you have used @kbd{M-# b} first, @kbd{M-# k} instead invokes
  1147. the @code{full-calc-keypad} command, which takes over the whole
  1148. Emacs screen and displays the keypad, the Calc stack, and the Calc
  1149. trail all at once.  This mode would normally be used when running
  1150. Calc standalone (@pxref{Standalone Operation}).
  1151. X
  1152. If you aren't using the X window system, you must switch into
  1153. the @samp{*Calc Keypad*} window, place the cursor on the desired
  1154. ``key,'' and type @key{SPC} or @key{RET}.  If you think this
  1155. is easier than using Calc normally, go right ahead.
  1156. X
  1157. Calc commands are more or less the same in keypad mode.  Certain
  1158. keypad keys differ slightly from the corresponding normal Calc
  1159. keystrokes; all such deviations are described below.
  1160. X
  1161. Keypad Mode includes many more commands than will fit on the keypad
  1162. at once.  Click the right mouse button [@code{calc-keypad-menu}]
  1163. to switch to the next menu.  The bottom five rows of the keypad
  1164. SHAR_EOF
  1165. true || echo 'restore of calc.texinfo failed'
  1166. fi
  1167. echo 'End of  part 50'
  1168. echo 'File calc.texinfo is continued in part 51'
  1169. echo 51 > _shar_seq_.tmp
  1170. exit 0
  1171. exit 0 # Just in case...
  1172. -- 
  1173. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1174. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1175. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1176. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1177.