7

I'm using vim to edit LaTeX code, and I'm often writing intervals like (a,b] but this messes with other vim features. For instance,

  • Jumping with %: if I have something like \phi((a,b]), the final ) will match the second ( and some closing parenthesis later in the code will match the first.
  • There's a feature (I'm not sure if it's specific to vimtex or just a feature of vim) where ]] closes any open delimiters, and this makes that behave wrongly - it'll try to close the ) from many lines ago.
  • The tsd/csd/dsd features of vimtex which toggle/change/delete surrounding delimiters don't work (I think csd and dsd are extensions of vim-surround but I'm not sure). In particular, either they select the wrong delimiters or do nothing at all.

Currently I'm putting )s in comments to mitigate this. This solves the problem of parentheses later in the file matching wrongly, but matching in the same line doesn't work (and things like tsd from vimtex don't work properly).

Is there any better solution, or a standard solution for this kind of problem? Ideally this would deal with [a,b) also.

5
  • 3
    This is a very difficult problem, actually. It is very hard to know how to match parantheses if the start and end paranthesis is of different type. I remember we had a discussion about this at a vimtex issue once. You could try to search the issue threads and see if you find anything, or you could create a new issue. May 23, 2018 at 6:29
  • @KarlYngveLervåg I think this is the relevant issue?
    – B. Mehta
    May 23, 2018 at 19:31
  • Yes, that's relevant. although the topic is indentation. The point is still, as mentioned above, that it is inherently very difficult to get this right for unbalanced parantheses. May 24, 2018 at 6:01
  • A workaround might be to use the \DeclarePairedDelimiter command from the mathtools package to then just write like \leftopenint{a, b}. I learned about this in this question
    – Jan
    May 28, 2019 at 7:52
  • 1
    @Jan I quite like this solution! If you'd like to write it as an answer I'm happy to accept it.
    – B. Mehta
    May 28, 2019 at 17:02

1 Answer 1

1

A workaround might be to use the \DeclarePairedDelimiter command from the mathtools package to then just write like \leftopenint{a, b}. See the accepted answer to this question.

\documentclass{minimal}
\usepackage{mathtools}
\DeclarePairedDelimiter\leftopenint{(}{]}
\DeclarePairedDelimiter\rghtopenint{[}{)}

\begin{document}
  \begin{equation*}
   \leftopenint{-\infty, \frac{1}{N} } \cup \rghtopenint*{\frac{1}{N}, \infty}
  \end{equation*}
\end{document}

which gives me what is posted below. Note that the * makes the delimiters scale.

enter image description here

Just noted the asymmetric appearance of the brackets in the header also breaks syntax highlighting and the commands like closing of matching environments. I could fix this with outsourcing these definitions to a separate file and then use \include...

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.