I am writing a textbook with multiple chapters, and each chapter has a separate .lyx file. For convenience, I'd like to gather all my symbol definitions, etc. in a separate .tex file which I import just before the end of the preamble with \input. The publisher has a standard macro file, to which I have appended my definitions at the bottom:

%%% Local Definitions

\global\long\def\IntroChapter{Chapter 1}%
\global\long\def\FoundationsChapter{Chapter 2}%
\global\long\def\RelevantEarlierChapters{Chapters 2, 4, and 13}%

I then import it just prior to the end of the preamble as follows:




Something strange happens when I compile the file: If I insert a piece of TeX code that uses only standard letters and numbers - I have copied the generated TeX code here:

\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout

it works perfectly; I see the phrase "Chapter 1" exactly where I placed it in LyX. However, if I enter an equation that should result in a bold upright Greek letter mu (TeX code follows)

\begin_layout Standard
\begin_inset Formula $\bum$

I get four identical knitr errors (Undefined control sequence), all with the same description:

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.

If I now click on Show Output Anyway, I see the letter mu, and it is upright, but not bolded.

In contrast, if I define \bum in the main file, right after \begin_body as follows:

\begin_layout Standard
\begin_inset FormulaMacro

it works beautifully as I expect: no knitr errors and a perfect bold upright mu. What am I doing wrong in or with myMacros.tex and \input, and how can I fix this?

Sincerely and with many thanks in advance

Thomas Philips

  • "knitr" sounds like you are calling some external processing tool. Why should it know your input file? Btw: don't use \def, it won't warn you if you overwrite important commands. Always use \newcommand. Sep 9, 2020 at 7:35
  • Not meaning to imply that @UlrikeFischer's comment isn't a good idea (it is!), you have misused \long in most places here. \long is meant to indicate that the definition can include multiple paragraphs, i.e., a substitution that can contain a blank line. That will never be true for a single Greek letter, so that's just unnecessary, but it could get you in terrible trouble if such a definition takes an argument and you forget the final brace in the input. Oct 6, 2021 at 1:23
  • Thanks Barbara - I just reused some code I got from Springer, but will keep this in mind. In our case, it's not an issue, because our definitions are always just Greek letters, symbols or phrases (e.g. Sections 2.2 and 4.4), i.e. we never use an argument, but I will keep this is mind. Oct 7, 2021 at 2:20

1 Answer 1


Finally figured it out, but the answer is strange: Both amsmath and amssymb need to be included in the preamble - I had earlier included them using the document's settings. Once I added two lines to the preamble:


it worked exactly as it should have. Interestingly, both amsmath and amssymb are referenced almost immediately after the preamble, along with some other math packages (e.g. mathdots and mathtools, but that is not good enough - they have to be in the preamble.

Ulrike, thank you for your advice about \def vs. \newcommand - i'll revise the file accordingly.

Thomas Philips

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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