Why Is My Algorithm Missing from the PDF?
At a glance
- 1. Check the log
Fix the first LaTeX error, then compile again and confirm that you are viewing the newly generated PDF.
- 2. Check the packages
Load matching packages for the algorithm float and the pseudocode commands you use.
- 3. Check float placement
Algorithms are often floats, so LaTeX may move them to another page or later in the document.
- 4. Test a minimal file
Compile a small example to separate package or source problems from TeXstudio and build settings.
If an algorithm does not appear where you expected—or seems to be absent entirely—the cause is usually a LaTeX compile problem or float placement. TeXstudio is an editor and front end for LaTeX tools; the compiler and document source determine what gets written to the PDF.
Start by checking the build log for errors, then search the full PDF for the algorithm’s caption or text. The example below shows a standard setup using the algorithm float and algpseudocode for pseudocode commands.
Check the compilation log first
A LaTeX error earlier in the document can prevent a successful build. Depending on your settings and the error, TeXstudio may still show a PDF from an earlier successful compile. Read the log from the first error onward: later errors are often consequences of the first one. Correct the error and compile again.
Also confirm that you are opening the PDF produced by the current build. Projects can use a separate output directory, and a viewer may still have an older PDF open. The log and TeXstudio’s build messages can help identify the output file and whether compilation finished successfully.
Use compatible algorithm packages
For a floating algorithm numbered and captioned like a figure, one common combination is algorithm plus algpseudocode. The first supplies the algorithm environment; the second supplies commands such as \State, \If, and \EndIf inside the pseudocode block.
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
Here is the procedure described in Algorithm~\ref{alg:example}.
\begin{algorithm}[htbp]
\caption{Add two numbers}
\label{alg:example}
\begin{algorithmic}[1]
\Require Integers $a$ and $b$
\Ensure The sum $a+b$
\State $s \gets a+b$
\State \Return $s$
\end{algorithmic}
\end{algorithm}
\end{document}
Save this as a .tex file and compile it with a LaTeX engine. If it works, compare its package declarations and environment names with your larger document. Do not assume that similarly named packages are interchangeable: for example, algorithmic, algpseudocode, and algorithm2e have different commands and conventions. Choose one syntax and follow that package’s documentation rather than mixing examples from different packages.
Remember that algorithms are floats
The algorithm environment in the example is a float: LaTeX may move it to a suitable location instead of placing it exactly at the point where it occurs in the source. The [htbp] option asks LaTeX to try here, the top or bottom of a page, or a float page. These letters are placement preferences, not a guarantee of exact positioning.
Search the entire PDF for the caption or a distinctive phrase. The algorithm may be on a later page, near the end of a section, or on a page containing only floats. A float can also be held back if earlier floats have not yet been placed. If you want to inspect where LaTeX placed it, temporarily add \listofalgorithms after \begin{document}; this prints a list of algorithm captions and page numbers. It is optional and does not make missing algorithms appear by itself.
If an algorithm must stay at a specific point, the float package provides the [H] placement option. Add \usepackage{float} and change the opening line to \begin{algorithm}[H]. Use this sparingly: forcing many floats can leave awkward gaps or cause layout problems.
Check the environment and source
Make sure each environment has a matching beginning and ending, and that the names match exactly. For example, \begin{algorithmic} needs \end{algorithmic}. The pseudocode block usually belongs inside the algorithm float; putting only pseudocode commands in a float—or using commands from a package that is not loaded—can produce errors or unexpected output.
If the algorithm is in another file, check that the main document includes that file with the intended \input{...} or \include{...} command, and that the path and filename are correct. Check for conditional code that may skip the algorithm, such as an \if... branch, and confirm that the source you edited is the source TeXstudio is compiling.
Common mistakes
- Expecting source order to fix float position. LaTeX can move a float even when it appears halfway through a section in the source.
- Mixing package syntax. Commands from
algorithm2e,algpseudocode, andalgorithmicare not a single shared command set. - Looking only at the current page. Search the complete PDF or inspect the list of algorithms.
- Ignoring the first error. A later error message may be caused by an earlier missing package or unmatched environment.
- Viewing an old output file. Check the build result and output path before diagnosing a source change that is not visible.
If the minimal example compiles but your document does not, add the relevant packages and algorithm code back in stages until the problem returns. That usually reveals whether the issue is a package conflict, a source-file path, a float constraint, or an unrelated LaTeX error.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.