环境配置请看LaTeX环境配置-TexLive,实测有效http://t.csdnimg.cn/0txlL
VScode写LaTeX配置
0.smatra pdf下载
如果使用外部pdf查看器,比如我用的sumatra pdf,官网是Sumatra PDF reader download page
下载对应版本,比如64位,下载直达链接https://www.sumatrapdfreader.org/dl/rel/3.5.2/SumatraPDF-3.5.2-64-install.exe
1.VScode配置
先下载扩展LaTeX Workshop
安装完成后,按图示打开VScode的json配置文件
将下面的配置添加进自己的json中,我的配置如下
//latex配置部分,来源于https://zhuanlan.zhihu.com/p/166523064"latex-workshop.latex.autoBuild.run": "never", //使用第一个编译链自动编译,可选onFileChange,onSave ,never"latex-workshop.showContextMenu": true, //将编译和正向查找添加到右键菜单"latex-workshop.intellisense.package.enabled": true, //设置为true,则该拓展能够从使用的宏包中自动提取命令和环境,从而补全正在编写的代码。"latex-workshop.message.error.show": false, //编译错误时弹窗"latex-workshop.message.warning.show": false, //编译警告时弹窗"latex-workshop.latex.tools": [{"name": "xelatex","command": "xelatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "pdflatex","command": "pdflatex","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","%DOCFILE%"]},{"name": "latexmk","command": "latexmk","args": ["-synctex=1","-interaction=nonstopmode","-file-line-error","-pdf","-outdir=%OUTDIR%","%DOCFILE%"]},{"name": "bibtex","command": "bibtex","args": ["%DOCFILE%"]}],"latex-workshop.latex.recipes": [{"name": "XeLaTeX","tools": ["xelatex"]},{"name": "PDFLaTeX","tools": ["pdflatex"]},{"name": "BibTeX","tools": ["bibtex"]},{"name": "LaTeXmk","tools": ["latexmk"]},{"name": "xelatex -> bibtex -> xelatex*2","tools": ["xelatex","bibtex","xelatex","xelatex"]},{"name": "pdflatex -> bibtex -> pdflatex*2","tools": ["pdflatex","bibtex","pdflatex","pdflatex"]},],"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-workshop.latex.autoClean.run": "onFailed", //清除辅助文件的时间,onBuilt,onFailed,never "latex-workshop.latex.recipe.default": "lastUsed", //默认编译链,可选first(recipes中第一条编译链),lastUsed"latex-workshop.view.pdf.internal.synctex.keybinding": "double-click", //反向查找,可选ctrl-click,double-click//配置外部PDF查看器"latex-workshop.view.pdf.viewer": "external", //设置默认PDF查看器,可选tab,browser,external"latex-workshop.view.pdf.ref.viewer": "external", //\ref引用查看,可选auto,tabOrBrowser,external"latex-workshop.view.pdf.external.viewer.command": "D:/ProgramFiles/SumatraPDF/SumatraPDF.exe", //注意选自己的sumatra pdf安装位置"latex-workshop.view.pdf.external.viewer.args": ["%PDF%"],"latex-workshop.view.pdf.external.synctex.command": "D:/ProgramFiles/SumatraPDF/SumatraPDF.exe", //注意选自己的sumatra pdf安装位置"latex-workshop.view.pdf.external.synctex.args": ["-forward-search","%TEX%","%LINE%","-reuse-instance","%PDF%"]
像我这样添加进去就行了,注意每行的上一行末尾有逗号
如果要实现VScode长行自动换行显示,可以在刚才的json文件中写
"editor.wordWrap": "on"
像我这样
2.smatra pdf配置
按图示进入设置页面
进入后,在最下方的设置反向搜索中填入
"D:\ProgramFiles\Microsoft VS Code\Code.exe" -r -g "%f:%l"
注意要填自己的VScode安装位置
3.快捷键及编译查看
编译快捷键为ctrl+alt+b,正向搜索快捷键为ctrl+alt+j,反向搜索只许在生成的pdf文件中双击即可
实现编译完成自动打开pdf,在设置中搜索afterbuild,即可找到选项,打钩即可实现,如图
或者也可以在json文件中添加如下信息,效果一样
"latex-workshop.synctex.afterBuild.enabled": true
4.测试
注意,使用时需要自己先手动启动smatra pdf软件,否则反向搜索不生效
测试用tex源码
\documentclass[a4paper, 12pt, draft]{ctexart}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\begin{document}
% 封面信息
\title{\LaTeX 练习}
\author{BOS}
\date{\today}
\maketitle\newpage
\setcounter{tocdepth}{2} %设置目录深度
\tableofcontents\section{题目} 内容
\subsection{title} 内容
\subsection{title} 内容
\subsubsection{小小节} 内容
\subsubsection{小小节} 内容
\section{题目} 内容
\subsection{title} 内容
\subsection{title} 内容
\section{题目} 内容
\subsection{title} 内容
\subsection{title} 内容
\section{测试-节} 内容
\uline{uline} \uuline{uuline} \uwave{uwave} \sout{sout}
\xout{xout} \dashuline{dashuline} \dotuline{dotuline}
\emph{emph}
\begin{flushleft}居左\\段落
\end{flushleft}\begin{flushright}居右\\段落
\end{flushright}\begin{center}居中\\段落
\end{center}\section{数学公式测试}
\emph{行内公式:}
$\sum_{i=1}^n i^2 = \frac{1}{6}n(n+1)(2n+1)$\emph{行间公式:}
\[\sum_{i=1}^n i^2 = \frac{n(n+1)(2n+1)}{6}\]\emph{内联公式:}
给定两个矩阵 \( A \) 和 \( B \),若要进行矩阵乘法,其中 \( A \) 是一个 \( m \times n \) 矩阵,\( B \) 是一个 \( n \times p \) 矩阵,那么它们的乘积矩阵 \( C = AB \) 是一个 \( m \times p \) 矩阵,其元素 \( c_{ij} \) 的计算方式如下:
\emph{行间公式:}\[
c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}, \quad i = 1, 2, \ldots, m; \quad j = 1, 2, \ldots, p.
\]\end{document}
编译时,可以按下图的步骤1,2进行,或者只需点击步骤3即可
这里出现小对号表示编译成功
效果
至此,配置完成