# Is it possible to type LaTeX code and see its real time preview in LyX?

I'm new to LyX. I have just given it a try and written my first article.

I discovered a panel from `Menu > View > View Source`. It shows the source code of my article. But as far as I see, I am not able to edit this code preview panel. I want to edit both the panels. I want the other panel automatically update itself as I type one panel (like the split panels of code/design in Adobe Dreamweaver). If editing both the panels is not possible, at least I want to do it on the reverse; I only want to work on code and see its preview real time.

Is this possible in LyX?

-
e-birk has a good answer. You cannot edit the code in the preview like in Dreamweaver's view source. For this to work, LyX would have to re-import the LaTeX every time you edited it (into it's own internal representation). That's a difficult task. –  scottkosty Mar 20 '13 at 17:12

There is the possibility in LyX to preview graphics and math formulas. The settings can be found under "Tools > Preferences..." then "Look & Feel > Display". (Internally, LyX uses the `preview` package of LaTeX, see http://wiki.lyx.org/LyX/InstantPreview.)

This is how your example looks with instant preview on.

Furthermore, LyX is a document processor that generates LaTeX code. As you have discovered you can preview the generated code but you cannot edit this. Nevertheless, you can

• insert LaTeX code via "TeX code/ERT" (Ctrl+L), or
• insert entire LaTeX files via "Insert > File > Child Document...".
-

Following e-birk's solution a step further, yes you can preview raw TeX code instantly inside LyX 2.0.6.

1. Go to Tools>preferences>Look&Feel>Display and select Display graphics and instant preview "On".

2. Type Ctrl+M to insert a new formula region.

3. Type Ctrl+L inside the math formatted region you created in (2) to insert your raw (La)TeX code.

4. If necessary, you may need to left click on the TeX code object and give it a second to read your raw LaTeX code and update the display. For tables, right-clicking and selecting "wrap by preview" seems to help when they are not displaying.

5. Finally, click outside the TeX code input to leave its active state. and you should see the TeX graphic beautifully drawn. If not, left click on it again and then click outside it, it should update with the graphic.

Notes:

There are some instances where pasting raw LaTex can result in the textual "\backslash" being interpreted rather than programmatic "\". Make sure you first write or paste in the ERT without an environment. Then, add the environment in manually once it is correctly registered as a math equation (you can do this in a text editor with your ERT just copied from Lyx). Now paste it back in (with the environments added manually) and it wont be registered as text but instead as math (because when you copied it from Lyx it was encoded as math not a string).

If the Tex code is copied from LaTex source, usually this backslash isn't an issue. It is mainly an issue when copying from a richly formatted text editor as the newline characters and other invisible formatting gets copied along with it.

There are limitations, especially as you integrate Tex code which contains spaces (since in math mode you cant have spaces with Lyx - that I know of). Worst case scenario, at least you can type everything in ERT.

-