简体   繁体   English

如何配置Emacs使用可变字体来显示LaTeX公式的预可视化?

[英]How to configure Emacs to use variable fonts to display the previsualisation of LaTeX formulas?

I would like to use Emacs 24.2.1 in orgmode 7.9.3 on a data projector in class. 我想在课堂上的数据投影仪上使用orgmode 7.9.3中的Emacs 24.2.1。

  • I can pre-visualize latex formulas using org-preview-latex-fragment (Cc Cx Cl), and 我可以使用org-preview-latex-fragment(Cc Cx Cl)预先显示乳胶配方
  • I can increase the font used to display the text using text-scale-increase (C-+). 我可以使用text-scale-increase(C- +)增加用于显示文本的字体。

The problem is that the math fonts are not increasing along the text fonts. 问题是数学字体没有沿文本字体增加。

Is there a way to configure Emacs so that the math fonts are variable too? 有没有办法配置Emacs,以便数学字体也可变? Was this solved in a later version of orgmode (I was planning to wait for the end of the term to upgrade to version 8+, being afraid of having to invest a lot of time in updating my configuration). 这是在orgmode的更高版本中解决的(我计划等待该术语的结束升级到版本8+,害怕不得不花费大量时间来更新我的配置)。

A poor man's solution that works with advices and hooks is shown below. 下面显示了一个与建议和钩子一起使用的穷人解决方案。 Paste the code into your .emacs configuration file and re-start emacs. 将代码粘贴到.emacs配置文件中,然后重新启动emacs。 Afterwards, the equation images should be scaled 之后,应该缩放方程图像 at along with the text if you press C-+/-/0. 如果按 C - + / - / 0, 则与文本一起 They are just previews and their 他们只是预览和他们的 The bad thing is that the 坏事是 resolution is not enlarged. 决议没有扩大。 To get equation images with a good resolution hit Cc Cx Cl to regenerate the images. 为了获得具有良好分辨率的方程图像命中Cc Cx Cl以重新生成图像。 Note, that this sets the :scale property of the customization variable org-format-latex-options. 注意,这设置了自定义变量org-format-latex-options的:scale属性。 The customization of this variable will be lost for the current emacs session. 对于当前的emacs会话,此变量的自定义将丢失。

You need a gnu-emacs with built-in imagemagick. 你需要一个内置imagemagick的gnu-emacs。 Should be standard by now. 现在应该是标准的。

(defvar text-scale-mode-hook nil
"Hook run at end of command `text-scale-mode'.")

(defadvice text-scale-mode (after text-scale-mode-hooks nil activate)
  "Run `text-scale-mode-hook' at end of command `text-scale-mode'."
  (if (functionp text-scale-mode-hook)
      (funcall text-scale-mode-hook)
    (loop for hook in text-scale-mode-hook do
      (if (eq hook 't)
          (run-hooks (default-value text-scale-mode-hook))
        (run-hooks hook)))))

(defun org-text-scale-eye ()
  "Scale equation images according to text-scale-mode-amount."
  (when (boundp 'text-scale-mode-amount)
    (let ((relwidth (* (expt text-scale-mode-step text-scale-mode-amount))))
    (loop for ol in (overlays-in (point-min) (point-max)) do
      (when (eq (overlay-get ol 'org-overlay-type) 'org-latex-overlay)
        (unless (overlay-get ol 'org-image-original-width)
          (overlay-put ol 'org-image-original-width (car (image-size (overlay-get ol 'display) t))))
        (let ((ol-disp-plist (cdr (overlay-get ol 'display))))
          (setq ol-disp-plist (plist-put ol-disp-plist :type 'imagemagick))
          (setq ol-disp-plist (plist-put ol-disp-plist :width (round (* relwidth (overlay-get ol 'org-image-original-width)))))
          (overlay-put ol 'display (append '(image) ol-disp-plist))
          ))))
    (force-window-update)
    ))

(add-hook 'org-mode-hook '(lambda () (add-hook 'text-scale-mode-hook 'org-text-scale-eye)))

(defadvice org-format-latex (before set-scale activate)
  "Set :scale in `org-format-latex-options' to the scaling factor resulting from `text-scale-mode' and clear cache."
  (let ((relwidth (expt text-scale-mode-step text-scale-mode-amount)))
    (unless (= (plist-get org-format-latex-options :scale) relwidth)
      (plist-put org-format-latex-options :scale relwidth))))

Actually, I had a look at the code in org.el: The font height is regarded in the function org-create-formula-image-with-dvipng and the resolution option -D is set. 实际上,我看了一下org.el中的代码:在函数org-create-formula-image-with-dvipng中设置了字体高度,并设置了分辨率选项-D。 Maybe, there goes something wrong. 也许,出了点问题。 Furthermore, pityingly, in org-format-latex the images are cached and not reproduced after font size changes. 此外,可惜的是,在org-format-latex中,图像被缓存,并且在字体大小改变之后不再复制。

If you want to increase the size of the latex-formulas for one session in general with good quality you can set the :scale value of the customization option "Org Format Latex Options" in the group "org-latex" to a higher value. 如果要增加一个会话的乳胶配方的大小,通常具有良好的质量,您可以将“org-latex”组中的自定义选项“Org Format Latex Options”的:scale值设置为更高的值。

Edit 2013-10-10 (marked as italic throughout the answer except the code, naturally): The :scale property of the option org-format-latex-options is now set automagically. 编辑2013-10-10(除了代码之外,在整个答案中标记为斜体,当然):选项org-format-latex-options的:scale属性现在自动设置。 Therefore, the above hack should be quite usable (such as the latex version mentioned below). 因此,上述黑客应该是非常有用的(例如下面提到的乳胶版本)。


The same problem as you describe in the original-post exists for latex-preview. 乳胶预览中存在与原始帖子中描述的问题相同的问题。 But, for that case there is a better solution: 但是,对于这种情况,有一个更好的解决方案:

(require 'face-remap)
(defadvice preview-inherited-face-attribute (after preview-inherit-local-face nil activate)
  "Scale preview images with respect to buffer-local face"
  (when (and text-scale-mode (eq attribute :height))
    (setq ad-return-value (* (expt text-scale-mode-step text-scale-mode-amount) ad-return-value))))

After C-+/-/0 type Cc Cp Cd to re-generate all formulas of the document. 在C - + / - / 0之后键入Cc Cp Cd以重新生成文档的所有公式。 Afterwards, the formulas have just the right size and the right resolution. 之后,公式具有正确的大小和正确的分辨率。

If switching to latex documents with preview is an option for you I would recommend it. 如果使用预览切换到乳胶文档是一个选项,我会推荐它。 I use org only for notes and time-tables with easy links. 我只将org用于带有简单链接的笔记和时间表。

For more descriptive documents I use latex documents with auctex/preview. 对于更具描述性的文档,我使用带有auctex / preview的乳胶文档。 But, I actually compile them only very seldom to a final pdf document. 但是,我实际上很少将它们编译成最终的pdf文档。 The preview is good enough. 预览足够好了。 See the following Figure. 请参见下图。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM