Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable subscript in siunitx macros #30

Open
Waelwindows opened this issue Jan 23, 2022 · 10 comments
Open

Disable subscript in siunitx macros #30

Waelwindows opened this issue Jan 23, 2022 · 10 comments

Comments

@Waelwindows
Copy link

Waelwindows commented Jan 23, 2022

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
Copy link
Collaborator

ymarco commented Jan 23, 2022 via email

@Sinthoras7
Copy link

Sinthoras7 commented Sep 12, 2022

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
Copy link
Collaborator

ymarco commented Sep 12, 2022 via email

@Sinthoras7
Copy link

Sinthoras7 commented Sep 12, 2022

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
Copy link
Collaborator

ymarco commented Sep 12, 2022 via email

@ymarco
Copy link
Collaborator

ymarco commented Sep 12, 2022 via email

@Sinthoras7
Copy link

Sinthoras7 commented Sep 12, 2022

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
Copy link
Collaborator

ymarco commented Sep 12, 2022 via email

@Waelwindows
Copy link
Author

Waelwindows commented Sep 15, 2023

Hey, long time no see! I completely forgot about this issue.

I can confirm that TeX-current-macro does work in org, both inside of math fragments and outside of them.
However, it only returns the macro if there isn't a closer macro. e.g.

Here is some org prose \qty{123}{\km} blah blah blah

If the cursor is above qty or 123, it returns qty as expected. However, if the cursor is above \km it'll return km

In light of this, can we address this issue now?

@ymarco
Copy link
Collaborator

ymarco commented Sep 16, 2023

Sure, open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants