1

This question is related to how to detect if inside a LaTeX math environment?.

How to do the correct settings in .emacs in such a way that the variable texmathp takes the value t (like in math formulae) when the cursor is at the following commands?

\newpage ;command for creating a new page \label{blabla} \cite{blabla} \ref{blabla} \footnote{blabla} \section{blabla} \chapter{blabla} \\ ;command for creating a new line 

In the answer it was mentioned that one can use texmathp-tex-commands to achieve such things. Let me ask how to do it for the above formulae.

5
  • 1
    TeX-current-macro returns the name of the current macro point is on, is it what you need? Commented Jan 18, 2015 at 12:08
  • @giordano Let me say no, I just want a Boolean variable which tells me if I am at a LaTeX command (like texmathp for math formulae). T. Verron says in that answer that one can do such things with texmathp by adding new values to texmathp-tex-commands. I just want to see how to do it. Commented Jan 18, 2015 at 12:15
  • 2
    Why do you want to abuse texmathp? TeX-current-macro is there for that reason, returns the name of the macro if there is one at point, nil otherwise, so it can be used as a boolean. Commented Jan 18, 2015 at 20:17
  • Thanks @giordano I am now persuaded that your approach is far better than what I had in mind. Could you please convert your comment to an answer in order that I may be able to mark it as accepted (for example printing the message in the echo area "Inside LaTeX environment" if TeX-current-macro is non-nil otherwise printing "Outside LaTeX environment"). Commented Jan 21, 2015 at 13:21
  • Uh, did you mean "macro" instead of "environment"? Commented Jan 22, 2015 at 5:04

1 Answer 1

2

The function you are looking for is TeX-current-macro. Here is an example of how you can use it to print a message depending on whether point is inside or outside a TeX macro:

(defun mg-TeX-current-macro-p () (interactive) (if (TeX-current-macro) (message "Inside a LaTeX macro") (message "Outside a LaTeX macro"))) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.