I'm using org-mode in emacs, but I think the question is also relevant for auctex users.

In org-mode you can show latex fragments, as the manual demonstrates.

But: these fragments (mostly math formulae) seem to have constant size. When I type C-x C-+ or C-x C-- only the buffer text size changes. How can I change the fragments size from the buffer?

(I know I can make the fragments larger or smaller with org-format-latex-options, but this is permanent. I want to change the size of the fragments (the png files) like the text.)


Here is a start: hook into text-scale-mode-hook and update org-format-latex-options accordingly.

(defun update-org-latex-fragments ()
  (org-toggle-latex-fragment '(16))
  (plist-put org-format-latex-options :scale text-scale-mode-amount)
  (org-toggle-latex-fragment '(16)))
(add-hook 'text-scale-mode-hook 'update-org-latex-fragments)

A scaling factor might be needed before text-scale-mode-amount though...

  • No org-toggle-latex-fragment function in latest org-mode. – Leu_Grady Jan 30 '15 at 1:46
  • @user3173715 Your latest is not my latest then... – thisirs Feb 1 '15 at 0:37
  • you are using development org-mode? – Leu_Grady Feb 1 '15 at 0:38
  • @user3173715 Use org-preview-latex-fragment (obsolete since Aug 2014) – thisirs Feb 1 '15 at 10:46

Based on the answer from thisirs, I am using the following with success. The scale factor in this example is 2.3:

(defun update-org-latex-fragment-scale ()
  (let ((text-scale-factor (expt text-scale-mode-step text-scale-mode-amount)))
    (plist-put org-format-latex-options :scale (* 2.3 text-scale-factor)))
(add-hook 'text-scale-mode-hook 'update-org-latex-fragment-scale)

Note that I have removed the code that toggles the preview, since I prefer to do that manually, and it can take a while if there are many fragments to preview. This code only adjusts the scale of previewed fragments, so that the next time they are displayed using C-c C-x C-l, they will have an appropriate size that matches the text.

  • Is hardcoding the factor necessary? – T. Verron Jun 10 '15 at 8:52
  • @T.Verron the scale factor is something that affects how large or small the previewed fragment is with respect to the text size. The ratio between those two probably depends on the font you're using, and possibly the dpi of your screen. It may be possible to automate the computation of a scale-factor, but I prefer to just fiddle with it until it looks to my liking. Note that the "hard-coded scale factor" is not the same as the text-scale-factor, which does automatically change as you zoom your text. – Mark Jun 11 '15 at 15:54
  • Oh, ok, indeed I thought that it would be the zoom factor. Sorry! – T. Verron Jun 11 '15 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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