Skip to content

Instantly share code, notes, and snippets.

@bofish
Last active October 15, 2020 03:45
Show Gist options
  • Save bofish/705646b160e6370ba06f7c3932895ec9 to your computer and use it in GitHub Desktop.
Save bofish/705646b160e6370ba06f7c3932895ec9 to your computer and use it in GitHub Desktop.

LaTex在MacOS安裝大全

  • Distribution: MacTeX (BasicTex)
  • Editor: Sublime Text
  • PDF viewer: Skim

References

  1. https://latextools.readthedocs.io/en/latest/install/
  2. http://www.readern.com/sublime-text-latex-chinese-under-mac.html
  3. https://blog.json.tw/teaching-sublime-write-latex-using-powerful-tools-beginners-to-try-to-get-started
  4. http://pangomi.blogspot.tw/2012/11/latex-in-ubuntu.html
  5. https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/
  6. http://leavedcorn.pixnet.net/blog/post/24773932-%E6%96%B0%E6%89%8B%E5%AE%89%E8%A3%9Dlatex%E6%87%B6%E4%BA%BA%E6%95%99%E5%AD%B8%28step-by-step%29

安裝 Ediotr: Sublime Text

先安裝最簡單的Editor推薦用SublimeText簡稱ST,按照這篇文章[Ref.5]安裝至少要設定好Command line、Package Control然後用快捷鍵cmd+shiit+p安裝LaTexTools的Package。

LaTexTools設定

到 Sublime Text > Preferences > Package Settings > LaTeXTools > Reset user setting to default重設LaTeXTools.sublime-settngs,之後一樣在LaTeXTools > Settings - User打開LaTeXTools.sublime-settngs檔案並修改以下值:

"builder": "traditional",  % The val Should be "traditional" or None

"builder_settings" : {

    "osx" : {
          // See README or third-party documentation
          "program" : "xelatex",
          "command" : ["latexmk", "-cd", "-e", "$pdflatex = 'xelatex -interaction=nonstopmode -synctex=1 %S %O'", "-f", "-pdf"]
        },
}

在LaTeXTools > Check System 中可以檢查目前缺少的套件,接下來就是要補足這些東西。

安裝PDF Viewer: Skim

下載完之後打開 Skim > Preferences > Sync > Preset 改成Sublime Text。

之後到 Sublime Text > ... > LaTeXTools > Check System 確認Viwer 如下:

Viewer  Status     Location
------  ------     --------
skim    available  /Applications/Skim.app

 

安裝 Distribution: MacTeX/BasicTeX

MacTeX網站有兩種安裝包MacTeX(3GB)與BasicTeX(300MB),我第一次用BasicTex問題真的蠻多的,建議直接安裝MacTex而且MT還自帶editor跟viewer,如果你是直接安裝MT那安裝完就可以去Check System確認

Program      Location                                                  Status     Version
-------      --------                                                  ------     -------
latexmk      /usr/local/texlive/2017basic/bin/x86_64-darwin/latexmk    available  Latexmk, John Collins, 19 Jan. 2017. Version 4.52c
pdflatex     /usr/local/texlive/2017basic/bin/x86_64-darwin/pdflatex   available  pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017)
xelatex      /usr/local/texlive/2017basic/bin/x86_64-darwin/xelatex    available  XeTeX 3.14159265-2.6-0.99998 (TeX Live 2017)
lualatex     /usr/local/texlive/2017basic/bin/x86_64-darwin/lualatex   available  This is LuaTeX, Version 1.0.4 (TeX Live 2017)
biber                                                                  missing    unavailable
bibtex       /usr/local/texlive/2017basic/bin/x86_64-darwin/bibtex     available  BibTeX 0.99d (TeX Live 2017)
bibtex8                                                                missing    unavailable
kpsewhich    /usr/local/texlive/2017basic/bin/x86_64-darwin/kpsewhich  available  kpathsea version 6.2.3
magick       /usr/local/bin/magick                                     available  ImageMagick 7.0.7-6 Q16 x86_64 2017-10-06 http://www.imagemagick.org
ghostscript  /usr/local/bin/gs                                         available  GPL Ghostscript 9.22 (2017-10-04)

但由於我是用BT所以並沒有預設安裝latexmk、magick、ghostscript,這三點路徑若跟你不一樣就參考就好。接下來我要解釋當用BT安裝完之後要如何補齊剩下的三個Program。

設定tlmgr路徑與安裝latexmk、magick、ghostscript

打開terminal輸入tlmgr -h失敗的話就繼續接下來得步驟,繼續在termial輸入

$ subl ~/.bash_profile

如果之前ST的Command line安裝成功那應該會跳出個文檔,加入以下文字

# Latex
export PATH=/usr/local/texlive/2017basic/bin/x86_64-darwin:$PATH

其中的/usr/local/texlive/2017basic/bin/x86_64-darwin路徑自行去你電腦的資料夾找,~/usr是個隱藏資料夾我的做法是打開Finder > 前往 > 前往資料夾或ctrl+cmd+g輸入資料夾路徑,確認x86_64-darwin資料夾下有tlmgr這個檔案才行,這個步驟其實是在建立快捷鍵,讓Terminal能直接打開tlmgr這個bash。設完就試試terminal輸入tlmgr -h

之後如果你是安裝MacTeX而且Check System中都有latexmk、magick、ghostscript那就不用繼續下去了。

先安裝latexmk,在Terminal輸入

sudo tlmgr update --self
sudo tlmgr install latexmk

成功後安裝magick、ghostscript,一樣Terminal

brew install imagemagick
brew install ghotstscript

沒成功可能是沒安裝Homebrew,就去https://brew.sh/ 裝吧。

到這邊差不多了,再去Check System查看一下吧,我弄好的結果是

Variable   Value
--------   -----
PATH       /usr/local/texlive/2017basic/bin/x86_64-darwin:/usr/local/Cellar/qt/5.9.1/bin:/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/Users/ben/anaconda3/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/texlive/2017basic/bin/x86_64-darwin:/usr/local/Cellar/qt/5.9.1/bin:/usr/local/sbin:/Users/ben/anaconda3/bin:/Library/TeX/texbin:/usr/texbin:/usr/local/bin:/opt/local/bin
BIBINPUTS  .:/usr/local/texlive/2017basic/texmf-dist/bibtex/bib:/usr/local/texlive/2017basic/texmf-dist/bibtex/bib/base:/usr/local/texlive/2017basic/texmf-dist/bibtex/bib/oberdiek
BSTINPUTS  .:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/amscls:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/babelbib:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/base:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/index:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/natbib:/usr/local/texlive/2017basic/texmf-dist/bibtex/bst/revtex

Program      Location                                                  Status     Version
-------      --------                                                  ------     -------
latexmk      /usr/local/texlive/2017basic/bin/x86_64-darwin/latexmk    available  Latexmk, John Collins, 19 Jan. 2017. Version 4.52c
pdflatex     /usr/local/texlive/2017basic/bin/x86_64-darwin/pdflatex   available  pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017)
xelatex      /usr/local/texlive/2017basic/bin/x86_64-darwin/xelatex    available  XeTeX 3.14159265-2.6-0.99998 (TeX Live 2017)
lualatex     /usr/local/texlive/2017basic/bin/x86_64-darwin/lualatex   available  This is LuaTeX, Version 1.0.4 (TeX Live 2017)
biber                                                                  missing    unavailable
bibtex       /usr/local/texlive/2017basic/bin/x86_64-darwin/bibtex     available  BibTeX 0.99d (TeX Live 2017)
bibtex8                                                                missing    unavailable
kpsewhich    /usr/local/texlive/2017basic/bin/x86_64-darwin/kpsewhich  available  kpathsea version 6.2.3
magick       /usr/local/bin/magick                                     available  ImageMagick 7.0.7-6 Q16 x86_64 2017-10-06 http://www.imagemagick.org
ghostscript  /usr/local/bin/gs                                         available  GPL Ghostscript 9.22 (2017-10-04)

Packages for equation preview  Status
-----------------------------  ------
standalone                     missing
preview                        missing
xcolor                         available
amsmath                        available
amssymb                        available
latexsym                       available
mathtools                      available

Builder      Status
-------      ------
traditional  available

Builder Setting  Value
---------------  -----
display_log      False
linux            {}
osx              {'program': 'xelatex', 'command': ['latexmk', '-cd', '-e', "$pdflatex = 'xelatex -interaction=nonstopmode -synctex=1 %S %O'", '-f', '-pdf']}
windows          {}

Viewer  Status     Location
------  ------     --------
skim    available  /Applications/Skim.app

測試

在ST開新檔副檔名存為LaTeX(*.tex)內容就

\documentclass{article}
\usepackage{fontspec, xunicode, xltxtra}
\setmainfont{Hiragino Sans GB}

\title{Title}
\author{}

\begin{document}

\maketitle{}

\section{Introduction}

This is where you will write your content.

\end{document}

之後在Tools > Build System 選 LaTeX,若在跳出Build with...就選xelatex

成功的話就會在Skim跳出PDF了,不喜歡用Skim的話其實在LaTexTools.sublime-setting中

"viewer": "preview",

就可以了,但Skim跟LaTeXTools都是開源跨平臺插件,且Skim確實對LaTeX的PDF支援很好。

此外在Skim中若按cmd+shift然後選文字,便會跳到對應的LaTeX代碼。此功能稱SyncTex。

LaTeX Package的安裝

MacTeX或BasicTeX都是基於Unix下的TexLive開發的,所以基本上我們可以用Tex Live Utility這個程式安裝package。或是在 ctan.org找到Package的*.sty檔,然後找到LaTex的package路徑丟進去,然後打指令安裝。

現在說明如何找到放置package的路徑,先說我自己的路徑是放在

/usr/local/texlive/2017basic/texmf-dist/tex/latex/

譬如,今天下載了changepage 這個package檔案結構如

~/changepage
  - changepage.sty
  - chngpage.sty

就將chagepage整個資料夾放入 /usr/.../texmf-dist/tex/latex/

然後在terminal執行

$ tlmgr install changepage

就安裝成功了。

LaTeX中文環境

利用xeCJKpackage完成,先在Tex Live Utility安裝,然後在你的*.tex檔中加入

\usepackage{fontspec}   %加這個就可以設定字體
\usepackage{xeCJK}       %讓中英文字體分開設置
\setCJKmainfont{楷體-繁} %設定中文為系統上的字型,而英文不去更動,使用原TeX字型
\XeTeXlinebreaklocale "zh"             %這兩行一定要加,中文才能自動換行
\XeTeXlinebreakskip = 0pt plus 1pt     %這兩行一定要加,中文才能自動換行

這可以了,其中字型必須要系統中有的才行,以下是範例

\documentclass[a4paper,10pt]{article}

% packages
\usepackage{amsmath, amsfonts, bm, cite}
\usepackage{color, subfig}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{makeidx, chngpage}
\usepackage{fontspec}   %加這個就可以設定字體
\usepackage{xeCJK}       %讓中英文字體分開設置
\setCJKmainfont{楷體-繁} %設定中文為系統上的字型,而英文不去更動,使用原TeX字型
\XeTeXlinebreaklocale "zh"             %這兩行一定要加,中文才能自動換行
\XeTeXlinebreakskip = 0pt plus 1pt     %這兩行一定要加,中文才能自動換行

% line spacing
\newlength{\defbaselineskip}
\setlength{\defbaselineskip}{\baselineskip}
\newcommand{\setlinespacing}[1]{\setlength{\baselineskip}{#1 \defbaselineskip}}
\newcommand{\halfspacing}{\setlength{\baselineskip}{0.30 \defbaselineskip}}
\newcommand{\singlespacing}{\setlength{\baselineskip}{1.20 \defbaselineskip}}
\newcommand{\oneandahalfspacing}{\setlength{\baselineskip}{1.33 \defbaselineskip}}
\newcommand{\doublespacing}{\setlength{\baselineskip}{1.67 \defbaselineskip}}

\renewcommand{\arraystretch}{1.5}

% commandsa
\newcommand{\muX}{\bm{\mu}_{\mathbf{X}}}
\newcommand{\bitem}{\begin{itemize}}
\newcommand{\eitem}{\end{itemize}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\ba}{\begin{eqnarray}}
\newcommand{\ea}{\end{eqnarray}}
\newcommand{\nn}{\notag}
\renewcommand{\vec}{\mathbf} % vector is bold, non-italic

%\renewcommand{\baselinestretch}{2} % double spacing

\begin{document}

\begin{center}~\\~\\

{\Large {\sc SOLab Paper Template}}\\~\\

\singlespacing
Michael Jordan\footnote[1]{Graduate Student}, Kuei-Yuan Chan\footnote[2]{Corresponding Author, Associate Professor, Fax:+886-2-2363-1755}, \\
 {\tt chanky@ntu.edu.tw}\\
試試看中文\\
Department of Mechanical Engineering, \\
National Taiwan University, Taipei, Taiwan\\~\\

%Submitted for Publication in the {\em Journal of Mechanical Design}%\\ Special Issue on Design Under Uncertainty

\doublespacing
\end{center}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{abstract}
Here is where the abstract should be. In general, abstract has only one paragraph with no equations and figures.
\end{abstract}
~\\~\\
\textbf{Keywords} : put some keywords that you think are relevant to your work, keyword 1, keyword 2\newpage
\noindent \textbf{Nomenclature}
\begin{description}
\item[$a_0$] the average rate of change of the objective function.
\item[$a_j$] the average rate of change of the $j$th constraint function.
\item[$c_j$] the weight coefficient of the $j$th inequality constraint.
\item[$d$] the size of the subspace, the distance between center and vertex, a half of diagonal.
\item[$d_{\mathrm{c},i}^{k}$] the size of the $k$th subspace from $i$th  parent space.
\item[$f_*$ or $f_{\mathrm{min}}$] current best function value.
\item[$f_{\mathrm{c},i}^{k}$] sampling the $k$th result by SQP from $i$th parent space in S.A. DIRECT.
\item[$g_j^r$] the violation value of the $r$th sub space violate the $j$th constraint.
\item[$i$] the dummy number of design variables($i=1,\cdots n$).
\item[$j$] the dummy number of the constraint($j=1,\cdots m$).
\item[$K$] tuning parameter.
\item[$l_i$] the $i$th design variables lower bound.
\item[$lb_i$] the $i$th lower boundary.
\item[$m$] the number of all constraint.
\item[$n$] the dimension(or number) of the design variables.
\item[$\mathcal{S}_{\mathrm{p}, i}$] the $i$th parent space, selected from all subspace in S.A. DIRECT.
\item[$\mathcal{S}_{\mathrm{c}, i}^k$] the $k$th subspace(or child space), produced from the $i$th parent space in S.A. DIRECT.
\item[$s_0$] the sum of observed rates of change of the objective function.
\item[$s_j$] the sum of observed rates of change of the $j$th constraint function.
\item[$u_i$]   the $i$th upper bound.
\item[$ub_i$]   the distance between sample and the $i$th upper bound.
\item[$x_r$] sampling point by DIRECT algorithm.
\item[$\vec{x}_{\mathrm{c},i}^{k}$] the $k$th sampling point by SQP from $i$th parent space in S.A. DIRECT.
\item[$\theta$] the relation of global and local with respect to current optimum.
\item[$\varepsilon$] balance parameter, adjusting the process of selecting, avoiding to selecting the subspace too small.
\item[$\epsilon$] $\varepsilon \times f_{min}$,  the concept likes $\varepsilon$.
\end{description}
\newpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}

\section{Literature Review}

\section{Methodology}


\section{Engineering case study : design of a belt-pulley mechanism}

\bibliography{d}
\bibliographystyle{unsrt}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment