1

I use emacs in frame-only mode and org to typeset latex equations and technical writing.

Since it is hard to see and understand the latex equations in their raw format, I use a package called org-fragtog which just calls the function org-latex-preview to convert the latex code to an image, and insert it in the current buffer.

The problem is, every time a new equation is inserted for the first time, org-latex-preview calls dvipng which opens a new window with the message:

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

Is there a way to suppress this window 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.

Update

While not knowing a lot of elisp, I could craft the function below. The only problem is it is not being called after org-latex-preview is executed. Anyone know why?

(defun kill-latex-preview-window ()
  (interactive
  (let ((buffer "*Org Preview LaTeX Output*"))
    (if (get-buffer buffer)
        (progn
        (delete-frame (select-frame-by-name buffer))
        (kill-buffer buffer)
        )
    )
  )
  )
)

(add-hook 'post-command-hook 'kill-latex-preview-window )
6
  • I think you mean a new window, not buffer. I don't think you can inhibit the buffer creation, but maybe you can dismiss the window.
    – Muihlinn
    Commented May 14, 2020 at 20:46
  • Hi Muihlinn! Thanks, in fact on second look what I am trying to delete is a frame with a lone window. I tried adding a hook to post-command-hook with delete-window but I am getting the error: Attempt to delete minibuffer or sole ordinary window. Do you have some suggestion?
    – Elijah
    Commented May 14, 2020 at 21:00
  • I don't get a new window at all. Can you reproduce this with emacs -q? If you cannot, then something in your init file is doing this. Alternatively, you might try to install imagemagick and do (setq org-preview-latex-default-process 'imagemagick) and see if that behaves any better.
    – NickD
    Commented May 14, 2020 at 21:12
  • I don't use embebbed latex as much to feel such things like an annoyance. Anyhoo I guess that you can pass -q to dvips to silence it, customizing org-preview-latex-process-alist. It's just a wild guess, I don't know if silencing it will have the desired effect.
    – Muihlinn
    Commented May 14, 2020 at 21:27
  • Hi @NickD, what is creating the new window is the frames-only mode. It is important for me since I use a tilling window manager, so no reason to split windows in Emacs. If I disable it, the problem goes away. @Muihlinn, I update my post with a function is almost correct. I just need to figure out how to call it with a hook after the org-latex-preview execution.
    – Elijah
    Commented May 14, 2020 at 22:40

2 Answers 2

1

Probably the simplest thing to do is to define your own preview function that locally redefines the function that pops up the buffer so that it does nothing, then redo the key binding so that it calls your function instead:

(defun my-org-latex-preview ()
  (interactive)
  (cl-letf (((symbol-function 'display-message-or-buffer) (lambda (msg) nil)))
    (org-latex-preview)))

(define-key org-mode-map (kbd "C-c C-x C-l" 'my-org-latex-preview)

Since it's a local redefinition it is unlikely to cause any problems, except in the case where you really want to see that buffer (e.g. in case of errors), but then you can switch to it manually: the buffer is still around, it is just not popped up.

I see also that you opened an issue which was a good thing to do: at the very least, they should know about the problem, but there may be a less hackish solution too (or they might implement one).

2
  • I upvoted, but dont have enough reputation yet for it to appear to you. Thanks again Nick!
    – Elijah
    Commented May 18, 2020 at 15:13
  • No problem - glad it was fixed!
    – NickD
    Commented May 18, 2020 at 15:53
0

Thanks to everyone who helped.

I contacted the package author which corrected the bug.

The solution is detailed on commit 67de558 and issue 32.

It basically added the function org-compile-file to the list of functions that are blacklisted in frames-only-mode in the function frames-only-mode-use-window-functions. This way, every time the function is called it only opens a window, and not a frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.