skills/43-wentorai-research-plugins/skills/writing/latex/tex-render-guide/SKILL.md
Render LaTeX math expressions to images in PNG, JPEG, and SVG
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research tex-render-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Researchers frequently need to render LaTeX mathematical expressions as standalone images—for inclusion in presentations, posters, web pages, documentation, social media posts, or any context where native LaTeX rendering is unavailable. Converting a LaTeX equation into a crisp PNG, JPEG, or SVG image requires selecting the right toolchain and configuring it for the appropriate output quality and format.
This skill covers multiple approaches to LaTeX-to-image rendering, from command-line tools to web APIs and JavaScript libraries. It provides guidance on choosing the right approach for your use case, achieving publication-quality output, and handling common challenges like transparent backgrounds, high DPI scaling, and color customization.
Whether you need a one-off equation image for a slide deck or a batch pipeline that renders hundreds of equations for a web application, this guide provides the tools and techniques to get it done.
This is the highest-quality approach, producing output identical to what you would see in a compiled LaTeX document.
Create a minimal LaTeX document containing only your equation:
# Create a temporary LaTeX file
cat > equation.tex << 'EOF'
\documentclass[border=2pt]{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\begin{document}
$\displaystyle \int_{-\infty}^{\infty} e^{-x^2} \, dx = \sqrt{\pi}$
\end{document}
EOF
# Render to PDF, then convert to PNG
pdflatex equation.tex
# Convert PDF to high-resolution PNG (300 DPI)
convert -density 300 equation.pdf -quality 100 equation.png
# Alternative: use dvipng for direct DVI-to-PNG
latex equation.tex
dvipng -D 300 -T tight -bg Transparent equation.dvi -o equation.png
-D 300 — Resolution in DPI (300 for print, 150 for screen, 600 for high-quality)-T tight — Crop tightly to the equation with minimal margins-bg Transparent — Transparent background (essential for slides and web)-fg "rgb 1.0 1.0 1.0" — White foreground (for dark backgrounds)-o output.png — Output filenameSVG is the best format for web use and scalable documents:
# Using dvisvgm (included with TeX Live)
latex equation.tex
dvisvgm --no-fonts equation.dvi -o equation.svg
# Or from PDF:
pdf2svg equation.pdf equation.svg
The --no-fonts flag in dvisvgm converts text to paths, ensuring the SVG displays correctly without requiring the original fonts to be installed.
For rendering multiple equations, use a script:
#!/bin/bash
# render_equations.sh - Render a list of LaTeX equations to PNG
INPUT_FILE="equations.txt" # One equation per line
OUTPUT_DIR="rendered"
DPI=300
mkdir -p "$OUTPUT_DIR"
counter=1
while IFS= read -r equation; do
cat > /tmp/eq_temp.tex << EOF
\documentclass[border=2pt]{standalone}
\usepackage{amsmath,amssymb}
\begin{document}
\$\displaystyle ${equation}\$
\end{document}
EOF
(cd /tmp && pdflatex -interaction=nonstopmode eq_temp.tex > /dev/null 2>&1)
convert -density $DPI /tmp/eq_temp.pdf -quality 100 -trim "$OUTPUT_DIR/eq_$(printf '%03d' $counter).png"
echo "Rendered equation $counter: $equation"
((counter++))
done < "$INPUT_FILE"
KaTeX is a JavaScript library that renders LaTeX math to HTML/CSS or SVG. It is significantly faster than MathJax and is ideal for web applications and real-time rendering.
# Install KaTeX CLI
npm install -g katex
# Render to HTML
echo "E = mc^2" | katex --display-mode
# For SVG output, use the katex API programmatically:
const katex = require('katex');
const html = katex.renderToString(
'\\int_{-\\infty}^{\\infty} e^{-x^2} \\, dx = \\sqrt{\\pi}',
{
displayMode: true,
output: 'html', // or 'mathml'
throwOnError: false
}
);
console.log(html);
MathJax supports the widest range of LaTeX commands and produces high-quality output. Use it when KaTeX does not support the notation you need.
// Using mathjax-node
const mjAPI = require('mathjax-node');
mjAPI.config({ MathJax: {} });
mjAPI.start();
mjAPI.typeset({
math: '\\sum_{n=1}^{\\infty} \\frac{1}{n^2} = \\frac{\\pi^2}{6}',
format: 'TeX',
svg: true, // Output as SVG
// png: true, // Or output as PNG
}, function(data) {
if (!data.errors) {
// data.svg contains the SVG string
require('fs').writeFileSync('equation.svg', data.svg);
}
});
If you need PNG output from MathJax SVG:
# Using Inkscape for high-quality SVG-to-PNG conversion
inkscape equation.svg --export-type=png --export-dpi=300 --export-filename=equation.png
# Or using ImageMagick
convert -density 300 equation.svg equation.png
For quick, no-install rendering, use web APIs:
# Using the codecogs API (free for reasonable usage)
# URL-encode your LaTeX and fetch the image
curl "https://latex.codecogs.com/png.image?\dpi{300}\bg{white}\int_{0}^{1}x^2\,dx" \
-o equation.png
# SVG variant:
curl "https://latex.codecogs.com/svg.image?\int_{0}^{1}x^2\,dx" \
-o equation.svg
Note: web APIs require internet access and may have usage limits. For privacy-sensitive equations (unpublished research), prefer local rendering.
| Use Case | Recommended Method | Format | |----------|-------------------|--------| | Print publication figures | LaTeX + dvipng | PNG (600 DPI) | | Web pages / documentation | KaTeX or MathJax | SVG or HTML | | Presentations (PowerPoint, Keynote) | LaTeX + dvipng | PNG (300 DPI, transparent) | | Dark-background slides | LaTeX + dvipng with white fg | PNG (transparent) | | Batch processing (100+ equations) | LaTeX script or KaTeX | PNG or SVG | | Quick one-off equation | Web API | PNG or SVG | | Real-time preview | KaTeX | HTML |
For equations on dark backgrounds or with custom styling:
% White equation on transparent background
\documentclass[border=2pt]{standalone}
\usepackage{amsmath,xcolor}
\begin{document}
\color{white}
$\displaystyle E = mc^2$
\end{document}
# Render with transparent background
dvipng -D 300 -T tight -bg Transparent equation.dvi -o equation.png
For colored equations or partial coloring:
$\displaystyle \textcolor{blue}{\nabla} \times \textcolor{red}{\mathbf{E}} = -\frac{\partial \mathbf{B}}{\partial t}$
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.