diff --git a/.vscode/settings.json b/.vscode/settings.json index 03ba48b..77bf791 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,74 @@ { - "files.associations": { - "new": "cpp" +// Latex workshop + +"latex-workshop.latex.recipes": [ + { + "name": "texify", //放在最前面为默认编译方案, 适用于MikTex + "tools": [ + "texify" + ] + }, + { + "name": "xelatex", + "tools": [ + "xelatex" + ] + }, + { + "name": "xe->bib->xe->xe", + "tools": [ + "xelatex", + "bibtex", + "xelatex", + "xelatex" + ] } + ], + + "latex-workshop.latex.tools": [ + { + "name": "texify", + "command": "texify", + "args": [ + "--synctex", + "--pdf", + "--tex-option=\"-interaction=nonstopmode\"", + "--tex-option=\"-file-line-error\"", + "%DOC%.tex" + ] + }, + { + // 编译工具和命令 + "name": "xelatex", + "command": "xelatex", + "args": [ + "-synctex=1", + "-interaction=nonstopmode", + "-file-line-error", + "%DOC%" + ] + }, + { + "name": "pdflatex", + "command": "pdflatex", + "args": [ + "-synctex=1", + "-interaction=nonstopmode", + "-file-line-error", + "%DOC%" + ] + }, + { + "name": "bibtex", + "command": "bibtex", + "args": [ + "%DOCFILE%" + ] + } + ], + + + + + } \ No newline at end of file diff --git a/Journal/latex.pdf b/Journal/latex.pdf deleted file mode 100644 index 359d374..0000000 Binary files a/Journal/latex.pdf and /dev/null differ diff --git a/Journal/latex.synctex.gz b/Journal/latex.synctex.gz deleted file mode 100644 index 2c721f6..0000000 Binary files a/Journal/latex.synctex.gz and /dev/null differ diff --git a/Journal/latex.tex b/Journal/latex.tex deleted file mode 100644 index 924e211..0000000 --- a/Journal/latex.tex +++ /dev/null @@ -1,15 +0,0 @@ -%导言区 -\documentclass{article} - -\usepackage{ctex} - -%正文区 -\begin{document} - %字体族设置(罗马字体,无衬线字体,打字机字体) - \textrm{Roman Family} - \texttt{Roman Family} - \rmfamily Roman Family {\sffamily Sans Serif Family} {\ttfamily Typewriter Family} - {\ttfamily Typewriter Family} -\end{document} - - diff --git a/cpp/Algorithm.md b/cpp/Algorithm.md index 9f97c5a..5ccce75 100644 --- a/cpp/Algorithm.md +++ b/cpp/Algorithm.md @@ -8009,3 +8009,696 @@ private: ## 10-2.红黑树的代码 ```cpp +// RB.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include +#include +#include +#include +#include +#include +using namespace std; +// 红黑树代码 +template +class RBTree +{ +public: + RBTree() :root_(nullptr) {} + // 插入操作 + void insert(const T& val) + { + if (root_ == nullptr) + { + root_ = new Node(val); + return; + } + + Node* parent = nullptr; + Node* cur = root_; + while (cur != nullptr) + { + if (cur->data_ > val) + { + parent = cur; + cur = cur->left_; + } + else if (cur->data_ < val) + { + parent = cur; + cur = cur->right_; + } + else + { + return; + } + } + + // 设置当前节点的parent和颜色 + Node* node = new Node(val, parent, nullptr, nullptr, RED);//节点的颜色是RED + //尽最小的可能不影响红黑树的性质 + if (parent->data_ > val) + { + parent->left_ = node; + } + else + { + parent->right_ = node; + } + + // 如果新插入的红色节点,父节点也是红色,不满足红黑树性质,进行插入调整操作 + if (RED == color(parent)) + { + fixAfterInsert(node); + } + } + // 删除操作 + void remove(const T& val) + { + if (root_ == nullptr) + { + return; + } + Node* cur = root_; + while (cur != nullptr) + { + if (cur->data_ > val) + { + cur = cur->left_; + } + else if (cur->data_ < val) + { + cur = cur->right_; + } + else + { + break; + } + } + + // 没找到val节点返回 + if (cur == nullptr) + { + return; + } + + // 删除前驱节点 情况三 + if (cur->left_ != nullptr && cur->right_ != nullptr) + { + Node* pre = cur->left_; + while (pre->right_ != nullptr) + { + pre = pre->right_; + } + cur->data_ = pre->data_; + cur = pre; // cur指向前驱节点 + } + + // 删除cur指向的节点 情况一和二 + Node* child = cur->left_; // 让child指向不为空的孩子 + if (child == nullptr) + { + child = cur->right_; + } + + // left right parent + if (child != nullptr) + { + child->parent_ = cur->parent_; + if (cur->parent_ == nullptr) + { + // root_ -> cur_ + root_ = child; + } + else + { + if (cur->parent_->left_ == cur) + { + cur->parent_->left_ = child; + } + else + { + cur->parent_->right_ = child; + } + } + + Color c = color(cur); + delete cur; + + if (c == BLACK) // 删除的是黑色节点,要进行删除调整操作 + { + fixAfterRemove(child); + } + } + else + { + // child == nullptr + if (cur->parent_ == nullptr) + { + delete cur; + root_ = nullptr; + return; + } + else + { + // 删除的cur就是叶子节点 + if (color(cur) == BLACK) + { + fixAfterRemove(cur); + } + + if (cur->parent_->left_ == cur) + { + cur->parent_->left_ = nullptr; + } + else + { + cur->parent_->right_ = nullptr; + } + + delete cur; + } + } + } +// 递归前序遍历操作 + void preOrder() + { + cout << "[递归]前序遍历:"; + preOrder(root_); + cout << endl; + } + // 非递归前序遍历操作 + void n_preOrder() + { + cout << "[非递归]前序遍历:"; + if (root_ == nullptr) + { + return; + } + + stack s; + s.push(root_); + while (!s.empty()) + { + Node* top = s.top(); + s.pop(); + + cout << top->data_ << " "; // V + + if (top->right_ != nullptr) + { + s.push(top->right_); // R + } + + if (top->left_ != nullptr) + { + s.push(top->left_); // L + } + } + cout << endl; + } + // 递归中序遍历操作 + void inOrder() + { + cout << "[递归]中序遍历:"; + inOrder(root_); + cout << endl; + } + // 非递归中序遍历操作 + void n_inOrder() + { + cout << "[非递归]中序遍历:"; + if (root_ == nullptr) + { + return; + } + stack s; + Node* cur = root_; + + while (!s.empty() || cur != nullptr) + { + if (cur != nullptr) + { + s.push(cur); + cur = cur->left_; + } + else + { + Node* top = s.top(); + s.pop(); + cout << top->data_ << " "; + cur = top->right_; + } + } + + cout << endl; + } + // 递归后序遍历操作 + void postOrder() + { + cout << "[递归]后序遍历:"; + postOrder(root_); + cout << endl; + } + // 非递归后序遍历操作 + void n_postOrder() + { + cout << "[非递归]后序遍历:"; + if (root_ == nullptr) + { + return; + } + stack s1; + stack s2; + s1.push(root_); + while (!s1.empty()) + { + Node* top = s1.top(); + s1.pop(); + + s2.push(top); // V + if (top->left_ != nullptr) + { + s1.push(top->left_); // L + } + if (top->right_ != nullptr) + { + s1.push(top->right_); // R + } + } + while (!s2.empty()) + { + cout << s2.top()->data_ << " "; + s2.pop(); + } + cout << endl; + } + // 递归层序遍历操作 + void levelOrder() + { + cout << "[递归]层序遍历:"; + int h = high(); // 树的层数 + for (int i = 0; i < h; ++i) + { + levelOrder(root_, i); // 递归调用树的层数次 + } + + cout << endl; + } + // 非递归层序遍历操作 + void n_levelOrder() + { + cout << "[非递归]层序遍历:"; + if (root_ == nullptr) + { + return; + } + queue que; + que.push(root_); + while (!que.empty()) + { + Node* front = que.front(); + que.pop(); + + cout << front->data_ << " "; + if (front->left_ != nullptr) + { + que.push(front->left_); + } + if (front->right_ != nullptr) + { + que.push(front->right_); + } + } + cout << endl; + } + + // 递归求二叉树层数 + int high() + { + return high(root_); + } + // 递归求二叉树节点个数 + int number() + { + return number(root_); + } + +private: + // 节点的颜色 + enum Color + { + BLACK, + RED + }; + // 节点类型 + struct Node + { + Node(T data = T(), Node* parent = nullptr, + Node* left = nullptr, Node* right = nullptr, + Color color = BLACK) + :data_(data) + , left_(left) + , right_(right) + , parent_(parent) + , color_(color) + {} + T data_; + Node* left_; + Node* right_; + Node* parent_; // 指向当前节点的父 节点 + Color color_; // 节点的颜色 + }; + + // 返回节点的颜色 + Color color(Node* node) + { + return node == nullptr ? BLACK : node->color_; + } + // 设置节点颜色 + void setColor(Node* node, Color color) + { + node->color_ = color; + } + // 返回节点的左孩子 + Node* left(Node* node) + { + return node->left_; + } + // 返回节点的右孩子 + Node* right(Node* node) + { + return node->right_; + } + // 返回节点的父亲 + Node* parent(Node* node) + { + return node->parent_; + } + + // 左旋转 + void leftRotate(Node* node) + { + Node* child = node->right_; + child->parent_ = node->parent_; + if (node->parent_ == nullptr) + { + // node本身就是root节点 + root_ = child; + } + else + { + if (node->parent_->left_ == node) + { + // node在父节点的左孩子 + node->parent_->left_ = child; + } + else + { + // node在父节点的右孩子 + node->parent_->right_ = child; + + } + } + if (child->left_ != nullptr) + { + child->left_->parent_ = node; + } + + child->left_ = node; + node->parent_ = child; + } + // 右旋转 + void rightRotate(Node* node) + { + Node* child = node->left_; + child->parent_ = node->parent_; + if (node->parent_ == nullptr) + { + // node原来就是root节点 + root_ = child; + } + else + { + if (node->parent_->left_ == node) + { + // node在父节点的左边 + node->parent_->left_ = child; + } + else + { + // node在父节点的右边 + node->parent_->right_ = child; + } + } + + node->left_ = child->right_; + if (child->right_ != nullptr) + { + child->right_->parent_ = node; + } + + child->right_ = node; + node->parent_ = child; + } + // 红黑树的插入调整操作 + void fixAfterInsert(Node* node) + { + // 如果当前红色节点的父节点也是红色,继续调整 + while (color(parent(node)) == RED) + { + if (left(parent(parent(node))) == parent(node)) + { + //节点的爷爷的左孩子是父节点 + // 插入的节点在左子树当中 + Node* uncle = right(parent(parent(node))); + if (RED == color(uncle)) // 情况一 + { + setColor(parent(node), BLACK); + setColor(uncle, BLACK); + setColor(parent(parent(node)), RED); + node = parent(parent(node)); // 继续调整 + } + else + { + //插入的节点在右子树中 + // 先处理情况三 + if (right(parent(node)) == node) + { + node = parent(node); + leftRotate(node); + } + + // 统一处理情况二 + setColor(parent(node), BLACK); + setColor(parent(parent(node)), RED); + rightRotate(parent(parent(node))); + break; // 调整已经完成 + } + } + else + { + // 插入的节点在右子树当中 + Node* uncle = left(parent(parent(node))); + if (RED == color(uncle)) // 情况一 + { + setColor(parent(node), BLACK); + setColor(uncle, BLACK); + setColor(parent(parent(node)), RED); + node = parent(parent(node)); // 继续调整 + } + else + { + // 先处理情况三 + if (left(parent(node)) == node) + { + node = parent(node); + rightRotate(node); + } + + // 统一处理情况二 + setColor(parent(node), BLACK); + setColor(parent(parent(node)), RED); + leftRotate(parent(parent(node))); + break; // 调整已经完成 + } + } + } + + // 当前节点的父节点为不为红色,此处强制root为黑色节点 + setColor(root_, BLACK); + } + // 红黑树的删除调整操作 + void fixAfterRemove(Node* node) + { + while (node != root_ && color(node) == BLACK) + { + if (left(parent(node)) == node) + { + // 删除的黑色节点在左子树 + Node* brother = right(parent(node)); + if (color(brother) == RED) // 情况四 + { + setColor(parent(node), RED); + setColor(brother, BLACK); + leftRotate(parent(node)); + brother = right(parent(node)); + } + + if (color(left(brother)) == BLACK + && color(right(brother)) == BLACK) // 情况三 + { + setColor(brother, RED); + node = parent(node); + } + else + { + if (color(right(brother)) != RED) // 情况二 + { + setColor(brother, RED); + setColor(left(brother), BLACK); + rightRotate(brother); + brother = right(parent(node)); + } + + // 归结到情况一 + setColor(brother, color(parent(node))); + setColor(parent(node), BLACK); + setColor(right(brother), BLACK); + leftRotate(parent(node)); + break; + } + } + else + { + // 删除的黑色节点在右子树 + Node* brother = left(parent(node)); + if (color(brother) == RED) // 情况四 + { + setColor(parent(node), RED); + setColor(brother, BLACK); + rightRotate(parent(node)); + brother = left(parent(node)); + } + + if (color(left(brother)) == BLACK + && color(right(brother)) == BLACK) // 情况三 + { + setColor(brother, RED); + node = parent(node); + } + else + { + if (color(left(brother)) != RED) // 情况二 + { + setColor(brother, RED); + setColor(right(brother), BLACK); + leftRotate(brother); + brother = left(parent(node)); + } + + // 归结到情况一 + setColor(brother, color(parent(node))); + setColor(parent(node), BLACK); + setColor(left(brother), BLACK); + rightRotate(parent(node)); + break; + } + } + } + + // 如果发现node指向的节点是红色,直接涂成黑色,调整结束 + setColor(node, BLACK); + } + +//--------------------------------------------------//补充功能 + // 递归前序遍历的实现 VLR + void preOrder(Node* node) + { + if (node != nullptr) + { + cout << node->data_ << " "; // 操作V + preOrder(node->left_); // L + preOrder(node->right_); // R + } + } + // 递归中序遍历的实现 LVR + void inOrder(Node* node) + { + if (node != nullptr) + { + inOrder(node->left_); // L + cout << node->data_ << " "; // V + inOrder(node->right_); // R + } + } + // 递归后序遍历的实现 LRV + void postOrder(Node* node) + { + if (node != nullptr) + { + postOrder(node->left_); // L + postOrder(node->right_); // R + cout << node->data_ << " "; // V + } + } + // 递归层序遍历的实现 + void levelOrder(Node* node, int i) + { + if (node == nullptr) + return; + + if (i == 0)//若i = 0, 说明已经到达要打印的层数 + { + cout << node->data_ << " "; + return; + } + levelOrder(node->left_, i - 1); + levelOrder(node->right_, i - 1); + } + // 递归实现求二叉树层数 求以node为根节点的子树的高度并返回高度值 + int high(Node* node) + { + if (node == nullptr) + { + return 0; + } + int left = high(node->left_); // L + int right = high(node->right_); // R + return left > right ? left + 1 : right + 1; // V + } + // 递归求二叉树节点个数的实现 求以node为根节点的树的节点总数,并返回 + int number(Node* node) + { + if (node == nullptr) + return 0; + int left = number(node->left_); // L + int right = number(node->right_); // R + return left + right + 1; // V + } + + + // 指向红黑树的根节点 + Node* root_; +}; + +int main() +{ + int ar[] = {58,24,67,0,34,62,69,5,41,64,78}; + RBTree rb; + for (int v : ar) + { + rb.insert(v); + } + rb.preOrder(); + rb.inOrder(); + rb.postOrder(); + cout << "-------after remove 24 -----" << endl; + rb.remove(24); + rb.inOrder(); + cout << "-------after insert 24-------------" << endl; + rb.insert(24); + rb.inOrder(); +} +``` \ No newline at end of file diff --git a/latex/.vscode/settings.json b/latex/.vscode/settings.json new file mode 100644 index 0000000..9aa8735 --- /dev/null +++ b/latex/.vscode/settings.json @@ -0,0 +1,68 @@ +{ + // Latex configuration + "latex-workshop.latex.recipes": [ + { + "name": "xe->bib->xe->xe", + "tools": [ + "xelatex", + "bibtex", + "xelatex", + "xelatex" + ] + } + ], + "latex-workshop.latex.tools": [ + { + // 编译工具和命令 + "name": "xelatex", + "command": "xelatex", + "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.view.pdf.viewer": "tab", + "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" + ] + +} \ No newline at end of file diff --git a/latex/latex01/main.pdf b/latex/latex01/main.pdf new file mode 100644 index 0000000..a32d689 Binary files /dev/null and b/latex/latex01/main.pdf differ diff --git a/latex/latex01/main.tex b/latex/latex01/main.tex new file mode 100644 index 0000000..8d495b5 --- /dev/null +++ b/latex/latex01/main.tex @@ -0,0 +1,90 @@ +\documentclass{article} +% \documentclass{IEEEtran}%将文章的格式改为IEEE的样式 + +% -------------------导言区------------------------% +\usepackage[fontset=ubuntu]{ctex} +\usepackage{graphicx}%宏包 +\usepackage{verbatim}%主要用于多行注释 +\usepackage +\title{Second Intro} +\author{Kim James} +\date{December 2022} + +% 1. 多行注释 +\begin{comment} %此处用于多行注释 +1.想要中文的话,直接改变 + 1-1. article->ctexart + 1-2. compiler->XeLatex +2.如果有生僻字 + 2-1.\usepackage[fontset=ubuntu]{ctex} + 2-2.\usepackage{ctex} +3.导言区主要加载一些宏包,宏包不能加入正文区 +\end{comment} + +%--------------------导言区-----------------------% + + +\begin{document} + +%-------------------正文区------------------------% +\maketitle %this is the way they use to locate the things above% +% 2.maketitle执行到maketitle了,那么先加载导言区的内容,再加载maketitle以下地方的内容 + +% 3.多行注释主要方法(注意的是!内容大于形式!) +% 4.分级的方法 +% 4-1.“."式的方法 +\begin{itemize} + \item sdfdsf + \item sdf + +\end{itemize} + +% 4-2.“1"式的方法 +\begin{enumerate} + \item 1sdf + \item 2sdf + \item 3sdf + \item 4sdf +\end{enumerate} + +% 5.section +\section{Introduction} +\subsection{Intro2} +Youth is not a of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and supple knees; it is a matter of the will, a quality of the imagination, a vigor of the emotions; it is the freshness of the deep springs of life. +I don't think this is gonna be good. +Youth means a temperamental predominance of courage over timidity, of the appetite for adventure over the love of ease. This often exists in a man of 60 more than a boy of 20. Nobody grows old merely by a number of years. We grow old by deserting our ideals. + +Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul. Worry, fear, self-distrust bows the heart and turns the spirit back to dust. + +\paragraph{Intro3} +this is the paragraph, which I think is the right. + + +\section{Second section} +Hello everyone! This is a great day! + +\subsection{Background01} +Whether 60 or 16, there is in every human being’s heart the lure of wonders, the unfailing appetite for what’s next and the joy of the game of living. In the center of your heart and my heart, there is a wireless station; so long as it receives messages of beauty, hope, courage and power from man and from the infinite, so long as you are young. + + +\subsection{Background02} + +when your aerials are down, and your spirit is covered with snows of cynicism and the ice of pessimism, then you’ve grown old, even at 20; but as long as your aerials are up, to catch waves of optimism, there’s hope you may die young at 80.this is the equation $a = b^2 + \frac{n}{b}$ + +\begin{equation} + x = \frac{b^2}{2n} + \sqrt{n} +\end{equation} + + +\begin{equation} + y = \frac{a^{b+c}}{\Sigma_{i=0}^{\infty}x_{i}} +\end{equation} + +\begin{equation} + $$x = \sum_{i = 0}^{\infty}$$ +\end{equation} + +\end{document} + +%-------------------正文区------------------------------% + diff --git a/latex/latex02/test02.pdf b/latex/latex02/test02.pdf new file mode 100644 index 0000000..e94a8a8 Binary files /dev/null and b/latex/latex02/test02.pdf differ diff --git a/latex/latex02/test02.synctex.gz b/latex/latex02/test02.synctex.gz new file mode 100644 index 0000000..3fdbed4 Binary files /dev/null and b/latex/latex02/test02.synctex.gz differ diff --git a/latex/latex02/test02.tex b/latex/latex02/test02.tex new file mode 100644 index 0000000..a776a47 --- /dev/null +++ b/latex/latex02/test02.tex @@ -0,0 +1,94 @@ +\documentclass{article} +% \documentclass{IEEEtran}%将文章的格式改为IEEE的样式 + +% -------------------导言区------------------------% +\usepackage[fontset=ubuntu]{ctex} +\usepackage{graphicx}%宏包 +\usepackage{verbatim}%主要用于多行注释 + +\title{Second Intro} +\author{Kim James} +\date{December 2022} + +% 1. 多行注释 +\begin{comment} %此处用于多行注释 +1.想要中文的话,直接改变 + 1-1. article->ctexart + 1-2. compiler->XeLatex +2.如果有生僻字 + 2-1.\usepackage[fontset=ubuntu]{ctex} + 2-2.\usepackage{ctex} +3.导言区主要加载一些宏包,宏包不能加入正文区 + +\end{comment} + +%--------------------导言区-----------------------% + + +\begin{document} + +%-------------------正文区------------------------% +\maketitle %this is the way they use to locate the things above% +% 2.maketitle执行到maketitle了,那么先加载导言区的内容,再加载maketitle以下地方的内容 + +% 3.多行注释主要方法(注意的是!内容大于形式!) +% 4.分级的方法 +% 4-1.“."式的方法 +\begin{itemize} + \item sdfdsf + \item sdf +\end{itemize} +\begin{enumerate} + \item 1set + \item 2st + \item 3st + \item +\end{enumerate} +\begin{equation} + $\Sigma_{f_x}^{\infty}\Sigma_{f_x}^{\infty}x_{ij}$ +\end{equation} + +% 4-2.“1"式的方法 +\begin{enumerate} + \item 1sdf + \item 2sdf + \item 3sdf + \item 4sdf +\end{enumerate} + +% 5.section +\section{Introduction} +\subsection{Intro2} +Youth is not a of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and supple knees; it is a matter of the will, a quality of the imagination, a vigor of the emotions; it is the freshness of the deep springs of life. +I don't think this is gonna be good. +Youth means a temperamental predominance of courage over timidity, of the appetite for adventure over the love of ease. This often exists in a man of 60 more than a boy of 20. Nobody grows old merely by a number of years. We grow old by deserting our ideals. + +Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul. Worry, fear, self-distrust bows the heart and turns the spirit back to dust. + +\paragraph{Intro3} +this is the paragraph, which I think is the right. + + +\section{Second section} +Hello everyone! This is a great day! + +\subsection{Background01} +Whether 60 or 16, there is in every human being’s heart the lure of wonders, the unfailing appetite for what’s next and the joy of the game of living. In the center of your heart and my heart, there is a wireless station; so long as it receives messages of beauty, hope, courage and power from man and from the infinite, so long as you are young. + + +\subsection{Background02} + +when your aerials are down, and your spirit is covered with snows of cynicism and the ice of pessimism, then you’ve grown old, even at 20; but as long as your aerials are up, to catch waves of optimism, there’s hope you may die young at 80.this is the equation $a = b^2 + \frac{n}{b}$ + +\begin{equation} + x = \frac{b^2}{2n} + \sqrt{n} +\end{equation} + + +\begin{equation} + y = \frac{a^{b+c}}{\Sigma_{i=0}^{\infty}x_{i}} +\end{equation} + +\end{document} +%-------------------正文区------------------------------% + diff --git a/latex/latex03/test01.pdf b/latex/latex03/test01.pdf new file mode 100644 index 0000000..0619267 Binary files /dev/null and b/latex/latex03/test01.pdf differ diff --git a/latex/latex03/test01.synctex.gz b/latex/latex03/test01.synctex.gz new file mode 100644 index 0000000..4d4c7fb Binary files /dev/null and b/latex/latex03/test01.synctex.gz differ diff --git a/latex/latex03/test01.tex b/latex/latex03/test01.tex new file mode 100644 index 0000000..26e1d3b --- /dev/null +++ b/latex/latex03/test01.tex @@ -0,0 +1,25 @@ +\documentclass{article} +% \documentclass{IEEEtran}%将文章的格式改为IEEE的样式 + +% -------------------导言区------------------------% +\usepackage[fontset=ubuntu]{ctex} +\usepackage{graphicx}%宏包 +\usepackage{verbatim}%主要用于多行注释 + +\author{a} +\date{\today} + +\begin{document} + \maketitle + \section{a} + \begin{equation} + $$a + b = c$$ + $a = b$ + $$a = 1$$ + \end{equation} + \section{b} + \section{c} + \section{d} + \section{e} + +\end{document} \ No newline at end of file diff --git a/latex/latexLearn.md b/latex/latexLearn.md new file mode 100644 index 0000000..3b0f625 --- /dev/null +++ b/latex/latexLearn.md @@ -0,0 +1,154 @@ +# 第一章 LATEX 的基本概念 +## 1-1.源代码结构 +```tex +\documentclass{...} % ... 为某文档类 +% 导言区 +\begin{document} +% 正文内容 +\end{document} +% 此后内容会被忽略 +``` +## 1-2.命令 +```tex +\begin{⟨environment name⟩}[⟨optional arguments⟩]{⟨mandatory arguments⟩} +… +\end{⟨environment name⟩} +``` + + `其中⟨environment name⟩ 为环境名,\begin 和 \end 中填写的环境名应当一致。类似命令, +{⟨mandatory arguments⟩} 和 [⟨optional arguments⟩] 为环境所需的必选和可选参数` + +## 1-3.latex宏包和文档类 +### 1-3-1.文档类 + +```tex +\documentclass[⟨options⟩]{⟨class-name⟩} +``` +**注意** +1. article 文章格式的文档类,广泛用于科技论文、报告、说明文档等。 +2. report 长篇报告格式的文档类,具有章节结构,用于综述、长篇论文、简单 +的书籍等。 +3. book 书籍文档类,包含章节结构和前言、正文、后记等结构。 +4. proc 基于 article 文档类的一个简单的*学术文档模板*。 +5. slides *幻灯格式*的文档类,使用无衬线字体。 +6. minimal 一个极其精简的文档类,只设定了纸张大小和基本字号,用作代码测试的最小工作示例(Minimal Working Example)。 + +### 1-3-1.宏包 + +**结构** +```tex +% 调用单个宏包 +\usepackage[⟨options⟩]{⟨package-name⟩} +% 一次性调用三个排版表格常用的宏包 +\usepackage{tabularx, makecell, multirow} +``` + +## 1-4.latex可能用到文件 + +* sty 宏包文件。宏包的名称与文件名一致。 +* cls 文档类文件。文档类名称与文件名一致。 +* bib BIBTEX 参考文献数据库文件。 +* bst BIBTEX 用到的参考文献格式模板。详见 6.1.4 小节。 +LATEX 在编译过程中除了生成 .dvi 或 .pdf 格式的文档外9,还可能会生成相当多的辅助文件和日志。一些功能如交叉引用、参考文献、目录、索引等,需要先通过编译生成辅助文件,然 +后再次编译时读入辅助文件得到正确的结果,所以复杂的 LATEX 源代码可能要编译多次: + +* log 排版引擎生成的日志文件,供排查错误使用。 +* aux LATEX 生成的主辅助文件,记录交叉引用、目录、参考文献的引用等。 +* toc LATEX 生成的目录记录文件。 +* lof LATEX 生成的图片目录记录文件。 +* lot LATEX 生成的表格目录记录文件。 +* bbl BIBTEX 生成的参考文献记录文件。 +* blg BIBTEX 生成的日志文件。 +* idx LATEX 生成的供 makeindex 处理的索引记录文件。 +* ind makeindex 处理 .idx 生成的用于排版的格式化索引文件。 +* ilg makeindex 生成的日志文件。 +* out hyperref 宏包生成的 PDF 书签记录文件。 + +## 1-5.文件的组织形式 + +* LATEX 提供了命令 \include 用来在源代码里插入文件: +`\include{⟨filename⟩}` + +`⟨filename⟩ `为文件名(不带 .tex 扩展名),如果和要编译的主文件不在一个目录中,则要加上 +\include{chapters/file} % 相对路径 +\include{/home/Bob/file} % *nix(包含 Linux、macOS)绝对路径 +\include{D:/file} % Windows 绝对路径,用正斜线 + +值得注意的是 \include 在读入 ⟨filename⟩ 之前会另起一页。有的时候我们并不需要这样, +而是用 \input 命令,它纯粹是把文件里的内容插入: +*\input{⟨filename⟩}* + +当导言区内容较多时,常常将其单独放置在一个 .tex 文件中,再用 \input 命令插入。复杂的图、表、代码等也会用类似的手段处理。 +LATEX 还提供了一个 \includeonly 命令来组织文件,用于导言区,指定只载入某些文件。 +导言区使用了 \includeonly 后,正文中不在其列表范围的 \include 命令不会起效: +\includeonly{⟨filename1⟩,⟨filename2⟩,…} + + +# 第二章 用 LATEX 排版文字 + +## 2-1.排版中文 +```tex +\documentclass{ctexart} +\begin{document} +在\LaTeX{}中排版中文。 +汉字和English单词混排,通常不需要在中英文之间添加额外的空格。 +当然,为了代码的可读性,加上汉字和 English 之间的空格也无妨。 +汉字换行时不会引入多余的空格。 +\end{document} +``` +## 2-2.latex中的字符 +1. 空格和分段 + 1. ,空格键和 Tab 键输入的空白字符视为“空格”。连续的若干个空白字符视为一个空格,连续的2个换行会将文字分段 + 2. 多个空行被视为一个空行 +```tex +Several spaces equal one. +Front spaces are ignored. +An empty line starts a new +paragraph.\par +A \verb|\par| command does +the same. +``` +2. 注释 +```tex +This is an % short comment +% --- +% Long and organized +% comments +% --- +example: Comments do not bre% +ak a word. +``` +3. 特殊字符 +*如 % 表示注释,$、^、_ 等用于排版数学公式,& 用于排 +版表格,等等。直接输入这些字符得不到对应的符号,还往往出错* +```tex +in = {\# \$ \% \& \{ \} \_ +\^{} \~{} \textbackslash} + +out = {# $ % & { } _ ^ ~ \} +``` +4. 练字 +```tex +% input +It's difficult to find \ldots\\ +It's dif{}f{}icult to f{}ind \ldots +% output +It’s difficult to find … +It’s difficult to find … +``` + +5. 标点符号 + 1. 引号: +```tex +``Please press the `x' key.'' +``` + 2. 连字号和破折号 +```tex +daughter-in-law, X-rated\\ +pages 13--67\\ +yes---or no? +``` + 3. 省略号:\dots + + +## 2-3.断行和断页 \ No newline at end of file diff --git a/latex/latexLearn.pdf b/latex/latexLearn.pdf new file mode 100644 index 0000000..43798cf Binary files /dev/null and b/latex/latexLearn.pdf differ diff --git a/problems/problems.md b/problems/problems.md index 945e431..f30d946 100644 --- a/problems/problems.md +++ b/problems/problems.md @@ -540,33 +540,6 @@ $ sudo update-alternatives --config python 2 /usr/bin/python3.4 1 手动模式 - - - - - - - - - - - - - - - - - - - - - - - - - - - 要维持当前值[*]请按回车键,或者键入选择的编号: 原来是因为默认选中了自动模式,而Python2的优先级高于Python3,这时候只要键入2,就可以使用Python3了。 ```