4. LaTex standalone
包的配置¶
本教程是基於由 Martin Scharrer
開發的
standalone
包(自帶 standalone
類),故此於此對此包稍作講解。
備註
standalone
(complex) [1]
standalone
是LaTex中非常有用的一個包。本教程主要講述怎樣利用此包來進行圖片的轉換,但此包其實還有其它相當多的應用。 Overleaf 上有一個非常有用的教程。
4.1. standalone
的轉換命令配置¶
standalone
本身的 說明文檔 已經對配置有詳盡的說明,此處重點說一下轉換成圖片需要用到的 convert
選項。
配置 convert
需要在 documentclass
中進行。以下是一個利用 pdf2svg
轉換為SVG的範例配置。
1 2 3 | \documentclass[tikz, convert, convert={outext=.svg, command=\unexpanded{
pdf2svg \infile\space \outfile\space all
}}]{standalone}
|
其中,
tikz
此選項告訴
standalone
LaTex文檔中存在tikz
圖片。
convert
此選項開啟
standalone
的轉換功能。
convert={}
此選項是
convert
的詳細配置項。
outext=.svg
設置輸出文件的後綴名為“.svg”。更詳細的說明請參看
standalone
本身的 說明文檔 中的表1。
command=\unexpanded{}
此項是將要調用系統運行的命令。
pdf2svg
調用的轉換工具。
備註
pdf2svg
的語法pdf2svg
的語法可以參看 這裡。其中,將一多頁PDF轉換為分頁的多個SVG的語法為:
pdf2svg <輸入文件名>.pdf <輸出文件名>%d.svg all
注意,尖括號,及其所包裹中的內容需要替換為所需的文件名。
\infile
輸入文件名,包含後綴名。默認後綴名為“.pdf”或“.ps”。 更詳細的說明請參看
standalone
本身的 說明文檔 中的表1。
\space
空格。若不使用此參數,
\infile
後不會有空格,無論你實際上鍵入了多少個。\outfile
也是這樣。
\outfile
輸出文件名,包含後綴名。默認後綴名為“.png”。此處已經通過
outext
更改為“.svg”。更詳細的說明請參看standalone
本身的 說明文檔 中的表1。
SVG配置範例中之命令將會被翻譯為如下(可以通過查看LOG文件確認)。其中,
mew_to_svg
為所用的TEX文件的文件名。
1 | pdf2svg mwe_to_svg.pdf mwe_to_svg-%01d.svg all
|
由此可以看出,轉換的重點,是要把 convert={}
中的配置正確設置,以令LaTex將其翻譯成正確的系統命令來進行圖片的轉換。用戶可以把多個系統命令整合為一行,以做出豐富多彩的組合來達成不同的目標(在Windows中可以通過“&”或“&&”把多行命令合併為一行)。在 轉換流程 中將會詳細敘述各種圖片轉換的流程。
備註
運行系統命令
其實在本小結就可以看出,既然 standalone
可以調用以上的命令,那當然也可以調用其它系統命令。理論上,用戶可以調用各種命令來做各種事,不僅僅是圖片的轉換。如果你有興趣,應該可以做到編譯完後自動上傳到某個網絡位置,或者刪除整個硬盤這一類有趣的事情。
4.2. 編譯命令¶
standalone
需要在編譯時使用 -shell-escape
參數。一個使用 xelatex
對 mew_to_svg.tex
進行編譯的命令如下(用 xelatex
是因為需要處理中文)。如果你使用LaTex編輯器進行書寫,比如 TEXsutdio
,則需要在其中編輯其命令。你也當然可以直接在TEX文件所在之目錄下打開CMD,用命令直接編譯。
1 | xelatex -synctex=1 -interaction=nonstopmode -shell-escape mwe_to_svg.tex
|
4.3. 簡例¶
以下提供一個轉換為單頁多個SVG的簡例。詳細的例子會在後文說明。
以下的文件可以在此項目的根目錄和 mew
文件夾中找到。
主文件:
mew
文件夾中的 mwe_to_svg.tex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | % 这是一个将tikz图片转换成多张SVG的示例文件,使用pdf2svg来实现转换
% 這是一個將tikz圖片轉換成多張SVG的示例文件,使用pdf2svg來實現轉換
% This is a demo file for tikz to multiple SVGs using pdf2svg
\documentclass[tikz, convert, convert={outext=.svg, command=\unexpanded{
pdf2svg \infile\space \outfile\space all
}}]{standalone}
\usepackage{xeCJK}
\setCJKmainfont{Microsoft YaHei}
\usepackage{scalefnt}
\usepackage{tikz}
% tikz和colour的设定
% tikz和colour的設定
% tikz and colour configs
\input{../configs_tikz.tex}
\input{../configs_colour.tex}
\begin{document}
% 全局字体缩放
% 全局字體縮放
% global font scale
\scalefont{1.3}
% tikz图像文档
% tikz圖像文檔
% tikz pics file
\input{../tikz_pics.tex}
\end{document}
|
tikz配置文件:
本教程根目錄中的 configs_tikz.tex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | % 以下是关于tikz中画流程图的设置
% 以下是關於tikz中畫流程圖的設置
% configure flowchart shapes
\usetikzlibrary{shapes.geometric, arrows, positioning, calc}
% start, end shape
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm,
minimum height=1cm,text centered, text=white, draw=black,
fill=colorStarstop]
% process shape
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm,
text centered, text=white, draw=black, fill=colorPro]
% decision shape
\tikzstyle{decision}=[diamond, minimum width=3cm, minimum height=1cm,
text centered, draw=black, fill=colorDec]
% comment shape
\tikzstyle{comment}=[dashed, draw=black, fill=gray!10, minimum width=3cm, minimum height=1cm, text centered]
% docstring shape
\tikzstyle{docstring}=[draw=orange, fill=white, minimum width=50mm, text width=80mm, minimum height=1cm]
% arrows shape
\tikzstyle{arrow} = [ultra thick,->,>=stealth, line width=1.5mm]
% comment shape
\tikzstyle{comment}=[dashed, draw=black, fill=gray!10, minimum width=3cm, minimum height=1cm, text centered]
\tikzset{
subprocess/.style = {rectangle, draw=black, semithick, fill=orange!30,
minimum width=#1, minimum height=1cm, inner xsep=3mm, % <-- changed
text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep},
align=flush center,
path picture={\draw
([xshift =2mm] \ppbb.north west) -- ([xshift= 2mm] \ppbb.south west)
([xshift=-2mm] \ppbb.north east) -- ([xshift=-2mm] \ppbb.south east);
},
},
subprocess/.default = 24mm % <-- added
}% end of tikzset
\usetikzlibrary{positioning}
|
color配置文件:
本教程根目錄中的 configs_colour.tex
1 2 3 4 5 6 7 8 9 | % 以下是颜色的设置
% 以下是顏色的設置
% colour defs
\usepackage{color}
\definecolor{colorStarstop}{RGB}{174, 23, 21}
\definecolor{colorPro}{RGB}{0, 175, 121}
\definecolor{colorDec}{RGB}{255, 192, 0}
\definecolor{colorYes}{RGB}{51, 153, 51}
\definecolor{colorNo}{RGB}{255, 0, 0}
|
[1] | Ghost In Shell : Standalone Complex |