* [WISH] Latex WYSIWYG
@ 2011-06-21 0:22 Sebastian Berchtold
2011-06-21 15:30 ` Eric S Fraga
2011-06-24 14:14 ` Jan Böcker
0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Berchtold @ 2011-06-21 0:22 UTC (permalink / raw)
To: emacs-orgmode
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 question: Is there a simple way to activate latex syntax highlighting in org-mode?)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [WISH] Latex WYSIWYG
2011-06-21 0:22 [WISH] Latex WYSIWYG Sebastian Berchtold
@ 2011-06-21 15:30 ` Eric S Fraga
2011-06-24 14:14 ` Jan Böcker
1 sibling, 0 replies; 3+ messages in thread
From: Eric S Fraga @ 2011-06-21 15:30 UTC (permalink / raw)
To: Sebastian Berchtold; +Cc: emacs-orgmode
Sebastian Berchtold <Sebastian.Berchtold@campus.lmu.de> 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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [WISH] Latex WYSIWYG
2011-06-21 0:22 [WISH] Latex WYSIWYG Sebastian Berchtold
2011-06-21 15:30 ` Eric S Fraga
@ 2011-06-24 14:14 ` Jan Böcker
1 sibling, 0 replies; 3+ messages in thread
From: Jan Böcker @ 2011-06-24 14:14 UTC (permalink / raw)
To: Sebastian Berchtold; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: latex-live-preview.el --]
[-- Type: text/x-emacs-lisp; name="latex-live-preview.el", Size: 8274 bytes --]
;; latex-live-preview.el by Jan Böcker <jan.boecker@jboecker.de>
;; 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 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)))
(cd tmpdir)
(set-process-sentinel
(start-process "live-latex-preview-dvipng"
nil
"dvipng"
"-fg" fg "-bg" bg
"-D" dpi
;;"-x" scale "-y" scale
"-T" "tight"
"-o" pngfile
dvifile)
'jb/call-dvipng-sentinel)
))
(defun jb/call-dvipng-sentinel (process event)
(when (string= event "finished\n")
(copy-file (concat jb/current-texfilebase ".png") jb/current-tofile 'replace)
(loop for e in '(".dvi" ".tex" ".aux" ".log" ".png") do
(delete-file (concat jb/current-texfilebase e)))
(when (get-buffer jb/latex-live-preview-filename)
(set-buffer jb/latex-live-preview-filename)
(jb/refresh-current-image-buffer))
(setq jb/current-tmpdir nil)
(jb/update-latex-preview)
))
(defun jb/refresh-current-image-buffer ()
(flet ((message (msg &rest args) nil))
(clear-image-cache)
(revert-buffer nil t t)
(image-mode)
))
(defun jb/update-latex-preview ()
(when (and jb/latex-preview-job
(not jb/current-tmpdir))
(jb/preview-fragment jb/latex-preview-job)
(setq jb/latex-preview-job nil)))
(defun jb/preview-fragment (latex)
(save-excursion
(let ((temporary-file-directory jb/latex-live-preview-tempdir))
(jb/ocfi latex (concat jb/latex-live-preview-tempdir jb/latex-live-preview-filename) org-format-latex-options nil))
))
(defun jb/plfp ()
"Preview the latex fragment at point"
(interactive)
(catch 'exit
(save-excursion
(save-restriction
(let ((at (org-inside-LaTeX-fragment-p))
beg end msg start-delimiter end-delimiter
(add-end-delimiter nil))
(if (not at)
(progn
(setq jb/latex-preview-job "$ $")
(jb/update-latex-preview))
(progn
(goto-char (cdr at))
(setq beg (point))
(setq start-delimiter (car at))
;; (message "start-delimiter is %s " start-delimiter)
;; Determine what the end of this block must look like
(setq end-delimiter (cdr (assoc start-delimiter
'(("$$" . "$$"),
("\\[" . "\\]"),
("\\(" . "\\)")))))
;; Set end-delimiter to \end{region} if block starts
;; with \begin{region}
(when (not end-delimiter)
(save-match-data
(if (not (string-match "\\\\begin{\\([^}]*\\)}" start-delimiter))
(throw 'exit nil))
(setq end-delimiter (concat "\\end{" (match-string 1 start-delimiter) "}"))))
;; (message "end-delimiter is %s " end-delimiter)
;; set end of our region
(goto-char (1+ beg))
(setq end (re-search-forward (regexp-quote end-delimiter) nil t))
;; If there is no end delimiter, make a note that we
;; need to add it later before creating the image.
;; This will make the preview work on unfinished LaTeX blocks.
(when (not end)
(setq end (point-max))
(setq add-end-delimiter t))
(narrow-to-region beg end)
;; (message "-%s-" (buffer-string))
(goto-char beg)
(setq jb/latex-preview-job (concat (buffer-string) (if add-end-delimiter end-delimiter "") ))
(jb/update-latex-preview))))))))
(defun pseudo-message (format-string &rest args)
nil)
(defun jb/ach (a b c)
"hook for after-change-functions"
(when jb/enable-live-preview
(let ((message (lambda (s &rest args) nil)))
(jb/plfp)
(setq deactivate-mark nil))))
(defun jb/pch ()
"hook for post-command-hook"
(when jb/enable-live-preview
(let ((message (lambda (s &rest args) nil)))
(jb/plfp)
(setq deactivate-mark nil))))
(defun jb/toggle-latex-live-preview ()
"toggles the buffer-local variable jb/enable-live-preview"
(interactive)
(setq jb/current-tmpdir nil)
(make-variable-buffer-local 'jb/enable-live-preview)
(setq jb/enable-live-preview (not jb/enable-live-preview)))
(defun jb/clear-current-tmpdir ()
(interactive)
(setq jb/current-tmpdir nil))
(remove-hook 'after-change-functions 'jb/ach)
(remove-hook 'post-command-hook 'jb/pch)
(add-hook 'post-command-hook 'jb/pch)
(add-hook 'after-change-functions 'jb/ach)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-24 14:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-21 0:22 [WISH] Latex WYSIWYG Sebastian Berchtold
2011-06-21 15:30 ` Eric S Fraga
2011-06-24 14:14 ` Jan Böcker
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).