Repository: shinyypig/latex-vscode-config Branch: main Commit: 2a78c30a6651 Files: 5 Total size: 39.0 KB Directory structure: gitextract_8ut69hyn/ ├── .gitignore ├── README.en.md ├── README.md ├── latex.hsnips └── shinyypig_commit_config.json ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store ================================================ FILE: README.en.md ================================================ # Configure LaTeX in VSCode English | [中文](README.zh.md) This guide shows how to set up a LaTeX environment in VSCode for editing and previewing, so you can work efficiently and comfortably. Supported features: - Auto compile on save - XeLaTeX and PdfLaTeX support (Chinese and English) - Output to a dedicated folder `./tmp` - English word completion with Chinese translations - LaTeX syntax completion - Fast math snippets (e.g. `@a` expands to `\alpha`) - Path auto-completion - Auto-generate matrix and figure environments - Live preview for equations and images - Auto-format `.tex` files Example result after a full setup: ![Alt text](img/iShot_2023-02-13_12.26.45.gif) The configuration includes: - [Software installation](#software-installation) - [Install TeX Live](#install-tex-live) - [Install VSCode](#install-vscode) - [VSCode extensions](#vscode-extensions) - [How to install](#how-to-install) - [Recommended extensions](#recommended-extensions) - [LaTeX Workshop configuration](#latex-workshop-configuration) - [Basic settings](#basic-settings) - [Compile toolchain](#compile-toolchain) - [Advanced configuration](#advanced-configuration) - [Format LaTeX with latexindent](#format-latex-with-latexindent) - [Fast math input with HyperSnips for Math](#fast-math-input-with-hypersnips-for-math) - [Version control with Git](#version-control-with-git) - [Speed up with TikZ externalize](#speed-up-with-tikz-externalize) ## Software installation ### Install TeX Live TeX Live is a full LaTeX distribution and is recommended for compiling LaTeX documents. If you previously installed MikTeX, uninstall it completely before installing TeX Live. Windows / Linux users can download the installer here: [texlive.iso](https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/). Download the ISO and run the installer. Mac users can download: [MacTeX.pkg](https://mirrors.tuna.tsinghua.edu.cn/ctan/systems/mac/mactex/). Download the pkg and run it. ### Install VSCode VSCode is a lightweight editor that supports LaTeX. Download the installer from [Visual Studio Code](https://code.visualstudio.com/download) and install it. ## VSCode extensions ### How to install Click the Extensions icon on the left: ![Extensions](img/iShot_2023-02-13_10.19.01.png) Search for the extension and click Install. ### Recommended extensions Everything below is optional except LaTeX Workshop. - LaTeX Workshop LaTeX Workshop provides compilation, preview, and syntax checking. ![latex workshop](img/iShot_2023-02-13_10.22.55.png) - English Word Hint English Word Hint suggests English words and shows Chinese translations to improve English writing efficiency. ![English word hint](img/iShot_2023-02-13_10.24.58.png) - Path Auto Complete Path Auto Complete inserts image paths quickly. ![Alt text](img/iShot_2023-02-13_11.57.52.png) - indent rainbow indent rainbow colorizes indentation levels. ![Alt text](img/iShot_2023-02-13_10.27.37.png) - Word Count CJK Word Count CJK counts words for Chinese documents. ![Alt text](img/iShot_2023-02-13_10.29.03.png) - Code Spell Checker Code Spell Checker checks English spelling with low memory overhead. ![Alt text](img/iShot_2023-02-13_10.31.35.png) - LTex LTex checks spelling and grammar, but is slower and uses more memory. Choose either LTex or Code Spell Checker. ![Alt text](img/iShot_2023-02-13_10.31.59.png) - Project Manager Project Manager helps you switch between multiple VSCode projects. ![Alt text](img/iShot_2023-02-13_10.36.21.png) - Material Icon Theme Material Icon Theme adds icons to the VSCode file tree. ![Alt text](img/iShot_2023-02-13_10.38.20.png) - WakaTime WakaTime tracks coding time by language for better time planning. ![Alt text](img/iShot_2023-02-13_10.39.39.png) ## LaTeX Workshop configuration The settings below are my personal configuration. Adjust as needed. ### Basic settings ```json "latex-workshop.hover.preview.mathjax.extensions": [ "boldsymbol" ], "latex-workshop.intellisense.package.enabled": true, "latex-workshop.latex.outDir": "./tmp", "latex-workshop.latex.recipe.default": "lastUsed", "latex-workshop.mathpreviewpanel.cursor.enabled": true, "latex-workshop.message.error.show": false, "latex-workshop.message.warning.show": false, "latex-workshop.view.pdf.invert": 1, "latex-workshop.view.pdf.invertMode.enabled": "auto", ``` Click the gear icon in the lower-left corner of VSCode, choose Settings, and search for each option to update it. For example: ![Alt text](img/iShot_2023-02-13_10.47.32.png) If you are comfortable with VSCode, open Command Palette, search for settings, open settings.json, and paste the snippet directly. Explanation of each setting: ```text // Enable boldsymbol in hover preview "latex-workshop.hover.preview.mathjax.extensions": [ "boldsymbol" ], // Enable IntelliSense for package commands and environments "latex-workshop.intellisense.package.enabled": true, // Output directory for compiled files "latex-workshop.latex.outDir": "./tmp", // Default recipe uses the last one you ran "latex-workshop.latex.recipe.default": "lastUsed", // Enable the math preview panel for complex formulas "latex-workshop.mathpreviewpanel.cursor.enabled": true, // Disable error popups "latex-workshop.message.error.show": false, // Disable warning popups "latex-workshop.message.warning.show": false, // Invert colors when previewing PDF "latex-workshop.view.pdf.invert": 1, // Auto detect when to invert PDF colors "latex-workshop.view.pdf.invertMode.enabled": "auto", ``` ### Compile toolchain I recommend using latexmk, which automatically detects changes and supports multiple engines such as XeLaTeX and PdfLaTeX. In settings.json, find `latex-workshop.latex.tools` and `latex-workshop.latex.recipes`, delete them, and replace with: ```json "latex-workshop.latex.recipes": [ { "name": "XeLaTeX", "tools": [ "xelatexmk" ] }, { "name": "PdfLaTeX", "tools": [ "pdflatexmk" ] } ], "latex-workshop.latex.tools": [ { "args": [ "-synctex=1", "-pdfxe", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "xelatexmk" }, { "args": [ "-synctex=1", "-pdf", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "pdflatexmk" } ], ``` ## Advanced configuration This section is optional. ### Format LaTeX with latexindent Install latexindent.pl first, following [latexindent.pl](https://github.com/cmhughes/latexindent.pl). Add this to settings.json: ```json "latex-workshop.latexindent.args": [ "-g", "./%OUTDIR%/indent.log", "%TMPFILE%", "-y=defaultIndent: '%INDENT%'" ], ``` This sends latexindent.pl logs to `tmp/indent.log` for easier management. ### Fast math input with HyperSnips for Math Install HyperSnips for Math and follow the extension's setup instructions. With this extension, typing `eq` expands to: ```latex \begin{equation} \end{equation} ``` [latex.hsnips](latex.hsnips) is my personal config and supports two features. Type `bmat n m` and press Space to generate an empty matrix: ```latex // bmat 3 4 \begin{bmatrix} & & & \\ & & & \\ & & & \\ \end{bmatrix} ``` Type `fig label n` and press Space to generate a figure block with multiple subfigures: ```latex \begin{figure}[htb!] \centering \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_1} \end{subfigure} \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_2} \end{subfigure} \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_3} \end{subfigure} \caption{} \label{fig:example} \end{figure} ``` Adjust other snippets as needed. ### Version control with Git Install Git first. Click the Source Control icon in VSCode. If Git is missing, VSCode will prompt you to install it. ![Alt text](img/iShot_2023-02-15_16.45.42.png) Recommended extensions: - GitLens GitLens adds blame and history features. Some features require a Pro subscription, so turn them off in settings. You can also use the free alternatives below. - Git Graph Git Graph shows the commit history visually. - Commit Message Editor Commit Message Editor formats commit messages. You can import this [config](shinyypig_commit_config.json). ![Alt text](img/iShot_2023-02-15_16.54.32.png) ### Speed up with TikZ externalize Make sure your output directory is `./tmp/`, then add this to your `.tex` file: ```latex \usetikzlibrary{external} \immediate\write18{mkdir -p tmp/tmp/} \tikzexternalize[ prefix=tmp/, mode=list and make, ] ``` Then create a `latexmkrc` file at the project root: ```perl $clean_ext .= ' %R.figlist %R-figure* %R.makefile fls.tmp'; $latex = 'internal tikzlatex latex %B %O %S'; $pdflatex = 'internal tikzlatex pdflatex %B %O %S'; $lualatex = 'internal tikzlatex lualatex %B %O %S'; $xelatex = 'internal tikzlatex xelatex %B %O %S'; $hash_calc_ignore_pattern{'pdf'} = '^(/CreationDate|/ModDate|/ID)'; $hash_calc_ignore_pattern{'ps'} = '^%%CreationDate'; sub tikzlatex { my ($engine, $base, @args) = @_; my $ret = 0; print "Tikzlatex: ===Running '$engine @args'...\n"; $ret = system( $engine, @args ); print "Tikzlatex: Fixing .fls file ...\n"; system "echo INPUT \"$aux_dir1$base.figlist\" > \"$aux_dir1$base.fls.tmp\""; system "echo INPUT \"$aux_dir1$base.makefile\" >> \"$aux_dir1$base.fls.tmp\""; system "cat \"$aux_dir1$base.fls\" >> \"$aux_dir1$base.fls.tmp\""; rename "$aux_dir1$base.fls.tmp", "$aux_dir1$base.fls"; if ($ret) { return $ret; } if ( -e "$aux_dir1$base.makefile" ) { if ($engine eq 'xelatex') { print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under xelatex\n"; system( 'perl', '-i', '-p', '-e', 's/^\^\^I/\t/', "$aux_dir1$base.makefile" ); } elsif ($engine eq 'latex') { print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under latex\n"; system( 'perl', '-i', '-p', '-e', 's/\.epsi/\.ps/', "$aux_dir1$base.makefile" ); } print "Tikzlatex: ---Running 'make -f $aux_dir1$base.makefile' ...\n"; if ($aux_dir) { # system "perl -i -p -e 's#-shell-escape#-shell-escape -output-directory=\"$aux_dir1\"#g' $aux_dir1$base.makefile"; system "perl -i -p -e 's#$base.figlist#$aux_dir1$base.figlist#g' $aux_dir1$base.makefile"; system "cp $aux_dir1$aux_dir1*.md5 $aux_dir1"; system "rm -rf $aux_dir1$aux_dir1"; $ret = system "make", "-j", "10", "-f", "$aux_dir1$base.makefile"; system "rm $base.run.xml"; } else { $ret = system "make", "-j", "10", "-f", "$base.makefile"; } if ($ret) { print "Tikzlatex: !!!!!!!!!!!!!! Error from make !!!!!!!!! \n", " The log files for making the figures '$aux_dir1$base-figure*.log'\n", " may have information\n"; } } else { print "Tikzlatex: No '$aux_dir1$base.makefile', so I won't run make.\n"; } return $ret; } ``` Finally, update LaTeX Workshop tools as follows: ```json "latex-workshop.latex.tools": [ { "args": [ "-synctex=1", "--pdfxe", "-shell-escape", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "xelatexmk" }, { "args": [ "-synctex=1", "-pdflatex", "-shell-escape", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "pdflatexmk" } ], ``` ================================================ FILE: README.md ================================================ # 在 VSCode 中配置 LaTeX 环境 中文 | [English](README.en.md) 本教程将介绍如何在 VSCode 中配置 LaTeX 环境,以便于在 VSCode 中进行 LaTeX 的编写和预览,打造一个舒适便捷的 LaTeX 编写环境。 支持的功能有: - 保存文件时自动编译 - 支持 XeLaTeX 和 PdfLaTeX 编译 (中英文) - 编译结果输出到特定文件夹./tmp - 英文单词补全,以及中文翻译 - LaTeX 语法自动补全 - 支持快速输入公式,比如输入`@a`会自动补全为`\alpha` - 自动补全路径 - 自动生成矩阵和图片环境 - 实时预览公式、图片 - 自动格式化 tex 文件 完整配置后的效果如下: ![Alt text](img/iShot_2023-02-13_12.26.45.gif) 配置部分主要包含以下内容: - [软件安装](#软件安装) - [TeX Live 安装](#tex-live-安装) - [VSCode 安装](#vscode-安装) - [VSCode 插件](#vscode-插件) - [如何安装](#如何安装) - [插件推荐](#插件推荐) - [LaTeX Workshop 配置](#latex-workshop-配置) - [基本配置](#基本配置) - [编译工具链配置](#编译工具链配置) - [进阶配置](#进阶配置) - [使用 latexindent 格式化 LaTeX 代码](#使用-latexindent-格式化-latex-代码) - [使用 HyperSnips for Math 插件快速输入公式](#使用-hypersnips-for-math-插件快速输入公式) - [使用 Git 进行版本管理](#使用-git-进行版本管理) - [TiKZ Externalize 加速编译](#tikz-externalize-加速编译) ## 软件安装 ### TeX Live 安装 TeX Live 是一个 LaTeX 发行版,并且包含较为完整的 LaTeX 环境,推荐使用 TeX Live 进行 LaTeX 的编译。如果之前安装过 MikTeX,一定要将其完全卸载后,再安装 TeX Live。 Windows / Linux 用户可以直接下载安装包进行安装,安装包下载地址为:[texlive.iso](https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/),下载 texlive.iso 文件,双击安装即可。 Mac 用户下载 Mac 版本的发行包,安装包下载地址为:[MacTeX.pkg](https://mirrors.tuna.tsinghua.edu.cn/ctan/systems/mac/mactex/),下载 MacTeX.pkg 文件,双击安装即可。 ### VSCode 安装 VSCode 是一个轻量级的编辑器,支持多种语言的编写,包括 LaTeX。安装包下载地址为:[Visual Studio Code](https://code.visualstudio.com/download),下载对应系统的安装包,双击安装即可。 ## VSCode 插件 ### 如何安装 点击左侧的扩展按钮 ![Extensions](img/iShot_2023-02-13_10.19.01.png) 搜索对应的插件,点击安装即可。 ### 插件推荐 除了 LaTeX Workshop 之外,其他插件都是可选的,可以根据自己的需求进行安装。 - LaTeX Workshop LaTeX Workshop 支持 LaTeX 的编译、预览、语法检查等功能。 ![latex workshop](img/iShot_2023-02-13_10.22.55.png) - English Word Hint English Word Hint 是一个英语单词提示插件,可以在编写英语文档时,自动提示相关英语单词,并显示对应的中文翻译,提高英文文档编写效率。 ![English word hint](img/iShot_2023-02-13_10.24.58.png) - Path Auto Complete Path Auto Complete 可以自动补全路径,方便快速插入图片。 ![Alt text](img/iShot_2023-02-13_11.57.52.png) - indent rainbow indent rainbow 可以为不同层级的缩进添加不同的颜色,方便阅读。 ![Alt text](img/iShot_2023-02-13_10.27.37.png) - Word Count CJK Word Count CJK 可以统计中文文档的字数。 ![Alt text](img/iShot_2023-02-13_10.29.03.png) - Code Spell Checker Code Spell Checker 可以检查文档中的英文单词拼写错误,轻量级插件,速度快,内存占用少。 ![Alt text](img/iShot_2023-02-13_10.31.35.png) - LTex LTex 是一个拼写以及语法检查插件,不仅仅可以检查拼写错误,还可以检查语法错误,功能强大,但是速度较慢,内存占用较大。与 Code Spell Checker 两者可以视配置二选一。 ![Alt text](img/iShot_2023-02-13_10.31.59.png) - Project Manager Project Manager 可以管理多个 VSCode 项目,方便快速打开或切换项目。 ![Alt text](img/iShot_2023-02-13_10.36.21.png) - Material Icon Theme Material Icon Theme 可以为 VSCode 左侧的文件树添加图标,方便查看。 ![Alt text](img/iShot_2023-02-13_10.38.20.png) - WakaTime WakaTime 可以统计编程时间,以及编程语言的使用时间,以帮助我们更好的规划学习时间。 ![Alt text](img/iShot_2023-02-13_10.39.39.png) ## LaTeX Workshop 配置 下面的配置是我个人的配置,可以根据自己的需求进行修改。 ### 基本配置 ```json "latex-workshop.hover.preview.mathjax.extensions": [ "boldsymbol" ], "latex-workshop.intellisense.package.enabled": true, "latex-workshop.latex.outDir": "./tmp", "latex-workshop.latex.recipe.default": "lastUsed", "latex-workshop.mathpreviewpanel.cursor.enabled": true, "latex-workshop.message.error.show": false, "latex-workshop.message.warning.show": false, "latex-workshop.view.pdf.invert": 1, "latex-workshop.view.pdf.invertMode.enabled": "auto", ``` 点击 VSCode 左下角的齿轮按钮,选择 settings (设置),进入设置界面。 搜索对应的条目,并修改为相应的配置,其余配置默认即可。比如: ![Alt text](img/iShot_2023-02-13_10.47.32.png) 如果比较熟悉 VSCode,可以点击左下角的齿轮按钮,选择 Command Palette (命令面板),在命令面板中搜索 settings,打开 settings.json 文件,直接复制粘贴上面的代码,从而快速修改配置。 配置项的具体解释如下: ```text // 鼠标悬停,预览公式时,支持 boldsymbol 宏 "latex-workshop.hover.preview.mathjax.extensions": [ "boldsymbol" ], // 是否启用 IntelliSense,自动补全引用的包中的环境和命令 "latex-workshop.intellisense.package.enabled": true, // 编译后的文件输出目录 "latex-workshop.latex.outDir": "./tmp", // 默认编译引擎为上次使用的 "latex-workshop.latex.recipe.default": "lastUsed", // 预览复杂公式,使用时需要通过 command palette (命令面板) 打开 "latex-workshop.mathpreviewpanel.cursor.enabled": true, // 不允许弹窗显示错误信息 "latex-workshop.message.error.show": false, // 不允许弹窗显示警告信息 "latex-workshop.message.warning.show": false, // 预览 PDF 时,反转颜色 "latex-workshop.view.pdf.invert": 1, // 预览 PDF 时,自动检测是否需要反转颜色 "latex-workshop.view.pdf.invertMode.enabled": "auto", ``` ### 编译工具链配置 推荐使用 latexmk 进行编译,latexmk 可以自动检测文档中的变化,自动进行编译,并且同时支持多种编译引擎,包括 XeLaTeX、PdfLaTeX。 在 settings.json 文件中找到 latex-workshop.latex.tools 和 latex-workshop.latex.recipes 配置项,将其全部删除,并修改为如下配置: ```json "latex-workshop.latex.recipes": [ { "name": "XeLaTeX", "tools": [ "xelatexmk" ] }, { "name": "PdfLaTeX", "tools": [ "pdflatexmk" ] } ], "latex-workshop.latex.tools": [ { "args": [ "-synctex=1", "-pdfxe", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "xelatexmk" }, { "args": [ "-synctex=1", "-pdf", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "pdflatexmk" } ], ``` ## 进阶配置 这一部分的配置可选,如果不需要可以跳过。 ### 使用 latexindent 格式化 LaTeX 代码 首先需要安装 latexindent.pl,具体安装方法可以参考 [latexindent.pl](https://github.com/cmhughes/latexindent.pl)。 修改 settings.json 文件,添加如下配置: ```json "latex-workshop.latexindent.args": [ "-g", "./%OUTDIR%/indent.log", "%TMPFILE%", "-y=defaultIndent: '%INDENT%'" ], ``` 该配置的主要目的是将 latexindent.pl 的输出信息输出到 tmp/indent.log 文件中,方便统一管理。 ### 使用 HyperSnips for Math 插件快速输入公式 首先安装 HyperSnips for Math, 然后根据插件说明进行基本配置。 利用该插件可以快速输入公式,比如输入 `eq` 就可以自动生成 ```latex \begin{equation} \end{equation} ``` [latex.hsnips](latex.hsnips)是我的个人配置,主要支持两个功能 输入 `bmat n m` 然后按空格键,可以自动生成对应大小的空矩阵: ```latex // bmat 3 4 \begin{bmatrix} & & & \\ & & & \\ & & & \\ \end{bmatrix} ``` 输入 `fig label n` 然后按空格键,可以自动生成对应数量的图片插入代码,label 则为对应的标签: ```latex \begin{figure}[htb!] \centering \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_1} \end{subfigure} \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_2} \end{subfigure} \begin{subfigure}{.3\textwidth} \centering \includegraphics[width=\textwidth]{./img} \caption{} \label{fig:example_3} \end{subfigure} \caption{} \label{fig:example} \end{figure} ``` 其余配置可以根据自己的需求进行修改。 ### 使用 Git 进行版本管理 首先需要安装 Git:点击 VSCode 左侧的 Source Control (源代码管理) 图标,如果没有安装 Git,会提示安装,根据提示安装即可。 ![Alt text](img/iShot_2023-02-15_16.45.42.png) 推荐安装的插件有: - GitLens GitLens 拓展了 VSCode 的源代码管理功能,可以查看每一行代码的提交记录,以及每一次提交的详细信息。但是需要 pro 会员才能解锁全部功能,建议直接在设置中关闭 pro 功能。相关功能,安装下方开源免费插件替代即可。 - Git Graph Git Graph 可以以图形化的方式展示 Git 仓库的提交记录,方便查看。 - Commit Message Editor Commit Message Editor 可以格式化 commit 信息。可以导入该[配置](shinyypig_commit_config.json),方便统一管理,效果如下。 ![Alt text](img/iShot_2023-02-15_16.54.32.png) ### TiKZ Externalize 加速编译 确保你的 LaTeX 的输出目录为`./tmp/`,然后在你的 tex 文件中添加如下代码: ```latex \usetikzlibrary{external} \immediate\write18{mkdir -p tmp/tmp/} \tikzexternalize[ prefix=tmp/, mode=list and make, ] ``` 接着在文档根目录下新建`latexmkrc`文件,添加如下代码: ```perl $clean_ext .= ' %R.figlist %R-figure* %R.makefile fls.tmp'; $latex = 'internal tikzlatex latex %B %O %S'; $pdflatex = 'internal tikzlatex pdflatex %B %O %S'; $lualatex = 'internal tikzlatex lualatex %B %O %S'; $xelatex = 'internal tikzlatex xelatex %B %O %S'; $hash_calc_ignore_pattern{'pdf'} = '^(/CreationDate|/ModDate|/ID)'; $hash_calc_ignore_pattern{'ps'} = '^%%CreationDate'; sub tikzlatex { my ($engine, $base, @args) = @_; my $ret = 0; print "Tikzlatex: ===Running '$engine @args'...\n"; $ret = system( $engine, @args ); print "Tikzlatex: Fixing .fls file ...\n"; system "echo INPUT \"$aux_dir1$base.figlist\" > \"$aux_dir1$base.fls.tmp\""; system "echo INPUT \"$aux_dir1$base.makefile\" >> \"$aux_dir1$base.fls.tmp\""; system "cat \"$aux_dir1$base.fls\" >> \"$aux_dir1$base.fls.tmp\""; rename "$aux_dir1$base.fls.tmp", "$aux_dir1$base.fls"; if ($ret) { return $ret; } if ( -e "$aux_dir1$base.makefile" ) { if ($engine eq 'xelatex') { print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under xelatex\n"; system( 'perl', '-i', '-p', '-e', 's/^\^\^I/\t/', "$aux_dir1$base.makefile" ); } elsif ($engine eq 'latex') { print "Tikzlatex: ---Correcting '$aux_dir1$base.makefile' made under latex\n"; system( 'perl', '-i', '-p', '-e', 's/\.epsi/\.ps/', "$aux_dir1$base.makefile" ); } print "Tikzlatex: ---Running 'make -f $aux_dir1$base.makefile' ...\n"; if ($aux_dir) { # system "perl -i -p -e 's#-shell-escape#-shell-escape -output-directory=\"$aux_dir1\"#g' $aux_dir1$base.makefile"; system "perl -i -p -e 's#$base.figlist#$aux_dir1$base.figlist#g' $aux_dir1$base.makefile"; system "cp $aux_dir1$aux_dir1*.md5 $aux_dir1"; system "rm -rf $aux_dir1$aux_dir1"; $ret = system "make", "-j", "10", "-f", "$aux_dir1$base.makefile"; system "rm $base.run.xml"; } else { $ret = system "make", "-j", "10", "-f", "$base.makefile"; } if ($ret) { print "Tikzlatex: !!!!!!!!!!!!!! Error from make !!!!!!!!! \n", " The log files for making the figures '$aux_dir1$base-figure*.log'\n", " may have information\n"; } } else { print "Tikzlatex: No '$aux_dir1$base.makefile', so I won't run make.\n"; } return $ret; } ``` 最后,LaTeX Workshop 的工具配置需要修改为: ```json "latex-workshop.latex.tools": [ { "args": [ "-synctex=1", "--pdfxe", "-shell-escape", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "xelatexmk" }, { "args": [ "-synctex=1", "-pdflatex", "-shell-escape", "-interaction=nonstopmode", "-file-line-error", "-outdir=%OUTDIR%", "%DOC%" ], "command": "latexmk", "env": {}, "name": "pdflatexmk" } ], ``` ================================================ FILE: latex.hsnips ================================================ global function gen_matrix(nrow, ncol, index) { let results = "\n"; let order = 1; for (var i=0; i\n"; } else { let order = 1; for (var i=0; i\n"; order ++; } } results += "\n"; return results; } function gen_columns(m) { if (m == 1) return ""; let results = "\\begin{columns}[c]\n"; let order = 2; for (var i=0; i textcolor snippet txc "textcolor" iA \textcolor{c}{ ${1:${VISUAL}} }$0 endsnippet ############################# tikz ############################ snippet `^( *)tikz` "theorem" bA ``rv = m[1]``\begin{tikzpicture} ``rv = m[1]`` $1 ``rv = m[1]``\end{tikzpicture}$0 endsnippet snippet `scatter\(([^,]+), ([^,]+)\) ` "scatter" bA \addplot[ only marks, mark=*, mark size=1.5, mark options={draw=``rv=m[2]``,fill=``rv=m[2]``!80}, ] table[x=x, y=y, col sep=comma] {``rv=m[1]``}; endsnippet snippet `plot\(([^,]+), ([^,]+)\) ` "plot line" bA \addplot[ ``rv=m[2]``, thick, ] table[x=x, y=y, col sep=comma] {``rv=m[1]``}; endsnippet snippet `scatter3\(([^,]+), ([^,]+)\) ` "scatter" bA \addplot[ only marks, mark=*, mark size=1.5, mark options={draw=``rv=m[2]``,fill=``rv=m[2]``!80}, ] table[x=x, y=y, z=z, col sep=comma] {``rv=m[1]``}; endsnippet snippet `plot3\(([^,]+), ([^,]+)\) ` "plot line" bA \addplot[ ``rv=m[2]``, thick, ] table[x=x, y=y, z=z, col sep=comma] {``rv=m[1]``}; endsnippet snippet `axis2 ` "pgfaxis" bA \begin{axis}[ xlabel=$ x $, ylabel=$ y $, xmin=-3.5, xmax=3.5, ymin=-2.5, ymax=2.5, grid, axis equal image, legend cell align=left, legend style={ at={(axis cs:3.5,2.5)}, anchor=north east, font=\tiny, draw=none, fill=none } ] $0 \end{axis} endsnippet snippet `axis3 ` "pgfaxis" bA \begin{axis}[ xlabel=$ x $, ylabel=$ y $, zlabel=$ z $, xmin=-3.5, xmax=3.5, ymin=-2.5, ymax=2.5, zmin=-2.5, zmax=2.5, grid, axis equal image, ] $0 \end{axis} endsnippet ############################# beamer ############################# #snippet only "beamer only" iA #\only<${1:1}>{ # ${2:${VISUAL}} #}$0 #endsnippet snippet ani "animategraphics" bA \animategraphics[width=\textwidth,autoplay,loop,palindrome]{${1:12}}{./img${2}}{${3:0}}{${4:10}} endsnippet snippet `col ([0-9]+) ` "columns" bA ``rv = gen_columns(m[1])``$0 endsnippet # frame abc -> \begin{frame} snippet `frame (\S+) ([0-9]+) ` "label" A \begin{frame}{``rv = m[1]``} ``rv = gen_columns(m[2])``$0 \end{frame} endsnippet ############################# latex enverniments ############################# # txt -> \text{} snippet txt "text" iA \text{${1:${VISUAL}}}$0 endsnippet # tit -> \textit{} snippet tit "text it" iA \textit{${1:${VISUAL}}}$0 endsnippet # tbf -> \textbf{} priority 10 snippet tbf "textbf" iA \textbf{${1:${VISUAL}}}$0 endsnippet # lemma snippet `^( *)lemma` "lemma" bA ``rv = m[1]``\begin{lemma} ``rv = m[1]`` $1 ``rv = m[1]``\end{lemma}$0 endsnippet # theorem snippet `^( *)thm` "theorem" bA ``rv = m[1]``\begin{theorem} ``rv = m[1]`` $1 ``rv = m[1]``\end{theorem}$0 endsnippet snippet `^( *)def` "theorem" bA ``rv = m[1]``\begin{definition} ``rv = m[1]`` $1 ``rv = m[1]``\end{definition}$0 endsnippet snippet == "inline Math" iA \\( ${1:${VISUAL}} \\)$0 endsnippet snippet `^( *)\\\[` "inline Math" bA ``rv = m[1]``\[ ``rv = m[1]`` ${VISUAL}$0 ``rv = m[1]``\] endsnippet snippet `^( *)eq` "equation" bA ``rv = m[1]``\begin{equation} ``rv = m[1]`` ${VISUAL}$0 ``rv = m[1]``\end{equation} endsnippet snippet `^( *)beg` "begin{} / end{}" bA ``rv = m[1]``\begin{$1} ``rv = m[1]`` ${VISUAL}$0 ``rv = m[1]``\end{$1} endsnippet snippet `^( *)minipage` "minipage" bA ``rv = m[1]``\begin{minipage}{.${1:45}\textwidth} ``rv = m[1]`` ${VISUAL}$0 ``rv = m[1]``\end{minipage} endsnippet # lab abc -> \label{abc} snippet `lab (\S+) ` "label" A \label{``rv = m[1]``} endsnippet # bmat m n -> a matrix with the size of m*n snippet `(bm|pm|m|vm)at ([0-9]+) ([0-9]+) ` "matrix" bA \begin{``rv = m[1]``atrix}`` rv = gen_matrix(m[2],m[3],1); ``\end{``rv = m[1]``atrix}$0 endsnippet # vec m -> a vector with the size of 1*m snippet `vec ([0-9]+) ` "matrix" bA \begin{bmatrix} ``rv = gen_vector(m[1])`` \end{bmatrix}$0 endsnippet # fig label n -> figure enverniment with n subfigures, and the labels are specified by label snippet `fig (\S+) ([0-9]+) ` "figure" bA ``rv = gen_fig(m[1], m[2])``$0 endsnippet snippet `ref (\S+) ` "reference" A \cref{``rv = m[1]``} endsnippet snippet `cite (\S+) ` "cite" A \cite{``rv = m[1]``} endsnippet snippet `(chapter|section|subsection|subsubsection) (\S+) ` "paragraph" bwA \\``rv = m[1]``{``rv = m[2]``} $0 endsnippet ############################# Math ############################# ############################# Greek letters snippet @a "alpha" iAm \alpha endsnippet snippet @A "alpha" iAm \alpha endsnippet snippet @b "beta" iAm \beta endsnippet snippet @B "beta" iAm \beta endsnippet snippet @c "chi" iAm \chi endsnippet snippet @C "chi" iAm \chi endsnippet snippet @p "pi" iAm \pi endsnippet snippet :p "partial" iAm \partial endsnippet snippet @P "Pi" iAm \Pi endsnippet snippet @g "gamma" iAm \gamma endsnippet snippet @G "Gamma" iAm \Gamma endsnippet snippet @d "delta" iAm \delta endsnippet snippet @D "Delta" iAm \Delta endsnippet snippet @e "epsilon" iAm \epsilon endsnippet snippet @E "epsilon" iAm \epsilon endsnippet snippet :e "varepsilon" iAm \varepsilon endsnippet snippet :E "varepsilon" iAm \varepsilon endsnippet snippet @n "nabla" iAm \nabla endsnippet snippet @z "zeta" iAm \zeta endsnippet snippet @Z "zeta" iAm \zeta endsnippet snippet @t "theta" iAm \theta endsnippet snippet @T "Theta" iAm \Theta endsnippet snippet :t "tau" iAm \tau endsnippet snippet @k "kappa" iAm \kappa endsnippet snippet @K "kappa" iAm \kappa endsnippet snippet @l "lambda" iAm \lambda endsnippet snippet @L "Lambda" iAm \Lambda endsnippet snippet @m "mu" iAm \mu endsnippet snippet @M "mu" iAm \mu endsnippet snippet @r "rho" iAm \rho endsnippet snippet @R "rho" iAm \rho endsnippet snippet @s "sigma" iAm \sigma endsnippet snippet @S "Sigma" iAm \Sigma endsnippet snippet @o "omega" iAm \omega endsnippet snippet @O "Omega" iAm \Omega endsnippet snippet \{ "bracket" iAm \\{ ${1:${VISUAL}} \\}$0 endsnippet snippet @| "left| right|" iAm \left| ${1:${VISUAL}} \right|$0 endsnippet snippet :| "left\| right\|" iAm \left\| ${1:${VISUAL}} \right\|$0 endsnippet snippet @} "\left\{ \right\}" iAm \left\\{ ${1:${VISUAL}} \right\\}$0 endsnippet snippet ` bl ` "left\{ right." iAm \left\\{ ${1:${VISUAL}} \right.$0 endsnippet snippet ` br ` "left. right\}" iAm \left. ${1:${VISUAL}} \right\\}$0 endsnippet snippet @] "left[ right]" iAm \left[ ${1:${VISUAL}} \right]$0 endsnippet snippet @) "left( right)" iAm \left( ${1:${VISUAL}} \right)$0 endsnippet snippet @> "leftangle rightangle" iAm \left< ${1:${VISUAL}} \right>$0 endsnippet ############################# math symbols # RR -> \mathbb{R} snippet `RR` "sets" iwAm \\mathbb{``rv=m[0].charAt(0)``} endsnippet # => -> \Rightarrow snippet `->` "implies" iAm \rightarrow endsnippet # =< -> \Leftarrow snippet `<-` "implied by" iAm \leftarrow endsnippet # <= -> \leq snippet `<=` "leq" iAm \leq endsnippet # >= -> \geq snippet `>=` "geq" iAm \geq endsnippet # != -> \neq snippet `!=` "neq" iAm \neq endsnippet snippet `~=` "approx: iAm \approx endsnippet # ... -> \cdots snippet ... "dots" iAm \dots endsnippet snippet *** "cdots" iAm \cdots endsnippet snippet ;;; "vdots" iAm \vdots endsnippet snippet ::: "ddots" iAm \ddots endsnippet # inf -> \infty snippet inf "\infty" iAm \infty endsnippet ############################# math functions priority 200 snippet norm "norm" iAm \left\| ${1:${VISUAL}} \right\|$0 endsnippet snippet ^ "superscript" iAm ^{${1}}$0 endsnippet snippet _ "subscript" iAm _{${1}}$0 endsnippet # spl -> the split enverniment with the selected text snippet spl "split" Am \begin{split} ${VISUAL}$0 \end{split} endsnippet # ali -> the aligned enverniment the selected text snippet ali "aligned" Am \begin{aligned} ${VISUAL}$0 \end{aligned} endsnippet # case -> the cases enverniment the selected text snippet case "cases" Am \begin{cases} ${VISUAL}$0 \end{cases} endsnippet # fr -> fractor enverniment with the selected text snippet // "frac" iAm \frac{${1:${VISUAL}}}{$2}$0 endsnippet # \mathbf{A}^T -> \mathbf{A}^{\mathbrm T} snippet `\^\{T` "transpose" iAm ^{\mathrm{T} endsnippet # \mathbf{A}^H -> \mathbf{A}^{\mathbrm H} snippet `\^\{H` "hermitian" iAm ^{\mathrm{H} endsnippet # ||x||_F -> ||x||_{\mathrm F} snippet `\_\{F` "frobenius" iAm _{\mathrm{F} endsnippet snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)(bf|BF)` "mathbf" iAm \mathbf{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)(bm|BM)` "mathbm" iAm \bm{``rv = m[1]``} endsnippet # priority 100 snippet `(\\?[a-zA-Z]\w*({?\w*})?)bb` iAm \mathbb{``rv = m[1]``}$0 endsnippet # priority 100 snippet `(\\?[a-zA-Z]\w*({?\w*})?)cal` "mathcal" iAm \mathcal{``rv = m[1].toUpperCase()``}$0 endsnippet # priority 100 snippet `(\\?[a-zA-Z]\w*({?\w*})?)(frak)` "mathfrak" iAm \mathfrak{``rv = m[1]``} endsnippet # priority 100 snippet `(? \in snippet ` (in|notin|subset|subseteq|supset|supseteq) ` "sets operator" wAm \``rv = m[1]`` endsnippet # cap -> \cap snippet ` (circ|cap|cup|land|lor|lnot|oplus|ominus|times|otimes|sqcap|sqcup|vdash|models) ` "logic operator" wAm \``rv = m[1]`` endsnippet snippet empty "empty set" Am \varnothing endsnippet snippet `(\\?[a-zA-Z0-9]\w*({?\w*})?)op` "operatorname" iAm \operatorname{``rv = m[1]``} endsnippet snippet `([0-9]+)d` "degrees" iAm ``rv = m[1]``^{\circ}$0 endsnippet snippet `sqrt` "sqrt" iAm \sqrt{${1:${VISUAL}}}$0 endsnippet snippet `sum` "sqrt" iAm \sum endsnippet ############################# hat operations snippet `(\\?[a-zA-Z]\w*({?\w*})?)(bar|BAR)` "Bar" iAm \overline{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(td|TD)` "tilde" iAm \tilde{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hat|HAT)` "hat" iAm \hat{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hvec)` "Vector postfix" iAm \vec{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(rta)` "Vector postfix" iAm \overrightarrow{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hdot)` "dot" iAm \dot{``rv = m[1]``} endsnippet snippet `(\\?[a-zA-Z]\w*({?\w*})?)(hddot)` "ddot" iAm \ddot{``rv = m[1]``} endsnippet ================================================ FILE: shinyypig_commit_config.json ================================================ { "$schema": "https://bendera.github.io/vscode-commit-message-editor/schemas/config-v1.schema.json", "configVersion": "1", "staticTemplate": [ "feat: Short description", "", "Message body" ], "dynamicTemplate": [ "{type} {description}", "", "{body}" ], "tokens": [ { "label": "Type", "name": "type", "type": "enum", "combobox": true, "options": [ { "label": "✨ 新功能或文本", "value": "✨", "description": "新增功能或文本" }, { "label": "📝 添加说明文档", "value": "📝", "description": "添加说明文档" }, { "label": "🎨 润色或美化", "value": "🎨", "description": "润色文本或美化代码" }, { "label": "🩹 修复简单错误", "value": "🩹", "description": "简单修复非关键性问题" }, { "label": "🐛 修复关键错误", "value": "🐛", "description": "修复关键错误" }, { "label": "💩 初稿", "value": "💩", "description": "写的很差需要进一步修改" }, { "label": "💥 引入重大改变", "value": "💥", "description": "引入重大改变" }, { "label": "🎉 初次提交", "value": "🎉", "description": "初次提交" }, { "label": "🔥 删除", "value": "🔥", "description": "删除代码或文件" }, { "label": "📦 编译", "value": "📦", "description": "新增或更新已编译的文件或包" }, { "label": "➖ 移除依赖", "value": "➖", "description": "移除依赖" }, { "label": "➕ 添加依赖", "value": "➕", "description": "添加依赖" }, { "label": "🚚 移动或重命名", "value": "🚚", "description": "移动或重命名文件文件夹" }, { "label": "🔀 合并分支", "value": "🔀", "description": "合并分支" }, { "label": "⏪ 还原", "value": "⏪", "description": "还原修改" }, { "label": "🗑 清理", "value": "🗑", "description": "清理废弃代码或文本" }, { "label": "🙈 .gitignore", "value": "🙈", "description": "添加或更新 .gitignore 文件" }, { "label": "👥 新增或更新贡献者", "value": "👥", "description": "新增或更新贡献者" } ], "description": "Type of changes" }, { "label": "Short description", "name": "description", "description": "Short description in the subject line.", "type": "text", "multiline": false }, { "label": "Body", "name": "body", "description": "Optional body", "type": "text", "multiline": true, "lines": 5, "maxLines": 10 } ] }