(目录)


一、LaTeX的安装

  • 下载LaTeX的编译包TeXLive:https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive.iso
  • 在文件夹中直接双击texlive.iso进入安装包
  • 右击install-tl-windows.bat,选择以管理员身份运行

image.png

不要的原因是我们使用VSCode作为编译环境(即前端)。

image.png

image.png

image.png

image.png

二、配置VSCode的LaTeX环境

  • 为VSCode安装LaTex Workshop插件和LTeX插件

image.png

image.png

  • 然后开始配置VSCode Ctrl + Shirt + p
  • 输入JSON

image.png

  • 然后输入配置内容:
{
    "latex-workshop.latex.tools": [
        {
            "name": "xelatex",
            "command": "xelatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%DOCFILE%"
            ]
        },
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%%DOCFILE%"
            ]
        },
        {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ]
        }
    ],
    "latex-workshop.latex.recipes": [
        {
            "name": "pdflatex",
            "tools": [
                "pdflatex"
            ]
        },
        {
            "name": "xelatex",
            "tools": [
                "xelatex"
            ]
        },
        {
            "name": "pdflatex -> bibtex -> pdflatex*2",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex"
            ]
        },
        {
            "name": "xelatex ➞ bibtex ➞ xelatex*2",
            "tools": [
                "xelatex",
                "bibtex",
                "xelatex",
                "xelatex"
            ]
        }
    ],
    "latex-workshop.view.pdf.viewer": "external",				// 使用sumatraPDF
    "latex-workshop.view.pdf.external.viewer.command": "D:/software/SumatraPDF/SumatraPDF.exe", // 注意修改为自己路径
    "latex-workshop.view.pdf.external.viewer.args": [
        "%PDF%"
    ],
    "latex-workshop.view.pdf.external.synctex.command": "D:/software/SumatraPDF/SumatraPDF.exe", // 注意修改为自己路径
    "latex-workshop.view.pdf.external.synctex.args": [ // 前向搜索
        "-forward-search",
        "%TEX%",
        "%LINE%",
        "%PDF%"
    ]
}
  • 使用:
    • PDF预览上Ctrl + 鼠标左键,可以跳到tex代码。
    • 选中tex代码部分 Ctrl + Alt + j,就可以从代码跳到对应的PDF预览部分(会以红色背景条显示)。
  • 这里*.tex为LaTeX的源文件,通过TeXLive编译器可以将其编译为pdf文件。
  • 可以使用VSCode自带的LaTeX插件来预览生成的pdf文件。
  • 也可以使用SumatraPDF(https://www.sumatrapdfreader.org/download-free-pdf-viewer)
  • XeLaTeX编译方式主要是针对中文PDF的。
  • 在VSCode中只要对源文件*.tex一保存,则自动就会进行编译。
  • VSCode中关闭缩略图 image.png

  • VSCode中预览LaTeX编译生成的pdf image.png

image.png

三、LaTex的使用

一般是到出版社的网站上下载tex源代码的模板文件(一个文件夹下的所有文件,不只是tex文件),然后在有了骨架后照猫画虎地填内容。

通用模板 https://www.overleaf.com/latex/templates

1. 线上参考

  • https://editor.codecogs.com/
  • https://www.latexlive.com/home
  • https://zhuanlan.zhihu.com/p/517492374

2. 书籍

《一份(不太)简短的 LATEX 2ε 介绍》 https://blog.csdn.net/weixin_44333889/article/details/123593555

3. 数学公式的引入

  • 正文行中的特殊字符和短公式 使用两个$符号:
$公式$
  • 单行公式带编号
\begin{equation} \label{公式标签}
...
\end{equation}

自动引用

\autoref{公式标签}
% 上述功能需要导入依赖包
\usepackage{hyperref}
  • 无编号公式
\[公式\]
\[
公式
\]

% 或者

$$公式$$
$$
公式
$$

出现??表示需要再编译一次(需要两次编译)。

  • 多行公式
\begin{split}
   & 公式\\
   & 公式\\
   & 公式
\end{split}
上边的\\表示换行,&表示对齐

% 需要导入依赖包
\usepackage{amsmath} 有的环境可能自带
  • 分情况讨论
f(x)=
\begin{case}
  0&, \text{if $x<0$}\\
  1&, \text{other}
\end{case}

% 需要导入依赖包
\usepackage{amsmath} 有的环境可能自带

需要用正文样式输出的地方用\text{}

辅助工具:AxMath

4. 图片

image.png

5. 表格

  • 表格的基本指令 image.png

  • 在线辅助工具:

  • http://www.latex-tables.com/ 可以所见即所得的设计,然后转成LaTeX代码。

  • https://tablesgenerator.com/

6. 引用文献

image.png

image.png

7. 其他在线工具

  • 手写公式转LaTeX https://editor.codecogs.com/

  • 截图看公式 https://mathpix.com/