Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>MathVarNew to Visual Studio Code? Get it now.
MathVar

MathVar

wenliangx

|
6 installs
| (0) | Free
To display var in math form
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

MathVar

English | 中文


English

A VS Code extension that renders mathematical formulas inline for variables with mv_ prefix.

✨ Features

  • Inline LaTeX Rendering: Variables starting with mv_ are automatically displayed as beautiful mathematical formulas
  • Multi-Language Support: Works seamlessly with Python, C, and C++
  • Smart Syntax: Use underscores to build complex mathematical expressions
    • _ - Grouping and LaTeX commands
    • __ - Subscripts
    • ___ - Superscripts
  • Context-Aware: Formulas appear when not editing, original code shows when cursor is on the variable
  • Auto-Scaling: Formulas automatically adapt to your editor's font size

🚀 Quick Start

  1. Install the extension from VS Code Marketplace
  2. Open a Python, C, or C++ file
  3. Write variables with mv_ prefix:
# Basic
mv_x = 5          # → x

# Greek letters
mv_alpha = 0.5    # → α
mv_beta = 1.2     # → β

# Subscripts
mv_x__i = 10      # → xᵢ
mv_a__1 = 3       # → a₁

# Superscripts
mv_x___2 = 25     # → x²
mv_e___minus_x = 1  # → e⁻ˣ

# Complex expressions
mv_alpha__i___2 = 0.1           # → αᵢ²
mv_bm_v__i = [1, 2, 3]          # → 𝒗ᵢ (bold italic vector)
mv_frac_a_b__plus_c = 0.5       # → (a/b) + c
mv_x__i___2 = 100  # Displays as: xᵢ²

📚 Supported Keywords

  • Greek Letters: alpha, beta, gamma, delta, theta, lambda, mu, sigma, omega, etc.
  • Math Operators: sum, prod, integral, lim, sqrt, frac
  • Trigonometric: sin, cos, tan, log, ln, exp
  • Symbols: infty, partial, nabla, times, cdot, div
  • Fonts: bold, bm (bold italic for vectors), mathrm, mathit, mathcal, mathbb
  • Accents: dot, ddot

💡 Tips

  • Click on a variable to edit it in its original form
  • Clear cache if formulas don't update: Ctrl+Shift+P → "MathVar: Clear Formula Cache"
  • Formulas automatically adapt to your editor's font size

中文

一个可以将 mv_ 前缀的变量内联渲染为数学公式的 VS Code 插件。

✨ 功能特性

  • 内联 LaTeX 渲染:以 mv_ 开头的变量自动显示为精美的数学公式
  • 多语言支持:无缝支持 Python、C 和 C++
  • 智能语法:使用下划线构建复杂的数学表达式
    • _ - 分组和 LaTeX 命令
    • __ - 下标
    • ___ - 上标
  • 上下文感知:非编辑时显示公式,光标在变量上时显示原始代码
  • 自动缩放:公式自动适配编辑器字体大小

🚀 快速上手

  1. 从 VS Code 扩展市场安装本插件
  2. 打开 Python、C 或 C++ 文件
  3. 编写带 mv_ 前缀的变量:
# 基础用法
mv_x = 5          # → x

# 希腊字母
mv_alpha = 0.5    # → α
mv_beta = 1.2     # → β

# 下标
mv_x__i = 10      # → xᵢ
mv_a__1 = 3       # → a₁

# 上标
mv_x___2 = 25     # → x²
mv_e___minus_x = 1  # → e⁻ˣ

# 复杂表达式
mv_alpha__i___2 = 0.1           # → αᵢ²
mv_bm_v__i = [1, 2, 3]          # → 𝒗ᵢ(粗斜体向量)
mv_frac_a_b__plus_c = 0.5       # → (a/b) + c

📚 支持的关键字

  • 希腊字母:alpha, beta, gamma, delta, theta, lambda, mu, sigma, omega 等
  • 数学运算符:sum, prod, integral, lim, sqrt, frac
  • 三角函数:sin, cos, tan, log, ln, exp
  • 符号:infty, partial, nabla, times, cdot, div
  • 字体:bold, bm(向量用粗斜体), mathrm, mathit, mathcal, mathbb
  • 修饰:dot, ddot

💡 使用技巧

  • 点击变量即可编辑其原始形式
  • 如果公式未更新,清除缓存:Ctrl+Shift+P → "MathVar: Clear Formula Cache"
  • 公式会自动适配编辑器字体大小

License

MIT

Release Notes

0.1.4

  • Improved width estimation with precise Greek letter and command width mappings
  • Added vector support: bm, boldsymbol keywords for bold italic vectors
  • Added ddot accent keyword
  • Optimized rendering performance
  • Removed unused height calculation code

0.1.3

  • Enhanced formula rendering with better alignment
  • Multi-language support for Python, C, and C++
  • Performance improvements with multi-level caching

0.0.1

  • Initial release
  • Basic LaTeX rendering for mv_ prefixed variables
  • SVG-based rendering with caching

中文

一个 VS Code 扩展,可以自动为特殊命名的 Python 变量渲染 LaTeX 数学公式。

功能特性

  • 自动公式渲染:带有 mv_ 前缀的变量会自动转换并渲染为 LaTeX 公式
  • 智能语法:基于下划线的直观数学符号语法
    • 单下划线 _:大括号或 LaTeX 命令(例如:mv_alpha → α)
    • 双下划线 __:下标(例如:mv_x__2 → x₂)
    • 三下划线 ___:上标(例如:mv_x___2 → x²)
  • 上下文感知显示:
    • 光标远离变量时显示渲染的公式
    • 编辑或光标在变量上时显示原始代码
  • 字体大小自适应:根据编辑器字体大小设置自动缩放公式渲染
    • 公式动态调整大小、高度和间距
    • 在不同字体大小下保持完美对齐
  • 动态尺寸调整:根据公式复杂度自动调整大小(下标、上标、大型运算符)
  • 统一配色方案:所有公式以一致的蓝色显示
  • 高性能:基于 SVG 的高效渲染并支持文件缓存

使用方法

只需在 Python 变量名前添加 mv_ 前缀,并使用下划线定义数学结构:

# 基本变量
mv_x = 5  # 显示为:x

# 希腊字母
mv_alpha = 0.5  # 显示为:α

# 下标
mv_x__i = 10  # 显示为:xᵢ

# 上标
mv_x___2 = 25  # 显示为:x²

# 组合
mv_x__i___2 = 100  # 显示为:xᵢ²

# 带上下限的大型运算符
mv_sum__1___n = total  # 显示为:Σ₁ⁿ

系统要求

  • VS Code 1.106.0 或更高版本
  • Python 语言支持

扩展命令

  • MathVar: Clear Formula Cache - 清除缓存的 SVG 公式文件

配置说明

扩展会自动读取编辑器设置:

  • 字体大小:公式会自动随 editor.fontSize 设置缩放
    • 当你更改编辑器字体大小时,公式会立即重新渲染
    • 支持从小字体(10px)到大字体(24px+)的任意大小
    • 所有间距和尺寸按比例缩放

调整字体大小:文件 > 首选项 > 设置 > 编辑器: 字体大小

已知问题

  • 仅适用于 Python 文件(.py)
  • 变量必须使用 mv_ 前缀才能被识别

版本说明

0.0.4

改进:

  • 重构为灵活的四步处理流程:识别、分组、替换、合并
  • 引入关键词配置表,支持更细粒度的控制:
    • removeBraces: 控制是否去掉花括号
    • acceptSub: 控制是否接受下标参数
    • acceptSup: 控制是否接受上标参数
  • 增强合并逻辑:分为参数合并、去括号和上下标合并三个阶段
  • 支持关键词接受参数(例如:mv_frac__1___2 → \frac{1}{2})

移除:

  • 删除了与分数显示相关的特殊高度和宽度计算代码

0.0.3

新功能:

  • 新增 dot 关键词支持点记号(例如:mv_x_dot → ẋ)
  • 新增符号关键词:lparen(左括号)、rparen(右括号)、division(除号)
  • 新增 integral 关键词映射到 \int(替代之前的 int)

改进:

  • 重构代码为清晰的四步处理流程
  • 改进多个连续下标/上标的处理:现在自动合并到单个括号中
    • 例如:mv_p__partial__x → p_{\partial x}(而非 p_{\partial}_{x})
  • 单个关键词替换后不再保留花括号
    • 例如:{dot} → \dot(而非 {\dot})

移除:

  • 移除 int 关键词(改用 integral)
  • 移除 frac 特殊处理(使用符号关键词组合来表示分数)

0.0.2

新功能:

  • 字体大小自适应:公式现在可以根据编辑器字体大小自动缩放
  • 基于字体大小动态调整所有尺寸(宽度、高度、间距)
  • 字体大小改变时实时重新渲染
  • 所有公式采用统一蓝色配色方案
  • 字体大小更新时显示通知

0.0.1

MathVar 首次发布

功能:

  • 为 mv_ 前缀变量提供 LaTeX 公式渲染
  • 支持下标、上标和 LaTeX 命令
  • 动态公式大小调整和定位
  • 上下文感知显示(编辑时隐藏)
  • 基于 SVG 的渲染和缓存

License

MIT

  • Visual Studio Code's Markdown Support
  • Markdown Syntax Reference

Enjoy!

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