I'm trying to define a LyX macro, Insert -> Math -> Macro on the menus. It's a very simple macro. Source code under View -> View Source:


The file compiles nicely if I don't use the macro. However, once I put a \Z inside a Math formula and try to compile, it gives me an Undefined control sequence with the following error message:

! Undefined control sequence.
\Z ->\mathbb 
l.32 d$\Z
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

Now, the most peculiar thing is that I have used this exact same macro on other files, where it works perfectly.

In case it might be of any help, I'm using the article document class on LyX 2.0.0. Could it be that the document encoding or document class make a difference? Or maybe the document language setting?

A complete log of the LaTeX errors is available at this link.


  • 2
    Can you report the complete error message? I suspect that the undefined control sequence is \mathbb. Do you load the amssymb package?
    – egreg
    Commented Nov 14, 2012 at 16:00
  • Also (and unrelated) \global and \long are not doing anything for a top level definition with no arguments. Commented Nov 14, 2012 at 16:51
  • 1
    The error message says that \mathbb is the undefined command, as I suspected. Neither amssymb nor amsfonts that would define it are loaded, according to the log. I really don't know how to coerce LyX into loading amssymb, but this is the thing you should try to do.
    – egreg
    Commented Nov 14, 2012 at 22:07
  • 2
    To tell LyX to load amssymb one can do either 1) Document --> Settings --> Math options, and check Use AMS Package, or 2) Document --> Settings --> LaTeX preamble, and add \usepackage{amssymb}. Commented Nov 16, 2012 at 18:51
  • 1
    @ShlomiA You misunderstood slightly, Use AMS automatically will not force LyX to load AMS packages, it will only do so if you add e.g. an AMS environment (Insert --> Math --> ...), so to force loading, uncheck the automatic choice, and check Use AMS Package, just below. I'll add an answer. Commented Dec 20, 2012 at 11:06

1 Answer 1


As egreg mentions in a comment, the reason you get the error is that neither the amsfonts nor amssymb package, where \mathbb is defined, is loaded. To force LyX to add one of these you can do one of two things:

  1. Go to Document --> Settings --> LaTeX preamble and add there either



  2. Go to Document --> Settings --> Math options. Uncheck Use AMS math package automatically and check Use AMS math package, as in the screenshot below. LyX will now have added


    to the document preamble.

    The first of these, the automatic one, adds these packages only if you use some of their features through the LyX GUI. E.g. if you do Insert --> Math --> AMS Align, the amsmath package will be added, and if you e.g. add some text with Blackboard bold via the math font button on the toolbar -- enter image description here -- then amssymb will be added.

    enter image description here

  • 1
    Why should LyX use \global\long\def\Z{\mathbb{Z}} is beyond my understanding.
    – egreg
    Commented Dec 20, 2012 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .