Latex使用手冊記錄


入門可以看一下下面的部分內容

1.LaTeX軟件的安裝和使用 
方法A(自助):在MikTeX的官網下載免費的MikTeX編譯包(150Mb)並安裝。下載WinEdt(9.5Mb)(收費)或TexMaker(32Mb)(免費)等編輯界面軟件並安裝。 
方法B(打包):在ctex.org下載ctex套裝(203Mb或1.3Gb)(含MikTeX及WinEdt)

哈哈這一部分當然不包含在標題的30分鍾里。

新人不必糾結軟件問題,隨便什么軟件隨便什么版本只要下載下來能編譯出pdf來就可以,先下載了裝上來試試再說。我推薦winedt也是方便我在介紹按鈕樣子的時候可以統一描述。在真正開始跑步之前沒有必要糾結該買NIKE跑鞋還是ADI跑鞋,跑起來再說。不要瞻前顧后,just try it.

2.第一個文檔 
打開WinEdt,建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8。 

\documentclass{article} 
\begin{document} 
  hello, world 
\end{document} 

然后在WinEdt的工具欄中找到編譯按鈕(在垃圾桶和字母B中間),在下拉菜單中選擇XeLaTeX,並點擊編譯。 (這里請注意一下我之前一直筆誤寫的XeTeX,給大家帶來困擾深感歉意) 
如果順利的話,我們就可以順利生成出第一個pdf文件,點擊工具欄中的放大鏡按鈕就可以快速打開生成的pdf文件。 


3.標題、作者和注釋 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察現象。 

\documentclass{article} 
  \author{My Name} 
  \title{The Title} 
\begin{document} 
  \maketitle 
  hello, world % This is comment 
\end{document}

%為本行右邊所有內容被注釋掉,在生成的pdf中不會顯示。

塊注釋也有專門的語句,不過更方便的方式是選中一塊區域點鼠標右鍵,點comment 


4.章節和段落 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察現象。 

\documentclass{article} 
  \title{Hello World} 
\begin{document} 
  \maketitle 
  \section{Hello China} China is in East Asia. 
    \subsection{Hello Beijing} Beijing is the capital of China. 
      \subsubsection{Hello Dongcheng District} 
        \paragraph{Tian'anmen Square}is in the center of Beijing 
          \subparagraph{Chairman Mao} is in the center of Tian'anmen Square 
      \subsection{Hello Guangzhou} 
        \paragraph{Sun Yat-sen University} is the best university in Guangzhou. 
\end{document} 

  



退格只是我個人偏好,看起來層次清晰美觀。實際操作上未必要如此,每一行之前的空格不影響編譯生成PDF的排版結果。 


5.加入目錄 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察現象。 

\documentclass{article} 
\begin{document} 
  \tableofcontents 
  \section{Hello China} China is in East Asia. 
    \subsection{Hello Beijing} Beijing is the capital of China. 
      \subsubsection{Hello Dongcheng District} 
        \paragraph{Hello Tian'anmen Square}is in the center of Beijing 
          \subparagraph{Hello Chairman Mao} is in the center of Tian'anmen Square 
\end{document} 

  



6.換行 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察對比現象。 

\documentclass{article} 
\begin{document} 
  Beijing is 
  the capital 
  of China. 

  Washington is 

  the capital 

  of America. 

  Amsterdam is \\ the capital \\ 
  of Netherlands. 
\end{document}

  

空一行為另起一段,\\為段內強制換行。

我對之前手滑寫出New York is the capital of America這類低級錯誤表示非常抱歉。

7.數學公式 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察對比現象。 

\documentclass{article} 
  \usepackage{amsmath} 
  \usepackage{amssymb} 
\begin{document} 
  The Newton's second law is F=ma. 

  The Newton's second law is $F=ma$. 

  The Newton's second law is 
 

F=maF=ma
 

  The Newton's second law is 
 

F=maF=ma
 

  Greek Letters $\eta$ and $\mu$ 

  Fraction $\frac{a}{b}$ 

  Power $a^b$ 

  Subscript $a_b$ 

  Derivate $\frac{\partial y}{\partial t} $ 

  Vector $\vec{n}$ 

  Bold $\mathbf{n}$ 

  To time differential $\dot{F}$ 

  Matrix (lcr here means left, center or right for each column) 
  \[ 
    \left[ 
      \begin{array}{lcr} 
        a1 & b22 & c333 \\ 
        d444 & e555555 & f6 
      \end{array} 
    \right] 
  \] 

Equations(here \& is the symbol for aligning different rows) 
\begin{align} 
  a+b&=c\\ 
  d&=e+f+g 
\end{align} 

\[ 
  \left\{ 
    \begin{aligned} 
      &a+b=c\\ 
      &d=e+f+g 
    \end{aligned} 
  \right. 
\] 

\end{document} 

  


具體細節可以自行搜索LaTeX的數學符號表或別人給的例子。

 

$...$是開啟行內數學模式,用於和文本合在一起使用。

 

......

......

是另起一行居中開啟數學模式。通常用起來差別不是很大,不過$$會修改默認的公式行間距,有時可能會對文章的整體效果有影響。

 

有一些網站可以通過畫圖的方式來生成公式,有的編輯器集成了各種數學功能按鈕。這對於公式需求少的人來說很方便,具體信息可以自己去搜索。但是如果你的文章中要出現大段的證明過程,就會發覺還是老老實實地google一篇latex數學符號表,然后不懂的去查代碼,自己用手指敲來得干脆利索。再進階一點,可以去搜一下有關LaTeX的自定義command的內容去看一下,在敲公式時能省很多力氣。

8.插入圖片 
將待插入的圖片姑且先命名為figure1.jpg 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,放在和圖片文件同一個文件夾里,編譯並觀察現象。 

\documentclass{article} 
  \usepackage{graphicx} 
\begin{document} 
  \includegraphics[width=4.00in,height=3.00in]{figure1.jpg} 
\end{document}

 


在老版本的LaTeX中是只支持eps圖片格式的,現在的LaTeX對jpg、bmp、png等等常見圖片都可以支持。

9.簡單表格 
建立一個新文檔,將以下內容復制進入文檔中,保存,保存類型選擇為UTF-8,編譯並觀察對比現象。 

\documentclass{article} 
\begin{document} 
  \begin{tabular}{|c|c|} 
    aaa & b \\ 
    c & ddddd\\ 
  \end{tabular} 

  \begin{tabular}{|l|r|} 
    \hline 
    aaaa & b \\ 
    \hline 
    c & ddddd\\ 
    \hline 
  \end{tabular} 

  \begin{center} 
    \begin{tabular}{|c|c|} 
      \hline 
      a & b \\ \hline 
      c & d\\ 
      \hline 
    \end{tabular} 
  \end{center} 
\end{document}

  

注意觀察有無\hline和有無\begin{center}的區別。注意觀察\begin{tabular}后的lcr的區別,分別是left對齊,center對齊和right對齊。 

詳細的Latex手冊可以看下這篇博客

https://blog.csdn.net/gsww404/article/details/78684278?utm_medium=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-baidujs-1.nonecase

可以看一下一部分完成的工作展示、

\documentclass{article}
\usepackage{CJK}
\usepackage{ctex}
\usepackage{amsmath}
\begin{document}
\begin{CJK*}{GBK}{song}

作業一:\\

要使公式$\max\limits_{p_{1},...,p_{m}}-\sum\limits_{k=1}^{m}p_{k}logp_{k}$ 熵最大,根據最大熵原則可以引入拉格朗日因子$w_{0}$來表示對$\sum\limits_{k=1}^mp_{k}=1$ 的限制。有定義一個拉格朗日函數:
\begin{equation}
L(p,w)=\sum\limits_{i=1}^{m}p(y_{i})logp(y_{i})+w_{0}(\sum\limits_{i=1}^{m}p(y_{i})-1)
\end{equation}

根據拉格朗日對偶性,可以通過求解拉格朗日對偶最優化問題得到原始最優解的解,所以求解
\begin{equation}
\max\limits_{w}\min\limits_{p}L(p,w)
\end{equation}
首先可以先求解關於P的極小化問題,固定w0,求偏導數:
\begin{equation*}
\begin{aligned}
\partial L(p,w)/\partial p(y_{1}) &= 1+logp(y_{1}) + w0
\\
\partial L(p,w)/\partial p(y_{2}) &= 1+logp(y_{2}) + w0
\\
......
\\
\partial L(p,w)/\partial p(y_{m}) &= 1+logp(y_{m}) + w0
\\
\end{aligned}
\end{equation*}
令各偏導數為零,解得:
\begin{equation*}
\begin{aligned}
p(y_{1})=p_{2}=...=p(y_{m})=e^{-w0-1}
\end{aligned}
\end{equation*}
帶入於是得
\begin{equation*}
\begin{aligned}
\min\limits_{p}L(p,w) = L(p_{w},w) = -me^{-w_{0}-1}-w_{0}
\end{aligned}
\end{equation*}
再求解$L(p_{w},w)$關於w得極大化問題:
\begin{equation*}
\begin{aligned}
\max\limits_{w}L(p,w) = L(p_{w},w) = -me^{-w_{0}-1}-w_{0}
\end{aligned}
\end{equation*}
分別對$L(P_{w},w)$對$w_{0}$的偏導數並令其為0,得到:$me^{-w_{0}-1}= 1$
所以$e^{-w_{0}-1} = 1/m$因此當每個$p_{i}=1/m$時取得最大熵,代入求得最大熵是$logm$


作業二:

因為
\begin{equation*}
\begin{aligned}
因為\int_{x}p_{data}(x)logD(x)\, dx + \int_{x}p_{G}(x)log(1-D(x))\, dx
\\
=\int_{x}[p_{data}(x)logD(x) + p_{G}(x)log(1-D(x))]\, dx
\end{aligned}
\end{equation*}
為簡化表示,此時令$a = p_{data}(x)$, $b = logD(x)$, $c =p_{G}(x) $, $D = log(1-D(x))$
尋找一個x,這個最優化的D*使式子$aD + bD$最大即可,有
\begin{equation*}
\begin{aligned}
df(D)/dD &= a*1/D + b*1/(1-D)*(-1) = 0\\
a*1/D^{*} &= b*1/(1-D^{*})\\
a*(1-D^{*}) &= b*D^{*}\\
a - a*D^{*} &= b*D^{*}\\
D^{*} &= a/(a+b)\\
所以 D*(x) &= p_{data}(x)/p_{data}(x)+P_{G}(x)\\
\end{aligned}
\end{equation*}
為最優判別器
\end{CJK*}
\end{document}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM