By-Product of Research

We continued to do research and got annoyed by the need to promote inline math environment to equation/align/equation*/align* environment repeatedly, so we quickly wrote some elisp code. (lol, totally procedural programming in Lisp.) We also defined interactive functions based on this one, but they are not posted.

We do not personally use the $$...$$ environment, but the code treats this as well. [Usage: Put point inside $...$ and execute. Then $...$ changes into \begin{stuff}...\end{stuff}. It also takes care of putting punctuation marks INSIDE the environment as suggested by Knuth... It probably should also deal with white space after punctuation, but we forgot to implement it.]

(defun LaTeX-promote-$(environment) "promote$...$to environment." (when (texmathp) (let ((dollar (car texmathp-why))) (when (or (equal dollar "$") (equal dollar ""))
(save-excursion
(search-backward dollar)
(delete-char (length dollar))
(insert "\n\\begin{" environment "}\n  ")
(search-forward dollar)
(backward-delete-char (length dollar))
;; dealing with trailing punctuation...
(while (equal (char-syntax (char-after)) ?\.)
(forward-char))
(insert "\n\\end{" environment "}\n"))))))

Crash course on Emacs

For people less familiar with Emacs than we.
Let M = Alt, C = Ctrl and S=Shift on PC. Define equivalents for Mac yourselves.
Interactive functions are those functions with (interactive ...) in its body. (It has to be the first thing after list of arguments and the optional doc string, we believe.) The rest of the functions are non-interactive. See manual for interactive for more details. (To see manual for function-like things, press C-h f, then name of function-like thing. Here type interactive. C-h is always your friend.)

One can run interactive functions by M-x function-name. One cannot run non-interactive functions in this way. However one can always evaluate elisp expressions directly by pressing M-: and typing elisp expression into the buffer that appears.

Here are the two interactive functions we use that are based on the non-interactive one above.

(defun LaTeX-promote-to-equation (&optional f)
"promote $...$ to equation* environment. If f is non-nil, promote to equation environment."
(interactive "P")
(LaTeX-promote-(concat "equation" (if f "" "*")))) (defun LaTeX-promote-to-align (&optional f) "promote...$to equation* environment. If f is non-nil, promote to equation environment." (interactive "P") (LaTeX-promote-$ (concat "align" (if f "" "*"))))

How does one supply arguments to an interactive function? For example C-u 42 M-x LaTeX-promote-to-equation will set f to 42. If 42 is omitted, f still gets a value which defaults to 4 (magic!). This is called numerical prefix and this is one way to supply arguments. Again see manual for interactive for other means and more details.

Then one may bind keys to avoid typing M-x LaTeX-promote-to-align repeatedly, but we haven't figured out a good key binding. How about C-c S-<up>?

To check current key map so that one knows what bindings are unused, one may look into the package which-key. To bind key, one may look into the packages bind-key and use-package.

To install packages, go to Melpa and follow instructions there. It tells one to configure a package repository