Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Mon, May 22, 2023 at 7:50 AM Mosè Giordano wrote: > > On Mon, 22 May 2023 at 00:45, Hongyi Zhao wrote: > > Mine is as follows: > > > > --8<---cut here---start->8--- > > $ runs the command cdlatex-dollar (found in cdlatex-mode-map), which > > is an interactive byte-compiled Lisp function in ‘cdlatex.el’. > > > > It is bound to $. > > > > (cdlatex-dollar ARG) > > > > Insert a pair of dollars unless number of backslashes before point is odd. > > With arg, insert pair of double dollars. > > --8<---cut here---end->8--- > > Then it's not a surprise that `TeX-electric-math' is ignored. I'm not > familiar with cdlatex, but that's apparently overtaking AUCTeX > keybindings. I confirm that the recommended method here is effective after disabling cdlatex. > Bye, > Mosè Regards, Zhao
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Mon, May 22, 2023 at 7:50 AM Mosè Giordano wrote: > > On Mon, 22 May 2023 at 00:45, Hongyi Zhao wrote: > > Mine is as follows: > > > > --8<---cut here---start->8--- > > $ runs the command cdlatex-dollar (found in cdlatex-mode-map), which > > is an interactive byte-compiled Lisp function in ‘cdlatex.el’. > > > > It is bound to $. > > > > (cdlatex-dollar ARG) > > > > Insert a pair of dollars unless number of backslashes before point is odd. > > With arg, insert pair of double dollars. > > --8<---cut here---end->8--- > > Then it's not a surprise that `TeX-electric-math' is ignored. I'm not > familiar with cdlatex, but that's apparently overtaking AUCTeX > keybindings. I filed an issue here [1]. [1] https://github.com/cdominik/cdlatex/issues/60 > Bye, > Mosè Regards, Zhao
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Mon, 22 May 2023 at 00:45, Hongyi Zhao wrote: > Mine is as follows: > > --8<---cut here---start->8--- > $ runs the command cdlatex-dollar (found in cdlatex-mode-map), which > is an interactive byte-compiled Lisp function in ‘cdlatex.el’. > > It is bound to $. > > (cdlatex-dollar ARG) > > Insert a pair of dollars unless number of backslashes before point is odd. > With arg, insert pair of double dollars. > --8<---cut here---end->8--- Then it's not a surprise that `TeX-electric-math' is ignored. I'm not familiar with cdlatex, but that's apparently overtaking AUCTeX keybindings. Bye, Mosè
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Mon, May 22, 2023 at 12:35 AM Mosè Giordano wrote: > > On Sun, 21 May 2023 at 14:34, Hongyi Zhao wrote: > > But I still cannot observe the desired behavior, as shown in the > > attached screenshot. > > Are you sure that `$' is bound to `TeX-insert-dollar'? In a LaTeX > buffer, what does `C-h k $' give you? I get Mine is as follows: --8<---cut here---start->8--- $ runs the command cdlatex-dollar (found in cdlatex-mode-map), which is an interactive byte-compiled Lisp function in ‘cdlatex.el’. It is bound to $. (cdlatex-dollar ARG) Insert a pair of dollars unless number of backslashes before point is odd. With arg, insert pair of double dollars. --8<---cut here---end->8--- > --8<---cut here---start->8--- > $ runs the command TeX-insert-dollar (found in LaTeX-mode-map), which is an > interactive native-compiled Lisp function in ‘tex.el’. > > It is bound to $. > > (TeX-insert-dollar ARG) > > Insert dollar sign. > > If current math mode was not entered with a dollar, refuse to > insert one when ‘TeX-refuse-unmatched-dollar’ is non-nil. > > Show matching dollar sign if this dollar sign ends the TeX math > mode and ‘blink-matching-paren’ is non-nil. > > When outside math mode, the behavior is controlled by the variable > ‘TeX-electric-math’. > > With raw C-u prefix, insert exactly one dollar sign. > With optional ARG, insert that many dollar signs. > > --8<---cut here---end--->8--- > > Bye, > Mosè Best, Zhao
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Sun, 21 May 2023 at 14:34, Hongyi Zhao wrote: > But I still cannot observe the desired behavior, as shown in the > attached screenshot. Are you sure that `$' is bound to `TeX-insert-dollar'? In a LaTeX buffer, what does `C-h k $' give you? I get --8<---cut here---start->8--- $ runs the command TeX-insert-dollar (found in LaTeX-mode-map), which is an interactive native-compiled Lisp function in ‘tex.el’. It is bound to $. (TeX-insert-dollar ARG) Insert dollar sign. If current math mode was not entered with a dollar, refuse to insert one when ‘TeX-refuse-unmatched-dollar’ is non-nil. Show matching dollar sign if this dollar sign ends the TeX math mode and ‘blink-matching-paren’ is non-nil. When outside math mode, the behavior is controlled by the variable ‘TeX-electric-math’. With raw C-u prefix, insert exactly one dollar sign. With optional ARG, insert that many dollar signs. --8<---cut here---end--->8--- Bye, Mosè
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Sun, May 21, 2023 at 9:33 PM Hongyi Zhao wrote: > > On Sun, May 21, 2023 at 7:14 PM Mosè Giordano wrote: > > > > Hi Zhao > > > > On Sun, 21 May 2023 at 09:41, Hongyi Zhao wrote: > > > I want to convert `bla` to `$bla$` automatically when be highlighted > > > and typeset a `$'. > > > > I believe you want to look at `TeX-electric-math' > > (https://www.gnu.org/software/auctex/manual/auctex/Quotes.html#index-TeX_002delectric_002dmath): > > > > --8<---cut here---start->8--- > > TeX-electric-math is a variable defined in ‘tex.el’. > > > > Its value is ("\\(" . "\\)") > > Original value was nil > > Local in buffer foo.tex; global value is nil > > > > If non-nil, when outside math mode ‘TeX-insert-dollar’ will > > insert symbols for opening and closing inline equation and put > > the point between them. If there is an active region, > > ‘TeX-insert-dollar’ will put around it symbols for opening and > > closing inline equation and keep the region active, with point > > after closing symbol. If you press ‘$’ again, you can toggle > > between inline equation, display equation, and no equation. > > > > If non-nil and point is inside math mode right between a couple > > of single dollars, pressing ‘$’ will insert another pair of > > dollar signs and leave the point between them. > > > > If nil, ‘TeX-insert-dollar’ will simply insert "$" at point, > > this is the default. > > > > If non-nil, this variable is a cons cell whose CAR is the string > > to insert before point, the CDR is the string to insert after > > point. You can choose between "$...$" and "\(...\)". > > > > Automatically becomes buffer-local when set. > > You can customize this variable. > > --8<---cut here---end--->8--- > > Based on the above document, I've added the following hook entry in > AUCTeX's use-package configuration: > > (LaTeX-mode . (lambda () (set (make-local-variable 'TeX-electric-math) > (cons "$" "$" > > But I still cannot observe the desired behavior, as shown in the > attached screenshot. I tried a lot, and only find the following code snippet does the trick: (defun xah-insert-bracket-pair (LBracket RBracket WrapMethod) "Insert brackets around selection, word, at point, and maybe move cursor in between. LBracket and RBracket are strings. WrapMethod must be either `line' or `block'. `block' means between empty lines. • if there is a region, add brackets around region. • If WrapMethod is `line', wrap around line. • If WrapMethod is `block', wrap around block. • if cursor is at beginning of line and its not empty line and contain at least 1 space, wrap around the line. • If cursor is at end of a word or buffer, one of the following will happen: xyz▮ → xyz(▮) xyz▮ → (xyz▮) if in one of the lisp modes. • wrap brackets around word if any. e.g. xy▮z → (xyz▮). Or just (▮) URL `http://xahlee.info/emacs/emacs/elisp_insert_brackets_by_pair.html' Version: 2017-01-17 2021-08-12" (if (region-active-p) (progn (let ( ($p1 (region-beginning)) ($p2 (region-end))) (goto-char $p2) (insert RBracket) (goto-char $p1) (insert LBracket) (goto-char (+ $p2 2 (let ($p1 $p2) (cond ((eq WrapMethod 'line) (setq $p1 (line-beginning-position) $p2 (line-end-position)) (goto-char $p2) (insert RBracket) (goto-char $p1) (insert LBracket) (goto-char (+ $p2 (length LBracket ((eq WrapMethod 'block) (save-excursion (let (($bds (xah-get-bounds-of-block-or-region))) (setq $p1 (car $bds) $p2 (cdr $bds))) (goto-char $p2) (insert RBracket) (goto-char $p1) (insert LBracket) (goto-char (+ $p2 (length LBracket) ( ; do line. line must contain space (and (eq (point) (line-beginning-position)) ;; (string-match " " (buffer-substring-no-properties (line-beginning-position) (line-end-position))) (not (eq (line-beginning-position) (line-end-position (insert LBracket ) (end-of-line) (insert RBracket)) ((and (or ; cursor is at end of word or buffer. i.e. xyz▮ (looking-at "[^-_[:alnum:]]") (eq (point) (point-max))) (not (or (string-equal major-mode "xah-elisp-mode") (string-equal major-mode "emacs-lisp-mode") (string-equal major-mode "lisp-mode") (string-equal major-mode "lisp-interaction-mode") (string-equal major-mode "common-lisp-mode") (string-equal major-mode "clojure-mode") (string-equal major-mode "xah-clojure-mode") (string-equal major-mode "scheme-mode" (progn (setq $p1 (point) $p2 (point)) (insert LBracket RBracket) (search-backward RBracket ))) (t (progn ;; wrap around
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Sun, May 21, 2023 at 7:14 PM Mosè Giordano wrote: > > Hi Zhao > > On Sun, 21 May 2023 at 09:41, Hongyi Zhao wrote: > > I want to convert `bla` to `$bla$` automatically when be highlighted > > and typeset a `$'. > > I believe you want to look at `TeX-electric-math' > (https://www.gnu.org/software/auctex/manual/auctex/Quotes.html#index-TeX_002delectric_002dmath): > > --8<---cut here---start->8--- > TeX-electric-math is a variable defined in ‘tex.el’. > > Its value is ("\\(" . "\\)") > Original value was nil > Local in buffer foo.tex; global value is nil > > If non-nil, when outside math mode ‘TeX-insert-dollar’ will > insert symbols for opening and closing inline equation and put > the point between them. If there is an active region, > ‘TeX-insert-dollar’ will put around it symbols for opening and > closing inline equation and keep the region active, with point > after closing symbol. If you press ‘$’ again, you can toggle > between inline equation, display equation, and no equation. > > If non-nil and point is inside math mode right between a couple > of single dollars, pressing ‘$’ will insert another pair of > dollar signs and leave the point between them. > > If nil, ‘TeX-insert-dollar’ will simply insert "$" at point, > this is the default. > > If non-nil, this variable is a cons cell whose CAR is the string > to insert before point, the CDR is the string to insert after > point. You can choose between "$...$" and "\(...\)". > > Automatically becomes buffer-local when set. > You can customize this variable. > --8<---cut here---end--->8--- Based on the above document, I've added the following hook entry in AUCTeX's use-package configuration: (LaTeX-mode . (lambda () (set (make-local-variable 'TeX-electric-math) (cons "$" "$" But I still cannot observe the desired behavior, as shown in the attached screenshot. > Bye, > Mosè Best, Zhao
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
Hi Zhao On Sun, 21 May 2023 at 09:41, Hongyi Zhao wrote: > I want to convert `bla` to `$bla$` automatically when be highlighted > and typeset a `$'. I believe you want to look at `TeX-electric-math' (https://www.gnu.org/software/auctex/manual/auctex/Quotes.html#index-TeX_002delectric_002dmath): --8<---cut here---start->8--- TeX-electric-math is a variable defined in ‘tex.el’. Its value is ("\\(" . "\\)") Original value was nil Local in buffer foo.tex; global value is nil If non-nil, when outside math mode ‘TeX-insert-dollar’ will insert symbols for opening and closing inline equation and put the point between them. If there is an active region, ‘TeX-insert-dollar’ will put around it symbols for opening and closing inline equation and keep the region active, with point after closing symbol. If you press ‘$’ again, you can toggle between inline equation, display equation, and no equation. If non-nil and point is inside math mode right between a couple of single dollars, pressing ‘$’ will insert another pair of dollar signs and leave the point between them. If nil, ‘TeX-insert-dollar’ will simply insert "$" at point, this is the default. If non-nil, this variable is a cons cell whose CAR is the string to insert before point, the CDR is the string to insert after point. You can choose between "$...$" and "\(...\)". Automatically becomes buffer-local when set. You can customize this variable. --8<---cut here---end--->8--- Bye, Mosè
Re: Convert bla to $bla$ automatically when be highlighted and typeset a $.
On Sun, May 21, 2023 at 4:41 PM Hongyi Zhao wrote: > > Hi here, > > I want to convert `bla` to `$bla$` automatically when be highlighted > and typeset a `$'. > > Currently, my observed result is `bla$$`, which is not consistent with > the LaTeX math environment. I tried the following, but failed to do the trick: (defun my-insert-dollar () "Insert pair of dollar signs around region or at point." (interactive) (if (use-region-p) (let ((beg (region-beginning)) (end (region-end))) (goto-char end) (insert "$") (goto-char beg) (insert "$")) (insert "$"))) ;; Add to your Emacs configuration file (~/.emacs or ~/.emacs.d/init.el) (define-key LaTeX-mode-map "$" 'my-insert-dollar) Regards, Zhao
Convert bla to $bla$ automatically when be highlighted and typeset a $.
Hi here, I want to convert `bla` to `$bla$` automatically when be highlighted and typeset a `$'. Currently, my observed result is `bla$$`, which is not consistent with the LaTeX math environment. Regards, Zhao -- Assoc. Prof. Hongsheng Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province