GitLab Markdown LaTeX Math Rendering Limit Issue
GitLab enforces a default limit on LaTeX inline math expressions per page; beyond that limit, expressions render as raw text rather than formatted math or color.
[01] The LaTeX Rendering Limits Issue
Symptom
When using LaTeX inline math to apply colors in GitLab markdown documents:
1
1. I only **$`\textcolor{orange}{\textsf{use}}`$** smartphone these days.
Past a certain count of such expressions on a single page, color rendering stops and the raw LaTeX commands are printed instead:
Figure 1. LaTeX expressions rendered as raw text past the limit
Cause
Excessive LaTeX inline math expressions can cause significant CPU overhead during page rendering. GitLab protects server performance by imposing a rendering limit by default.
| Setting | Default value | Effect |
|---|---|---|
math_rendering_limits_enabled |
true |
Stops rendering LaTeX after a threshold |
References:
[02] Fix (Disabling the Rendering Limit)
This procedure applies to a self-hosted GitLab instance running inside a Docker container.
2-1. Access the GitLab container
1
docker exec -it <gitlab-container-name> /bin/bash
2-2. Disable the limit via the GitLab Rails console
1
gitlab-rails console
Once inside the Rails console:
1
2
3
4
5
6
7
8
# Disable the rendering limit
console> ApplicationSetting.update(math_rendering_limits_enabled: false)
# Verify the change took effect
console> ApplicationSetting.current.math_rendering_limits_enabled
# Exit the console
console> exit
Then reconfigure GitLab:
1
gitlab-ctl reconfigure
Figure 2. Disabling the setting in the Rails console
Figure 3. Verifying the setting was applied
2-3. Restart the GitLab container
1
docker restart <gitlab-container-name>
After restarting, allow 1–2 minutes for GitLab services to fully come back online before testing.
[03] Result
After disabling the limit and restarting, all LaTeX color expressions render correctly regardless of count:
Figure 4. LaTeX color expressions now rendered properly
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Rails console command returns false
|
Setting not saved | Re-run ApplicationSetting.update(...) and check for errors |
| Still rendering raw text after restart | Cache not cleared | Run gitlab-ctl reconfigure again, then restart |
docker exec fails |
Container name mismatch | Run docker ps to confirm the container name |
[06] Notes
If you maintain a fleet of GitLab instances, codify the math_rendering_limits_enabled setting in your provisioning scripts (Ansible/Terraform via the GitLab Rails console) so the override survives upgrades. After each upgrade, re-verify the setting since some patch releases reset operator preferences. For projects that need long LaTeX expressions, consider pre-rendering with MathJax or KaTeX in CI and committing the output as images.