安裝瘦身版 LaTeX - 實(shí)現(xiàn) Sphinx 生成 pdf ,并集成 CI/CD 流失線中(Ubuntu)

簡(jiǎn)介

LaTeX 是當(dāng)今世界上最流行和使用最為廣泛的TeX 格式,可以在短短的時(shí)間內(nèi)生成高質(zhì)量的 pdf 文檔。它構(gòu)筑在 Plain TeX 的基礎(chǔ)之上,并加進(jìn)了很多的功能以使得使用者可以更為方便的利用 TeX 的強(qiáng)大功能。

使用 LaTeX,一般需要安裝 TexLive,但TexLive 安裝包太大,有好幾 G,且每個(gè)環(huán)境安裝方式不一樣。為了減少安裝成本以及方便的集成到 CI/CD 環(huán)境中,本文推薦使用 TinyTeX。TinyTeX 是一個(gè)瘦身版的TeX Live,安裝后大概 100M 左右。TinyTeX 是國(guó)內(nèi)大神謝益輝作品,請(qǐng)參考https://yihui.name/tinytex/cn/

Sphinx 是一個(gè)自動(dòng)文檔生成工具,可以自動(dòng)的把 docstring 轉(zhuǎn)換為文檔,并支持多種輸出格式包括 html,pdf 等。

實(shí)現(xiàn) Sphinx 自動(dòng)生成 pdf 步驟

以下是 Ubuntu 實(shí)現(xiàn)步驟,其它系統(tǒng)讀者可以自行實(shí)現(xiàn),原理一樣

安裝 python3

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install -y python3.6

安裝 python 虛擬環(huán)境

sudo apt-get install -y python3-pip
sudo pip3 install virtualenv
virtualenv -p /usr/bin/python3.6 ~/virtualenvs/venv_devopspy
source ~/virtualenvs/venv_devopspy/bin/activate

安裝 git(可選)

apt-get install -y git
git clone git@code.aliyun.com:payun/api-site.git
git checkout "sphinx 文檔"

安裝 sphinx 主題(可選)

pip3 install --index-url https://pypi.tuna.tsinghua.edu.cn/simple/ sphinx jieba
cd sphinx_payun_theme/
python setup.py install
cd ../

安裝瘦身版 TinyteX(關(guān)鍵)

apt-get install -y libfontconfig
wget -qO- "https://yihui.name/gh/tinytex/tools/install-unx.sh" | sh
export PATH=$PATH:~/bin
tlmgr install cmap psnfss fncychap fancyhdr titlesec tabulary varwidth wrapfig parskip capt-of needspace cjk collection-fontsrecommended

編譯

make clean
make html
make latexpdf

總結(jié)

將上訴步驟集成在流水線中,能一鍵生成精美 pdf 文檔。經(jīng)實(shí)測(cè)集成在阿里云流水線中,生成文檔時(shí)間在3分鐘內(nèi),提高了開發(fā)效率。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容