Linux 配置 VS Code Latex環(huán)境

[TOC]

vscode 小巧靈活, 與LaTex結(jié)合起來體驗(yàn)不錯(cuò), 加上git進(jìn)行版本控制,可以方便的管理版本,這樣可以方便多人進(jìn)行協(xié)作,對于批注可以使用latexdiff來進(jìn)行操作

image.png

更改后,保存文件,自動(dòng)在預(yù)覽圖里面顯示。

如果按照步驟一步步進(jìn)行,應(yīng)該不會(huì)出現(xiàn)問題,如果有問題可以直接評論,看到立即回復(fù)。

1、安裝textlive

# 這一步會(huì)安裝比較久,稍等一會(huì)
sudo apt-get install texlive-full cjk-latex latex-cjk-chinese

2、安裝中文

通過使用自定義的字體、中文配置、編碼選項(xiàng)等。使 LaTex 支持中文,當(dāng)然 XeTeX 原生支持中文。這也是個(gè)人優(yōu)先選擇配置 xelatex 環(huán)境的原因。

拷貝 Windows 下字體 C 盤 Windows 路徑下,F(xiàn)onts 文件夾,
(C:\windows\fonts)

存儲(chǔ)全部 Windows 上的字體文件,將其拷貝。

或者直接下載我準(zhǔn)備好的windows字體文件:
鏈接: https://pan.baidu.com/s/1rIU6MwxXQef-HQ9u5Nul8g 提取碼: 1yie

復(fù)制到 Linux 對應(yīng)字體路徑下
** 建立字體存儲(chǔ)文件夾,在Linux字體路徑下**

sudo mkdir /usr/share/fonts/winfonts

復(fù)制到 /usrshare/fonts/winfonts

安裝字體

cd /usr/share/fonts/winfonts
sudo mkfontscale
sudo mkfontdir
刷新字體緩存
sudo fc-cache -vf
# 查看宋體是否安裝
fc-list -vf | grep '宋體'

或者直接復(fù)制字體文件到~/.font/ 目錄下

fc-cache -fv
fc-list -vf | grep '字體'

3、編譯文件

在目錄下創(chuàng)建demo.tex文件,文檔內(nèi)容

\documentclass{article}
\usepackage[a4paper, left=1in, right=1in, top=1in, bottom=1in]{geometry}
\usepackage{xeCJK} %調(diào)用 xeCJK 宏包
\usepackage{listings}
\author{ ice }
\date {2019.01.28}
\setCJKmainfont{WenQuanYi Micro Hei Mono:style=Regular} %設(shè)置 CJK 主字體為 SimSun (宋體)
\title{Latex入門學(xué)習(xí)}
\begin{document}
\maketitle
\begin{center}
\end{center}

\tableofcontents %添加目錄

\tableofcontents 

\begin{abstract}
this is abstract。
\end{abstract}

\section{asf}
你好。

\section{as}
hello world  

% Lorem  \cite{Lutz2017} ipsum dolor sit amet, consectetur adipisicing

% \bibliography{info}
\bibliographystyle{ieeetr}

\end{document}

然后輸入命令

xelatex demo.tex

命令執(zhí)行完畢查看是否有demo.pdf文件生成

4、安裝vscode 插件

如果想集成到vscode,可以在vscode 中安裝
latex-workshop這個(gè)插件

5、配置vscode

打開 vscode 選項(xiàng)配置ctrl+,,在User settings中,加入如下配置內(nèi)容:

  "editor.wordWrap": "on",
  "latex-workshop.latex.tools": [
    {
      "name": "latexmk",
      "command": "latexmk",
      "args": [
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "-pdf",
        "%DOC%"
      ]
    },
    {
      "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%"
      ]
    }
  ],
  "latex-workshop.latex.recipes": [
   {
      "name": "latexmk",
      "tools": [
        "latexmk"
      ]
    },
    {
      "name": "xelatex -> bibtex -> xelatex*2",
      "tools": [
        "xelatex",
        "bibtex",
        "xelatex",
        "xelatex"
      ]
    },
    {
      "name": "xelatex",
      "tools": [
        "xelatex"
      ]
    },
    {
      "name": "pdflatex -> bibtex -> pdflatex*2",
      "tools": [
        "pdflatex",
        "bibtex",
        "pdflatex",
        "pdflatex"
      ]
    }
  ],
  "latex-workshop.view.pdf.viewer": "browser",
  "files.autoSave": "afterDelay"

6、配置latexdiff

latex 工具主要用于訂正,可以方便的顯示出改變內(nèi)容。

latexdiff old.tex new.tex > diff.tex

默認(rèn)latexdiff對git的支持比較弱,如果想對git進(jìn)行集成使用,可以安裝:git-latexdiff

如果提示安裝失敗,可以嘗試安裝

sudo apt install asciidoc

默認(rèn)gitlatexdiff 想支持中文可以嘗試如下的命令:

# 比較上一個(gè)版本的變化
git latexdiff --xelatex --quiet --main demo.tex HEAD~1
# 對比兩個(gè)版本中的變化8486ea3為老版本,cc306a6為新版本
git latexdiff --xelatex --quiet --main demo.tex 8486ea3 cc306a6

7、支持代碼

如果想要在latex里支持代碼,可以嘗試如下的方式

\lstset{
    columns=fixed,       
    numbers=left,                                        % 在左側(cè)顯示行號(hào)
    frame=none,                                          % 不顯示背景邊框
    backgroundcolor=\color[RGB]{245,245,244},            % 設(shè)定背景顏色
    keywordstyle=\color[RGB]{40,40,255},                 % 設(shè)定關(guān)鍵字顏色
    numberstyle=\footnotesize\color{darkgray},           % 設(shè)定行號(hào)格式
    commentstyle=\it\color[RGB]{0,96,96},                % 設(shè)置代碼注釋的格式
    stringstyle=\rmfamily\slshape\color[RGB]{128,0,0},   % 設(shè)置字符串格式
    showstringspaces=false,                              % 不顯示字符串中的空格
    language=bash,                                        % 設(shè)置語言
}

\begin{lstlisting}
    # 8486ea3為老版本,cc306a6為新版本,此命令會(huì)自動(dòng)創(chuàng)建對比版本,
    # 如果有安裝pdf閱讀器,則會(huì)自動(dòng)用pdf閱讀器打開
    git latexdiff --xelatex --quiet --main demo.tex 8486ea3 cc306a6
\end{lstlisting}

8、添加參考文獻(xiàn)

plain,按字母的順序排列,比較次序?yàn)樽髡?、年度和?biāo)題.

unsrt,樣式同plain,只是按照引用的先后排序.

alpha,用作者名首字母+年份后兩位作標(biāo)號(hào),以字母順序排序.

abbrv,類似plain,將月份全拼改為縮寫,更顯緊湊.

ieeetr,國際電氣電子工程師協(xié)會(huì)期刊樣式.acm,美國計(jì)算機(jī)學(xué)會(huì)期刊樣式.

siam,美國工業(yè)和應(yīng)用數(shù)學(xué)學(xué)會(huì)期刊樣式.

apalike,美國心理學(xué)學(xué)會(huì)期刊樣式.

首先在文件夾下添加info.lib

內(nèi)容如下:

@Article{GraffZivin2018,
    author  = {Graff Zivin, Joshua and Hsiang, Solomon M and Neidell, Matthew},
    title   = {Temperature and Human Capital in the Short and Long Run},
    journal = {Journal of the Association of Environmental and Resource Economists},
    year    = {2018},
    volume  = {5},
    number  = {1},
    pages   = {77-105},
    issn    = {2333-5955},
    type    = {Journal Article},
}

@Book{Lutz2017,
    title     = {World Population \& Human Capital in the Twenty-First Century: An Overview},
    publisher = {Oxford University Press},
    year      = {2017},
    author    = {Lutz, Wolfgang and Butz, William P and Samir, KC ed},
    isbn      = {0192542834},
    type      = {Book},
}

@Article{Zeng2017,
    author  = {Zeng, X. and Liu, L. and Leung, S. and Du, J. and Wang, X. and Li, T.},
    title   = {A decision support model for investment on P2P lending platform},
    journal = {PLoS One},
    year    = {2017},
    volume  = {12},
    number  = {9},
    pages   = {e0184242},
    issn    = {1932-6203 (Electronic)
            1932-6203 (Linking)},
    doi     = {10.1371/journal.pone.0184242},
    type    = {Journal Article},
    url     = {https://www.ncbi.nlm.nih.gov/pubmed/28877234},
}

可以將如下的代碼放在\end{document}之前

通過\cite就可以直接使用文獻(xiàn)了。

這個(gè)是文獻(xiàn)\cite{Lutz2017}.
\bibliography{info}
\bibliographystyle{ieeetr}

效果如下圖所示:

image.png

參考文章:

http://ctan.mirror.rafal.ca/info/lshort/english/lshort.pdf

其他文章:

Fish Shell使用心得
Deepin系統(tǒng)的初步使用

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

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

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