LaTex

使用Sublime Text+LaTeXTools+Skim配置latex環(huán)境。

[TOC]

安裝MacTeX

MacTeX是mac上的MacTex分發(fā)軟件,包含眾多軟件包。

進(jìn)入MacTex官網(wǎng),下載MacTeX.pkg文件安裝MacTeX。

安裝LaTeXTools、LaTexing

如果Sublime Text沒有安裝Package Control,先安裝Package Control。
打開 Sublime Text 3 選擇 View 中的 Show Console 。

這時(shí)sublime text下面會(huì)顯示一個(gè)輸入窗口,復(fù)制下面這段代碼到窗口里面并且回車執(zhí)行,然后重啟 Sublime Text 3 。

import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

安裝 LaTeXTools插件

按下 shift + ? + P,輸入 Install Package ,回車。

輸入LaTeXTools ,回車安裝LaTeXTools插件。

安裝 LaTexing插件

LaTexing是LaTex自動(dòng)填充的插件。

按下 shift + ? + P,輸入 Install Package ,回車。
輸入LaTexing,回車安裝該插件。

安裝Skim

安裝好后運(yùn)行Skim,進(jìn)入Skim——選項(xiàng),點(diǎn)擊同步進(jìn)行設(shè)置

勾選檢查文件變化,在PDF-Tex同步支持那里選擇sublime Text,這樣當(dāng)你編譯tex后就會(huì)自動(dòng)打開pdf預(yù)覽了。

配置中文文檔編寫環(huán)境

打開終端,運(yùn)行:

sudo tlmgr update --self
sudo tlmgr install latexmk

在sublime Text里打開LaTeXTools.sublime-settings(也就是LaTeXTools的用戶設(shè)置,如果你是從舊版本升級(jí)上來(lái)或者擔(dān)心這個(gè)配置文件出現(xiàn)問題,可以依次點(diǎn)擊Preferences——Package Settings——LaTeXTools——Reconfigure LaTeXTools and migrate settings重建配置文件),在builder-settings下面新增兩項(xiàng)配置:

"program" : "xelatex",
"command" : ["latexmk", "-cd", "-e", "$pdflatex = 'xelatex -interaction=nonstopmode -synctex=1 %S %O'", "-f", "-pdf"],

另外注意之前應(yīng)該有"builder": "default"(或直接設(shè)置為空或”traditional”)。

注意:中文編寫LaTex可能會(huì)出現(xiàn)排版的問題,解決辦法是在代碼的開頭加上!TEX program = xelatex,然后添加\usepackage[UTF8]{ctex}這樣一個(gè)package就好了。如圖,

LaTex編寫

建立第一個(gè)文檔

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

文章標(biāo)題、作者

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

章節(jié)和段落

"section"即章節(jié)的標(biāo)記,在section前加一個(gè)"sub"前綴表示章節(jié)的子章節(jié),如果加兩個(gè)"sub",表示子章節(jié)的子章節(jié),以此類推。"paragraph"與"subparagraph"為段落表示,與section使用類似。

\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}

插入目錄

在\section之前的一行加入"\tableofcontents",即可生成目錄。

\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}

數(shù)學(xué)公式

作為初學(xué)者先看一下基本的公式生成,用到相應(yīng)公式時(shí)再去維基百科|數(shù)學(xué)公式查應(yīng)該夠用了。

\documentclass{article}
\begin{document}
This is an equation \[f(x) = 3x + 7\] %數(shù)學(xué)公式的前后要加上 $ 或 \( 和 \),如果用 \[ 和 \],或者使用 $$ 和 $$,則改公式獨(dú)占一行;
This is an equation  \(f(x) = 3x + 7\)
$$\sum_{i=1}^n a_i=0$$ %用 ^ 來(lái)表示上標(biāo),用 _ 來(lái)表示下標(biāo)
$$f(x)=x^{x^x}$$
$$f(x_1,x_x,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 $$ %\ldots 表示跟文本底線對(duì)齊的省略號(hào);\cdots 表示跟文本中線對(duì)齊的省略號(hào)
\[a^{2}=\sqrt+\sqrt[4]{y}\]   %開方使用\sqrt[n]{x}命令
\end{document}
LaTex命令 預(yù)覽效果
$ x_i $ x_i
$ x^2 $ x^2
$ x^ {y^z} $ x^ {y^z}
$ \int_a^b f(x) $ \int_a^b f(x)
$ \frac ab $ \frac ab

參考:MathJax basic tutorial

etexify LaTeX handwritten symbol recognition.:識(shí)別手寫的symbol然后給出相應(yīng)的Latex代碼并且給出需要include的package,識(shí)別的準(zhǔn)確度很高。

列表

列表使用enumitem包。導(dǎo)言區(qū)引用:

\usepackage{enumitem}

有序列表

\begin{enumerate}
\item one
\item two
\item three
\end{enumerate}

無(wú)序列表

\begin{itemize}
\item these components
\item reference implementation
\item which are built according
\item reference specification
\end{itemize}

插入圖片

將待插入的圖片姑且先命名為 figure1.jpg 建立一個(gè)新文檔,將以下內(nèi)容復(fù)制進(jìn)入文檔中,保存,保存類型選擇為 UTF-8,放在和圖片同一個(gè)文件夾中,編譯并觀察現(xiàn)象

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

插入表格

表格的幾種插入格式,注意觀察有無(wú)\hline 和有無(wú)\begin{center}的區(qū)別。注意觀察\begin{tabular} 后的 lcr 的區(qū)別,分別是 left 對(duì)齊,center 對(duì)齊和 right 對(duì)齊。

\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}

可使用在線LaTex表格生成器tablesgenerator。

版面設(shè)置

頁(yè)面模板

頁(yè)面模板在\documentclass引用處設(shè)置,下面是一些常用的屬性:

  • 字號(hào)大小:有四種可能的字號(hào),分別是9pt, 10pt, 11pt, 12pt, 加粗的為默認(rèn)值,默認(rèn)值適用于大多數(shù)paper,無(wú)需修改。
  • 草稿模式:同樣此處有四種可能的模式,分別是draft, draftcls, draftclsnofoot, final, 倘若使用draft模式則文章的行距被調(diào)整為二倍行距以方便加批注,默認(rèn)為final即最終稿模式,此處也無(wú)需修改,保持默認(rèn)即可。
  • 模板類型:此處有5種可能的類型,分別是conference, journal, technote, peerreview, peerreviewca。
  • 紙張類型:此處有三個(gè)可選項(xiàng):letterpaper, a4paper, cspaper。
  • 單雙面:oneside, twoside,默認(rèn)為單面,暫且保持默認(rèn)即可。
  • 單雙欄:onecolumn, twocolumn,默認(rèn)為雙欄,暫且保持默認(rèn)即可。

向以太坊的黃皮書,就是9pt,單面,雙欄,a4紙的,設(shè)置如下:

\documentclass[9pt,oneside,twocolumn,a4paper]{article}

頁(yè)邊距

設(shè)置頁(yè)邊距,推薦使用geometry宏包??梢栽谶@里查看它的說明文檔。

比如我希望,將紙張的長(zhǎng)度設(shè)置為 20cm、寬度設(shè)置為 15cm、左邊距 1cm、右邊距 2cm、上邊距 3cm、下邊距 4cm,可以在導(dǎo)言區(qū)加上這樣幾行:

\usepackage{geometry}
\geometry{papersize={20cm,15cm}}
\geometry{left=1cm,right=2cm,top=3cm,bottom=4cm}

頁(yè)面背景色

設(shè)置顏色相關(guān)的,比如字體顏色、文本背景或頁(yè)面背景顏色,都是要xcolor宏包。見文檔wiki/LaTeX/Colors。

設(shè)置頁(yè)面背景顏色,先在導(dǎo)言區(qū)引用xcolor包:

\usepackage{xcolor}
\definecolor{pagecolor}{rgb}{1,0.98,0.9}

然后在\begin{document}下添加\pagecolor

\pagecolor{pagecolor}

頁(yè)眉頁(yè)腳

設(shè)置頁(yè)眉頁(yè)腳,推薦使用fancyhdr宏包??梢栽谶@里查看它的說明文檔。

比如我希望,在頁(yè)眉左邊寫上我的名字,中間寫上今天的日期,右邊寫上我的電話;頁(yè)腳的正中寫上頁(yè)碼;頁(yè)眉和正文之間有一道寬為 0.4pt 的橫線分割,可以在導(dǎo)言區(qū)加上如下幾行:

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{\author}
\chead{\date}
\rhead{152xxxxxxxx}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headwidth}{\textwidth}
\renewcommand{\footrulewidth}{0pt}

行間距

我們可以通過 setspace宏包提供的命令來(lái)調(diào)整行間距。比如在導(dǎo)言區(qū)添加如下內(nèi)容,可以將行距設(shè)置為字號(hào)的 1.5 倍:

\usepackage{setspace}
\onehalfspacing

具體可以查看該宏包的文檔。

段間距

我們可以通過修改長(zhǎng)度 \parskip 的值來(lái)調(diào)整段間距。例如在導(dǎo)言區(qū)添加以下內(nèi)容

\addtolength{\parskip}{.4em}

則可以在原有的基礎(chǔ)上,增加段間距 0.4em。如果需要減小段間距,只需將該數(shù)值改為負(fù)值即可。

參考文獻(xiàn)

bib文件的寫法,推薦先通讀bibtex官方的文檔。

示例references.bib

@book{adams1995hitchhiker,
  title={The Hitchhiker's Guide to the Galaxy},
  author={Adams, D.},
  isbn={9781417642595},
  url={http://books.google.com/books?id=W-xMPgAACAAJ},
  year={1995},
  publisher={San Val}
}

將其保存為references.bib后,在文章的tex文件中,最后引用:

\bibliographystyle{plain}
\bibliography{references}

參考

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文已過時(shí),請(qǐng)到 www.loggerhead.me 查看最新版 說明 本文的目標(biāo)是讓需要對(duì)中文論文進(jìn)行排版的OS...
    loggerhead閱讀 4,424評(píng)論 1 9
  • Latex(/?lɑ?t?x/,常被讀作/?lɑ?t?k/或/?le?t?k/),是一種基于TEX的排版系統(tǒng),利用...
    繁著閱讀 34,970評(píng)論 10 23
  • 工具集合軟件ST插件 下載Sublime Text 3BasicTeXSkimPackage Control 配置...
    染微言閱讀 5,076評(píng)論 3 5
  • 我報(bào)名參加汽車考試已經(jīng)很久了,然而,到現(xiàn)在我還沒參加科目一考試,因?yàn)橹拔乙恢庇X得教練會(huì)主動(dòng)聯(lián)系我,既然教練都不找...
    Eva華閱讀 228評(píng)論 0 0
  • 又是一個(gè)周五,我們每周一節(jié)的餐飲課時(shí)間又到了。想想自己能在老師的帶領(lǐng)下做出美味的好吃的心里開心得不得了。第...
    楊尚峰閱讀 266評(píng)論 0 0

友情鏈接更多精彩內(nèi)容