AI Generated LaTeX That Compiled Perfectly, but the Knot Was Wrong.
AI can produce TikZ figures that compile without errors yet encode wrong knots. Silent failures require visual and mathematical verification.
Key Takeaways
- A successful LaTeX compile does not prove an AI-generated TikZ figure is correct; most failures were silent visual errors.
- Knot diagrams are especially risky because crossings encode over/under information, which AI-written code can easily misrepresent while still rendering cleanly.
- The figure-eight example required iterative rendering and visual inspection; HaloMate’s write-compile-render-inspect loop caught failures that the compiler did not.
- Correct diagrams need verification against external ground truth, such as known knot properties or 3D parametrizations, not just code output.
Meta description: Four AI-generated TikZ figures and three silent failures show why a LaTeX compile is not a reliable correctness check for knot diagrams, plots, and tables.
Tags: AI-generated TikZ, LaTeX diagrams, knot theory, visual verification, HaloMate
Featured image: Abstract friendly illustration of a LaTeX knot diagram compiling into a PDF, with small gaps at crossings and a magnifying glass over rendered output; no text, no logos, no people.
If you ask an AI to produce LaTeX diagrams, the real risk is not a red compiler log. Four AI-generated TikZ figures, three silent failures, and one knot-theory request show why “it compiles” is the weakest possible check for a figure. This report explains how a model can make a diagram that looks complete in source, renders cleanly, and still tells the wrong story.
The trigger was a Reddit post on r/LaTeX. Someone had photographed a handwritten calculation and asked for help converting it to LaTeX. They had already tried an AI and given up, and no one had answered.
The calculation is a standard exercise from a first knot theory course. Start with the figure-eight knot, switch one crossing, smooth the same crossing, and repeat until every piece becomes a circle. The bottom result, 1 − z², is the Conway polynomial of the figure-eight knot, and the value can be checked on the Knot Atlas.
Typesetting the equations was easy. The hard part was the six little knot drawings inside the brackets.
A second, simpler request was also tested: a square pyramid with four right triangles highlighted, one for each Pythagorean relation involving height, slant height, lateral edge, and half the base. The AI handled that with tikz-3dplot in about 30 lines. Each point is a 3D coordinate, hidden edges are dashed, and each triangle is a filled path through three named points. Because every element is numeric, a model writing code has no trouble with it.
A knot diagram is different.
Why knots break AI-written TikZ
A knot diagram is mostly blank space, with the real information living in a few crossings. Each crossing says which strand goes over and which goes under. If one crossing changes, the picture can become another knot or a tangled circle.
On paper, over and under appear as a small gap in the lower strand. The code therefore needs to know where each crossing lands and then choose which strand is cut. That is a 3D fact compressed into a 2D drawing, and the model writing the code never sees the final page.
The proper tool is the knots library from the spath3 package. It lets the code draw each strand, locate crossings, and use an option called flip crossing to decide which strand goes on top. Even with the right library, the task took four attempts.
Four bugs, one compiler error
The first attempt compiled cleanly and produced circles. The curve was there, but every crossing was just two lines touching. No gap settings were present, and the knots library options clip width and knot gap had not been set. The compiler said nothing, while the PDF showed a drawing of nothing in particular.
The second attempt looked like a knot. It had gaps and seemed woven, which made it the dangerous failure. Following the strand around the figure-eight, the simplest drawing alternates over, under, over, under. This version did not. Two crossings were reversed, so the picture was not the figure-eight knot. It was another thing with four crossings.
Visual inspection alone did not solve it. The fix came from a fact outside the picture: the figure-eight is alternating, so each crossing must flip relative to the previous one when the strand is followed. Two of four crossings did not. The knots library option flip crossing fixed crossings 2 and 4, making the diagram alternate. The same correction can be checked in 3D: the standard parametrization of the figure-eight has a height coordinate z = sin 4t, and computing which strand is higher at each crossing finds the same two wrong crossings.
The third attempt also produced zero errors, but the brackets were empty. In an effort to shorten code, four separate strands were rewritten as a loop with \foreach. The compiler treated the change as harmless. The knots disappeared from the output. Writing the four strands out by hand restored them.
The fourth bug was the only one that generated a message: “Dimension too large”, appearing after the diagrams were scaled down to fit inside the equation. It was annoying, but at least it announced itself.
The score was four bugs and one error message. The three silent failures were visual.
How the loop caught the failures
The process was run in HaloMate, where the AI has a computer attached. It wrote TikZ code, compiled it, rendered the PDF to an image, looked at the image, and returned to the code. Each silent failure above was caught at the step where the model looked at the rendered image. The loop ran without copying between windows.
The same loop can be done by hand with any chatbot and Overleaf: paste code, compile, take a screenshot, paste the screenshot back, and describe what looks wrong. In that setup, the human becomes the eyes and the clipboard.
The Reddit poster had already tried a different AI and stopped. Many people stop around the second round, once the code compiles and they assume the work is finished. That assumption is the problem.
The useful question is not which AI is best at LaTeX. The model that produced empty circles was the same model that later corrected them. It did not become smarter. It became able to see what it had made.
What readers should do next
Rendering catches a figure that is obviously broken. It does not catch a figure that is confidently wrong. For any picture that contains a claim, such as a crossing, a plotted column, or a label, the output must be checked against a ground truth that exists outside the figure.
The final calculation was assembled this way. Every crossing was checked against the 3D heights. The first line is exact: the figure-eight, the same diagram with one crossing switched, which gives an unknot, and the two-component link from smoothing that crossing, with linking number −1. Later lines use simplified pictures, matching the style of the handwritten original. The answer matches the Knot Atlas.
The whole calculation compiles with pdfLaTeX on a stock TeX Live setup. If someone builds it locally, adding draft mode=crossings to any knot reveals crossing numbers, and the needed crossings can then be flipped.
For plots, tables, and diagrams, the rule is simple: if the output is a picture, someone must look at it. If the picture makes a claim, someone must verify the claim. AI can often do the first part. The second part remains a human responsibility.
The original account was published in Towards AI on Medium, where readers continue the discussion.

Comments (0)