Why I'm using LyX

2023-01-12
2023-01-12
Header: why-lyx

LyX is a great software you can use to replace those plain-text-based LaTeX editors. Here I will show you why I chose LyX.

Pains with plain LaTeX#

Below is a screenshot of the LaTeX workshop. Many LaTeX users are using similar software for writing documents. It's obvious why nearly all those LaTeX editors have a preview pane of the rendered PDF file: the raw LaTeX code is not intuitive. It's a mixture of commands and contents, and it's missing visual clues for the document structure. On the contrary, finding the related contents in rendered PDF is much easier and quicker.

Screenshot of LaTeX workshop in light theme

Screenshot by Ormulogun on Wikimedia: https://commons.wikimedia.org/wiki/File:VsCode_LaTex_Workshop.png

The PDF preview is nice, but there are some problems with it. The most annoying one for me is that splitting a pane on a small laptop screen is painful. On the one hand, 1/2 of the screen is too small for the generated PDF file which is usually on A4 paper. On the other hand, 1/2 of the screen is too small for larger equations and tables, which looks pretty bad when the line is wrapped. Even if I got a larger screen, having a PDF to preview every so often is distracting, and syncing the scroll position of the LaTeX code and the PDF file is not smooth.

Another source of pain is math editing. Although LaTeX math becomes quite a standard, we have to admit that it's not an easy task to write and edit math in raw LaTeX code. Every student who is trying to take LaTeX notes in a math-heavy lecture will soon get lost.

Introducing LyX#

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).

LyX combines the power and flexibility of TeX/LaTeX with the ease of use of a graphical interface. This results in world-class support for creation of mathematical content (via a fully integrated equation editor) and structured documents like academic articles, theses, and books.

Screenshot of LyX in light theme

Screenshot of LyX from https://www.lyx.org/Screenshots

So basically LyX is a WYSIWYM (what you see is what you mean) GUI document editor based on LaTeX and supports a wide range of LaTeX concepts, commands, and environments, coming with an excellent equation editor. But note that LyX is not a LaTeX editor. It's just an editor which is based on and has great support for LaTeX.

LyX solved many problems I mentioned in the previous section. With the graphical interface, editing the document feels at home. And it also eliminates the need for the PDF previewing pane, avoiding all the problems caused by an extra pane. Besides, the powerful math editor alone can be a good reason for adopting LyX in your workflow.

And here are some more awesome bits about LyX:

No LaTeX knowledge is required for onboarding. The graphical interface is friendly and the manual is detailed and doesn't assume prior knowledge of LaTeX. And many frequently used LaTeX packages and settings are presented with a friendly GUI. However, some LaTeX knowledge is required for better customization of your document, just as what you do for plain LaTeX.

As mentioned above, LyX has almost full LaTeX compatibility. Although the built-in support is finite, LyX allows users to tell LyX how to display and render other environments and commands. Even if your needs don't fit into all existing ways of customization, you can still insert raw LaTeX command, or so-called evil red text (ERT).

A large collection of templates are available. LyX has built-in support for some commonly used LaTeX templates, including the Beamer, and there are many people sharing their LyX templates on the Internet, but that's only part of it. The really great part is that you can easily use almost any LaTeX template in LyX with some simple setups.

LyX template search results

It's highly customizable. Customizing the appearance, key bindings, and UI layouts are simple. But LyX is not programmable, although there are many LyX functions to use and can be combined.

Why WYSIWYM instead of WYSIWYG?#

Some people don't like WYSIWYM in LyX and prefer some truly WYSIWYG software, for example, TeXmacs, even though TeXmacs is not based on TeX. And they might think LyX is WYSIWYM because the design and the developers are incapable.

But you really can't have both true WYSIWYG and nearly full LaTeX compatibility. That's because LaTeX doesn't support typesetting in real time, so it's impossible to build WYSIWYG based on LaTeX. And it's also very difficult to build a true real-time engine with full compatibility with LaTeX.

Therefore, LyX chose to render it approximately while preserving the document structures in a WYSIWYM way. One may still say that LyX can do the approximate rendering better. But that inevitably involves applying some class-specific styles, which has a marginal benefit and requires a lot of work if done manually, and is also impossible to do automatically because LaTeX files are not data and are hard to parse, especially when working with the @-macros.

Overall, WYSIWYM is an approximation that must be made and covers 90%+ what you need to overcome the problems in non-intuitive plain LaTeX.

Why not TeXmacs#

TeXmacs is a true WYSIWYG document editor with many advanced features, but it's another typesetting system instead of real TeX.

Screenshot of TeXmacs in light theme

Screenshot of TeXmacs from http://www.texmacs.org/tmweb/home/welcome.en.html

TeXmacs is programmable with the Scheme language, and the whole .tm document is Scheme data so it's easy to be parsed as a tree. But when things get complex, Scheme data is not friendly to humans, for example, something like this.

  <assign|tit|<macro|body|<with-tit-color|<with|ornament-color|<title-bar-color>|<ornament|<title-left|<arg|body>><htab|5mm><with|font-series|bold|math-font-series|bold|<large|<space|0em|-0.6ex|1.6ex><arg|body>>><htab|5mm><title-right|<arg|body>>>>>>>

And most importantly, TeXmacs has a rather small community. Small in community size plus the difficulties for customization is a disaster, which means it's hard to find the solutions to your problems on the Internet. Another example is that there are few community Beamer templates and the metropolis template doesn't even support adding page numbers!

I was trying to use TeXmacs to make some slides but failed to migrate my existing template based on metropolis to TeXmacs. So I gave up TeXmacs.

Shortcomings of LyX#

LyX does have some shortcomings.

Formatting images is still a pain because LyX doesn't provide clues about the final typesetting result, and I have to check the PDF render result.

Although LyX supports collaboration, your co-workers probably don't know LyX, so if you are writing a paper with others, some online LaTeX collaboration systems like Overleaf might still be a preferred option.

LyX has a smaller community than LaTeX, but larger than TeXmacs. You are strongly suggested, but don't have to, read the documentation before searching on the Internet.

Also, LyX can sometimes crash on my machine (Linux), But its auto-saving and the backup mechanism are good, and I haven't encountered big data loss.

Appendix: How to learn LyX#

Leave your comments and reactions on GitHub