Tx · LaTeX & TikZ

How to Fix Errors in LyX

Published By the 9to5Science editorial team

At a glance

  1. 1. Read the first error

    Open the detailed LaTeX log and find the earliest actionable error, not just the final stop message.

  2. 2. Inspect the source

    Check the generated LaTeX around the reported line, especially any raw TeX or recently changed content.

  3. 3. Fix the LyX document

    Correct the content, document settings, or preamble in LyX rather than editing temporary generated files.

  4. 4. Compile and check again

    Recompile after each change; one corrected error may reveal a separate problem.

LyX is a graphical editor, but it usually turns your document into LaTeX and sends that code to a LaTeX compiler. An error window therefore often reports a problem in the generated LaTeX rather than a fault in LyX itself. The reliable approach is to read the compiler’s first useful error, trace it to the document content or settings that produced it, and then compile again.

Find the detailed error message

When compilation fails, LyX usually reports that LaTeX could not process the document and offers access to more detail. Open the log or error details from that message. The exact menu location varies by LyX version; the log is the key, rather than the wording of the initial popup.

Look for the first actionable error. Later messages such as “Emergency stop” may only mean that LaTeX gave up after an earlier problem. A useful error often begins with ! and names a cause, such as an undefined command, a missing file, or a missing brace. The lines immediately before and after it can provide context.

The line number in the log refers to the generated .tex file. It may not match a paragraph or line number in the LyX window, because LyX generates additional LaTeX code. Use the nearby text and the source view to identify the corresponding content.

Trace the error back to LyX

Check what you changed most recently, then inspect the relevant area in the generated source. LyX’s View Source command can show the LaTeX it produced. Use this to diagnose the problem, but normally make the correction in the LyX document, not in a generated .tex file that LyX may overwrite.

Pay particular attention to:

  • ERT (Evil Red Text) or other raw LaTeX. A missing brace or misspelled command here can stop compilation.
  • Document settings and the preamble. A package or command may be missing, or a package may conflict with another one.
  • Inserted files. Check that an image or bibliography file exists and that its name and path are correct.
  • The compiler and encoding. A document may rely on a TeX engine or font setup that is not selected or installed.

If the error is hard to isolate, temporarily remove or disable the suspected content and compile again. Restore it in small pieces until the error returns. This narrows down the source without changing many things at once.

Common errors and their usual causes

Log message or symptomWhat to check
Undefined control sequenceThe command may be misspelled, unavailable in the selected LaTeX setup, or defined by a package that is not loaded. Check the command near the reported line and the preamble.
Missing $ insertedLaTeX may have encountered a math-only character, such as _, in text or in raw LaTeX. Put the expression in the appropriate text or math context, or escape the character where required.
File ... not foundCheck the file name, capitalization, extension, and path. Also confirm that the file is in a location LyX and the compiler can access.
Runaway argument or a missing-brace messageLook for an unmatched { or }, especially in a command, a citation, or an ERT inset.
A package or class errorCheck the document class and package settings, and confirm the required package is installed in the TeX distribution.

These messages are clues rather than guaranteed diagnoses. For example, one unmatched brace can make LaTeX misread later content and produce several confusing errors.

Worked example: an underscore in raw LaTeX

Suppose an ERT inset contains \texttt{sample_data.csv}. In LaTeX, an underscore is special in ordinary text, so this can trigger “Missing $ inserted.” Escape the underscore as \_:

\documentclass{article}

\begin{document}
The file is named \texttt{sample\_data.csv}.
\end{document}

This example needs no extra packages. In LyX, make the correction in the ERT inset that produced the problematic command. For ordinary prose, prefer entering text using LyX’s normal text editing rather than adding raw LaTeX unnecessarily.

Common troubleshooting mistakes

  • Fixing the last message instead of the first: Later errors often cascade from the earliest one. Start at the top of the log’s error list.
  • Editing the exported file as the permanent fix: LyX may regenerate it on the next compile. Change the LyX document, its preamble, or its settings instead.
  • Changing several things at once: If the error disappears, you may not know which change fixed it. Make one targeted change and compile again.
  • Assuming every warning is fatal: Warnings can flag issues such as unresolved references without stopping the build. Distinguish them from errors that prevent output.
  • Reinstalling LyX before checking the document: Many failures come from a typo, an absent image, or a package setting. Confirm the cause in the log first.

If the message remains unclear, save a copy of the document and share the exact first error, the surrounding log lines, your LyX and TeX distribution versions, and a minimal version of the document that still fails. That information makes it possible to distinguish a document problem from a compiler or installation problem.

References

  1. LyX Documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.