Why Does CodeCogs Say “Invalid Equation” When StackEdit Accepts It?
At a glance
- 1. Check the input format
See whether CodeCogs expects a math fragment or also accepts dollar-sign delimiters.
- 2. Find unsupported syntax
Look for environments, commands, or custom macros that the two renderers handle differently.
- 3. Reduce the equation
Remove parts until the error disappears, then add them back one at a time.
- 4. Test a standard form
Rewrite the expression using basic LaTeX math commands and a supported environment.
An equation that renders in StackEdit can still be rejected by CodeCogs. The two services do not necessarily process math with the same parser, command set, or input rules. “Invalid equation” therefore does not by itself show that the expression is invalid in LaTeX generally.
The exact cause depends on the equation and the text entered into CodeCogs. If you have the original expression and the full error message, those are needed to pinpoint the failing command. In the meantime, these checks usually narrow down the problem.
Check what CodeCogs expects as input
Some equation editors expect only the math expression; others accept or require delimiters such as $...$. If the editor expects a fragment, entering the delimiters themselves may cause an error. Conversely, removing delimiters from an interface that expects them may also fail. Follow the input instructions shown by the specific CodeCogs editor or try both forms with a simple test such as x^2.
An equation-image editor is also not the same as a full LaTeX document compiler. It generally expects math content, not a preamble, document class, or commands that load packages. For example, a fragment editor is unlikely to accept a complete document beginning with \documentclass.
Compare the commands and environments
A browser editor may display an expression even when it does not check it as a complete LaTeX document. Renderers also differ in which LaTeX commands and environments they implement. Check whether your expression uses:
- A custom command, such as
\foo, defined elsewhere with\newcommand. - A package-dependent command, such as
\text{...}or a specialized symbol. - An environment such as
align,aligned, orcasesthat the editor does not support in that context. - TeX features that are available in a full installation but not in a web math renderer.
For instance, \text{if } is commonly used in math with the amsmath package in a LaTeX document. A standalone renderer may support it, but that support should not be assumed. If needed, test the command separately or rewrite the phrase in a form the editor accepts.
Reduce the expression to find the failing part
Make a copy of the equation and simplify it systematically:
- Test a basic expression such as
x^2 + y^2. - Add the main structure of your equation, leaving out optional text and formatting.
- Add back commands or environments one at a time.
- When the error returns, inspect the most recently added part and check its spelling, braces, and support in that editor.
This method is more reliable than changing several commands at once. Pay particular attention to unmatched braces, missing arguments, and environment names that do not match—for example, opening \begin{aligned} but closing with \end{align}.
A minimal valid LaTeX example
For a full LaTeX document, this example uses the amsmath package and compiles as a displayed equation:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{aligned}
a^2 + b^2 &= c^2,\\
c &= \sqrt{a^2 + b^2}.
\end{aligned}
\end{equation*}
\end{document}
Here equation* creates an unnumbered display, while aligned lines up the expressions at &. The amsmath package provides these environments. This is a full-document example, not necessarily what you should paste into an online equation box. In a fragment-based editor, try only the math content, and use that editor’s expected delimiters and supported environments.
Common mistakes
- Assuming a successful preview proves compatibility. It proves only that one renderer accepted the input.
- Pasting document commands into a math box. A fragment editor may reject
\documentclass,\usepackage, or\begin{document}. - Using a custom macro without its definition. A renderer cannot interpret a command it has not been told about.
- Putting an environment in the wrong context. For example,
alignedbelongs inside math mode in a LaTeX document. - Treating every error as a syntax error. An editor can reject valid LaTeX because it does not support a command or environment.
If the reduced expression still fails, share the exact text entered—including delimiters—and the complete CodeCogs error. That makes it possible to distinguish a syntax mistake from a renderer limitation.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.