RE: Editing equations as latex rather than graphically.
-Original Message- From: Tim Hutt [mailto:tdh...@gmail.com] Sent: Mon 2/1/2010 7:54 PM To: lyx-users@lists.lyx.org Subject: Editing equations as latex rather than graphically. >Hi, I've searched but I can't find an answer: Is it possible to edit >the source latex code of equations rather than edit the equations in a >graphical way? I much prefer this method for equations and in my mind >it is one of the things that makes latex superior to for example, MS >Word. > >If this isn't a feature I'd suggest something like CTRL-clicking on an >equation (also accessible by right-click->Edit Source) shows you the >source of the equation and lets you edit it. Others have shown you ways of converting a lyx equation to latex. However, if you prefer to keep your math in tex form all the time, just use the ERT inset. Into it you can write any valid latex, including latex math. And unlike the math inset, it will stay latex code forever. Except in the output, where it obviously will be rendered. Two ways to test the validity of such latex code: 1. view->pdf. Simple, but slow if you have a big document 2. Put the cursor first in the tex-box, hit delete to dissolve it. The latex code becomes normal text. Mark it, and hit ctrl+M to see if it turns out right. Afterwards, hit "undo" a few times so you get your ERT inset back exactly as it was. You don't need to use the LyX math editor if you don't want to, even if you write math in LyX. Helge Hafting
Re: Editing equations as latex rather than graphically.
On 2010-02-02, Vincent van Ravesteijn - TNW wrote: >>This way, you can convert an equation to the source text > If you select the math contents and paste it in text, you'll see the > LaTeX code. This used to work with the mouse only in former versions, but it's fixed now to work also via keybindings. >>The other way round is already implemented: Mark a valid >>math expression (like \sin(x)) and press Ctrl-M. > I once made something to convert it to LaTeX and back, but the math > editor is that well that I doubted it would be very useful. It might be usefull for cleanup and nested constructs, where the LaTeX code can be clearer than the nested box corners... However, as the two-way conversion is already implemented, I just suggest to let the "Backspace at first position" act like in other insets (i.e. dissolving the inset). Günter
RE: Editing equations as latex rather than graphically.
>This way, you can convert an equation to the source text >(which might be desirable for copying as well). > >The other way round is already implemented: Mark a valid >math expression (like \sin(x)) and press Ctrl-M. > If you select the math contents and paste it in text, you'll see the LaTeX code. I once made something to convert it to LaTeX and back, but the math editor is that well that I doubted it would be very useful. Vincent
Re: Editing equations as latex rather than graphically.
On 2010-02-01, rgheck wrote: > On 02/01/2010 02:29 PM, Tim Hutt wrote: >> On 1 February 2010 19:22, rgheck wrote: > ... All you have to do is have a special mode where LyX displays the > raw LaTeX, which it knows how to generate. This would be kind of like > the "preview" mode, where it displays a little picture. Switching back > to "LyX" mode would then read the LaTeX---LyX knows how to do this in > the math case---and display the LyX form. How about a consistent behaviour of ERT, math, note, and other insets: If the cursor is on the very beginning and you press Backspace, the inset is dissolved and the content inserted as normal text. Currently, this works with ERT, ... but not math (where the cursor just moves out of the box). This way, you can convert an equation to the source text (which might be desirable for copying as well). The other way round is already implemented: Mark a valid math expression (like \sin(x)) and press Ctrl-M. (Having to mark the equation before the (back)conversion might be a disadvantage over a toggle. However, a toggle and a separate "raw math" state would need to be programmed and remembered separately. For "heavy users" I'd recommend a command sequence that sets a bookmark (or two) before the math-text conversion.) Günter
Re: Editing equations as latex rather than graphically.
The difference w.r.t. an ERT block is that you can see the formatted result on the screen (but editing through an external editor is not as comfortable as a collapsable inset). Remember I have the InsetPreview in my back pocket :) I didn't follow the thread further, so I don't know what the question is/was, but it seems perfect that with the InsetPreview, you can generate a preview of an ERT. Vincent
Re: Editing equations as latex rather than graphically.
On 02/01/2010 05:42 PM, Tommaso Cucinotta wrote: rgheck wrote: One question: isn't it possible to handle this case like the other external-material objects ? I mean, imagine you define another kind of external-material object, the "External Equation" type (e.g., a '*.eq' file), imagine you associate a text editor to such a type, and imagine you define a set of filters which just invoke externally LaTeX for computing the .eps of the file for both preview and print purposes. This way, for example, clicking on the image of the equation, would pop-up the external text editor on the .eq file, and after exiting it would be updated on the screen. Wouldn't you achieve exactly what this user is looking for ? In fact, the attached patch achieves such behaviour easily. If you have a ".eq" file with a contents such as: \begin{equation} U = \frac{C}{T} \end{equation} then you can do Insert->File->External Material->[Equation (LaTeX)], then select your .eq file. Now, if you have "Instant Preview" enabled in preferences, you can see the formatted equation on the screen. Furthermore, right-click on it and select "External Editor" and you can edit it with emacs. The difference w.r.t. an ERT block is that you can see the formatted result on the screen (but editing through an external editor is not as comfortable as a collapsable inset). Was kind of a learning excercise -- just in case anyone finds such patch useful (btw, I find the built-in LyX WYSIWYG/M equation editor extraordinary). I think you should post this to devel and commit it. In the case of very complex equations, which would basically be nothing but ERT, it could be very useful. LyX can handle it, of course, but perhaps not with the kinds of comments and so forth one might want. I'm sure there are some people in this sort of predicament. I hate to be greedy here, but does this handle math macros defined earlier in the document? That would be a good addition, if not. And it would, as it happens, allow me to use exactly this script for exporting little math images during XHTML output (if someone wanted a given equation to be output that way). Richard
Re: Editing equations as latex rather than graphically.
rgheck wrote: One question: isn't it possible to handle this case like the other external-material objects ? I mean, imagine you define another kind of external-material object, the "External Equation" type (e.g., a '*.eq' file), imagine you associate a text editor to such a type, and imagine you define a set of filters which just invoke externally LaTeX for computing the .eps of the file for both preview and print purposes. This way, for example, clicking on the image of the equation, would pop-up the external text editor on the .eq file, and after exiting it would be updated on the screen. Wouldn't you achieve exactly what this user is looking for ? In fact, the attached patch achieves such behaviour easily. If you have a ".eq" file with a contents such as: \begin{equation} U = \frac{C}{T} \end{equation} then you can do Insert->File->External Material->[Equation (LaTeX)], then select your .eq file. Now, if you have "Instant Preview" enabled in preferences, you can see the formatted equation on the screen. Furthermore, right-click on it and select "External Editor" and you can edit it with emacs. The difference w.r.t. an ERT block is that you can see the formatted result on the screen (but editing through an external editor is not as comfortable as a collapsable inset). Was kind of a learning excercise -- just in case anyone finds such patch useful (btw, I find the built-in LyX WYSIWYG/M equation editor extraordinary). T. Index: lib/scripts/eq2eps.py === --- lib/scripts/eq2eps.py (revisione 0) +++ lib/scripts/eq2eps.py (revisione 0) @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# file eq2eps.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# \author Angus Leeming +# \author Bo Peng +# \author Tommaso Cucinotta +# +# Full author contact details are available in file CREDITS + + +# This script converts a LaTeX equation (EQ) to Encapsulated PostScript (EPS). + +# Usage: +# python eq2eps.py ${base}.eq ${base}.eps +# This command generates +# ${base}.epsthe converted eps file + +import os, sys + +# We expect two args, the names of the input and output files. +if len(sys.argv) != 3: +sys.exit(1) + +input, output = sys.argv[1:] + +# Fail silently if the file doesn't exist +if not os.path.isfile(input): +sys.exit(0) + +# Strip the extension from ${input} +inbase = os.path.splitext(input)[0] +# Strip the extension from ${output} +outbase = os.path.splitext(output)[0] + +# Generate the EPS file +print 'latex -jobname=%s "\\documentclass{article}\\pagestyle{empty}\\begin{document}\\input{%s}\\end{document}"' % (inbase,input) +if os.system('latex -jobname=%s "\\documentclass{article}\\pagestyle{empty}\\begin{document}\\input{%s}\\end{document}"' % (inbase,input)) != 0 or \ + os.system('dvips -E -o %s.eps %s.dvi' % (outbase, inbase)) != 0: + print 'eq2eps fails' + sys.exit(1) Index: lib/external_templates === --- lib/external_templates (revisione 33314) +++ lib/external_templates (copia locale) @@ -159,6 +159,35 @@ TemplateEnd +Template Equation-LaTeX + GuiName "Eq: $$AbsOrRelPathParent$$Basename" + HelpText + A LaTeX Equation + HelpTextEnd + InputFormat eq + FileFilter "*.eq" + AutomaticProduction true + Transform Rotate + Transform Resize + Transform Clip + Transform Extra + Preview InstantPreview + Format LaTeX + TransformOption Rotate RotationLatexOption + TransformOption Resize ResizeLatexOption + TransformOption Clip ClipLatexOption + TransformOption Extra ExtraOption + Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]" + Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}" + UpdateFormat eps + UpdateResult "$$AbsPath$$Basename.eps" + Requirement "graphicx" + ReferencedFile latex "$$AbsPath$$Basename.eps" + ReferencedFile dvi "$$AbsPath$$Basename.eps" + FormatEnd +TemplateEnd + + Template ChessDiagram GuiName "Chess: $$AbsOrRelPathParent$$Basename" HelpText Index: lib/configure.py === --- lib/configure.py (revisione 33314) +++ lib/configure.py (copia locale) @@ -507,6 +507,7 @@ \Format sweave Rnw"Sweave"S "" "%%""document" \Format lilypond ly "LilyPond music""" "" "%%" "vector" \Format latex tex"LaTeX (plain)" L "" "%%" "document" +\Format eq eq "Equation (LaTeX)" L "" "%%" "document" \Format pdflatex tex"LaTeX (pdflatex)" "" "" "%%" "document" \Format xetex tex"LaTeX (XeTeX)" "" "" "%%" "document" \Format text txt"Plain text"a "" "%%" "document" @@ -585,6 +586,9 @@ def checkConverterEntries(): ''' Check all converters (\converter entries) ''' +addToRC(r'''\converter eq eps"python -tt $$s
Re: Editing equations as latex rather than graphically.
On 02/01/2010 03:44 PM, Tommaso Cucinotta wrote: rgheck wrote: Ah yes, I did that in an equation and it is almost exactly what I want - just need to be able to edit the text. Without looking at the code, it doesn't look like you'd have to do much to make it editable. I might have a go some time. It's harder than you think, in the general case, because *reading* the LaTeX back is not trivial. In the math case, however, it isn't so hard, and it'd be easier to do it in the editing pane. All you have to do is have a special mode where LyX displays the raw LaTeX, which it knows how to generate. This would be kind of like the "preview" mode, where it displays a little picture. Switching back to "LyX" mode would then read the LaTeX---LyX knows how to do this in the math case---and display the LyX form. One question: isn't it possible to handle this case like the other external-material objects ? I mean, imagine you define another kind of external-material object, the "External Equation" type (e.g., a '*.eq' file), imagine you associate a text editor to such a type, and imagine you define a set of filters which just invoke externally LaTeX for computing the .eps of the file for both preview and print purposes. This way, for example, clicking on the image of the equation, would pop-up the external text editor on the .eq file, and after exiting it would be updated on the screen. Wouldn't you achieve exactly what this user is looking for ? I think this might be useful in some cases, assuming you just included the LaTeX, rather than an image. But my thought was that it should actually be fairly easy to switch back and forth between LaTeX mode and LyX mode, which many people might like. And then you can do this right inside LyX. Richard
Re: Editing equations as latex rather than graphically.
rgheck wrote: Ah yes, I did that in an equation and it is almost exactly what I want - just need to be able to edit the text. Without looking at the code, it doesn't look like you'd have to do much to make it editable. I might have a go some time. It's harder than you think, in the general case, because *reading* the LaTeX back is not trivial. In the math case, however, it isn't so hard, and it'd be easier to do it in the editing pane. All you have to do is have a special mode where LyX displays the raw LaTeX, which it knows how to generate. This would be kind of like the "preview" mode, where it displays a little picture. Switching back to "LyX" mode would then read the LaTeX---LyX knows how to do this in the math case---and display the LyX form. One question: isn't it possible to handle this case like the other external-material objects ? I mean, imagine you define another kind of external-material object, the "External Equation" type (e.g., a '*.eq' file), imagine you associate a text editor to such a type, and imagine you define a set of filters which just invoke externally LaTeX for computing the .eps of the file for both preview and print purposes. This way, for example, clicking on the image of the equation, would pop-up the external text editor on the .eq file, and after exiting it would be updated on the screen. Wouldn't you achieve exactly what this user is looking for ? T.
Re: Editing equations as latex rather than graphically.
On Feb 1, 2010, at 12:29 PM, Tim Hutt wrote: > On 1 February 2010 19:22, rgheck wrote: >> Try View>Source if you want to *see* the LaTeX. > > Ah yes, I did that in an equation and it is almost exactly what I want > - just need to be able to edit the text. Without looking at the code, > it doesn't look like you'd have to do much to make it editable. I > might have a go some time. > > Cheers. Note that another option to see the LaTeX code is to copy the math environment into a text editor. That will give you the raw LaTeX. James
Re: Editing equations as latex rather than graphically.
On 02/01/2010 02:29 PM, Tim Hutt wrote: On 1 February 2010 19:22, rgheck wrote: Try View>Source if you want to *see* the LaTeX. Ah yes, I did that in an equation and it is almost exactly what I want - just need to be able to edit the text. Without looking at the code, it doesn't look like you'd have to do much to make it editable. I might have a go some time. It's harder than you think, in the general case, because *reading* the LaTeX back is not trivial. In the math case, however, it isn't so hard, and it'd be easier to do it in the editing pane. All you have to do is have a special mode where LyX displays the raw LaTeX, which it knows how to generate. This would be kind of like the "preview" mode, where it displays a little picture. Switching back to "LyX" mode would then read the LaTeX---LyX knows how to do this in the math case---and display the LyX form. rh
Re: Editing equations as latex rather than graphically.
On 1 February 2010 19:22, rgheck wrote: > Try View>Source if you want to *see* the LaTeX. Ah yes, I did that in an equation and it is almost exactly what I want - just need to be able to edit the text. Without looking at the code, it doesn't look like you'd have to do much to make it editable. I might have a go some time. Cheers.
Re: Editing equations as latex rather than graphically.
On 02/01/2010 01:54 PM, Tim Hutt wrote: Hi, I've searched but I can't find an answer: Is it possible to edit the source latex code of equations rather than edit the equations in a graphical way? I much prefer this method for equations and in my mind it is one of the things that makes latex superior to for example, MS Word. This is possible. First, you can enter LaTeX code at the keyboard, and then LyX will display it as "graphical". So just type Ctrl-M to enter math mode and then start typing: 2^x + \sqrt 3 = \frac ... Anything LyX doesn't understand it will display as raw commands. If this isn't a feature I'd suggest something like CTRL-clicking on an equation (also accessible by right-click->Edit Source) shows you the source of the equation and lets you edit it. Try View>Source if you want to *see* the LaTeX. There is no provision for editing it directly. However, if you really want to edit LaTeX, try this. Highlight just the *inside* of a math inset. Now exit it and paste. You should get the raw LaTeX code. Edit it. Now highlight it and hit Ctrl-M again. The request for "roundtrip" LaTeX editing is longstanding and difficult to implement. But the math case is special and actually wouldn't be that hard to do. As the workaround just given shows, LyX can essentially do this already. So you might file this special case, of math, as an enhancement request here: http://www.lyx.org/trac/wiki/BugTrackerHome. rh