cdominik / cdlatex

Fast input methods to enter LaTeX environments and math with GNU Emacs
231 stars 48 forks source link

BUG: left right parenthesis are not expanded properly (in org mode) #34

Closed roiholtzman closed 1 year ago

roiholtzman commented 2 years ago

There are a few scenarios in which left right parenthesis are not expanded properly in org mode.

Inline math mode

Typing an inline math mode with $, expanding lr( does not work. Typing lr( automatically closes the parenthesis, i.e. I get lr(|), and then hitting tab puts the cursor out of the parenthesis, i.e. lr()|. However when doing the same with lr[, it also closes the parenthesis automatically to lr[], but the hitting tab expand it properly to $\left[ | \right]$.

yas snippets

When typing a yas-snippet, with multiple insertion place, like \frac{}{}, I get that cdlatex is not expanded properly when the cursor is in the first spot, i.e. when \frac{|}{}. However, this happens only for lr< and lr{. These lr( and lr[ are expanded properly when hitting tab. I mean, when it does not work I get after expanding the snippet, and typing lr< and tab

$\frac{lr<}{|}$

and when doing this with lr( I get

$\frac{\left( | \right)}{}$

where the problem might be

It seems to me like the problem might be related in the special role of < and {, in this function

(defun cdlatex-lr-pair ()
  "Insert a \\left-\\right pair of parens."
  (interactive)
  (let* ((paren (char-to-string (preceding-char)))
         (close (cdr (assoc paren cdlatex-parens-pairs)))
         (paren1 paren)
         (close1 close))
    (if (string= paren "<") (setq paren1 "\\langle" close1 "\\rangle"))
    (if (string= paren "{") (setq paren1 "\\{" close1 "\\}"))
    (backward-delete-char 1)
    (if (and (stringp cdlatex-paired-parens)
             (string-match (regexp-quote paren) cdlatex-paired-parens)
             (string= close (char-to-string (following-char))))
        ; parens are inserted paired, and there is already a closing parenthesis
        (delete-char 1))
    (insert "\\left" paren1 " ? \\right" close1)
    (cdlatex-position-cursor)))

However, I do not know how to solve it. In case anyone does, it would be nice.

Of course, this does not explain the 1st issue with the inline math.

danielfleischer commented 2 years ago

I can't reproduce. I think there are some packages on your side that have adverse interaction. Start with giving more details: what Emacs version, orgmode version, cdlatex version. Do you have org-cdlatex-mode enabled? try disable yasnippet and see if you still have issues. What do you use for parenthesis completion, electric-pair-mode? try to disable it and see what happens.

cdominik commented 1 year ago

I am also not able to reproduce the problem.