Git Product home page Git Product logo

org-edit-latex's Introduction

MELPA

Org Edit LaTeX

With this package, you can edit a latex fragment/environment in an edit buffer, and you can even complete and preview LaTeX in the edit buffer.

The latest release of Org (version 9.1) provides a similar feature, i.e. edit a latex environment in an edit buffer. But there are still some features offered here are not in org yet. Some of them are:

  • Complete based on your latex header.

    With org-edit-latex, you can complete your latex commands according to the #+latex_header: lines in your main org buffer (powered by AucTeX). This is not possible in vanilla org.

  • Preview in the edit buffer.

    You don't have to quit your edit buffer to do the preview. You can just preview at point! With the fantastic AucTeX working behind, you can cache your preamble and preview really fast (faster than org-preview).

  • Edit and preview latex fragments in edit buffer.

    Besides LaTeX environments, you can also edit/preview latex fragments in edit buffer. This may not count as a feature. but in case you need it, it's there.

This package has been tested on Org 8.0 and above. Feel free to use it on Org mode shipped with emacs.

org-edit-latex

Install

First, download org-edit-latex and add following to your init file:

(require 'org-edit-latex)

You should add latex to your org-babel-load-languages:

(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp . t)
   (latex . t)   ;; <== add latex to the list
   (python . t)
   (shell . t)
   (ruby . t)
   (perl . t)))

Basic Usage

Turn on org-edit-latex-mode and use following commands to start/exit/abort a edit buffer.

  • org-edit-special: enter a dedicated LaTeX buffer.
  • org-edit-src-exit: exit LaTeX buffer when you finished editing.
  • org-edit-src-abort: quit editing without saving changes.

Note that all above commands are built-in Org commands and your current keybindings will probably do the job.

Inline Math

Inline latex is also supported, but I don't recommend using this package on simple inline math, such as math symbols, SI units, etc. For that use case, you may check cdlatex, which is more than enough to handle that. The setup of cdlatex is pretty straightforward, see jkitchin/scimax#117 to get a general idea.

Entry Point

To get started, you may also want to check out yasnippet to fast insert a latex environment before you can use org-edit-special to enter the edit buffer.

For instance, try M-x yas-new-snippet and insert a snippet like this:

# -*- mode: snippet -*-
# name: eqn
# key: eqn
# --
\begin{equation}
  \label{eq:1}
  $0
\end{equation}

After you loaded the snippet, type eqn and press tab to insert the snippet. Then you can call org-edit-special to enter the edit buffer.

TeX Master

By default, org-edit-latex will generate a TeX-master file automatically. The master file is used for:

  • Completion in edit buffer via AucTeX
  • Preview in the edit buffer

The LaTeX preamble used by the master file is the same as org-preview settings.

The master file locates in the same directory as the org file does. You can update the master file via org-edit-latex-update-master after changing the preview settings.

You can use org-edit-latex-preview-at-point to preview in a edit buffer. By default, the keybinding of preview-at-point (AucTeX) is remapped to this function.

Demo

w/o master: without master

with master: with master

Change Log

  • 0.8.0 Add support for TeX-master; provide preview function.
  • 0.7.0 Fix a few bugs regarding latex fragment/environment with name/caption/attrib.
  • 0.6.3 Fix inline math issue caused by a bug from org.
  • 0.6.2 src blocks will be untouched.
  • 0.6.1 Fix inline src block not recognized.
  • 0.6.0 Editing of inline latex (including non math latex fragments) is supported. ...

TODO

  • Mention cdlatex
  • Mention yasnippet
  • Add more demo gifs
  • Add support for inline math.
  • Turn this feature into a minor mode. (by purcell)

org-edit-latex's People

Contributors

et2010 avatar purcell avatar stardiviner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

org-edit-latex's Issues

Give an option not to use eldoc.

org-eldoc is not found in the org-mode version included in emacs. This results in the annoying message
eldoc error: (void-function org-eldoc-documentation-function)

It would be nice to include an option to disable calls to eldoc or at least list org-eldoc as a requirement.

Thanks.

Debugger entered--Lisp error: (void-variable org-src--beg-marker)

When I abort editing or exit the sub-editing, there is something wrong here.
However, I disable org-edit-latex to use the original function of org-mode for editing src block, there is no error.
Environment: Windows 7 x64, emacs 24.5, org-mode 8.2.10.
Error message is as follows. Because there is some messy code here, so the msg cannot be posted here completely. So there is also a screenshot to illustrate that.

Debugger entered--Lisp error: (void-variable org-src--beg-marker)
  org-edit-latex--unwrap-maybe(#[(&optional context) "\306......
\207" [org-edit-src-from-org-mode fixed-width-p org-edit-src-beg-marker beg org-edit-src-end-marker end boundp error "This is not a sub-editing buffer, something is wrong" string-match "Fixed Width" buffer-name buffer-string org-edit-src-force-single-line macro-definition 0 org-edit-src-allow-write-back-p nil untabify looking-at "[ 	\n]*\n" replace-match "" re-search-forward "\n[ 	\n]*\\'" t 1 count-lines "\\s-+\\'" "\n" "\\n" " " "\\s-*" org-escape-code-in-region "[ 	]*\\(,,\\)?\\(\\*\\|#+\\)" org-edit-src-picture "^" ": " make-string 32 "\\(^\\).+" 2 save erase-buffer set-buffer-modified-p org-src-switch-to-buffer marker-buffer exit save-buffer kill-buffer ...] 7 ("c:/emacs/share/emacs/24.5/lisp/org/org-src.elc" . 24584) nil] exit)

  apply(org-edit-latex--unwrap-maybe #[(&optional context) "\306\300!\203\n......
\207" [org-edit-src-from-org-mode fixed-width-p org-edit-src-beg-marker beg org-edit-src-end-marker end boundp error "This is not a sub-editing buffer, something is wrong" string-match "Fixed Width" buffer-name buffer-string org-edit-src-force-single-line macro-definition 0 org-edit-src-allow-write-back-p nil untabify looking-at "[ 	\n]*\n" replace-match "" re-search-forward "\n[ 	\n]*\\'" t 1 count-lines "\\s-+\\'" "\n" "\\n" " " "\\s-*" org-escape-code-in-region "[ 	]*\\(,,\\)?\\(\\*\\|#+\\)" org-edit-src-picture "^" ": " make-string 32 "\\(^\\).+" 2 save erase-buffer set-buffer-modified-p org-src-switch-to-buffer marker-buffer exit save-buffer kill-buffer ...] 7 ("c:/emacs/share/emacs/24.5/lisp/org/org-src.elc" . 24584) nil] exit)
  org-edit-src-exit(exit)
  org-edit-src-abort()
  call-interactively(org-edit-src-abort nil nil)
  command-execute(org-edit-src-abort)

error msg

Parse `#+LaTeX-CLASS` for styles

After reading jkitchin/scimax#117 I tried to use TeX-insert-macro in an org-edit-special.

I did not get any \si, \SI or related completion options.

It seems that org-edit-latex only parses the #+LATEX_HEADER: fields for e.g. \usepackage{siunitx} to determine which AUCTeX styles to load (by way of the generated TeX master file I assume). With this field explicitly set, the siunitx style is availabe in the org-edit-special. I use siunitx quite a bit and thus I placed the \usepackage{siunitx} into the class referenced by #+LaTeX_CLASS:.

Now the actual feature request: Parse the class set in #+LaTeX_CLASS: for \usepackage{siunitx} declarations (or use org-mode internal machinery to get those declarations) to add them to TeX master file generated by org-edit-latex.

Cannot preview with master file

(setq org-edit-latex-create-master t)

and there are frag-master.tex and auto in the same directory.
When run preview-at-point, I got following error:

Running `Preview-LaTeX' on `~/Documents/_region_' with ``xelatex  -file-line-error  --synctex=1 "\nonstopmode\nofiles\PassOptionsToPackage{active,tightpage,auctex}{preview}\AtBeginDocument{\ifx\ifPreview\undefined\RequirePackage[displaymath,floats,graphics,textmath,sections,footnotes]{preview}[2004/11/05]\fi}" "\input" "{\detokenize{" _region_.tex "}}"''
This is XeTeX, Version 3.14159265-2.6-0.999991 (TeX Live 2019) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2018-12-01>

No auxiliary output files.

(./_region_.tex  !name(<none>.tex)  !name(<none>) !offset(-2) 

./_region_.tex:3: LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.3 \begin{equation}
                    

Overfull \hbox (20.0pt too wide) in paragraph at lines 3--3
[] 

Overfull \hbox (7.40001pt too wide) detected at line 5
[]
 !name(<none>.tex) !offset(-7) )
! Emergency stop.
<*> ...5]\fi} \input {\detokenize{ _region_.tex }}
                                                  
No pages of output.
Transcript written on _region_.log.

TeX Output exited as expected with code 1 at Mon Sep 16 11:17:35
LaTeX: LaTeX found no preview images

Wrapping issues with named blocks

Hi,
I found a small issue with the environment detection and wrapping when dealing with named blocks, unfortunately My lisp skills are not good enough to fix it

org_edit_latex_before.txt
org_edit_latex_after.txt

I've attached some test files I made when I discovered the issue. Basically it only appears when a special latex environment is preceded by a #+name:, but no other org-special command seemed to be affected by it
As shown on the "after" file, the block is not properly escaped and either the #+name line is modified or the document is left in an invalid.

Still Kudos for the package which became an instant part of my setup

About #+BEGIN_SRC latex

While org-edit-latex enabled, you cannot edit normal latex src block by M-x org-edit-special since it will turn the src block into a latex fragment when you exit from edit buffer (only latex src blocks are affected). So if you really need do that, turn off org-edit-latex first.

This should be fixed instead of ADD NOTE TO README.

Generalize to other modes

While I was re-reading jorgenschaefer/elpy#498 (comment), I immediately thought about org-edit-latex and how one would go about to support editing Python docstrings in an org-edit-special like buffer with reStructuredText major mode. This would definitely be easier than the existing support for LaTeX, but I wondered whether you already thought about isolating the common bits to make them reusable for other scenarios where org-edit-special would be a good fit.

Make variable for location of frag-master.tex and auto folder

Especially with shared folders, it is extremely annoying that frag-master.tex and the auto folder are created in the same folder as the respective org-file. I suggest a variable with which one can set a fixed path where the file and folder live. If it is set to nil, the normal behavior would persist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.