当前位置:   article > 正文

Linux下安装TeXLive并配置VSCode中tex编写环境_linux安装texlive

linux安装texlive

Linux下安装TeXLive并配置VSCode中tex编写环境

这里我们以Ubuntu为例。

1.下载.iso镜像文件

TeXLive下载页

image-20240204124934713

终端使用curl获取.iso镜像文件:

sudo apt install curl && curl -L https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/texlive.iso -o texlive.iso
  • 1

image-20240204125309909

或者使用XDM获取:

image-20240204125549686

XDM安装教程

https://blog.csdn.net/M0rtzz/article/details/136023863

2.安装TeXLive

首先安装一个GUI工具包:

sudo apt install perl-tk
  • 1

image-20240204130227123

在下载iso的目录打开终端:

sudo chmod 777 texlive.iso
sudo mount -o loop texlive.iso /mnt
cd /mnt
ls
sudo ./install-tl -gui
  • 1
  • 2
  • 3
  • 4
  • 5

image-20240204145113354

image-20240204131918947

单击Install开始安装,显示Installed才可点击Close

image-20240204133319533

卸载挂载到/mnt的镜像:

cd ~
sudo umount /mnt
  • 1
  • 2

配置环境变量:

vi ~/.bashrc
  • 1

在末尾添加以下内容(年份填你的,本文是2023):

# LaTeX
export MANPATH=${MANPATH}:/usr/local/texlive/2023/texmf-dist/doc/man
export INFOPATH=${INFOPATH}:/usr/local/texlive/2023/texmf-dist/doc/info
export PATH=${PATH}:/usr/local/texlive/2023/bin/x86_64-linux
  • 1
  • 2
  • 3
  • 4

保存退出

source ~/.bashrc
  • 1

输入tex -v显示版本号即配置成功

image-20240204134353060

3.配置VSCode

首先安装Perl模块(后边格式化代码时需要用到,我这里已经提前安装过了):

sudo apt update && sudo apt install cpanminus
  • 1
sudo cpanm YAML::Tiny
sudo cpanm File::HomeDir
sudo cpanm Unicode::GCString
sudo cpanm Log::Log4perl
sudo cpanm Log::Dispatch
  • 1
  • 2
  • 3
  • 4
  • 5

image-20240204134747369

打开VSCode,点击侧边栏插件按钮,搜索LaTeX,安装下图两个插件:

image-20240204135028322

然后键入Ctrl+逗号进入设置页面,单击右上角次按钮进入Json配置文件:

image-20240204135608750

在末尾加入以下内容:

  "files.autoSave": "afterDelay", // 自动保存
  "editor.formatOnPaste": true, // 粘贴后自动格式化
  "editor.formatOnType": true, // 键入后自动格式化
  "editor.formatOnSave": true, // 保存时自动格式化
  //LaTeX
  "latex-workshop.latex.recipes": [
    {
      "name": "xelatex",
      "tools": [
        "xelatex"
      ]
    },
    {
      "name": "pdflatex",
      "tools": [
        "pdflatex"
      ]
    },
    {
      "name": "latexmk",
      "tools": [
        "latexmk"
      ]
    },
    {
      "name": "xelatex -> bibtex -> xelatex*2",
      "tools": [
        "xelatex",
        "bibtex",
        "xelatex",
        "xelatex"
      ]
    }
  ],
  "latex-workshop.latex.tools": [
    {
      "name": "latexmk",
      "command": "latexmk",
      "args": [
        "--shell-escape",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-pdf",
        "%DOC%"
      ]
    },
    {
      "name": "xelatex",
      "command": "xelatex",
      "args": [
        "--shell-escape",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOC%"
      ]
    },
    {
      "name": "pdflatex",
      "command": "pdflatex",
      "args": [
        "--shell-escape",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOC%"
      ]
    },
    {
      "name": "bibtex",
      "command": "bibtex",
      "args": [
        "%DOCFILE%"
      ]
    }
  ],
  "latex-workshop.latex.clean.fileTypes": [
    "*.aux",
    "*.bbl",
    "*.blg",
    "*.idx",
    "*.ind",
    "*.lof",
    "*.lot",
    "*.out",
    "*.toc",
    "*.acn",
    "*.acr",
    "*.alg",
    "*.glg",
    "*.glo",
    "*.gls",
    "*.ist",
    "*.fls",
    "*.log",
    "*.fdb_latexmk"
  ],
  "latex.linter.enabled": false,
  //tex文件浏览器,可选项为"none" "browser" "tab" "external"
  "latex-workshop.view.pdf.viewer": "tab",
  //自动编译tex文件
  "latex-workshop.latex.autoBuild.run": "never",
  //显示内容菜单:(1)编译文件;(2)定位游标
  "latex-workshop.showContextMenu": true,
  //显示错误
  "latex-workshop.message.error.show": true,
  //显示警告
  "latex-workshop.message.warning.show": false,
  //从使用的包中自动补全命令和环境
  "latex-workshop.intellisense.package.enabled": true,
  //设置为never,为不清除辅助文件
  "latex-workshop.latex.autoClean.run": "never",
  //设置vscode编译tex文档时的默认编译链
  "latex-workshop.latex.recipe.default": "lastUsed",
  // 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击
  "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click",
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117

配置完之后侧边栏会出现TEX按钮,里面的内容对应了我们刚才的配置:

image-20240204144520352

新建.tex文件,输入:

\documentclass{article}
\begin{document}

 {\Huge Hello, \LaTeX!}

\end{document}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

之后点击:

image-20240204143115049

再点击:

image-20240204143158321

若正常显示.pdf文件,则配置成功

image-20240204144037612

右键空白处选择使用...格式化文档

image-20240204143432155

选择LaTeX Workshop为默认格式化程序:

image-20240204143534684

这时键入Ctrl+S手动保存时,因刚才.json文件中设置了"editor.formatOnSave": true, // 保存时自动格式化,也安装了Perl模块,这时代码应该会自动格式化。

原先:

image-20240204144131168

格式化后:

image-20240204144344447

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号