Skip to content
| Marketplace
Sign in
Visual Studio Code>Visualization>Python/R Math LaTeX HoverNew to Visual Studio Code? Get it now.
Python/R Math LaTeX Hover

Python/R Math LaTeX Hover

Enzo R S

| (0) | Free
Hover over Python and R math expressions to see them rendered as LaTeX — inline with the editor definition.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Python/R Math LaTeX Hover

Hover over any mathematical expression in Python or R and see it rendered as a beautiful LaTeX formula — right inside the editor tooltip.


Features

  • Instant LaTeX preview — hover over a formula and see the full expression rendered via MathJax, with no external dependencies or internet connection required at render time.
  • Sub-expression drill-down — the innermost parenthesized expression around your cursor is shown separately, letting you inspect nested formulas piece by piece.
  • Python & R support — works with math.*, numpy.*, np.*, scipy.*, and native R expressions. Also activates in R Markdown (.Rmd) and Quarto (.qmd) files, and inside Jupyter notebooks.
  • 50+ built-in function mappings — trig, inverse trig, hyperbolic, exponential, logarithm, combinatorics, special functions, linear algebra, statistics, and more.
  • Automatic variable recognition — identifiers like sigma, alpha, mu, x_1, math.pi are automatically converted to the correct Greek letters and symbols.
  • Custom symbol mappings — define your own function-to-LaTeX templates in settings.json to match your project's naming conventions.
  • Theme-aware color — the SVG output uses currentColor and adapts to light and dark themes, with an explicit override option.
  • Non-intrusive — the LaTeX panel appears below the existing Pylance / R LSP definition, so you never lose your type information.

How It Works

The extension registers a hover provider for Python and R files. When you hold the cursor over a line containing a mathematical expression, it:

  1. Parses the expression using a recursive-descent parser that understands Python and R syntax.
  2. Converts the abstract syntax tree to a LaTeX string.
  3. Renders the LaTeX to an SVG using MathJax (server-side, in the extension host process).
  4. Embeds the SVG as a base64 data URL in the VS Code hover tooltip.

The MathJax instance is initialized once on activation and reused for all subsequent renders, so there is no startup cost per hover.


Requirements

  • VS Code 1.74 or later
  • Node.js 16 or later (required by mathjax-full, which is bundled)

Installation

From the Marketplace

Search for Python/R Math LaTeX Hover in the Extensions panel, or run:

ext install EnzoRSimette.math-latex-hover

From a .vsix file

# Clone and build
git clone https://github.com/EnzoRSimette/math-latex-hover
cd math-latex-hover
npm install
npm run compile

# Package
npm install -g @vscode/vsce
vsce package

# Install
code --install-extension math-latex-hover-0.1.0.vsix

Examples

Python code Rendered formula
math.cos(math.sqrt(abs((a+b)**2) + abs((b-a)**2))) cos(√(|a+b|² + |b-a|²))
(math.log(S/K) + (r + sigma**2/2)*T) / (sigma*math.sqrt(T)) (ln(S/K) + (r + σ²/2)T) / (σ√T)
(r_p - r_f) / math.sqrt(sigma**2) (rₚ − rᶠ) / √(σ²)
math.comb(n, k) * p**k * (1-p)**(n-k) C(n,k) · pᵏ · (1−p)ⁿ⁻ᵏ
math.exp(-r * T) e^(−rT)

Configuration

All settings are under the Math LaTeX Hover section in VS Code settings.

Setting Type Default Description
mathLatexHover.enabled boolean true Enable or disable the extension.
mathLatexHover.formulaColor "auto" | "white" | "black" "auto" Formula text color. Use "white" for dark themes or "black" for light themes.
mathLatexHover.showCode boolean true Show the raw LaTeX source block below the rendered formula.
mathLatexHover.extraDelay number (ms) 0 Additional delay on top of editor.hover.delay before the panel appears.
mathLatexHover.customSymbols object {} Custom function and variable mappings (see below).

Custom Symbols

Map your own function and variable names to LaTeX templates in settings.json. Each {} in the template is replaced by the next function argument in order.

// .vscode/settings.json  (or User Settings)
{
  "mathLatexHover.customSymbols": {
    // mt.sum(x)    →  \sum{x}
    "mt.sum":  "\\sum{}",

    // mt.norm(v)   →  \|v\|
    "mt.norm": "\\left\\|{}\\right\\|",

    // mt.frac(a,b) →  \dfrac{a}{b}
    "mt.frac": "\\dfrac{}{}",

    // mt.EV(X)     →  \mathbb{E}[X]
    "mt.EV":   "\\mathbb{E}\\left[{}\\right]",

    // mt.var(X)    →  \mathbb{V}[X]
    "mt.var":  "\\mathbb{V}\\left[{}\\right]",

    // SIGMA used as a variable  →  \Sigma
    "SIGMA":   "\\Sigma"
  }
}

If a template has no {} placeholders and the function is called with arguments, they are appended automatically inside \left(\ldots\right). Changes take effect on the next hover — no reload required.


Built-in Function Reference

Trigonometric & Inverse

Code LaTeX
math.cos(x) / cos(x) \cos(x)
math.sin(x) / sin(x) \sin(x)
math.tan(x) / tan(x) \tan(x)
math.acos(x) / acos(x) \arccos(x)
math.asin(x) / asin(x) \arcsin(x)
math.atan(x) / atan(x) \arctan(x)
math.atan2(y, x) \arctan(y/x)
math.cosh(x) / cosh(x) \cosh(x)
math.sinh(x) / sinh(x) \sinh(x)
math.tanh(x) / tanh(x) \tanh(x)

Roots, Powers & Logarithms

Code LaTeX
math.sqrt(x) / sqrt(x) \sqrt{x}
math.cbrt(x) \sqrt[3]{x}
math.exp(x) e^{x}
math.log(x) \ln(x)
math.log(x, b) \log_b(x)
math.log2(x) \log_2(x)
math.log10(x) \log_{10}(x)
math.pow(x, n) / x**n x^{n}
math.hypot(a, b) \sqrt{a^2 + b^2}

Rounding & Absolute Value

Code LaTeX
abs(x) / math.fabs(x) / np.abs(x) \|x\|
math.floor(x) / floor(x) \lfloor x \rfloor
math.ceil(x) / ceiling(x) \lceil x \rceil
math.factorial(n) n!

Combinatorics

Code LaTeX
math.comb(n, k) / choose(n, k) \binom{n}{k}
math.perm(n, k) P(n, k)
math.gcd(a, b) \gcd(a, b)

Special Functions

Code LaTeX
math.erf(x) \operatorname{erf}(x)
math.erfc(x) \operatorname{erfc}(x)
math.gamma(x) \Gamma(x)
math.lgamma(x) \ln\Gamma(x)

Linear Algebra (NumPy)

Code LaTeX
np.dot(a, b) a \cdot b
np.cross(a, b) a \times b
np.outer(a, b) a \otimes b
np.linalg.norm(x) \|x\|
np.linalg.det(A) \det(A)
np.trace(A) \operatorname{tr}(A)
np.linalg.inv(A) A^{-1}

Statistics

Code LaTeX
np.mean(x) \bar{x}
np.std(x) \sigma(x)
np.var(x) \sigma^2(x)
np.sum(x) \sum(x)
np.corrcoef(x, y) \rho(x, y)
np.cov(x, y) \operatorname{Cov}(x, y)

Automatic Variable Recognition

Identifiers matching Greek letter names (e.g. alpha, sigma, mu, omega) are automatically converted to the corresponding LaTeX symbol. Underscore notation creates subscripts: x_1 → x_{1}, sigma_i → \sigma_{i}.

Built-in constants are also recognized: math.pi / np.pi → \pi, math.inf / np.inf → \infty, math.e → e.


Known Limitations

  • Only single-line expressions are supported (the line under the cursor).
  • Array indexing (x[0]), list comprehensions, and chained attribute access beyond module prefixes are not parsed.
  • Lambda expressions and walrus operators (:=) are not supported.

Contributing

Bug reports and pull requests are welcome on GitHub.


License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft