Disable subscript in siunitx macros #30

Open
opened 2022-01-23 20:36:39 +00:00 by Waelwindows · 8 comments
Waelwindows commented 2022-01-23 20:36:39 +00:00 (Migrated from github.com)

Inspired by #23, we should disable subscripts within siunitx macros such as \qty, \num, and so on.

It's currently painful to write exponents for numbers in these macros as they they currently expand to something like \num{123e_3} instead of \num{123e3}

Inspired by #23, we should disable subscripts within `siunitx` macros such as `\qty`, `\num`, and so on. It's currently painful to write exponents for numbers in these macros as they they currently expand to something like `\num{123e_3}` instead of `\num{123e3}`
ymarco commented 2022-01-23 20:45:48 +00:00 (Migrated from github.com)

It's basically the same issue as in #23, we need a method to check if point is inside \qty or \num etc. If we don't care about nesting it shouldn't be too hard, PRs welcome.

A possible workaround meanwhile if it's only annoying on "e" would be to advise laas-auto-script-condition to return nil if we're subscripting "e".

It's basically the same issue as in #23, we need a method to check if point is inside \qty or \num etc. If we don't care about nesting it shouldn't be too hard, PRs welcome. A possible workaround meanwhile if it's only annoying on "e" would be to advise laas-auto-script-condition to return nil if we're subscripting "e".
Sinthoras7 commented 2022-09-12 18:37:27 +00:00 (Migrated from github.com)

I think the functions TeX-current-macro and LaTeX-current-environment (provided by AuCTeX) would be helping a lot in fixing this and also #23. (even #11 I think)

I think the functions `TeX-current-macro` and `LaTeX-current-environment` (provided by AuCTeX) would be helping a lot in fixing this and also #23. (even #11 I think)
ymarco commented 2022-09-12 19:05:08 +00:00 (Migrated from github.com)

I think the functions TeX-current-macro and LaTeX-current-environment (provided by AuCTeX) would be helping a lot in fixing this > and also #23.

I'm not familiar, what do they do? Would they work in Org?

> I think the functions TeX-current-macro and LaTeX-current-environment (provided by AuCTeX) would be helping a lot in fixing this > and also #23. I'm not familiar, what do they do? Would they work in Org?
Sinthoras7 commented 2022-09-12 19:10:20 +00:00 (Migrated from github.com)

They do exactly what their name implies, and I think exactly what we need here.

From the documentation of TeX-current-macro: "Return the name of the macro containing point, nil if there is none."
Source Code:

;; Defined in ~/.emacs.d/elpa/auctex-13.1.4/tex.el
(defun TeX-current-macro ()
  "Return the name of the macro containing point, nil if there is none."
  (let ((macro-start (TeX-find-macro-start)))
    (when macro-start
      (save-excursion
        (goto-char macro-start)
        (forward-char (length TeX-esc))
        (buffer-substring-no-properties
         (point) (progn (skip-chars-forward "@A-Za-z*") (point)))))))

From the documentation of LaTeX-current-environment:
Source Code

;; Defined in ~/.emacs.d/elpa/auctex-13.1.4/latex.el
;; Variable used to cache the current environment, e.g. for repeated
;; tasks in an environment, like indenting each line in a paragraph to
;; be filled.  It must not have a non-nil value in general.  That
;; means it is usually let-bound for such operations.
(defvar LaTeX-current-environment nil)

Edit: Regarding org, I don't know, since I don't use latex heavily in my org files. Do the other AuCTeX-functions work in org?

They do exactly what their name implies, and I think exactly what we need here. From the documentation of `TeX-current-macro`: "Return the name of the macro containing point, nil if there is none." Source Code: ``` ;; Defined in ~/.emacs.d/elpa/auctex-13.1.4/tex.el (defun TeX-current-macro () "Return the name of the macro containing point, nil if there is none." (let ((macro-start (TeX-find-macro-start))) (when macro-start (save-excursion (goto-char macro-start) (forward-char (length TeX-esc)) (buffer-substring-no-properties (point) (progn (skip-chars-forward "@A-Za-z*") (point))))))) ``` From the documentation of `LaTeX-current-environment`: Source Code ``` ;; Defined in ~/.emacs.d/elpa/auctex-13.1.4/latex.el ;; Variable used to cache the current environment, e.g. for repeated ;; tasks in an environment, like indenting each line in a paragraph to ;; be filled. It must not have a non-nil value in general. That ;; means it is usually let-bound for such operations. (defvar LaTeX-current-environment nil) ``` Edit: Regarding org, I don't know, since I don't use latex heavily in my org files. Do the other AuCTeX-functions work in org?
ymarco commented 2022-09-12 19:21:55 +00:00 (Migrated from github.com)

Ok, and what about Org? Would be odd if we check for siunitx in TeX and not in Org

Ok, and what about Org? Would be odd if we check for siunitx in TeX and not in Org
ymarco commented 2022-09-12 19:22:59 +00:00 (Migrated from github.com)

(Not trying to be sarcastic, sorry if it sounded like that)

(Not trying to be sarcastic, sorry if it sounded like that)
Sinthoras7 commented 2022-09-12 19:23:37 +00:00 (Migrated from github.com)

I edited my comment some minutes ago (should have marked it, my fault.)
I wrote: "Regarding org, I don't know, since I don't use latex heavily in my org files. Do the other AuCTeX-functions work in org?"
(Edit: Spelling)

I edited my comment some minutes ago (should have marked it, my fault.) I wrote: "Regarding org, I don't know, since I don't use latex heavily in my org files. Do the other AuCTeX-functions work in org?" (Edit: Spelling)
ymarco commented 2022-09-12 19:36:52 +00:00 (Migrated from github.com)

I edited my comment some minutes ago (should have marked it, my fault.)

Oh, I don't get the edits when reading by email.

I wrote: "Regarding org, I don't know, since I didn't use latex heavily in my org files. Do the other Auctex-functions work in org?"

Some do, we'll need to check edge cases. laas has auctex as a dependency so if they do work we can rely on them 100%.

> I edited my comment some minutes ago (should have marked it, my fault.) Oh, I don't get the edits when reading by email. > I wrote: "Regarding org, I don't know, since I didn't use latex heavily in my org files. Do the other Auctex-functions work in org?" Some do, we'll need to check edge cases. laas has auctex as a dependency so if they do work we can rely on them 100%.
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: tec/LaTeX-auto-activating-snippets#30
No description provided.