# How to preview LaTeX in Emacs?

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.

-
The most used package for emacs to preview latex is AucTeX (gnu.org/software/auctex/preview-latex.html) – M. Alaggan May 18 '11 at 3:54

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.

-
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 '11 at 9:13
preview-latex is supposed to work in PDF mode as well. – user9588 May 12 '12 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 '12 at 23:19
none of this works for me. I get error No file _region_.aux. – Nasser Feb 22 '14 at 13:06

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

-
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! – Amelio Vazquez-Reina Mar 15 '14 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 '14 at 11:54

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

-
Is it possible to edit a single environment with LPP (e.g. a single equation)? – sebhofer Jan 29 '15 at 18:01

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))))