File: texmathp.el.html

This code provides a function to determine if point in a buffer is
 inside a (La)TeX math environment. This is not trivial since many
 different ways are used to switch between the two. Examples:

   \begin{equation} ... \end{equation}
   $ ... $
   $$ ... $$
   M-x ... \ ( ... \)
   \ensuremath{...}
   \mbox{...}

 To install, put this file on your load-path and compile it.

 To use this in a Lisp program, do

    (require 'texmathp)

 You can then write code like this:

    (if (texmathp) ...)

 The call to texmathp leaves some extra information in the
 variable texmathp-why. It's value is a cons cell (MATCH . POSITION),
 specifying which command at what position is responsible for math
 mode being on or off.

 To configure which macros and environments influence LaTeX math
 mode, customize the variable texmathp-tex-commands. By default
 it recognizes the plain TeX and LaTeX core as well as AMS-LaTeX
 and packages mathtools, empheq and breqn (see the variable
 texmathp-tex-commands-default, also as an example).

 To try out the code interactively, use M-x texmathp RET.

 Of course, in order to work this function has to assume that the
 LaTeX above point is syntactically correct. In particular:

 o The different math delimiters are paired correctly. Thus if
   you do things like "\\begin{equation} $" or "\\[ ... \\)"
   the result of (texmathp) is undefined. It is in fact possible
   in LaTeX to pair M-x with $$ and \( with $, but this will confuse ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   texmathp (and human readers as well).

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
 o However, texmathp will correctly work with nested delimiters. ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   Something like the following will be parsed correctly at any point:

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
      \begin{equation} ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
         x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
      \end{equation}

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
 o texmathp is somewhat forgiving if you have an empty line inside ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   the current math environment, which is not legal in TeX but may ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   easily happen during editing. Depending upon the variable ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   `texmathp-search-n-paragraphs' several paragraphs are checked ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   backwards, by default 2. Paragraph here means something limited ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   by an empty line. ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
--------------------------------------------------------------------------

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
 BUGS:

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
 o If any of the the special macros like \mbox or \ensuremath has ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   optional arguments, math mode inside these optional arguments is ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
   *not* influenced by the macro.

( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\)
 o Nested \(\) and \[\ ( with $$ and \( with $, but this will confuse texmathp (and human readers as well).

o However, texmathp will correctly work with nested delimiters. Something like the following will be parsed correctly at any point:

\begin{equation} x = y \mbox{abc \ensuremath{\alpha} cba $2^3$} \end{equation}

o texmathp is somewhat forgiving if you have an empty line inside the current math environment, which is not legal in TeX but may easily happen during editing. Depending upon the variable `texmathp-search-n-paragraphs' several paragraphs are checked backwards, by default 2. Paragraph here means something limited by an empty line. --------------------------------------------------------------------------

BUGS:

o If any of the the special macros like \mbox or \ensuremath has optional arguments, math mode inside these optional arguments is *not* influenced by the macro.

o Nested \(\) and \[\) can confuse texmathp. It returns nil at AAA
   in the following examples:
 M-x x=y \mbox{abc \(\alpha\) cba} AAA \ ( x=y \mbox{abc \(\alpha\) cba} AAA \)
 M-x x=y \begin{minipage}{3cm} abc \[\alpha\ ( x=y \begin{minipage}{3cm} abc \[\alpha\) cba \end{minipage} AAA \]

 o In the "text column" of cases* environment, texmathp doesn't
   consider it's non-math mode. The same applies for variants of
   cases* environents, both provided by mathtools package.

--------------------------------------------------------------------------

Defined variables (6)

texmathp-allow-detached-argsNon-nil means, allow arguments of macros to be detached by whitespace.
texmathp-search-n-paragraphsNumber of paragraphs to check before point.
texmathp-syntax-tableSyntax table used while texmathp is parsing.
texmathp-tex-commandsList of environments and macros influencing (La)TeX math mode.
texmathp-tex-commands-defaultThe default entries for ‘texmathp-tex-commands’, which see.
texmathp-whyAfter a call to ‘texmathp’ this variable shows why math-mode is on or off.

Defined functions (5)

texmathp()
texmathp-compile()
texmathp-match-environment(BOUND)
texmathp-match-macro(BOUND)
texmathp-match-switch(BOUND)

Defined faces (0)