在Mathematica中输入LaTeX格式的公式

1. How to type LaTeX equations in Mathematica

1.1. MaTeX (Recommended)

1.1.1. Installation

1. Make sure LaTeX is installed on your computer.

pdflatex --version

Make sure it gives the correct version information.

2. Install MaTeX:
(1) Download .paclet file from MaTeX GitHub Releases

(2) Drag the .paclet file to the Mathematica application. One can do it in any Mathematica window.

(3) Mathematica will automatically install the MaTeX package. Click Install to install the package.

3. Install Ghostscript:

(1) Download from Ghostscript GitHub Releases: Windows 10 64-bit user can download gs1005w64.exe. Note that the version number may be different.

(2) Run the downloaded Ghostscript.exe file to install Ghostscript.

(3) Default installation path: C:\Program Files\gs\gs10.05.0\bin\gswin64c.exe

Find the location of Ghostscript.exe in the CMD:

where gswin64c.exe

1.1.2. Set MaTeX Environment

Run the following code in Mathematica to set the MaTeX environment:

Needs["MaTeX`"] (*setting for MaTeX*)
ConfigureMaTeX[
  "pdfLaTeX" -> "address of pdfLaTeX.exe",(*pdfLaTeX address*)
  "Ghostscript" -> "address of gswin64c.exe",(*replace Ghostscript address*)
  "CacheSize" -> 100 (*increase cache size*)
  ];

Author setting (Win10):
1. pdfLaTeX address: This is the address of pdfLaTeX.exe. The author’s setting can be found in the following path:
D:\\Program Files\\MikTeX\\basic\\miktex\\bin\\x64\\pdflatex.exe

2. Ghostscript address: This is the address of gswin64c.exe. The author’s setting can be found in the following path:
C:\\Program Files\\gs\\gs10.05.0\\bin\\gswin64c.exe

1.1.3. Example – MaTeX

1. Export a formula to a .svg file:

Export["formula.svg", MaTeX["\\int_0^1 x^2 \\, dx"]]

This can also be .pdf, .png, .jpg, etc.

2. Display a formula in Mathematica:

MaTeX["\\int_0^1 x^2 \\, dx"]

Change the font size using Magnification:

MaTeX["\\int_0^1 x^2 \\, dx", Magnification -> 1.5]

3. Display a formula in a Text object:

Graphics[
    {Line[{{pt1,pt2},{pt2,pt3},...}]},
    {
        Text[MaTeX["\\boldsymbol{U_i}",
        Magnification -> 1.5], {0, 0.3}]
    }
]

Text[MaTeX["\\boldsymbol{U_i}",Magnification -> 1.5], {0, 0.3}] shows the formula U i \boldsymbol{U_i} Ui at the position {0, 0.3} and the font is magnified by 1.5.

1.2. Download Fonts

1.2.1. Latin Modern Math

1. Download from CTAN website: zip file.

2. Unzip the downloaded file.

3. Click latinmodern-math.otf to install the Latin Modern Math font.

4. In mathematica, it will be available in the FontFamily setting.

FontFamily -> "Latin Modern Math"

1.2.2. CMU Serif

1. Download CMU Serif:
(1) CMU Official Website

(2) Directly download the font package:
CMU fonts file
Latest Version: cm-unicode-0.7.0.zip

2. Unzip the downloaded file.

Go to fonts/otf or fonts/ttf folder,find the following files:
cmunrm.ttf (CMU Serif Regular)
cmunbx.ttf (CMU Serif Bold)
cmunti.ttf (CMU Serif Italic)
cmunbi.ttf (Bold and Italic)

Click and install all the fonts.

Alt text

1.3. Author Information

码字不易,转发请备注。

Update: 2025-04-09
Author: HG

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值