2

Q: how do I get the bounds of a LaTeX footnote?

I'd like to be able to detect, programmatically, if point is inside a LaTeX footnote environment. Ideally, I'd like to be able to extract the beginning and end points of the footnote. How would one do so?

I'm aware of the TeX-current-macro function, but it's not quite what I need. If, for example, point is inside a citation inside a footnote, it will stop at detecting the citation. It also does not provide the bounds.

Dan
  • 32,584
  • 6
  • 98
  • 168

1 Answers1

2

I couldn't find anything ready-made, but it turns out not to be too hard to write up with a combination of TeX-current-macro, TeX-find-macro-start, and TeX-find-macro-boundaries. This function will also serve as a predicate, and could be adapted to other kinds of macros pretty easily:

(defun LaTeX-footnote-bounds ()
  "Return bounds of a LaTeX footnote as a cons cell, or nil if
not in a footnote."
  (let ((macro (TeX-current-macro)))
    (when macro
      (save-excursion
        (while (not (equal "footnote" macro))
          (goto-char (- (TeX-find-macro-start)
                        (if (equal "footnote" (setq macro (TeX-current-macro)))
                            0
                          1))))
        (TeX-find-macro-boundaries)))))
Dan
  • 32,584
  • 6
  • 98
  • 168