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?
    – giordano
    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.
    – Name
    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.
    – giordano
    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").
    – Name
    Jan 21, 2015 at 13:21
  • Uh, did you mean "macro" instead of "environment"?
    – giordano
    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")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.