How do I use the fixed-pitch font for math fragments in org-mode buffers? I.e., I want to use a monospace font for all strings of the form \(...\) or \[...\], where ... may include newline characters as well, as is common for equations written in math display mode.

I’m an Emacs newb, so the best I could come up with was a regex-based font-lock:

(progn
  (setq-local font-lock-keywords
              `((,(rx (group
                       (or "\\[" "\\(")
                       (zero-or-more anything)
                       (or "\\]" "\\)"))) (1 'fixed-pitch))))
  (font-lock-fontify-buffer))

And then running this on an org-mode-hook.

But this is definitely wrong. Not only does it remove all the nice org-mode styling applied to things like section headers, but it’s also applying the fixed-pitch font to more than just the intended math fragments, suggesting issues with the regex at least.

  • nonreligiousB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    If you have the name of the font you want to use in the LaTeX fragments, have you tried using a LaTeX header at the top of the file, e.g.

    #+LaTeX_HEADER:\usepackage{mlmodern}
    

    (Replace mlmodern with whatever typeface you prefer)

    If you don’t want your .org file to become too cluttered at the start, you could alternatively use a setup file via #+SETUPFILE: /path/to/setup-file.org – create an org file e.g. setup-file.org, and include a line like

    #+LaTeX_HEADER:\usepackage{mlmodern}
    

    or whatever your fixed-pitch/monospace font is supposed to be, as well as all the other options you want to use for LaTeX (like other \usepackage declarations, \newcommand definitions etc.).