# The second and third best features of LyX you aren’t using.

LyX is a WYSIWYG editor for latex files. It’s a little bit clunky to use at first, and isn’t perfect (thank you, open source developers– I’m not ungrateful!) but after becoming familiar with it, it’s probably the single piece of software that has most improved my productivity. I like it so much I use it not just for papers but often as a scratchpad for math. Many times during random discussions I’ve used it to quickly bang out some equations and after seeing how fast it was, others immediately switched to using it.

Anyway, while macros may be the best feature you LyX aren’t using, I recently discovered another couple excellent ones I wasn’t familiar with after years of use so I thought I’d publicize. Specifically, I’ve always hated the process of including explanatory figures into LyX. Exporting plots from an experiment is tricky to improve, but when trying to create explanatory graphs, I’ve always hated the process.

Before, I thought the options were.

1) Create the graph in an external program. This is fine, of course, but is quite inconvenient when you want to go back and revise it. The external program usually saves it in some other format, so you have to open the graphic in open it again, revise it, export it to .pdf (or whatever), then open the document in LyX, compile it. Then, when you don’t like the way it looks, you have to repeat the whole process. It works, but it’s not efficient, since you can’t edit the content in place. (Which is the whole point of using a WYSIWYG editor in the first place– remove the need for thinking about anything but content.)

2) Write the graphics directly in LyX in a language like TikZ. This is more “in-place” in that you don’t have external files to find and manipulate. However, I find TikZ to be quite painful to get right with many re-compilations necessary. If the TikZ document is in place each requires a full compilation of the document. This is hilariously slow when making something like Beamer slides. Further, this totally violates the whole point of WYSIWYG since you’re looking at code, rather than the output.

There are better ways! I’ve wasted countless hours not being aware of these.

## Preview Boxes

First, LyX has a beautiful feature of “preview boxes”. Take the following very simple TikZ code, which just draws a square:

 \begin{tikzpicture} \draw[red] (0,0) -- (0,1); \draw[green] (0,1) -- (1,1); \draw[red] (1,1) -- (1,0); \draw[blue] (1,0) -- (0,0); \end{tikzpicture} 

Typically, I’d include this in LyX files by inserting a raw tex box:

And then putting the the TikZ code inside:

This is OK, but has the disadvantages from (2) above. The code can be huge, if I have a lot of graphics, I can’t tell what corresponds to what, and I have to do a (slooooooow) recompile of the whole document to see what it looks like.

However, if you just add a “preview box”:

You get something that looks like this:

So far, so pointless, right? However, when you deselect, LyX shows the graphic in-place:

You can then click on it to expand the code. This solves most of the problems: You can see what you are doing at a glance, and you don’t need to recompile the whole document to do it.

## Native SVG support

Newer versions of LyX also natively support SVG files. You first have to create the file externally using something like Inkscape, which itself saves directly to the SVG format. Then, you can include it in LyX by doing Insert->File->External Material:

And then selecting the SVG file:

Again, LyX will show it in-place and (if LyX is configured correctly…) correctly output vector graphics in the final document.

What’s even better is that LyX can automatically open the file in the external editor for you. If you right click, you can “edit externally”:

Then the external editor will automatically open the file. You can then save it with a keystroke and go back to LyX. No hunting around for the file, no cycles of exporting to other formats, and you see exactly what the final output will look like at all stages. You can really tell that LyX was created by people using it themselves.

## Bonus feature

This one is described well-enough already, but helps a lot in big documents: you can click on a point in a generated .pdf and automatically have LyX sync the editor to the corresponding point in the file.

## 6 thoughts on “The second and third best features of LyX you aren’t using.”

1. Seems extremely useful indeed, nut unfortunately I couldn’t make it work. I tried it on version 2.2.2 and 2.0 and the result is the same. After deselection I am still left with the nested black and red text boxes.
However, in the pdf document the tikz drawing shows up correctly. Any idea what is wrong with my configuration?

2. Manfred says:

I have the same problem
Any solution found in the meantime?

3. justindomke says:

Unfortunately, I have no idea what could be the problem with the configuration. However, I’ve found the LyX community to be pretty helpful if asked directly on their mailing list. There’s a huge amount of knowledge about the software that doesn’t seem to be formally documented, for better or for worse.

4. Stephen says:

Fantastic information, I appreciate it, however I will note that Lyx is not mean to be a WYSIWYG editor, as can be seen in the opening paragraph on the Lyx home page (https://www.lyx.org/):
“LyX is a document processor that encourages an approach to writing based on the structure of your documents (WYSIWYM) and not simply their appearance (WYSIWYG).”

And from wikipedia (https://en.wikipedia.org/wiki/LyX):
“Unlike most word processors, which follow the WYSIWYG (“what you see is what you get”) paradigm, LyX has a WYSIWYM (“what you see is what you mean”) approach, where what shows up on the screen is only an approximation of what will show up on the page.”

5. justindomke says:

Hi Stephen, thanks for the reply and apologies that it was trapped in the spam queue for so long.

6. Jana says:

To answer Manfred’s and Andrei’s question (and for future reference):
Choose Tools –> Preferences –> Display –> select Instant preview