I have been having a problem where I want an up-sexp command that treats paired delimiters like $ in LaTeX-mode just as if they were pairs of balanced parentheses. There are hacks I can use that get me some useful information, but I'd much rather use a built-in command, if one exists.

My problem is that functions like syntax-ppss don't care about paired delimiters: for example (nth 0 syntax-ppss) returns 0 if I'm in paired delimiters but no parentheses, and there's no special part of the list for paired delimiters like there is for strings. Is there any standard way to get this information?

sp-up-sexp and similar commands don't help me, because they also ignore paired delimiters.

Of course, I can write a function to do something like count $s in my buffer up to the point, but the problem with this approach is that, for example, $$ is a separate paired delimiter in LaTeX. It's not a practical problem for me because I never use that notation (it's deprecated and very much not recommended), but I want to get this information from a syntax parser that understands the whole syntax table, not from a hack.

  • 1
    Warning: it's basically impossible to parse (La)TeX this way. That's probably why the paired-delimiter "thingy" in syntax-tables is so poorly supported (and completely ignored by parse-partial-sexp. So to stay sane you'll probably want to only count $ (and $$) between point and the nearest "open-like thing" you can find. – Stefan May 10 '19 at 20:59
  • Ahhhh, I see. I think that I will use something involving multiple cases and texmathp in that case, and just live with weird behavior regarding parentheses. – Zorgoth May 10 '19 at 23:29
  • Is there a way to convince syntax-ppss that the buffer has changed without actually changing the buffer or seriously messing up its cache? As in, to add hallucinatory braces around math sections. EDIT: I don't think I want to do this, actually. – Zorgoth May 10 '19 at 23:45

Your Answer

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

Browse other questions tagged or ask your own question.