增加代码片段可以在日常写文档的过程中,提高效率。因为很多写作的内容都是重复的,没必要每次都要去写一次。代码片段很好的解决了这个问题。
分享我的Vscode LaTeX的代码片段:
复制直接使用即可。
在VSCode中,按ctrl+shift+P弹出搜索,输入snippets,找到或者输入latex,进入latex.json,粘贴进去就可以了。
{
"compile setting":{
"prefix": "compile",
"body": ["%!TEX program = ${1:xelatex} -> bibtex -> xelatex -> ${1:xelatex}"],
"description": "set default the compile order"
},
"insert figure":{
"prefix": "figure",
"body":["\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=${1}\\textwidth]{picture/${2}}\n\t\\caption{${3}}\n\t\\label{${4}}\n\\end{figure}"],
"description": "insert figure snippet"
},
"insert table":{
"prefix": "table",
"body":["\\begin{table}[${1:htbp}]\n\t\\centering\n\t\\caption{${2:caption}}\n\t\t\\begin{tabular}{${3:c|c}}\n\t\t\\hline\n\t\t${4:column1 & column2}\n\t\t\\end{tabular}\n\t\\label{${5:label}}\n\\end{table}"],
"description": "insert table snippet"
},
"insert enumerate":{
"prefix": "enumerate",
"body":["\\begin{enumerate}\n\t\\item ${1:enumerate1}\n\t\\item ${2:enumerate2}\n\\end{enumerate}"],
"description": "insert enumerate snippet"
},
"insert item":{
"prefix": "itemize",
"body":["\\begin{itemize}\n\t\\item ${1:itemsize1}\n\t\\item ${2:itemsize2}\n\\end{itemize}"],
"description": "insert item snippet"
},
"insert frame":{
"prefix": "frame",
"body":["\\begin{frame}{${1}}\n\t${2}\n\\end{frame}"],
"description": "insert frame snippet"
},
"insert paragraph":{
"prefix": "paragraph",
"body":["\\paragraph{${1}}~{}\\par"],
"description": "insert paragraph snippet"
},
"insert columns":{
"prefix": "columns",
"body":["\\begin{columns}\n\t\\column{0.5\\textwidth}\n${1}\n\t\\column{0.5\\textwidth}\n\\end{columns}"],
"description": "insert columns snippet"
},
"insert figures":{
"prefix": "figures",
"body":["\\begin{figure*}[htbp]\n\t\\begin{minipage}{0.5\\textwidth}\n\t\t\\includegraphics[width=${1}\\textwidth]{picture/${2}}\n\t\t\\caption{${3}}\n\t\t\\label{${4}}\n\t\\end{minipage}\n\t\\hfill\n\t\\begin{minipage}{0.5\\textwidth}\n\t\t\\includegraphics[width=${1}\\textwidth]{picture/${2}}\n\t\t\\caption{${3}}\n\t\t\\label{${4}}\n\t\\end{minipage}\n\\end{figure*}"],
"description": "insert figures snippet"
},
"insert algorithmic":{
"prefix": "algorithmic",
"body":["%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n%\\STATE\\IF \\ENDIF\\FOR \\ENDFOR\\FOR \\TO \\ENDFOR\\FORALL \n%\\ENDFOR\\WHILE \\ENDWHILE\\REPEAT \\UNTIL\\LOOP\n%\\ENDLOOP\\REQUIRE \\ENSURE \\RETURN \\PRINT \\COMMENT,\\AND, \\OR, \\XOR, \\NOT, \\TO, \\TRUE, \\FALSE \n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\\begin{algorithm}[htbp]\n\t\\caption{${1}}\n\t\\label{al:${2}}\n\t\\begin{algorithmic}\n\t\t\\REQUIRE{${3}}\n\t\t\\ENSURE{${3}}\n\t\\end{algorithmic}\n\\end{algorithm}"],
"description": "insert algorithmic snippet"
},
"insert algorithm":{
"prefix": "algorithm",
"body":["\\begin{algorithm}[htbp]\n\t\\caption{${1}}\n\t\\label{al:${2}}\n\t\t\\KwIn{${3}}\n\t\t\\KwOut{${3}}\n\\end{algorithm}"],
"description": "insert algorithm snippet"
},
"insert thebibliography":{
"prefix": "thebibliography",
"body":["\\begin{thebibliography}{99}\n\t\\bibitem{ref1} \n\t\\bibitem{ref2} \n\\end{thebibliography}"],
"description": "insert thebibliography snippet"
},
}
以上代码片段主要有:
\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth]{picture/}
\caption{}
\label{}
\end{figure}
\begin{table}[htbp]
\centering
\caption{caption}
\begin{tabular}{c|c}
\hline
column1 & column2
\end{tabular}
\label{label}
\end{table}
(这个主要是用来写两栏内容的,比如Beamer多个图片并列放置)
\begin{columns}
\column{0.5\textwidth}
\column{0.5\textwidth}
\end{columns}
\begin{algorithm}[htbp]
\caption{}
\label{al:}
\KwIn{}
\KwOut{}
\end{algorithm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\STATE\IF \ENDIF\FOR \ENDFOR\FOR \TO \ENDFOR\FORALL
%\ENDFOR\WHILE \ENDWHILE\REPEAT \UNTIL\LOOP
%\ENDLOOP\REQUIRE \ENSURE \RETURN \PRINT \COMMENT,\AND, \OR, \XOR, \NOT, \TO, \TRUE, \FALSE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{algorithm}[htbp]
\caption{}
\label{al:}
\begin{algorithmic}
\REQUIRE{}
\ENSURE{}
\end{algorithmic}
\end{algorithm}
参考文献
\begin{thebibliography}{99}
\bibitem{ref1}
\bibitem{ref2}
\end{thebibliography}
使用beamer时,快速插入一个frame
\begin{frame}{}
\end{frame}
\begin{enumerate}
\item enumerate1
\item enumerate2
\end{enumerate}
\begin{itemize}
\item itemsize1
\item itemsize2
\end{itemize}
这个用来自动换行paragraph
\paragraph{}~{}\par