7. 一步到位

本章在 腳本詳解 的基礎上,講解怎樣把命令合併到一個腳本中從而簡化 documentclass 的配置。

腳本詳解 中可以看出,本教程爲了方便排錯,而把命令分到多個腳本之中,逐個擊破,但其實完全是可以把命令全部寫入單個腳本之中,而實現簡化 documentclass 的設置的。

本章將會提供這麼做的範例。

7.1. 一步轉換成SVG

本小結將使用 util 文件夾中之 qk_pdf_to_svg.bat 腳本,以 mwe 文件夾中的 qk_to_svg.tex 爲例,展示如何一步轉換到SVG。

qk_to_svg.tex 中的 documentclass 的配置如下:

1
2
3
4
5
6
\documentclass[tikz, convert, convert={outext=.svg, command=\unexpanded{
% 'out_svg'是用来存放SVG的文件夹
% 'out_svg'是用來存放SVG的文件夾
% 'out_svg' is the destination folder for SVG files
call ../util/qk_pdf_to_svg out_svg \infile\space \outfile\space
}}]{standalone}

其中, out_svg 是存放SVG的文件夾。

qk_pdf_svg.bat 腳本的內容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@echo off

set dst_dir=%1
set inputfile=%2
set outputfile=%3

if not exist %dst_dir%/NUL mkdir %dst_dir%

cd /d %dst_dir%

pdf2svg ../%inputfile% %outputfile% all

qk_pdf_to_svg.bat 中的命令,是把 demo_to_svg.tex 中的 documentclass 中的命令整合爲一,以達到簡化 documentclass 的配置的目的。

7.2. 一步轉換成PNG

本小結將使用 util 文件夾中之 qk_pdf_to_png.bat 腳本,以 mwe 文件夾中的 qk_to_png.tex 爲例,展示如何一步轉換到PNG 。

qk_to_png.tex 中的 documentclass 的配置如下:

1
2
3
4
5
6
\documentclass[tikz, convert, convert={outext=.svg, command=\unexpanded{
% 'out_png'是用来存放PNG的文件夹
% 'out_png'是用來存放PNG的文件夾
% 'out_png' is the destination folder for PNG files
call ../util/qk_pdf_to_png out_png 600 \infile\space
}}]{standalone}

其中, out_png 是存放PNG的文件夾。

qk_pdf_to_png.bat 腳本的內容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@echo off

set dst_dir=%1
set dpi=%2
set intputfile=%3

if not exist %dst_dir%/NUL mkdir %dst_dir%

cd /d %dst_dir%

pdftocairo -r  %dpi% -png ../%intputfile%

qk_pdf_to_png.bat 中的命令,是把 demo_to_png.tex 中的 documentclass 中的命令整合爲一,以達到簡化 documentclass 的配置的目的。

7.3. 一步轉換成EMF

本小結將使用 util 文件夾中之 qk_pdf_to_emf.bat 腳本,以 mwe 文件夾中的 qk_to_emf.tex 爲例,展示如何一步轉換到EMF。

qk_to_emf.tex 中的 documentclass 的配置如下:

1
2
3
4
5
6
7
\documentclass[tikz, convert, convert={outext=.pdf,
command=\unexpanded{
% 'out_emf'是用来存放EMF的文件夹
% 'out_emf'是用來存放EMF的文件夾
% 'out_emf' is the destination folder for EMF files
call ../util/qk_pdf_to_emf out_emf \outfile\space \infile\space
}}]{standalone}

其中, out_emf 是存放EMF的文件夾。

qk_pdf_to_emf.bat 腳本的內容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
@echo off

set dst_dir=%1
set outputfile=%2
set intputfile=%3

if not exist %dst_dir%/NUL mkdir %dst_dir%

gswin64c -sDEVICE=pdfwrite -dSAFER -dNOPAUSE -dBATCH -sOutputFile=%dst_dir%/%outputfile% %intputfile%

cd /d %dst_dir%

for /r %%i in (*.pdf) do inkscape %%i -M %%~pni.emf

del /F *.pdf

qk_pdf_to_emf.bat 中的命令,是把 demo_to_emf.tex 中的 documentclass 中的命令整合爲一,以達到簡化 documentclass 的配置的目的。

7.4. 一步轉換成EPS

本小結將使用 util 文件夾中之 qk_pdf_to_eps.bat 腳本,以 mwe 文件夾中的 qk_to_eps.tex 爲例,展示如何一步轉換到EPS。

qk_to_eps.tex 中的 documentclass 的配置如下:

1
2
3
4
5
6
7
\documentclass[tikz, convert, convert={outext=.pdf,
command=\unexpanded{
% 'out_eps'是用来存放EPS的文件夹
% 'out_eps'是用來存放EPS的文件夾
% 'out_eps' is the destination folder for EPS files
call ../util/qk_pdf_to_eps out_eps \outfile\space \infile\space
}}]{standalone}

其中, out_eps 是存放EPS的文件夾。

qk_pdf_to_eps.bat 腳本的內容如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
@echo off

set dst_dir=%1
set outputfile=%2
set intputfile=%3

if not exist %dst_dir%/NUL mkdir %dst_dir%

gswin64c -sDEVICE=pdfwrite -dSAFER -dNOPAUSE -dBATCH -sOutputFile=%dst_dir%/%outputfile% %intputfile%

cd /d %dst_dir%

for /r %%i in (*.pdf) do inkscape %%i -E %%~pni.eps

del /F *.pdf

qk_pdf_to_eps.bat 中的命令,是把 demo_to_eps.tex 中的 documentclass 中的命令整合爲一,以達到簡化 documentclass 的配置的目的。