标记语言(markdown、Latex)
标记语言:
- 本质:语法替代可视化排版操作
- 优点:使用更方便,迁移性高
- 缺点:仅支持基础排版操作
- markdown
- 轻量级标记语言
- *.md文件
- 支持少量排版功能,语法十分简单,学习成本极低
- 支持LaTeX数学公式
- 可导出 HTML、PDF 格式的文件
- 适用于对格式没有要求的场景,如博客……
- 编辑器:Typora即时渲染模式,vscode插件(markdown-all-in-one双栏渲染模式, Markdown Preview Enhanced即时渲染模式……)……
- latex
- 高质量的排版系统
- .tex
- 排版功能较多,语法相对复杂,学习成本相比markdown较高
- 原生支持数学公式
- 编译生成pdf
- 适用于对格式有一定要求的场景,如简历,论文……
- 编辑器:Overleaf,vscode插件(LaTeX Workshop……)……
- html
- 超文本标记语言
- 适用于前端网页开发
Latex
搭建编译环境
安装TexLive
设置vscode
- 下载vscode
- 安装插件LaTeX Workshop
Setting->json:Schemas->Edit in setting.json
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
{ // 设置是否自动编译 "latex-workshop.latex.autoBuild.run":"never", //右键菜单 "latex-workshop.showContextMenu":true, //从使用的包中自动补全命令和环境 "latex-workshop.intellisense.package.enabled": 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": "XeLaTeX*2", "tools": [ "xelatex", "xelatex" ] }, { "name": "PDFLaTeX", "tools": [ "pdflatex" ] }, { "name": "PDFLaTeX*2", "tools": [ "pdflatex", "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" ], //设置为onFaild 在构建失败后清除辅助文件 "latex-workshop.latex.autoClean.run": "onFailed", // 使用上次的recipe编译组合 "latex-workshop.latex.recipe.default": "lastUsed", // 用于反向同步的内部查看器的键绑定。ctrl/cmd +点击(默认)或双击 "latex-workshop.view.pdf.internal.synctex.keybinding": "double-click", "latex-workshop.view.pdf.viewer": "tab", }
展开
- 将这个复制并保存
使用
- 编写一个.tex的文件并保存
- 点击VSCode侧边栏的Latex图标(这里包含所有的命令),点击build LaTex project -> Recipe:XeLaTex 开始编译,或者用Ctrl+Alt+B代替此步骤
- 如果正确渲染pdf则代表成功
问题
1
Cannot find LaTeX root file. See https://github.com/James-Yu/LaTeX-Workshop/wiki/Compile#the-root-file
展开
- 编译日志
1 2
"latex-workshop.latex.build.forceRecipeUsage": true, "latex-workshop.addtexroot":false,
展开
- 需要在json文件加入
1
% !TeX root = 文件名.tex(可以是相对路径/绝对路径)展开
- 需要在tex文件上加入
- 需要在json文件加入
- 运行时Code language not supported or defined
1
"code-runner.defaultLanguage": "javascript",
展开
- 在json文件添加
- Does the executable exist? $PATH: undefined
- vscode默认读取不到MSVC环境变量
- 通过Developer Command Prompt启动vscode,可继承MSVC环境变量
- vscode默认读取不到MSVC环境变量
- 编译日志
小技巧
- 双击渲染的某文本可以跳转到对应的latex指令
常用语法
命令模式:使用命令改变上下文状态,文本格式发生改变
基础设置
% \命令
% []可选参数
% {}参数
% \取消转义
% 数值单位:pt磅 ≈ 0.03528 cm, cm……
% \\ 用于换行
\documentclass[纸张大小,文字大小……]{文章类型}% 文章开头必须使用
% 纸张大小:a4paper,letterpaper
% 文章类型:article较短的文章,report多章节的文档,proc,book,beamer
% 包
\usepackage{包名称,……} % 导入包
\usepackage[UTF8]{ctex} % 支持中文字体
\usepackage{amsmath} % 数学公式
\usepackage{calc} % 长度计算
%
\title{标题名}
\author{作者名}
\date{日期}
\maketitle %必须加上才能显示
% 文章开始,任何之前的命令都被视为前导命令,会影响整个文档
\begin{document}
% 内容
\end{document}
排版
% 章节
\section{章节名}
\subsection{子章节名}
\subsubsection{子子章节名}
\paragraph(标题名) % 内容紧跟随显示,不会换行
\subparagraph(标题名)
% 列表(1,2,3……)
\begin{enumerate} % 有序列表
\item 内容
\item 内容
\end{enumerate}
\begin{itemize} % 无序列表
\item 内容
\item 内容
\end{itemize}
\item[标志:-/+……] % 修改无序列表的标志符号
% 居中文本
\begin{center}
%内容
\end{center}
% 另起一页
\newpage
\clearpage
% 间距
\vspace{5 pt} % 行间距
\hspace{} % 水平间距
\hspace*{} % 强制插入指定间距,即时在行末也会保留
\linespread{1.5} % 设置行间距为1.5倍
\kern 5.0 pt % 水平间距
\hfill % 当前行中插入弹性间距,将内容推向两侧
% 盒子:创建不可分割的文本块
\mbox{文本块}
\fbox % 带框
\setlength{\parindent}{0pt} % 取消首行缩进
\setlength{\topsep}{0pt} % 设置顶部垂直间距为0
\par % 强制开始新段落
\centering % 居中对齐,否则默认左对齐
\unskip % 移除前面的空格或空白
\ignorespaces % 忽略命令后紧跟的空格
% 预留空间
\usepackage{needspace} % 需要空间宏包
\needspace{<长度>} % 剩余垂直空间是否有此长度,如果有正常排版,否则强制分页
% 4\baselineskip 表示 “4 倍的基线间距”
% 设置上下左右间距
\usepackage[
ignoreheadfoot, % 设置页边距时不考虑页眉和页脚
top= 1 cm,
bottom= 1 cm,
left= 1 cm,
right= 1 cm,
footskip=0 cm, % 正文与页脚的间距
]{geometry}
字体
\textbf{内容} % 黑体
\textit{} % 斜体
\underline{...} % 下划线
% 字号
\fontsize{25 pt}{25 pt} % 字体大小,行高
\tiny % 大小----
\scriptsize % 大小---
\footnotesize % 大小--
\small % 大小-
\normalsize % 大小不变
\large % 大小+
\Large % 大小++
\LARGE % 大小+++
\huge % 大小++++
\Huge % 大小+++++
\样式拼音 % 字体样式
\color{颜色名字} % 字体颜色:red,green,blue,cyan,magenta,yellow,white,black……
插入
% 链接
\usepackage{hyperref} % 超链接
\usepackage[hidelinks]{hyperref} % 隐藏边框
\url{链接}
\href{链接}{描述}
% 图片:应为pdf,png,jpg,jpeg,gif……,图片文件应当与 TeX 文件放在同一目录下
\usepackage{graphicx} %插入图片的宏包
\includegraphics[scale = ]{文件名(不用后缀)}% scale缩放图片 / witch = / height =
% 图标
\usepackage{fontawesome5}
% 详细命令……
% 默认使用空心版本
% 后面加*表示实心版本
% 表格
\begin{tabular}{|l|c|r|}% 生成3列表格,每列对齐方式分别是:左中右
% 上面的| 整列竖线
\hline % 整列水平分割线
文本 & 文本 % &竖分割线
\cline{a-b} % 近在a到b列水平分割线
\end{tabular}
\begin{table}[htbp] % 外面嵌套的浮动环境
\end{table}
\begin{minipage}{0\linewidth}% 内部嵌套子表格
\end{minipage}
\begin{figure}[位置参数]% 位置参数: h,t,b,p把图片放在 这里,页面顶端,底端,另起一页
\end{figure}% 通常配合图片使用
% 水平分割线
\usepackage{titlesec}
\titlerule
自定义
命令组合方便复用
% 自定义命令
\newcommand{\命令名}[可选]{具体定义} % 自定义命令
\renewcommand\labelitemi{$\circ$} % 设置列表符号为
% 自定义环境
\usepackage{changepage} % 自定义环境
\newenvironment{环境名}{开始代码}{结束代码}% 定义名为……的环境
\newenvironment{header}% 示例
{ % 在内容前执行的命令
……
}
{ % 在内容后执行的命令
……
}
\begin{header}% 使用
%内容
\end{header}
% 原始命令复制到新命令中
\let\新命令名\原命令名
% 定义颜色
\usepackage[dvipsnames]{xcolor} % 颜色包
\definecolor{颜色名}{色彩模式}{颜色值}
\definecolor{primaryColor}{RGB}{1, 1, 1}
% 自定义标题
\usepackage{titlesec}
\titleformat{标题命令}{标题排版与字体}{<label>}{<sep>}{<before-code>}[<after-code>]%重定制标题格式
本文由作者按照 CC BY 4.0 进行授权