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.
1.3. Author Information
码字不易,转发请备注。
Update: 2025-04-09
Author: HG
2846

被折叠的 条评论
为什么被折叠?



