Coder Social home page Coder Social logo

org-fragtog's Introduction

https://melpa.org/packages/org-fragtog-badge.svg https://github.com/io12/org-fragtog/actions/workflows/check.yml/badge.svg

org-fragtog

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them

About

Org mode supports inline image previews of LaTeX fragments. These can be toggled with C-c C-x C-l . org-fragtog automates this, so fragment previews are disabled for editing when your cursor steps onto them, and re-enabled when the cursor leaves.

./demo.gif

Setup

Install and load the package, then add the snippet below to your config.

(add-hook 'org-mode-hook 'org-fragtog-mode)

Although this package uses Org mode’s fragment preview feature, it should work with anything that uses the same fragment syntax, such as Markdown files or formulas in code comments.

org-fragtog's People

Contributors

awth13 avatar conao3 avatar io12 avatar wosined avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

org-fragtog's Issues

void function error

I'm using emacs 26.3 with org-mode 9.1.9 version, I get void-function error, do i need to upgrade the version any thing close I could find was org-version-issue

Org-Fragtog mode enabled in current buffer
Error in post-command-hook (org-fragtog--post-cmd): (void-function org-clear-latex-preview)
Quit
Making completion list...

can make this package work in markdown-mode?

This package is so useful for reproducible research.
But sometimes I write rmarkdown document which supports latex math too with markdown-mode.
So I wonder can make this package work in markdown-mode too?
Thanks.

Do not support chinese?

Describe the bug
$$ P{\mbox{拒绝} \mid H_{0} \mbox{为真}} = \alpha $$
I expect to display chinese chars . but the result is chinese chars are not show int the org mode.

Latex Preview problem

I am not sure the problem is introduced by fragtog or my configuration. Please help to check, Thank you~
When I type $\to$, it seems include some extra configuration detail
Screenshot 2021-02-25 下午9 18 09
While I type $A \to \lambda$, it is OK
Screenshot 2021-02-25 下午9 40 10

org-fragtog--post-cmd: wrong-type-argument on Emacs 29

First of all thanks for all the work put into the package. It's great :)

Describe the bug
org-fragtog-mode seems to not work on Emacs 29.

To Reproduce
Steps to reproduce the behavior:

  1. Toggle buffer-wide org-latex-preview
  2. M-x org-fragtog-mode
  3. The following error message is shown:
    Error in post-command-hook (org-fragtog--post-cmd): (wrong-type-argument number-or-marker-p nil)
    

The bug seems to take place within org-fragtog--frag-end. Bug trace:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  org-fragtog--frag-end((latex-environment (:standard-properties [724 923 nil nil 1 735 nil t nil nil nil nil element nil (section (:standard-properties [548 923 548 923 0 548 nil t nil 548 923 section element nil (headline ...) nil nil #<buffer calc.org>])) nil nil #<buffer calc.org>] :value [org-element-deferred org-element--substring (11 198) nil] :results (""))))
  org-fragtog--cursor-frag()
  org-fragtog--post-cmd()
  eval((org-fragtog--post-cmd) t)
  eval-expression((org-fragtog--post-cmd) nil nil 127)
  funcall-interactively(eval-expression (org-fragtog--post-cmd) nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

Expected behavior
org-fragtog-mode starts and inline previews of LaTeX equations work as expected.

Videos
Can provide if needed.

Version and environment

  • OS: Windows Subsystem for Linux (WSL) with Ubuntu 22.04
  • Emacs version: GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0)
    of 2022-07-12

Additional context
Can provide if needed.

Question: avoid creation of new buffer with dvipng message

Hi, first of all, thanks for the awesome package! I use it daily.

My question is the following: every time we have to compile a new equation, org-fragtog calls org-latex-preview which converts the latex to an image that appears on the Emacs buffer.

Unfortunately, every time a new equation is inserted, org-latex-preview calls dvipng which opens a new buffer with the message:

"This is dvipng 1.16 Copyright 2002-2015, 2019 Jan-Ake Larsson [1] ".

Is there a way to suppress this buffer to open in the first place, or to make it open only when there is an error? When you are creating lots of equations in a row this gets in the way and stops the flow.

Thanks!

Not working for begin environment

The package works for $ environment. However, it doesn't work for begin environment. I am able to toggle the preview using keybinding C-c C-x C-l for both cases.

I tried following block in org mode

\begin{align}
\label{myeq}
x=10
\end{align}

Thanks for creating this package. I love this package.

Preview is not displayed as I type

Suppose that I type $e^x$. No preview is generated as I finish the second $. If I then move the cursor inside the formula, and then move it outside the formula, the preview is generated correctly.

Is this the intended behavior? What to do if I want to see the preview as I finish typing, without moving my cursor in and out?

Thank you!

How to increase font size?

I am having an issue where the preview text is really small compared to my default text size. Below is an example of that. I was wondering if there is a way to change the default text size?

I tried adding (plist-put org-format-latex-options :scale 2), but that gives me the below error when launching emacs.

Debugger entered--Lisp error: (void-variable org-format-latex-options)
  (plist-put org-format-latex-options :scale 2)
  eval-buffer(#<buffer  *load*> nil "/home/hank/.emacs" nil t)  ; Reading at buffer position 3914
  load-with-code-conversion("/home/hank/.emacs" "/home/hank/.emacs" t t)
  load("~/.emacs" noerror nomessage)
  startup--load-user-init-file(#f(compiled-function () #<bytecode 0xc1956eca8e15ae2>) #f(compiled-function () #<bytecode -0x1f3c686ddc0cdc35>) t)
  command-line()
  normal-top-level()

I am using Emacs 28.2

image

org-fragtog seems to disable M-x org-latex-preview

If I've created a new org file with latex in it, I'd expect that M-x org-latex-preview would render all of the equations. However, after I installed org-fragtog, this command doesn't do anything; I have to manually put the cursor on each equation in order to cause the rendering.

Is there a way around this?

No space before and after $. math preview is not activated

sorry to bother again, this works great in markdown-mode, thanks. But I have a small problem.

When there is no space before and after $. math preview is not activated, for example:

math $\alpha$ frag, this line works.

math$\alpha$frag, this line doesn't.

When in English math fragment always have space before and after $, but when in Eastern Asian languages, no space before and after $ is common.

Can this be fixed? Thanks.

first open org with latex problem.

Thanks, this plug-in is good, but there are a few problems. When I first entered org, latex does not display directly, and each latex cursor has to be re-run to work properly

Possibility to toggle fragments on input

Thank you for the package! I have been using it for many months now and overall I am really happy with it. I would however like to make a suggestion.

When scrolling through a document with a lot of multi-line equations, it can be a bit disorienting, if the fragments automatically toggle. Also sometimes I just want to move the cursor over a multiline fragment which makes it harder when the fragment expands to a lot of code.

I thought about the situation, and for me personally I would be happy if there was a way treat fragments as images until you start typing while they are under point. At that time they could be toggled to the latex text. Maybe this could be a customize setting?

The behaviour of re-toggeling them back to would not be affected.

This would allow a cleaner navigation through the document where the content wouldn't be changing simply because of scrolling or moving the cursor.

If you see a simpler way for me to archieve this on my side I would also be interested to hear it!

Generating new pictures asynchronously

Hi, thank you for your efforts. I find this really helpful.

My only complaint is that when I move the point out of latex fragments, emacs blocks. It takes about 2 seconds for me to generate a new picture, and I am not able to do anything. My emacs-fu is not so good as to contribute this package. Can you give me some technical details on this issue? Is it possible to generate new pictures in the background and display it when it is ready without blocking my editing?

when new fragment is rendered, adjacent window redisplays

In the screenshots below:

The right-hand window has an Org Mode buffer in it; the left-hand window has a PDF in it. When fragtog renders a new fragment, the PDF on the left redisplays and recentres to the top of the page. (This disrupts my editing workflow when I have the PDF positioned so I can read the text on the bottom of the page!)

Screenshot-2021-03-07,20:57:54
Screenshot-2021-03-07,20:58:00

Feature Request: Evaluate the whole buffer

Is your feature request related to a problem? Please describe.
No problem but I just have a large org file that has a lot of small chunks of latex and would like to eval the whole buffer rather than moving my cursor through all of them.

Describe the solution you'd like
A function to evaluate the whole buffer with fragtog.

Describe alternatives you've considered
Just going through each chunk of latex to add in the preview.

it all breakt idk i fiel dump

I gat this error wan ever a auto preview gets generatet the preview still gets product put i dont anderstand the problem shod i just

  1. disable errors and ignor it her is the error:
■  Warning (org-element-cache): org-element--cache: Org parser error in 20230908094329-orglatexmath.org::89. Resetting.
The error was: (error "Invalid search bound (wrong side of point)")
Backtrace:
"  backtrace-to-string(nil)
 org-element-at-point()
 org--collect-keywords-1((\"SETUPFILE\" \"LATEX_CLASS\" \"LATEX_CLASS_OPTIONS\" \"LATEX_HEADER\" \"LATEX_HEADER_EXTRA\" \"DESCRIPTION\" \"KEYWORDS\" \"SUBTITLE\" \"LATEX_ENGRAVED_THEME\" \"LATEX_COMPILER\" \"DATE\" \"TITLE\" \"DATE\" \"AUTHOR\" \"EMAIL\" \"LANGUAGE\" \"SELECT_TAGS\" \"EXCLUDE_TAGS\" \"CREATOR\" \"CITE_EXPORT\" \"FILETAGS\" \"OPTIONS\") nil nil (\"/home/ck/org/Nots/20230908094329-orglatexmath.org\") nil)
 org-collect-keywords((\"LATEX_CLASS\" \"LATEX_CLASS_OPTIONS\" \"LATEX_HEADER\" \"LATEX_HEADER_EXTRA\" \"DESCRIPTION\" \"KEYWORDS\" \"SUBTITLE\" \"LATEX_ENGRAVED_THEME\" \"LATEX_COMPILER\" \"DATE\" \"TITLE\" \"DATE\" \"AUTHOR\" \"EMAIL\" \"LANGUAGE\" \"SELECT_TAGS\" \"EXCLUDE_TAGS\" \"CREATOR\" \"CITE_EXPORT\" \"FILETAGS\" \"OPTIONS\"))
 org-export--get-inbuffer-options(#s(org-export-backend :name latex :parent nil :transcoders ((bold . org-latex-bold) (center-block . org-latex-center-block) (clock . org-latex-clock) (code . org-latex-code) (drawer . org-latex-drawer) (dynamic-block . org-latex-dynamic-block) (entity . org-latex-entity) (example-block . org-latex-example-block) (export-block . org-latex-export-block) (export-snippet . org-latex-export-snippet) (fixed-width . org-latex-fixed-width) (footnote-definition . org-latex-footnote-definition) (footnote-reference . org-latex-footnote-reference) (headline . org-latex-headline) (horizontal-rule . org-latex-horizontal-rule) (inline-src-block . org-latex-inline-src-block) (inlinetask . org-latex-inlinetask) (italic . org-latex-italic) (item . org-latex-item) (keyword . org-latex-keyword) (latex-environment . org-latex-latex-environment) (latex-fragment . org-latex-latex-fragment) (line-break . org-latex-line-break) (link . org-latex-link) (node-property . org-latex-node-property) (paragraph . org-latex-paragraph) (plain-list . org-latex-plain-list) (plain-text . org-latex-plain-text) (planning . org-latex-planning) (property-drawer . org-latex-property-drawer) (quote-block . org-latex-quote-block) (radio-target . org-latex-radio-target) (section . org-latex-section) (special-block . org-latex-special-block) (src-block . org-latex-src-block) (statistics-cookie . org-latex-statistics-cookie) (strike-through . org-latex-strike-through) (subscript . org-latex-subscript) ...) :options ((:latex-class \"LATEX_CLASS\" nil org-latex-default-class t) (:latex-class-options \"LATEX_CLASS_OPTIONS\" nil nil t) (:latex-header \"LATEX_HEADER\" nil nil newline) (:latex-header-extra \"LATEX_HEADER_EXTRA\" nil nil newline) (:description \"DESCRIPTION\" nil nil parse) (:keywords \"KEYWORDS\" nil nil parse) (:subtitle \"SUBTITLE\" nil nil parse) (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format) (:latex-caption-above nil nil org-latex-caption-above) (:latex-classes nil nil org-latex-classes) (:latex-default-figure-position nil nil org-latex-default-figure-position) (:latex-default-table-environment nil nil org-latex-default-table-environment) (:latex-default-quote-environment nil nil org-latex-default-quote-environment) (:latex-default-table-mode nil nil org-latex-default-table-mode) (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format) (:latex-engraved-options nil nil org-latex-engraved-options) (:latex-engraved-preamble nil nil org-latex-engraved-preamble) (:latex-engraved-theme \"LATEX_ENGRAVED_THEME\" nil org-latex-engraved-theme) (:latex-footnote-defined-format nil nil org-latex-footnote-defined-format) (:latex-footnote-separator nil nil org-latex-footnote-separator) (:latex-format-drawer-function nil nil org-latex-format-drawer-function) (:latex-format-headline-function nil nil org-latex-format-headline-function) (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function) (:latex-hyperref-template nil nil org-latex-hyperref-template t) (:latex-image-default-scale nil nil org-latex-image-default-scale) (:latex-image-default-height nil nil org-latex-image-default-height) (:latex-image-default-option nil nil org-latex-image-default-option) (:latex-image-default-width nil nil org-latex-image-default-width) (:latex-images-centered nil nil org-latex-images-centered) (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format) (:latex-inline-image-rules nil nil org-latex-inline-image-rules) (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format) (:latex-src-block-backend nil nil org-latex-src-block-backend) (:latex-listings-langs nil nil org-latex-listings-langs) (:latex-listings-options nil nil org-latex-listings-options) (:latex-minted-langs nil nil org-latex-minted-langs) (:latex-minted-options nil nil org-latex-minted-options) (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels) ...) :filters ((:filter-options . org-latex-math-block-options-filter) (:filter-paragraph . org-latex-clean-invalid-line-breaks) (:filter-parse-tree org-latex-math-block-tree-filter org-latex-matrices-tree-filter org-latex-image-link-filter) (:filter-verse-block . org-latex-clean-invalid-line-breaks)) :blocks nil :menu (108 \"Export to LaTeX\" ((76 \"As LaTeX buffer\" org-latex-export-as-latex) (108 \"As LaTeX file\" org-latex-export-to-latex) (112 \"As PDF file\" org-latex-export-to-pdf) (111 \"As PDF file and open\" (lambda ... ...))))))
 org-export-get-environment(#s(org-export-backend :name latex :parent nil :transcoders ((bold . org-latex-bold) (center-block . org-latex-center-block) (clock . org-latex-clock) (code . org-latex-code) (drawer . org-latex-drawer) (dynamic-block . org-latex-dynamic-block) (entity . org-latex-entity) (example-block . org-latex-example-block) (export-block . org-latex-export-block) (export-snippet . org-latex-export-snippet) (fixed-width . org-latex-fixed-width) (footnote-definition . org-latex-footnote-definition) (footnote-reference . org-latex-footnote-reference) (headline . org-latex-headline) (horizontal-rule . org-latex-horizontal-rule) (inline-src-block . org-latex-inline-src-block) (inlinetask . org-latex-inlinetask) (italic . org-latex-italic) (item . org-latex-item) (keyword . org-latex-keyword) (latex-environment . org-latex-latex-environment) (latex-fragment . org-latex-latex-fragment) (line-break . org-latex-line-break) (link . org-latex-link) (node-property . org-latex-node-property) (paragraph . org-latex-paragraph) (plain-list . org-latex-plain-list) (plain-text . org-latex-plain-text) (planning . org-latex-planning) (property-drawer . org-latex-property-drawer) (quote-block . org-latex-quote-block) (radio-target . org-latex-radio-target) (section . org-latex-section) (special-block . org-latex-special-block) (src-block . org-latex-src-block) (statistics-cookie . org-latex-statistics-cookie) (strike-through . org-latex-strike-through) (subscript . org-latex-subscript) ...) :options ((:latex-class \"LATEX_CLASS\" nil org-latex-default-class t) (:latex-class-options \"LATEX_CLASS_OPTIONS\" nil nil t) (:latex-header \"LATEX_HEADER\" nil nil newline) (:latex-header-extra \"LATEX_HEADER_EXTRA\" nil nil newline) (:description \"DESCRIPTION\" nil nil parse) (:keywords \"KEYWORDS\" nil nil parse) (:subtitle \"SUBTITLE\" nil nil parse) (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format) (:latex-caption-above nil nil org-latex-caption-above) (:latex-classes nil nil org-latex-classes) (:latex-default-figure-position nil nil org-latex-default-figure-position) (:latex-default-table-environment nil nil org-latex-default-table-environment) (:latex-default-quote-environment nil nil org-latex-default-quote-environment) (:latex-default-table-mode nil nil org-latex-default-table-mode) (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format) (:latex-engraved-options nil nil org-latex-engraved-options) (:latex-engraved-preamble nil nil org-latex-engraved-preamble) (:latex-engraved-theme \"LATEX_ENGRAVED_THEME\" nil org-latex-engraved-theme) (:latex-footnote-defined-format nil nil org-latex-footnote-defined-format) (:latex-footnote-separator nil nil org-latex-footnote-separator) (:latex-format-drawer-function nil nil org-latex-format-drawer-function) (:latex-format-headline-function nil nil org-latex-format-headline-function) (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function) (:latex-hyperref-template nil nil org-latex-hyperref-template t) (:latex-image-default-scale nil nil org-latex-image-default-scale) (:latex-image-default-height nil nil org-latex-image-default-height) (:latex-image-default-option nil nil org-latex-image-default-option) (:latex-image-default-width nil nil org-latex-image-default-width) (:latex-images-centered nil nil org-latex-images-centered) (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format) (:latex-inline-image-rules nil nil org-latex-inline-image-rules) (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format) (:latex-src-block-backend nil nil org-latex-src-block-backend) (:latex-listings-langs nil nil org-latex-listings-langs) (:latex-listings-options nil nil org-latex-listings-options) (:latex-minted-langs nil nil org-latex-minted-langs) (:latex-minted-options nil nil org-latex-minted-options) (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels) ...) :filters ((:filter-options . org-latex-math-block-options-filter) (:filter-paragraph . org-latex-clean-invalid-line-breaks) (:filter-parse-tree org-latex-math-block-tree-filter org-latex-matrices-tree-filter org-latex-image-link-filter) (:filter-verse-block . org-latex-clean-invalid-line-breaks)) :blocks nil :menu (108 \"Export to LaTeX\" ((76 \"As LaTeX buffer\" org-latex-export-as-latex) (108 \"As LaTeX file\" org-latex-export-to-latex) (112 \"As PDF file\" org-latex-export-to-pdf) (111 \"As PDF file and open\" (lambda ... ...))))))
 org-create-formula-image(\"$1 - 3 = -1$\" \"/home/ck/org/Nots/ltximg/org-ltximg_7fc39c2dc1a834...\" (:foreground \"#bbc2cf\" :background \"#282c34\" :scale 2 :html-foreground \"Black\" :html-background \"Transparent\" :html-scale 1.0 :matchers (\"begin\" \"$1\" \"$\" \"$$\" \"\\\\(\" \"\\\\[\")) forbuffer imagemagick)
 org-format-latex(\"ltximg/org-ltximg\" 101 113 \"/home/ck/org/Nots/\" overlays nil forbuffer imagemagick)
 org--latex-preview-region(101 113)
 org-latex-preview()
 org-fragtog--enable-frag((latex-fragment (:value \"$1 - 3 = -1$\" :begin 101 :end 113 :post-blank 0 :parent (paragraph (:begin 90 :end 113 :contents-begin 90 :contents-end 113 :post-blank 0 :post-affiliated 90 :mode nil :granularity element :cached nil :parent (section (:begin 1 :end 113 :contents-begin 1 :contents-end 113 :robust-begin 1 :robust-end 111 :post-blank 0 :post-affiliated 1 :mode first-section :granularity element :cached nil :parent (org-data ...) :org-element--cache-sync-key (12 . 0))) :org-element--cache-sync-key (12 . 90))))))
 org-fragtog--post-cmd()
"
Please report this to Org mode mailing list (M-x org-submit-bug-report).
■  Warning (org-element-cache): org-element--cache: Org parser error in 20230908094329-orglatexmath.org::14. Resetting.
The error was: (error "org-element--cache: Emergency exit")
Backtrace:
"  backtrace-to-string(nil)
 org-element-at-point()
 org-back-to-heading(t)
 org-up-heading-safe()
 org-entry-get-with-inheritance(\"LOG_INTO_DRAWER\" t)
 org-entry-get(nil \"LOG_INTO_DRAWER\" inherit t)
 org-log-into-drawer()
 org-mode-flyspell-verify()
 flyspell-word()
 flyspell-post-command-hook()
"
Please report this to Org mode mailing list (M-x org-submit-bug-report).

  1. and her is may init.el:
(defun efs/org-babel-tangle-config ()
  (when (string-equal (buffer-file-name)
		      (expand-file-name "/home/ck/org/Nots/20230823070942-init.org"))
    ;; Dynamic scoping to the rescue
    (let ((org-confirm-babel-evaluate nil))
      (org-babel-tangle))))

(add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'efs/org-babel-tangle-config)))

(use-package dashboard
    :ensure t
    :config
    (dashboard-setup-startup-hook))

(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*")))

;;test23
(setq custom-file (locate-user-emacs-file "evars.el"))
(load custom-file 'noerror 'nomessage)

;; Minimize garbage collection during startup
(setq gc-cons-threshold most-positive-fixnum)

;; Lower threshold back to 8 MiB (default is 800kB)
(add-hook 'emacs-startup-hook
          (lambda ()
            (setq gc-cons-threshold (expt 2 23))))
(defun loadup-gen ()
  "Generate the lines to include in the lisp/loadup.el file
to place all of the libraries that are loaded by your InitFile
into the main dumped emacs"
  (interactive)
  (defun get-loads-from-*Messages* ()
    (save-excursion
      (let ((retval ()))
	(set-buffer "*Messages*")
	(beginning-of-buffer)
	(while (search-forward-regexp "^Loading " nil t)
	  (let ((start (point)))
	    (search-forward "…")
	    (backward-char 3)
	    (setq retval (cons (buffer-substring-no-properties start (point)) retval))))
	retval)))
  (map 'list
       (lambda (file) (princ (format "(load \"%s\")\n" file)))
       (get-loads-from-*Messages*)))
;; time the loading of the .emacs
;; keep this on top of your .emacs
(defvar *emacs-load-start* (current-time))
(defun anarcat/time-to-ms (time)
  (+ (* (+ (* (car time) (expt 2 16)) (car (cdr time))) 1000000) (car (cdr (cdr time)))))
(defun anarcat/display-timing ()
  (message ".emacs loaded in %fms" (/ (- (anarcat/time-to-ms (current-time)) (anarcat/time-to-ms *emacs-load-start*)) 1000000.0)))
(add-hook 'after-init-hook 'anarcat/display-timing t)

(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
			 ("elpa" . "https://elpa.gnu.org/packages/")))

(unless package-archive-contents
 (package-refresh-contents))

;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
   (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (emacs-lisp . t)
   (python . t)
   ))

(use-package org-auto-tangle
:hook (org-mode . org-auto-tangle-mode))

(define-key org-mode-map (kbd "C-c C-r") 'org-mode-restart)

(setq org-agenda-include-diary t)

(use-package sudo-edit)
(define-key org-mode-map (kbd "C-c e") 'sudo-edit)

(setq org-agenda-start-with-log-mode t)
(setq org-log-done 'time)
(setq org-log-into-drawer t)
(setq org-agenda-files '("~/org/Nots"))

(setq calendar-week-start-day 1

		  calendar-day-name-array ["Sonntag" "Montag" "Dienstag" "Mittwoch"
					   "Donnerstag" "Freitag" "Samstag"]
		  calendar-month-name-array ["Januar" "Februar" "März" "April" "Mai"
					     "Juni" "Juli" "August" "September" "Oktober" "November" "Dezember"])
	(setq solar-n-hemi-seasons '())
	(setq holiday-general-holidays '())

	(setq holiday-christian-holidays '())

(defun holiday-add-Block (start-date end-date list mark)
  "Add fixed holidays with MARK for all dates between START-DATE and END-DATE."
  (let* ((start-time (encode-time 0 0 0 (nth 1 start-date) (nth 0 start-date) 2023))
	 (end-time (encode-time 0 0 0 (nth 1 end-date) (nth 0 end-date) 2023))
	 (current-time start-time))
    (while (> (float-time (time-subtract end-time current-time)) 1)
     ;; Print the values of current-time and end-time
      (message "current-time: %s" current-time)
      (message "end-time: %s" end-time)

      (let ((date-list (decode-time current-time)))
	(add-to-list list
		     `(holiday-fixed ,(nth 4 date-list) ; month
				     ,(nth 3 date-list) ; day
				     ,mark)))
      (setq current-time (time-add current-time (* 60 60 24))))
    ;; Add the end-date to the list of holidays
    (let ((date-list (decode-time end-time)))
      (add-to-list list
		   `(holiday-fixed ,(nth 4 date-list) ; month
				   ,(nth 3 date-list) ; day
				   ,mark)))))

(holiday-add-Block '(1 1) '(1 5) 'holiday-general-holidays "Weihnachtsferien")
(holiday-add-Block '(7 13) '(8 25) 'holiday-general-holidays "Sommerferien")
(holiday-add-Block '(2 5) '(2 10) 'holiday-general-holidays "Winterferien")
(holiday-add-Block '(3 25) '(4 5) 'holiday-general-holidays "Osterferien")
(holiday-add-Block '(12 23) '(12 31) 'holiday-general-holidays "Weihnachtsferien")

(global-set-key (kbd "C-c a") 'org-agenda)

(use-package org-super-agenda)
(setq org-habit-following-days 7)
(setq org-habit-graph-column 51)
(setq habit-preceding-days 20)
(setq org-habit-show-habits t)
(setq org-habit-show-habits-only-for-today t)

(require 'org-tempo)
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(add-to-list 'org-structure-template-alist '("py" . "src python"))
(add-to-list 'org-structure-template-alist '("ja" . "src java"))

(use-package ya-org-capture
  :after yankpad
  :load-path "~/.emacs.d/lisp"
  :config
    (ya-org-capture/setup))

(use-package org-roam
  :ensure t
  :init
  (setq org-roam-v2-ack t)
  :custom
  (org-roam-directory "~/org/Nots")
  (org-roam-completion-everywhere t)
  (org-roam-capture-templates
      '(("d" "default" plain
       "%?"
       :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
       :unnarrowed t)

      ("p" "Protokoll" plain
       ":Schule: \n* Versuchsziel \n* Chemikalien \n* Theoretische Grundlagen des Versuches\n* [[id:c9b2830f-54e4-4545-a723-da2f60d3fb9a][MA]][[id:c9b2830f-54e4-4545-a723-da2f60d3fb9a][MA]]Durchführung und Beobachtungen\n* Messdaten\n* Berechnungen\n* Auswertung/Bewertung\n* Entsorgung\n* Angaben zur Arbeitssicherheit"
       :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
       :unnarrowed t)

      ("f" "Schuhl Fach" plain
       ":Schule: \n* Lehrer \n** Name \n** Kürzel \n** Publikationen / Leben \n* Fach \n** Inhalte\n** Glossa\n|||\n** Aufgaben\n** Hausaufgaben"
       :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
       :unnarrowed t)

       ("v" "Vormel" plain
       "\n* Vormel\n\n\n* Beispiel"
       :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
       :unnarrowed t)))

  :bind (("C-c n l" . org-roam-buffer-toggle)
	 ("C-c n f" . org-roam-node-find)
	 ("C-c n i" . org-roam-node-insert)
	 :map org-mode-map
	 ("C-M-i" . completion-at-point)
	 :map org-roam-dailies-map
	 ("Y" . org-roam-dailies-capture-yesterday)
	 ("T" . org-roam-dailies-capture-tomorrow))
  :bind-keymap
  ("C-c n d" . org-roam-dailies-map)
  :config
  (require 'org-roam-dailies) ;; Ensure the keymap is available
  (org-roam-db-autosync-mode))

(use-package org-roam-ui
:bind (
       ("C-c n u" . org-roam-ui-mode))
:config
  (setq org-roam-ui-sync-theme t
        org-roam-ui-follow t
        org-roam-ui-update-on-save t
        org-roam-ui-open-on-start t))

(defvar centered-visual-fill--original-org-faces nil
  "List of original org face attributes")

(define-minor-mode centered-visual-fill-mode
  "Center text, enable visual-fill-column-mode, and change org header font"
  :init-value nil
  :lighter " Centered"
  (if centered-visual-fill-mode
      (progn
	(setq-local visual-fill-column-center-text t)
	(visual-fill-column-mode 1)
	  (set-face-attribute (car face) nil :font "Menlo" :weight 'regular :height (cdr face))))
    (kill-local-variable 'visual-fill-column-center-text)
    (visual-fill-column-mode -1)
    (dolist (face centered-visual-fill--original-org-faces)
      (apply #'set-face-attribute `(,(car face) nil ,@(cdr face))))
    (setq centered-visual-fill--original-org-faces nil))

(use-package org-fragtog)
(use-package xenops)
      (setq org-latex-inputenc-alist '(("utf8" . "utf8x" )))
	(setq org-format-latex-options (plist-put org-format-latex-options :scale 2))
	(global-auto-revert-mode -1)
	(require 'ox-latex)
(setq org-startup-with-latex-preview t)
	(add-hook 'org-mode-hook 'org-fragtog-mode)

	(with-eval-after-load 'org
	  (add-to-list 'org-latex-packages-alist '("" "tikz" t))
	  (add-to-list 'org-latex-packages-alist '("" "chemfig" t))
	  (add-to-list 'org-latex-packages-alist '("" "circuitikz" t))
	)
	(setq org-preview-latex-default-process 'imagemagick)

(use-package forge)
(setq org-startup-numerated t)

(defun efs/org-mode-setup ()
  (org-indent-mode)
  (variable-pitch-mode 1)
  (visual-line-mode 1))
;; Org Mode Configuration ------------------------------------------------------
(customize-set-variable 'org-blank-before-new-entry'((heading . auto)(plain-list-item . auto)))
(setq org-cycle-separator-lines 3)
(defun efs/org-font-setup ()
  ;; Replace list hyphen with dot
  (font-lock-add-keywords 'org-mode
			  '(("^ *\\([-]\\) "
			     (0 (prog1 () (compose-region (match-beginning 1) (match-end 1) "•"))))))

  ;; Set faces for heading levels
  (dolist (face '((org-level-1 . 1.4)
		  (org-level-2 . 1.3)
		  (org-level-3 . 1.05)
		  (org-level-4 . 1.0)
		  (org-level-5 . 1.1)
		  (org-level-6 . 1.1)
		  (org-level-7 . 1.1)
		  (org-level-8 . 1.1)))
    (set-face-attribute (car face) nil :font "CMU Serif" :weight 'Bold :height (cdr face)))

  ;; Ensure that anything that should be fixed-pitch in Org files appears that way
  (set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch)
  (set-face-attribute 'org-code nil   :inherit '(shadow fixed-pitch))
  (set-face-attribute 'org-table nil   :inherit '(shadow fixed-pitch))
  (set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
  (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
  (set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
  (set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch))

(use-package org
 ;; :hook (org-mode . efs/org-mode-setup)
  :config
  (setq org-ellipsis "▾"
	org-hide-emphasis-markers t)


  (setq org-agenda-start-with-log-mode 1)
  (setq org-log-done 'time)
  (setq org-log-into-drawer t)

  (efs/org-font-setup))

(use-package org-bullets
  :after org
  :hook (org-mode . org-bullets-mode)
  :custom
  (org-bullets-bullet-list '(" " " " " " " " " " " " " ")))
(require 'org-tempo)
(set-face-attribute 'org-level-1 nil :height 250 )
(set-face-attribute 'org-level-2 nil :height 200 )
(set-face-attribute 'org-level-3 nil :height 150 )
(set-face-attribute 'org-level-4 nil :height 150 )

(defun my-org-depth () (org-content 1))
(add-hook 'org-mode-hook 'my-org-depth)

(define-key global-map "\C-cc"'org-capture)
(setq org-capture-templates
 '(
 ("t" "TODO" entry (file+headline "~/org/agenda/Calendar.org" "Tasks")
 "* TODO %?\n  %i\n")
 ("p" "profile" entry (file+headline "~/org/agenda/Calendar.org" "Profile")
 "* %^{Name}\n** Geburtstag%?")
 ))

(require 'org-habit)

(setq org-startup-with-inline-images t)
(use-package org-inline-pdf)

(setq org-image-actual-width 400)
(add-hook 'org-mode-hook #'org-inline-pdf-mode)

(setq bookmark-save-flag 0)

(setq org-agenda-custom-commands
      '(("w" "Agenda for next 2 weeks"
         ((agenda "" ((org-agenda-span 14))))
         ((org-agenda-write-buffer-name "Agenda for next 2 weeks")
          (org-agenda-write-to-absolute-file "~/agenda.txt")))))

(use-package mu4e
 :ensure nil
;; :load-path "/usr/share/emacs/site-lisp/mu4e/"
;; :defer 20 ; Wait until 20 seconds after startup
:config


(setq mu4e-change-filenames-when-moving t)


;; Refresh mail using isync every 10 minutes
(setq mu4e-update-interval (* 10 60))
(setq mu4e-get-mail-command "mbsync -a")
(setq mu4e-maildir "~/Mail")

(setq mu4e-drafts-folder "/[Gmail]/Drafts")
(setq mu4e-sent-folder   "/[Gmail]/Sent Mail")
(setq mu4e-refile-folder "/[Gmail]/All Mail")
(setq mu4e-trash-folder  "/[Gmail]/Trash")

(setq mu4e-maildir-shortcuts
    '(("/Inbox"             . ?i)
      ("/[Gmail]/Sent Mail" . ?s)
      ("/[Gmail]/Trash"     . ?t)
      ("/[Gmail]/Drafts"    . ?d)
      ("/[Gmail]/All Mail"  . ?a))))
(global-set-key (kbd "C-c k") 'mu4e)

(setq evil-want-keybinding nil)
  (use-package evil
    :config
    (evil-mode 1))

(use-package evil-collection
  :after evil
  :ensure t
  :config
  (evil-collection-init))

(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
(define-key evil-insert-state-map (kbd "C-g") 'evil-normal-state)

(use-package evil-org
  :ensure t
  :after org
  :hook (org-mode . (lambda () evil-org-mode))
  :config
  (require 'evil-org-agenda)
  (evil-org-agenda-set-keys))

(defun efs/org-babel-tangle-config ()
  (when (string-equal (buffer-file-name)
		      (expand-file-name "/home/ck/org/Nots/20230823070942-init.org"))
    ;; Dynamic scoping to the rescue
    (let ((org-confirm-babel-evaluate nil))
      (org-babel-tangle))))

(add-hook 'org-mode-hook (lambda () (add-hook 'after-save-hook #'efs/org-babel-tangle-config)))

(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (emacs-lisp . t)
   (python . t)
   ))
;;tes

;;test
(use-package no-littering)
(setq no-littering-etc-directory
       (expand-file-name "~/.emacs.d/etclit" user-emacs-directory))
(setq no-littering-var-directory
       (expand-file-name "~/.emacs.d/datalit" user-emacs-directory))
(setq auto-save-file-name-transforms
      `((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))

(require 'no-littering)

(use-package ivy
  :demand
  :diminish
  :bind (("C-s" . swiper)
	 :map ivy-minibuffer-map
	 ("TAB" . ivy-alt-done)
	 ("C-l" . ivy-alt-done)
	 ("C-j" . ivy-next-line)
	 ("C-k" . ivy-previous-line)
	 :map ivy-switch-buffer-map
	 ("C-k" . ivy-previous-line)
	 ("C-l" . ivy-done)
	 ("C-d" . ivy-switch-buffer-kill)
	 :map ivy-reverse-i-search-map
	 ("C-k" . ivy-previous-line)
	 ("C-d" . ivy-reverse-i-search-kill))
  :config
  (ivy-mode 1))

(set-face-attribute 'default nil :height 150)

(global-display-line-numbers-mode)

(setq inhibit-startup-message t
 use-dialog-box nil)
(setq display-line-numbers-type 'visual)
(set-fringe-mode 10)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(global-auto-revert-mode 1)


(use-package all-the-icons
   :ensure t)


(use-package doom-themes
  :ensure t
  :config
  (load-theme 'doom-one))
(use-package doom-modeline
  :ensure t
  :hook (after-init . doom-modeline-mode))

(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))
(use-package highlight-indentation
  :ensure t)
(use-package sage-shell-mode
  :ensure t
  :init (progn
(use-package auto-complete
     :init (progn
	     (setq ac-delay 0.3
		   ac-auto-start 2)))

   (eval-after-load "auto-complete"
     '(setq ac-modes (append '(sage-shell-mode sage-shell:sage-mode) ac-modes)))
   (add-hook 'sage-shell:sage-mode-hook 'ac-sage-setup)
   (add-hook 'sage-shell:sage-mode-hook 'auto-complete-mode)
   (add-hook 'sage-shell-mode-hook 'ac-sage-setup)
   (add-hook 'sage-shell-mode-hook 'auto-complete-mode)
   (setq ac-sage-show-quick-help t)))

(setq display-time-interval 60)
(setq display-time-format "%H:%M | %m.%d.%y")
(display-time-mode)
(display-battery-mode)

(use-package company-tabnine
  :ensure t)
(require 'company-tabnine)
(nconc company-backends '(company-tabnine))

(use-package quickrun
)
(require 'quickrun)
(with-eval-after-load 'lsp-mode
   (define-key lsp-mode-map (kbd "C-c C-c") 'quickrun))

;;test
(use-package undo-tree
 :defer t
 :diminish undo-tree-mode
 :init (global-undo-tree-mode)
 :custom
 (undo-tree-visualizer-diff t)
 (undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
 (undo-tree-visualizer-timestamps t))
(require 'undo-tree)
(global-undo-tree-mode)
(setq undo-tree-show-help-in-visualize-buffer t)
(setq undo-tree-show-minibuffer-help t)
(setq undo-tree-minibuffer-help-dynamic t)
(setq undo-tree-auto-save-history t)

(use-package quickrun)
(require 'quickrun)

(use-package flex-autopair)
(require 'flex-autopair)
(flex-autopair-mode 1)

(use-package projectile)
(use-package flycheck)
(use-package lsp-mode :hook ((lsp-mode . lsp-enable-which-key-integration)))
(use-package hydra)
(use-package company)
(use-package lsp-ui)
(use-package which-key :config (which-key-mode))
(use-package lsp-java :config (add-hook 'java-mode-hook 'lsp))
(use-package dap-mode :after lsp-mode :config (dap-auto-configure-mode))
(use-package dap-java :ensure nil)
(use-package helm-lsp)
(use-package helm
  :config (helm-mode))
(use-package lsp-treemacs)

(use-package python-mode
  :ensure t
  :hook (python-mode . lsp-deferred)
  :custom
  ;; NOTE: Set these if Python 3 is called "python3" on your system!
  ;; (python-shell-interpreter "python3")
  ;; (dap-python-executable "python3")
  (dap-python-debugger 'debugpy)
  :config
  (require 'dap-python))

(use-package pyvenv
  :config
  (pyvenv-mode 1))

(use-package typescript-mode
 :mode "\\.ts\\'"
 :hook (typescript-mode . lsp-deferred)
 :config
 (setq typescript-indent-level 2))

(use-package lsp-mode
  :init
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-c l")
  :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
	 (XXX-mode . lsp)
	 ;; if you want which-key integration
	 (lsp-mode . lsp-enable-which-key-integration))
  :commands lsp)

(use-package lsp-ui
  :hook (lsp-mode . lsp-ui-mode)
  :custom
  (lsp-ui-doc-position 'bottom))

(use-package dap-mode :after lsp-mode :config (dap-auto-configure-mode))

(defun efs/lsp-mode-setup ()
 (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols))
 (lsp-headerline-breadcrumb-mode))

(use-package helm-lsp)
(use-package helm
  :config (helm-mode))

(use-package projectile
  :diminish projectile-mode
  :config (projectile-mode)
  :custom ((projectile-completion-system 'ivy))
  :bind-keymap
  ("C-c p" . projectile-command-map)
  :init
  ;; NOTE: Set this to the folder where you keep your Git repos!
  (when (file-directory-p "~/Projects/Code")
    (setq projectile-project-search-path '("~/Projects/Code")))
  (setq projectile-switch-project-action #'projectile-dired))

(use-package company
   :ensure t
   :init
   (add-hook 'after-init-hook 'global-company-mode))
(setq company-idle-delay 0)

(use-package company-anaconda
  :ensure t)

(use-package company-math
  :ensure t)

(use-package company-auctex
  :ensure t)

(use-package company-box
  :hook (company-mode . company-box-mode))

(use-package mmm-mode
:ensure t
:init (progn
        (setq mmm-global-mode 'maybe))
:config  (progn (mmm-add-classes
                 '((python-rst
                    :submode rst-mode
                    :front "^ *[ru]?\"\"\"[^\"]*$"
                    :back "^ *\"\"\""
                    :include-front t
                    :include-back t
                    :end-not-begin t)))
                (mmm-add-mode-ext-class 'python-mode nil 'python-rst)
                (mmm-add-mode-ext-class 'sage-shell:sage-mode nil 'python-rst)
                ))

(use-package cython-mode
:ensure t
:mode (("\\.pyx\\'"  . cython-mode)
       ("\\.spyx\\'" . cython-mode)
       ("\\.pxd\\'"  . cython-mode)
       ("\\.pxi\\'"  . cython-mode)))

(use-package python-mode
:init (progn
        (add-hook 'python-mode-hook 'highlight-indentation-mode)
        (add-hook 'python-mode-hook 'anaconda-mode)
        (add-hook 'python-mode-hook 'eldoc-mode)
        (add-hook 'python-mode-hook 'sphinx-doc-mode))

:config (progn
          (setq-default python-indent 4)
          (setq python-fill-docstring-style 'onetwo)

          (when (executable-find "ipython")
            (setq
             python-shell-interpreter "ipython"
             python-shell-interpreter-args ""
             python-shell-prompt-regexp "In \\[[0-9]+\\]: "
             python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
             python-shell-completion-setup-code
             "from IPython.core.completerlib import module_completion"
             python-shell-completion-module-string-code
             "';'.join(module_completion('''%s'''))\n"
             python-shell-completion-string-code
             "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))))

(use-package which-key
  :init (which-key-mode)
  :diminish which-key-mode
  :config
  (setq which-key-idle-delay 0))

(use-package counsel
  :bind (("M-x" . counsel-M-x)
	 ("C-x b" . counsel-ibuffer))
  :config)

(use-package helpful
  :custom
  (counsel-describe-function-function #'helpful-callable)
  (counsel-describe-variable-function #'helpful-variable)
  :bind
  ([remap describe-function] . counsel-describe-function)
  ([remap describe-command] . helpful-command)
  ([remap describe-variable] . counsel-describe-variable)
  ([remap describe-key] . helpful-key))
(with-eval-after-load 'counsel
  (recentf-mode))

(use-package eglot-java)

(use-package pdf-tools
    :ensure t
    :config
(add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode)
  )
(pdf-tools-install)
(use-package saveplace-pdf-view)

(require 'saveplace-pdf-view)
(save-place-mode 1)

(defun my-render-org-table-at-point ()
(interactive)
(save-excursion
  (beginning-of-line)
  (if (overlays-at (point))
      ;; this is a rough solution, because there can
      ;; be other overlays at point
      (delete-overlay (car (overlays-at (point))))

    (let* ((element-type (org-element-type (org-element-at-point))))
      (if (and (not (eq element-type 'table))
               (not (eq element-type 'table-row)))
          (error "not at an org table")

        (while (not (eq 'table (org-element-type (org-element-at-point))))
          (forward-line -1))

        (my-render-org-table (org-element-at-point)))))))

(use-package systemd)



(setq initial-scratch-message "")
(setq initial-major-mode 'org-mode)

(use-package speed-type)

(recentf-mode 1)
(setq recentf-max-menu-items 25)
(setq recentf-max-saved-items 25)
(global-set-key (kbd "C-x e") 'recentf-open-files)

(setq split-width-threshold 0)
(setq split-height-threshold 100)

(use-package yasnippet
  :config
  (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  (yas-global-mode 1))

(use-package flycheck
  :ensure t
  :hook (org-mode . flyspell-mode)
  :hook (org-mode . flyspell-buffer)
  );;:init (global-flycheck-mode))

(with-eval-after-load "ispell"
  ;; Configure `LANG`, otherwise ispell.el cannot find a 'default
  ;; dictionary' even though multiple dictionaries will be configured
  ;; in next line.
  (setenv "LANG" "en_US.UTF-8")
  (setq ispell-program-name "hunspell")
  ;; Configure German, Swiss German, and two variants of English.
  (setq ispell-dictionary "de_DE,de_CH,en_GB,en_US")
  ;; ispell-set-spellchecker-params has to be called
  ;; before ispell-hunspell-add-multi-dic will work
  (ispell-set-spellchecker-params)
  (ispell-hunspell-add-multi-dic "de_DE,de_CH,en_GB,en_US")
  ;; For saving words to the personal dictionary, don't infer it from
  ;; the locale, otherwise it would save to ~/.hunspell_de_DE.
  (setq ispell-personal-dictionary "~/.hunspell_personal"))

;; The personal dictionary file has to exist, otherwise hunspell will
;; silently not use it.
(unless (file-exists-p ispell-personal-dictionary)
  (write-region "" nil ispell-personal-dictionary nil 0))


org fragtog mode stops working after a single error

I have just tried using org-fragtog mode and I really like the idea, I was looking for exactly this package. However I noticed a small issue with the way errors are handled, which is probably due to a weird appear I have.

When I type the following snippet normally

\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}

everything works exactly as intended, and this looks like a very cool mode. But I tend to write first begin{} and then fill in the braces with pmatrix. If I do that, when I move the cursor out of the braces, the hook to the org-fragtog--post-cmd fires although I haven't finished typing. Of course, since there is no \end, this is not a valid LaTeX code and the preview fails, I get the following error reported in the *Messages* buffer
Error in post-command-hook (org-fragtog--post-cmd): (error "File \"/tmp/orgtexIuM9v8.dvi\" wasn’t produced. Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.")

Just firing the error would be ok, but after this error, fragtog mode stops working completely, and I have to toggle manually the latex-preview again.

I am pretty new to emacs lisp, so not sure what the fix should be. I am wondering if catching the error with

(ignore-error (org-latex-preview))

could be a correct fix

How do I install and load your package in emacs?

Hi,

This package seems great but as I cannot see your package within the available list in emacs I'd like more details on how to 'install and load'.

What I do within emacs:
‘M-x package-list-packages’

In my .emacs I have the following lines:

(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(when (not package-archive-contents)
(package-refresh-contents))

Thanks in advance

feature request: display all expressions as rendered when first visiting buffer

@io12 I think what the poster in #9 meant was (paraphrasing):

Would it be possible to add a command to rerender all LaTeX expressions in the buffer, so that I can add that to my org-mode-hook?

At the level of implementation, perhaps it's also possible to cache the images somewhere, so that they aren't actually rerendered but simply re-inserted in the buffer.

I think it's a good feature request!

Can org-fragtog work in programming buffers in places where org-latex-preview works?

I just started using org-fragtog in org-mode buffers and it is really great.

I often add latex equations to python docstrings and I can see them just fine with org-latex-preview. It would be nice to have org-fragtog also working in python docstrings.

Is it feasible to extend it to work in places where org-latex-preview already works?

Not working with org-journal

I really enjoy this, thanks for your effort to make this into a package other people can use!

It doesn't work with org-journal buffers, any idea what could be going wrong?

Bug with snippets

Describe the bug
After release version 0.4.2, the cursor started shifting in some snippets.

To Reproduce
I just used the following snippet

# -*- mode: snippet -*-
# name: test
# key: test
# --
#+begin_latex latex
\begin{align*}
  $0
\end{align*}
#+end_latex

Videos
With enabled org-frag-tog:
Peek 2022-08-28 10-06

With disabled org-frag-tog:
Peek 2022-08-28 10-05

Equation numbering

Hello,

I am not sure it is a question for org-fragtog itself.

The equation environment in latex usually comes with a numbering.

The org latex preview does display this number but always with the same number (1),
probably because each equation is processed independently of others.

Should there be a way to improve this ? For example, by making org latex preview count
previous equation environments, except if they come with a *, before the current one ?

Regards

question: preferred SIunitx solution for units

In awth13/org-appear#2 I briefly discuss how I would like to work with units in org-mode for latex and pdf export.

Below I wrote a quick test to help illustrate my struggles with how to write nicely in org-mode and have stuff export nicely and tweakable:

* test siunitx for org-mode
#+latex_header: \usepackage{siunitx}
# example extra units
#+latex_header: \DeclareSIUnit\annum{a} % a year, used in years before present
#+latex_header: \DeclareSIUnit\year{yr} % a duration

#+options: toc:nil

#+begin_src emacs-lisp :exports none
  (setq org-entities-user
   '(("celsius" "\\(^{\\circ}\\)C" nil "&deg;C" "°C" "°C" "℃")
     ("us" "\\," nil "&nbsp;" " " " " " ")))
#+end_src

| name               | code                | output              | org-fragtog preview |
|--------------------+---------------------+---------------------+---------------------|
| plain              | ~35 m~                | 35 m                | NA                  |
| manual small space | ~35\(\,\)m~           | 35\(\,\)m           | yes                  |
| ~\us{}~ entity           | ~35\us{}m~                | 35\us{}m                | yes                 |
| inline SI          | ~\SI{35}{\metre}~     | \SI{35}{\metre}     | no                  |
| dollars            | ~$\SI{35}{\metre}$~   | $\SI{35}{\metre}$   | yes                 |
| round              | ~\(\SI{35}{\metre}\)~ | \(\SI{35}{\metre}\) | yes                 |
| square             | ~\[\SI{35}{\metre}\]~ | \[\SI{35}{\metre}\] | yes                 |

which looks as follows in my emacs:
2021-05-10-10:02:17_region
(additional minor issue: table outlining fails when previewing LaTeX fragments)

and looks like this in the PDF export:
2021-05-10-10:01:25_region

What are your thoughts on the ideal approach here?
Wrapping the \SI{xx}{xx} blocks in either $ or \(...\) seems to work nicely with the preview, but does put it all in math mode in the raw latex file (see details section below).
So far I've preferred to work with the inline SI solution.
Using the org-entity results in correct spacing but is less flexible than relying on SIunitx.

latex export of above file
% Created 2021-05-10 Mon 09:37
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{siunitx}
\DeclareSIUnit\annum{a} % a year, used in years before present
\DeclareSIUnit\year{yr} % a duration
\author{Ilja Kocken}
\date{\today}
\title{}
\begin{document}

\section{test siunitx for org-mode}
\label{sec:org91a7591}
\begin{center}
\begin{tabular}{lll}
name & code & output\\
\hline
plain & \texttt{35 m} & 35 m\\
manual small space & \texttt{35\textbackslash{}(\textbackslash{},\textbackslash{})m} & 35\(\,\)m\\
\texttt{\textbackslash{}us} entity & \texttt{35\textbackslash{}us\{\}m} & 35\,m\\
inline SI & \texttt{\textbackslash{}SI\{35\}\{\textbackslash{}metre\}} & \SI{35}{\metre}\\
dollars & \texttt{\$\textbackslash{}SI\{35\}\{\textbackslash{}metre\}\$} & \(\SI{35}{\metre}\)\\
round & \texttt{\textbackslash{}(\textbackslash{}SI\{35\}\{\textbackslash{}metre\}\textbackslash{})} & \(\SI{35}{\metre}\)\\
square & \texttt{\textbackslash{}[\textbackslash{}SI\{35\}\{\textbackslash{}metre\}\textbackslash{}]} & \[\SI{35}{\metre}\]\\
\end{tabular}
\end{center}
\end{document}

Upstream the feature to mainline org mode?

Do you consider upstream the code to org mode and make it a default?

I think upstreaming this feature has some benefits, like

  • ppl no long have to google "how to toggle org-latex". Finding tweaks or packages online always wastes time.
  • extra helps from org maintainers?
  • More users may enjoy it without even know it if this become default :)

Problem about determination of latex-fragment

Thanks for your packages. I find that when typing space before $, it will determine wrongly and begin to generate picture.
For example, when the context is $x\in$ and then type a space $x\in $. Or with $x\in X$ and then delete 'X" $x\in $

Toggle Entire Line

Describe the solution you'd like
I would love it if all of the fragments on the current line were toggled instead of only the fragments under the cursor. That way when you move to a new line you can see all of the relevant latex code but the entire line re-toggles upon leaving the line. I'm not sure how difficult this would be to implement I figured it would be worth a suggestion!

Additional context
Back when I used vim, one of my favorite packages was tex-conceal which provides very similar functionality.

‘org-element-property’ is not known to be defined.

Hi. When running package-install got.

In end of data:
org-fragtog.el:227:1:Warning: the function ‘org-element-property’ is not knownto be defined

When I write in org this works, but after restarting emacs (doom) it can't find it.

emacs        27.2
doom         21.12.0-alpha HEAD -> master, origin/master c7753adb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.