Displaying Non-Builtin Math Macros in LyX

I believe LyX is a great tool for writing LaTeX document. It makes writing formulas very easy and it allows you to see the formula as you are writing, as opposed to seeing only LaTeX code. However LyX doesn’t support every LaTeX package and the macros it defines. Sure it doesn’t stop you from using these macros in your formulas, but it doesn’t display nicely, you see the name of the macro instead of a schematic preview.

While LyX doesn’t support many of the great packages out there like mathtools (which I really hope it will someday), you can add some support to your documents. At the beginning of the document insert a comment, via Insert->Note->Comment. Inside the newly created comment insert a math-macro via Insert->Math->Macro. In the name part, put the name of the command you want to add support for. In the second box (caption LyX), use existing LyX commands to mimic how the macro will look like. For example, this is what it looks like for the \coloneqq macro (from the great mathtools package):
math-macro

After adding the math macro in the comment, when you will use the macro inside formulas it will display nicely:
math-macro2

A little explanation how things work. When you define a math macro in LyX, LyX does two things:

  1. Inserts LaTeX code to create the macro.
  2. Displays the macro nicely when editing the document.

While the latter is desirable, the former is problematic. If LyX inserts LaTeX code to define the existing macro, it will cause errors. So when you put the LyX macro in the comment environment, the code LyX generates gets ignored and only the second, desirable, outcome is achieved.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.