5

Q: how can I test if point is inside LaTeX ``quotes,'' and how can I get the bounds of that quote?

LaTeX quotation marks are kooky, typesetting ``text inside a double-quote'' and `text inside a single-quote' for the standard "text inside a double-quote" and 'text inside a single-quote'.

I'd like to detect if point is inside such a quote (either single or double) and, ideally, return the bounds of the quoted passage. However, syntax-ppss does not appear to recognize such passages as strings (re: elements 3 and 8 in the returned list; see parse-partial-sexp for details).

Is there a predicate function baked-in to AUCTeX to do so? Many of their functions also have curious naming conventions, so I may have missed it. If no such function already exists, what alternatives would work?

  • Similar to the answer of @abo-abo if you evaluate (font-latex-faces-present-p '(font-latex-string-face)) inside a double quotation, you get true, otherwise false. – Name Feb 13 '15 at 0:21
3

You need this:

(defun latex-quote-bnd ()
  (save-excursion
    (beginning-of-line)
    (when (font-latex-match-quotation
           (line-end-position))
      (cons
       (match-beginning 0)
       (match-end 0)))))

I found font-latex-match-quotation simply by following describe-face.

  • 1
    Thanks for the find. So far, though, it's a partial solution: it doesn't work for `single quotes', and it doesn't work for multi-line passages when point is not on the line with the opening ``. – Dan Feb 12 '15 at 16:48
  • In addition font-locking is lazy, in the sense that a not already visited region has no font face, so looking at it is pretty useless in that case. – giordano Feb 12 '15 at 23:17
  • 1
    It'd be more robust to just search for the quotes around point, and check that they're valid. – Malabarba Feb 13 '15 at 1:35
  • @Malabarba, I didn't even know about those type of quotes in LaTeX. Hence, just providing a proof-of-concept as a starting point, not trying to solve the whole thing. – abo-abo Feb 13 '15 at 8:44
  • @abo-abo Sure. Just trying to help. ;-) – Malabarba Feb 13 '15 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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