Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\global\long\def\Z{\mathbb{Z}}

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 
             {Z}
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.

Thanks!

share|improve this question
2  
Can you report the complete error message? I suspect that the undefined control sequence is \mathbb. Do you load the amssymb package? –  egreg Nov 14 '12 at 16:00
    
Also (and unrelated) \global and \long are not doing anything for a top level definition with no arguments. –  David Carlisle Nov 14 '12 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 Nov 14 '12 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}. –  Torbjørn T. Nov 16 '12 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. –  Torbjørn T. Dec 20 '12 at 11:06
show 3 more comments

1 Answer 1

up vote 6 down vote accepted

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

    \usepackage{amssymb}
    

    or

    \usepackage{amsfonts}
    
  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

    \usepackage{amsmath}
    \usepackage{amssymb}
    

    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

share|improve this answer
1  
Why should LyX use \global\long\def\Z{\mathbb{Z}} is beyond my understanding. –  egreg Dec 20 '12 at 12:00
    
Thanks @Torbjørn T. ! –  Shlomi A Dec 20 '12 at 18:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.