latex-preview-pane icon indicating copy to clipboard operation
latex-preview-pane copied to clipboard

Using latex-preview-pane with org-mode

Open cipher1024 opened this issue 8 years ago • 2 comments

I'm writing a multi-file document in org-mode and exporting to LaTeX. I've already setup a way of doing the compilation but now I'd like to use latex-preview-pane simply to display the resulting pdf. Is there a way to only monitor a selected pdf and display it when it changes?

cipher1024 avatar Apr 19 '18 20:04 cipher1024

Should be possible. You could do something like this:

  1. Add a hook for org-mode.

(add-hook 'org-mode-hook (lambda () (latex-preview-pane-mode 1)))

  1. Customize the settings for LPP. If you haven't already started LPP, do a M-x latex-preview-pane-mode then modify the variable pdflatex command. It should be whatever you use to compile your org mode document. Probably the best option here is to use a command line tool or script to behave in the same way that pdflatex does. That is, if the input file is my file.org ensure the output file is my file.pdf.

Let me know if it works! We can put it on the wiki if you want to write it up.

jsinglet avatar Apr 19 '18 22:04 jsinglet

Thanks for the fast response!

Before even getting to configure the pdflatex command, I've been struggling with a few things. I record them here as much to show sign of life as to walk myself through my own thinking process:

  1. making sure that the root org file gets converted to latex before latex-preview-pane-mode kicks in, compiles the latex file and displays it.
  2. selecting the root .tex of my multifile document rather than the current buffer's org file
  3. compiling the .tex file appropriately.

I've made the mistake of trying to tackle all three at once. I'm now temporarily dropping 2. and focusing on 1. and 3. So far, I still don't have any good results.

I think I have a decent approach for 1. I built a org-preview-pane-mode function as follows:

(defun org-export-and-compile ()
  (org-latex-export-to-latex)
  (latex-preview-pane-update))

(defun org-preview-pane-mode ()
  (latex-preview-pane-mode)
  (setq-local latex-preview-pane-multifile-mode 'prompt)
  (setq-local lpp-TeX-master
	      (replace-regexp-in-string "\.org$" ".tex"
					(buffer-file-name)))
  (setq-local pdf-latex-command "latexmk")
  (remove-hook 'after-save-hook 'latex-preview-pane-update)
  (add-hook 'after-save-hook 'org-export-and-compile t t))

A weird thing that's been happening is that the compilation seems to succeed but instead of displaying a pdf, latex-preview-pane displays` my org file.

I have to put it down to do some writing and I'll get back to it.

cipher1024 avatar Apr 21 '18 03:04 cipher1024