Re: Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
See below. > On Sep 29, 2020, at 11:53 AM, Richard Lawrence wrote: > > "Berry, Charles" writes: > >> The case Gutin describes conforms to the documentation, viz. `$x\beta$-` >> should produce math mode LaTeX as I read the next paragraph. >> >> From (info "(org) LaTeX fragments"): >> >> • Text within the usual LaTeX math delimiters. To avoid conflicts >> with currency specifications, single ‘$’ characters are only >> recognized as math delimiters if the enclosed text contains at most >> two line breaks, is directly attached to the ‘$’ characters with no >> whitespace in between, and if the closing ‘$’ is followed by >> whitespace, punctuation or a dash. > > Hmm, good point. > > It looks to me like the relevant function is > org-element-latex-fragment-parser, and the code for that hasn't changed > much in several years (last change was 2017). (Also, I was wrong, > parsing latex fragments is not done with just a regexp.) I can confirm > that this function parses "$foo" in "$foo$ bar" as a latex fragment, but > not in "$foo$-bar" > > Not sure if the problem here is the code or the documentation. Perhaps > the documentation should be updated to reflect the current behavior? > Using "\\(-\\|\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|'\\|$\\)" as the regexp for the `looking-at-p` seems to resolve this. To save you some eyestrain, there is "-\\|" added near the beginning right after "\\(" to match the trailing dash. Per (info (elisp) "Syntax Class Table"), neither \\s. nor \\s- include the dash. \\s_ includes dash, but also $, so that seems like trouble. Caveat: I've not run `make test`, so am unsure if there is a subtle gotcha hidden here. HTH, Chuck
Re: Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
"Berry, Charles" writes: > The case Gutin describes conforms to the documentation, viz. `$x\beta$-` > should produce math mode LaTeX as I read the next paragraph. > > From (info "(org) LaTeX fragments"): > >• Text within the usual LaTeX math delimiters. To avoid conflicts > with currency specifications, single ‘$’ characters are only > recognized as math delimiters if the enclosed text contains at most > two line breaks, is directly attached to the ‘$’ characters with no > whitespace in between, and if the closing ‘$’ is followed by > whitespace, punctuation or a dash. Hmm, good point. It looks to me like the relevant function is org-element-latex-fragment-parser, and the code for that hasn't changed much in several years (last change was 2017). (Also, I was wrong, parsing latex fragments is not done with just a regexp.) I can confirm that this function parses "$foo" in "$foo$ bar" as a latex fragment, but not in "$foo$-bar" Not sure if the problem here is the code or the documentation. Perhaps the documentation should be updated to reflect the current behavior? -- Best, Richard
Re: Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
See below. > On Sep 28, 2020, at 11:42 AM, Richard Lawrence wrote: > > Hi Gutin, > > gutin writes: > >> What I meant is that if you type >> >> $*$-algebra >> >> and hit C-c C-x C-l, then the "$*$" doesn't get replaced with a >> mathematical image. A similar problem happens when you export to Latex: >> The dollar signs get escaped. > > I believe this is intentional. There are too many other uses of dollar > signs that people might want to use in Org documents that might be > broken if Org treated them as math mode delimiters; so the regexp that > matches math mode delimiters is deliberately limited in scope. [rest deleted] The case Gutin describes conforms to the documentation, viz. `$x\beta$-` should produce math mode LaTeX as I read the next paragraph. From (info "(org) LaTeX fragments"): • Text within the usual LaTeX math delimiters. To avoid conflicts with currency specifications, single ‘$’ characters are only recognized as math delimiters if the enclosed text contains at most two line breaks, is directly attached to the ‘$’ characters with no whitespace in between, and if the closing ‘$’ is followed by whitespace, punctuation or a dash. But the $...$ and $$...$$ seem fragile. I recall advice to avoid them in favor of \(...\) and \[...\]. FWIW, my sanity has been aided by using yf/org-electric-dollar[1], which inserts `\(\)` when I type `$` and leaves point where you need it to enter math mode LaTex. A dash after the closing parenthesis is no problem. HTH, Chuck [1] https://orgmode.org/list/87vc913oh5@yahoo.fr/ ;; from Nicolas Richard ;; Date: Fri, 8 Mar 2013 16:23:02 +0100 ;; Message-ID: <87vc913oh5@yahoo.fr>
Re: Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
Hi Gutin, gutin writes: > What I meant is that if you type > > $*$-algebra > > and hit C-c C-x C-l, then the "$*$" doesn't get replaced with a > mathematical image. A similar problem happens when you export to Latex: > The dollar signs get escaped. I believe this is intentional. There are too many other uses of dollar signs that people might want to use in Org documents that might be broken if Org treated them as math mode delimiters; so the regexp that matches math mode delimiters is deliberately limited in scope. The recommended workaround is to use the \(...\) style of delimiter for math mode instead, which is much less ambiguous. Here is a function that makes this easy, by inserting these delimiters when you type "$". It's been posted on this mailing list before, and I use a version of it myself; it's very useful! ;; from Nicolas Richard ;; Date: Fri, 8 Mar 2013 16:23:02 +0100 ;; Message-ID: <87vc913oh5@yahoo.fr> (defun yf/org-electric-dollar nil "When called once, insert \\(\\) and leave point in between. When called twice, replace the previously inserted \\(\\) by one $." (interactive) (if (and (looking-at ")") (looking-back "(")) (progn (delete-char 2) (delete-char -2) (insert "$")) (insert "\\(\\)") (backward-char 2))) (define-key org-mode-map (kbd "$") 'yf/org-electric-dollar Hope that helps! -- Best, Richard
Re: Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
Hi Gutin, gutin writes: > If a pair of dollar signs is followed by a dash, then math mode doesn't > work. Can you say a bit more about what you are trying to do, what you are expecting to happen, and what you are seeing instead? Since you refer to math mode, I assume you are exporting to LaTeX. I just tested this: some text $$-1$$ other text and it exports fine to LaTeX on my machine (Emacs 26.1, Org 9.4). What's broken for you? -- Best, Richard
Bug: Math mode doesn't work if followed by a dash [9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/)]
Remember to cover the basics, that is, what you expected to happen and what in fact did happen. You don't know how to make a good report? See https://orgmode.org/manual/Feedback.html#Feedback Your bug report will be posted to the Org mailing list. - --- If a pair of dollar signs is followed by a dash, then math mode doesn't work. Emacs : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28 Package: Org mode version 9.4 (nil @ /home/gutin/.emacs.d/.local/straight/build/org-mode/) current state: == (setq org-footnote-auto-label 'plain org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode- configure-edit-buffer doom-modeline-set-org-src-modeline) org-fontify-whole-heading-line t org-link-shell-confirm-function 'yes-or-no-p org-mode-local-vars-hook '(eldoc-mode) org-babel-after-execute-hook '(org-redisplay-inline-images) org-insert-heading-respect-content t org-after-refile-insert-hook '(save-buffer) org-metadown-hook '(org-babel-pop-to-session-maybe) org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-refile-targets '((nil :maxlevel . 3) (org-agenda-files :maxlevel . 3)) org-html-format-inlinetask-function 'org-html-format-inlinetask- default-function org-enforce-todo-dependencies t org-odt-format-headline-function 'org-odt-format-headline-default- function org-special-ctrl-a/e t org-imenu-depth 8 org-agenda-files '("~/org/") org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask- default org-reveal-start-hook '(org-decrypt-entry) org-modules '(ol-bibtex) org-blocker-hook '(org-block-todo-from-children-or-siblings-or-parent) org-mode-hook '(doom--setq-gcmh-high-cons-threshold-for-org-mode-h er/add-org-mode-expansions +lookup--init-org-mode-handlers-h (closure (t) ( _) (add-hook 'before-save-hook 'org-encrypt-entries nil t)) #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-all append local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show- result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes #[0 "\301\211\207" [imenu-create-index-function org- imenu-get-tree] 2] doom-disable-show-paren-mode-h doom-disable-show- trailing-whitespace-h +org-enable-auto-reformat-tables-h +org-enable-auto- update-cookies-h +org-make-last-point-visible-h evil-org-mode toc-org- enable embrace-org-mode-hook org-eldoc-load) org-clock-persist 'history org-export-with-smart-quotes t org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"] org-outline-path-complete-in-steps nil org-archive-hook '(org-attach-archive-delete-maybe) org-agenda-finalize-hook '(+org-exclude-agenda-buffers-from-workspace- h +org-defer-mode-in-agenda-buffers-h) org-startup-indented t org-agenda-before-write-hook '(org-agenda-add-entry-text) org-metaup-hook '(org-babel-load-in-session-maybe) org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn ENTRY)"] org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"] org-agenda-deadline-faces '((1.001 . error) (1.0 . org-warning) (0.5 . org-upcoming-deadline) (0.0 . org-upcoming-distant-deadline)) org-crypt-key nil org-babel-pre-tangle-hook '(save-buffer) org-tab-first-hook '(+org-yas-expand-maybe-h +org-indent-maybe-h org- babel-hide-result-toggle-maybe org-babel-header-arg-expand +org-cycle-only- current-subtree-h +org-clear-babel-results-h) org-hide-leading-stars t org-load-hook '(+org-init-org-directory-h +org-init-appearance-h +org- init-agenda-h +org-init-attachments-h +org-init-babel-h +org-init- babel-lazy-loader-h +org-init-capture-defaults-h +org-init-capture-frame-h +org-init-custom-links-h +org-init-export-h +org-init-habit-h +org-init-hacks-h +org-init-keybinds-h +org-init-popup-rules-h +org-init-protocol-h +org- init-protocol-lazy-loader-h +org-init-smartparens-h) org-link-abbrev-alist '(("doom-repo" . " https://github.com/hlissner/doom-emacs/%s;) ("wolfram" . " https://wolframalpha.com/input/?i=%s;) ("wikipedia" . " https://en.wikipedia.org/wiki/%s;) ("duckduckgo" . "https://duckduckgo.com/?q=%s; ) ("gmap" . "https://maps.google.com/maps?q=%s;) ("gimages" . "https://google.com/images?q=%s;) ("google" . "https://google.com/search?q=;) ("youtube" .