jsinglet / latex-preview-pane

Makes LaTeX editing less painful by providing a updatable preview pane
130 stars 24 forks source link

Using latex-preview-pane with org-mode #44

Open cipher1024 opened 6 years ago

cipher1024 commented 6 years ago

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?

jsinglet commented 6 years ago

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.

cipher1024 commented 6 years ago

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.