Useful or not, from you.
cdlatex CDLaTeX interferes with smartparens on LaTeX-mode

When I activate cdlatex-mode on a LaTeX layer document smartparens stops working. When I input ( I don't get a matching ). The error I get is Search failed: there is an unmatched expression somewhere or we are at the beginning/end of file.

When I use cdlatex in org-mode, everything works fine.

That's a useful answer
Without any help

Hi Carsten, I managed to fix this issue (partially).

I think that what solves is to turn on cdlatex mode for latex mode, and org-cdlatex-mode for org-mode.

Now, I have a problem that TAB does not get out of parenthesis. When I type ( I get automatically the closing ) then I type some characters, and when I hit TAB it does not go out.

Do you know what is the problem?

I am using spacemacs, and this the relevant part of my configuration:

  (add-hook 'LaTeX-mode-hook 'turn-on-cdlatex) 

  ;; add toggle equations for latex mode
  ;; (eval-after-load 'LaTeX-mode `(evil-define-key 'normal python-mode-map [f5] 'python-shell-send-buffer))

  ;; latex stuff for org mode
  ;; cdlatex
  (add-hook 'org-mode-hook 'turn-on-org-cdlatex)
  ;; latex mode
  ;; (add-hook 'org-mode-hook 'LaTeX-math-mode)

  ;; cdlatex math keybindings
  (setq cdlatex-math-symbol-alist
        '((?< ("\\leftarrow" "\\Leftarrow" "\\longleftarrow" "\\Longleftarrow"))
          (?> ("\\rightarrow" "\\Rightarrow" "\\longrightarrow" "\\Longrightarrow"))

    ;; smartparens
  (require 'smartparens-config)
  (with-eval-after-load 'smartparens
    (sp-with-modes 'latex-mode
      (sp-local-pair "\\(" "\\)")
      (sp-local-pair "\\[" "\\]")
      (sp-local-pair "$" "$")
      (sp-local-pair "'" "'" :actions '(rem))
      (sp-local-pair "=" "=" :actions '(rem))
      (sp-local-pair "\\left(" "\\right)" :trigger "\\l(" :post-handlers '(sp-latex-insert-spaces-inside-pair))
      (sp-local-pair "\\left[" "\\right]" :trigger "\\l[" :post-handlers '(sp-latex-insert-spaces-inside-pair))
      (sp-local-pair "\\left\\{" "\\right\\}" :trigger "\\l{" :post-handlers '(sp-latex-insert-spaces-inside-pair))
      (sp-local-pair "\\left|" "\\right|" :trigger "\\l|" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  ;; (sp-local-pair 'org-mode "(" ")")
  (sp-local-pair 'org-mode "\\[" "\\]")
  (sp-local-pair 'org-mode "$" "$")
  (sp-local-pair 'org-mode "'" "'" :actions '(rem))
  (sp-local-pair 'org-mode "=" "=" :actions '(rem))
  (sp-local-pair 'org-mode "\\left(" "\\right)" :trigger "\\l(" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  (sp-local-pair 'org-mode "\\left[" "\\right]" :trigger "\\l[" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  (sp-local-pair 'org-mode "\\left\\{" "\\right\\}" :trigger "\\l{" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  (sp-local-pair 'org-mode "\\left|" "\\right|" :trigger "\\l|" :post-handlers '(sp-latex-insert-spaces-inside-pair))

  (add-hook 'org-mode-hook 'smartparens-mode)