33

I want a similar layout as in SO, I use it currently as my editor but I would like to find such tool under my fingers. I am more vi-prone so having hard time to get preview-latex working with emacs. I don't know whether it is the right tool but I want to see things shortly after typing some long latex equations without compiling cycle. How can I preview LaTeX?

Ps. I am using obsd and ubuntu.

1

4 Answers 4

29

The most common package to preview text in Emacs is Preview TeX, a package now build into AUCTeX

http://gnu.org/software/auctex

It works with both latex and pdflatex. Within a LaTeX buffer, just type C-c C-p C-b, or within the menu do Preview->for buffer.

A simpler, but less effective alternative is to use the X-Symbol package:

http://x-symbol.sourceforge.net/

This one only shows special symbols (such as math operators or greek letters), but not much more than that. This package also does not seem to be developed anymore.

5
  • For the preview to work in my case, I had to disable the pdf-mode. This can be done by: C-c C-t C-p
    – Dror
    Jun 1, 2011 at 9:13
  • preview-latex is supposed to work in PDF mode as well.
    – user9588
    May 12, 2012 at 12:25
  • could some #Emacs guru help me to press "C-c C-p C-b" in the right spot? CTRL+c (hands up) CTRL+P (hands up) CTRL+b? I am using Emacs23 from aptitude, now in Debian. I wish videos, researching...
    – hhh
    Oct 13, 2012 at 23:19
  • 1
    none of this works for me. I get error No file _region_.aux.
    – Nasser
    Feb 22, 2014 at 13:06
  • It wasn't clear to me that LaTeX software (e.g., MiKTex) was supposed to be installed for AUCTeX preview to work. In Windows, I installed AUCTeX within Emacs with Melpa, then MiKTeX, then reopened my .tex file and everything worked smoothly, asking confirmation for a few additional packages required in the .tex file code.
    – Halberdier
    Jan 22 at 18:28
9

Sorry, I don't know what SO is, but have you ever heard of latexmk? It re-runs pdftex or whatever every time you save your *.tex-file. Instead of preview I do:

  1. Open Emacs, C-x C-f => new file, type some skeleton of the LaTeX-file including \end{document}, save it (C-x C-s), compile it the first time (C-c C-c RET) and open it in the viewer (again C-c C-c RET).
  2. I open a command window (if you use Linux, you know what I mean, if you use windows, its cmd.exe), navigate into the folder containing my LaTeX-file and type latexmk -pvc -pdf filename.tex Then latexmk compiles my document and repeats that each time I save a new version inside Emacs.

If you employ a pdf-viewer which is able to reload the pdf from harddisk every time it changes (okular, evince, sumatra for windows . . .), you are very close to an instant preview.

Alexander

3
  • 1
    This is great. However, in OSX, Preview (the program) does not update / refresh the PDF unless you have it active. I wonder if anyone came with a solution to it! Mar 15, 2014 at 0:11
  • @user815423426 Nobody will see your question here. Please proceed as follows: a) Get a real nickname, user450328402398 is disturbing, sorry | b) search for OSX and latexmk, if no solution => c) ask a new question in this forum.
    – Keks Dose
    Mar 15, 2014 at 11:54
  • FWIW, switching to a different default PDF viewer, e.g. skim, which has the ability to automatically update will I believe solve this for you. Jan 5, 2022 at 16:31
8

Another option is LaTeX Preview Pane. It supports side by side editing and previews of your LaTeX document. It also supports error highlighting in your buffer, similar to flymake.

Emacs Wiki Page: http://www.emacswiki.org/emacs/LaTeXPreviewPane

1
  • Is it possible to edit a single environment with LPP (e.g. a single equation)?
    – sebhofer
    Jan 29, 2015 at 18:01
4

I wrote some elisp to simplify compiling and viewing a latex file using pdflatex:

(defun reload-pdf ()
  (interactive
  (let* ((fname buffer-file-name)
        (fname-no-ext (substring fname 0 -4))
        (pdf-file (concat fname-no-ext ".pdf"))
        (cmd (format "pdflatex %s" fname)))
    (delete-other-windows)
    (split-window-horizontally)
    (split-window-vertically)
    (shell-command cmd)
    (other-window 2)
    (find-file pdf-file)
    (balance-windows))))

(global-set-key "\C-x\p" 'reload-pdf)

Now, instead of (C-c C-c RET) twice, you just need to type (C-x p RET), after you save the file.

Hope this helps!

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .