doomemacs / doomemacs/core

Auctex's `TeX-insert-dollar` conflicts with smartparens

Open
#8,093 3 comments 1 reaction 0 assignees View on GitHub
is:bug re:smartparens
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### I confirm that...

- [X] I have searched the [issue tracker](https://github.com/doomemacs/doomemacs/issues), [documentation](https://docs.doomemacs.org), [FAQ](https://docs.doomemacs.org/-/faq), [Discourse](https://discourse.doomemacs.org), and [Google](https://google.com), in case this issue has already been reported/resolved.

- [X] I have read "[How to Debug Issues](https://doomemacs.org/d/how2debug)", and will use it to provide as much information about this issue as possible.

- [X] The issue can be reproduced on the **latest** available commit of Doom.

- [X] The issue can be reproduced on a stable release of Emacs, such as 27, 28, or 29. *(Unstable versions end in .50, .60, or .9x)*

### Expected behavior

In LaTeX mode with smartparens, inline math delimiters `$` should work the same as other delimiters with smartparens. For instance, when typing`$x$`, once the first `$` is typed, the matching `$` to end the inline math is automatically inserted, with the cursor placed between the two (i.e., `$|$`); then, after typing `x`, when `$` is pressed again, rather than inserting a new `$`, the cursor is moved to the position after the closing delimiter `$`, producing `$x$` with the cursor at the end, after the second `$`.

### Current behavior

Until recently, there appeared to be no built-in support for the smartparens-style delimiter matching with inline math in latex mode. Typing `$` simply inserted a `$` with no additional special behavior. As of [this commit in smartparens](https://github.com/Fuco1/smartparens/commit/ff2b2f4eaf3e5800d974952b5e721c6321bbe8c8), it seems smartparens is now treating the `$` specially in LaTeX-mode. However, the behavior is not quite as expected.

In the latest doom, pressing `$` now inserts two dollar signs with the cursor between them (i.e., `$|$`). However, if one types `x` (or any text, or even no text) followed by another `$`, rather than the typical smartparens behavior, a new `$` is inserted, producing `$x$|$` (where the `|` indicates the position of the cursor).

As far as I can tell, this only happens when editing `.tex` files in AuCTeX's `LaTeX-mode`. Switching to `latex-mode` instead causes the behavior to work as expected.

It appears that this is related to AuCTeX's own built-in special handling of `$` via `TeX-insert-dollar`. Disabling this by unbinding the `$` key so that it doesn't invoke `TeX-insert-dollar` seems to fix the issue, leading to the expected smartparens behavior described above.

As a temporary workaround, therefore, adding the following to my doom's `config.el` seems to produce the desired behavior:
```elisp
(map! :after tex :map TeX-mode-map :i "$" 'self-insert-command)
```

### Steps to reproduce

1. Open Emacs
2. Open a `.tex` file, ensuring that AucTeX (major mode `LaTeX-mode`) is being used
3. When editing the file, type (in insert state, for evil mode): `$`, followed by `x`, followed by `$`

### System Information

https://pastebin.com/WxcTd7kc

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.