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 的配置的目的。