Re: [O] [WISH] Latex WYSIWYG

2011-06-24 Thread Jan Böcker
On 06/21/2011 02:22 AM, Sebastian Berchtold wrote:
> Hi, my first post here: So big shout outs to all org-mode hackers.
> Great Stuff!
> 
> There is one feature I'd really like to have, but i couldn't find
> anything that does what i want. I guess it's just a small hack, but
> with my retarded elisp skills it would take me days to implement it.
> 
> WYSIWYG Latex is probably not the correct term for this. What i have
> in mind is more like seeing the formula, while editing the
> ASCII/Unicode representation. I'll try to explain the idea more
> detailed.

Hi Sebastian,

I have attached a quick and dirty hack I wrote in December 2010.
It works by updating an image file whenever the formula at point in your
Org buffer changes.
If that image file is currently open in an image buffer, that buffer is
automatically refreshed.

If LaTeX reports an error, the image will not be updated, so you have to
check if the image updates when you expect it to to avoid syntax errors.

See the comments at the top of the file for usage instructions.

Unfortunately, due to lack of time and knowledge of org-mode and elisp,
this thing likely still has a lot of bugs and is not implemented
properly (I guess it should be a minor mode).
However, it seems to work in simple cases.

Hope this helps,
  Jan
;; latex-live-preview.el by Jan Böcker 
;; Feel free to improve this.
;; License: Pick one of GNU GPL v3, BSD, MIT

;; This is a quick and dirty hack to show an automatically updated preview image
;; of the LaTeX formula at point in an org-mode buffer.

;; Usage:
;; * Eval the elisp code in this file in some way (e.g. M-x load-file or M-x eval-buffer)
;; * In your org buffer: M-x jb/toggle-latex-live-preview
;; * Split the window (e.g. C-x 2)
;; * open the exported image file (default: /tmp/livepreview.png) in
;;   the second buffer
;; * edit your Org file

;; To speed things up slightly, you might want to move the tempdir to a ramdisk.



;; the tempdir will contain the exported image and might be cluttered
;; with temporary files from running LaTeX if something goes wrong

(defconst jb/latex-live-preview-tempdir "/tmp/")  ; must include final /
(defconst jb/latex-live-preview-filename "livepreview.png")

(defvar jb/current-texfilebase "")
(defvar jb/current-tmpdir nil)
(defvar jb/current-tofile "")
(defvar jb/latex-preview-job nil)
(defvar jb/enable-live-preview nil)



(defun jb/ocfi (string tofile options buffer)
  "Modified version of org-create-formula-image"
  (require 'org-latex)
  (let* ((tmpdir (if (featurep 'xemacs)
		 (temp-directory)
		   temporary-file-directory))
	 (texfilebase (make-temp-name
		   (expand-file-name "orgtex" tmpdir)))
	 (texfile (concat texfilebase ".tex"))
	 (dvifile (concat texfilebase ".dvi"))
	 (pngfile (concat texfilebase ".png"))
	 (fnh (if (featurep 'xemacs)
  (font-height (get-face-font 'default))
(face-attribute 'default :height nil)))
	 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
	 (dpi (number-to-string (* scale (floor (* 0.9 (if buffer fnh 140.))
	 (fg (or (plist-get options (if buffer :foreground :html-foreground))
		 "Black"))
	 (bg (or (plist-get options (if buffer :background :html-background))
		 "Transparent")))
(if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
(if (eq bg 'default) (setq bg (org-dvipng-color :background)))
(with-temp-file texfile
  (insert (org-splice-latex-header
	   org-format-latex-header
	   org-export-latex-default-packages-alist
	   org-export-latex-packages-alist t
	   org-format-latex-header-extra))
  (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
  (require 'org-latex)
  (org-export-latex-fix-inputenc))
	(setq jb/current-texfilebase texfilebase)
	(setq jb/current-tmpdir tmpdir)
	(setq jb/current-tofile tofile)
	(jb/call-latex)
))

(defun jb/call-latex ()
  (cd tmpdir)
  (set-process-sentinel
   (start-process "live-latex-preview-latex" ; process name
  nil ; no buffer
  "latex"
  "--halt-on-error"
  (concat jb/current-texfilebase ".tex"))
   'jb/call-latex-sentinel)
  ;(message "latex-live-preview: started latex")
)

(defun jb/call-latex-sentinel (process event)
  ;(message "latex-sentinel: %s" event)
  (when (string= event "finished\n")
	(jb/call-dvipng))
  (when (string= event "exited abnormally with code 1\n")
	(setq jb/current-tmpdir nil)
	(jb/update-latex-preview)))

(defun jb/call-dvipng ()
  (let* ((tmpdir jb/current-tmpdir)
		 (buffer nil)
		 (options org-format-latex-options)
		 (texfilebase jb/current-texfilebase)
		 (texfile (concat texfilebase ".tex"))
		 (dvifile (concat texfilebase ".dvi"))
		 (pngfile (concat texfilebase ".png"))
		 (fnh (if (featurep 'xemacs)
  (font-height (get-face-font 'default))
(face-attribute 'default :height nil)))
		 (scale (or (plist-get options (if buffer :scale :html-scale)) 1.0))
		 (dpi (number-to-string (* scale (floor (* 0.9 (if b

Re: [O] [WISH] Latex WYSIWYG

2011-06-21 Thread Eric S Fraga
Sebastian Berchtold  writes:

> Hi, my first post here: So big shout outs to all org-mode hackers. Great 
> Stuff!
>
> There is one feature I'd really like to have, but i couldn't find
> anything that does what i want. I guess it's just a small hack, but
> with my retarded elisp skills it would take me days to implement it.
>
> WYSIWYG Latex is probably not the correct term for this. What i have
> in mind is more like seeing the formula, while editing the
> ASCII/Unicode representation.
> I'll try to explain the idea more detailed.

You might prefer to use LyX instead of org if you really need this!  It
has a very good latex math mode.  Just a thought but sorry I'm not
really answering your question. :(

[...]

> Another question: Is there a simple way to activate latex syntax
> highlighting in org-mode?)

Put your latex code within a babel src block:

,
| #+begin_src latex
|   \begin{something}
|  and so on
|   \end{something}
| #+end_src
`

HTH.
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.414.g56de5)



[O] [WISH] Latex WYSIWYG

2011-06-21 Thread Sebastian Berchtold
Hi, my first post here: So big shout outs to all org-mode hackers. Great Stuff!

There is one feature I'd really like to have, but i couldn't find anything that 
does what i want. I guess it's just a small hack, but with my retarded elisp 
skills it would take me days to implement it.

WYSIWYG Latex is probably not the correct term for this. What i have in mind is 
more like seeing the formula, while editing the ASCII/Unicode representation.
I'll try to explain the idea more detailed.

* Reason of Request:

** Finding Errors
There is no avoiding mistakes for me when writing latex formulas and i just 
take note of them after recognizing that the image can't be rendered. For 
longer formulas it can be quite annoying and time consuming finding the errors 
and I sometimes end up splitting to the math-environment to several parts when 
trying to locate.

** Importance of seeing the equations while writing 
Hey, latex formulas are much more pleasant to the eye and striking in the brain 
than their ASCII representation, that's why we're using em. When developing a 
train of thought in formulas, I always need to see what I've written so far. So 
I feel forced to to split the math-environments into many small parts, and 
putting them together after wards. 
Or even worse when i loose track: I need to copy the line I'm writing on and 
push org-preview-latex-fragment before i can go on.

** Summarizing
I write a bit, hit preview-latex-fragment and copy it to keep it in mind while 
writing on.

Surely everyone using org-mode for heavily formula dependent text has the same 
problem.
I would be glad for every hint to avoid this, probably there are already good 
solutions for this.
In the following the one i imagine:


* Description of the feature wished
- Keep all latex-fragments in image representation
- Only the one at cursor position is in ASCII representation (as in 
preview-latex)
  but still showing the corresponding image above it
- editing the latex code segment updates the image

Rephrased:
When the caret enters a latex environment (usually shown as a picture) it's 
code shows up (maybe in a different color) with the caret at the position as if 
there would have never been an image. 

Maybe the code should be should be shown aboveHi, my first post here: So big 
shoutouts to all org-mode hackers. Great Stuff!
There is one feature i'd really like to have, but i couldn't find anything that 
does what i want. I guess it's just a small hack, but with my retarded elisp 
skills it would take me days to implement it.

WYSIWYG Latex is probably not the correct term for this. What i have in mind is 
more like seeing the formula, while editing the ASCII/Unicode representation.
I'll try to explain the idea more detailed below.

* Reason of Request:
** Finding Errors
There is no avoding mistakes for me when writing latex formulas and i just take 
note of them after recognizing that the image can't be rendered. For longer 
formulas it can be quite annoying and time consuming finding the errors and I 
sometimes end up splitting to the math-environment to several parts when trying 
to locate.

** Importance of seeing the equations while writing 
Hey, latex formulas are much more pleasant to the eye and striking in the brain 
than their ASCII represenation, that's why we're using em. When devoloping a 
train of thought in formulas, I always need need to see what I've written so 
far. So I feel forced to to split the math-environments into many small parts, 
and putting them together afterwards. Or even worse when i loose track: I need 
to copy the line I'm writing on and push org-preview-latex-fragment before i 
can go on.

** Summarizing
I write a bit, hit preview-latex-fragment and copy it to keep it in mind while 
writing on.

Surley everyone using org-mode for heavly formula dependent text has the same 
problem.
I would be glad for every hint to avoid this, probably there are already good 
solutions for this.
In the following the one i imagine:




* Description of the feature wished
- Keep all latex-fragments in image represenation
- Only the one at cursor position is in ASCII representation (as in 
preview-latex)
  but still showing the corresponding image above it
- editing the latex code segment updates the image

Rephrased:
When the caret enters a latex environment (usually shown as a picture) it's 
code shows up (maybe in a diffrent color) with the caret at the position as if 
there would have never been an image. 

Maybe the code should be should be shown below/above the the corresponding 
image wheather the carret enters from the top/bottom to avoid jumping of the 
image at focus (if this doesn't lead to more confusion than it helps)



It shouldn't be to hard to do? Just auto evaluate the latex snippets and 
showing it's code when the cursor is above it.
Could any elisp crack who's already into the org-latex code hack this?
Or are there already better solutions?

Thank you for any response,
JonnyB.


Another questio