我刚刚了解到如何内联 PDF 代码使用\pdfliteral
命令和由METAPOST生成的纯化的Encapsulated PostScript或者purifyeps
可以通过pdfLaTeX转换成PDF代码。
但是,我无法找到通过嵌入转换后的 EPS 所需的实际转换代码\pdfliteral
。
我想要这样的东西:
\documentclass{minimal}
\begin{document}
\begin{purifiedeps}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 33 31
%%HiResBoundingBox: 0 0 32.0781 30.9844
%%Creator: MetaPost 1.803
%%CreationDate: 2014.04.30:1514
%%Pages: 1
%%BeginProlog
%%EndProlog
%%Page: 1 1
0 0 0 setrgbcolor
newpath 28.9375 30.1875 moveto
16.0312 7.76563 lineto
3.14063 30.1875 lineto
2.82813 30.6406 2.23438 30.9844 1.64063 30.9844 curveto
0.84375 30.9844 0 30.3906 0 29.5312 curveto
0 1.5 lineto
0 0.64063 0.73438 0 1.64063 0 curveto
2.57813 0 3.28125 0.64063 3.28125 1.5 curveto
3.28125 23.3594 lineto
7.0625 16.8281 10.7969 10.3125 14.5469 3.78125 curveto
14.7969 3.28125 15.3906 2.98438 16.0312 2.98438 curveto
16.7344 2.98438 17.125 3.39063 17.5312 3.78125 curveto
21.2656 10.3125 25 16.8281 28.7812 23.3594 curveto
28.7812 1.5 lineto
28.7812 0.64063 29.4844 0 30.4375 0 curveto
31.3281 0 32.0781 0.64063 32.0781 1.5 curveto
32.0781 29.4844 lineto
32.0781 30.3281 31.2344 30.9844 30.4375 30.9844 curveto
29.8281 30.9844 29.2344 30.7344 28.9375 30.1875 curveto
closepath fill
showpage
%%EOF
\end{purifiedeps}
\end{document}
其中purifiedeps
环境仍需定义。
EPS 代码产生 METAPOST- M
:
注意:我知道这是可能的,\includegraphics{somepurifiedeps.mps}
但我正在寻找不需要外部文件的内联解决方案。
编辑:我想我已经从 ConTeXt 包中收集了相关部分supp-pdf
:
\def\convertMPtoPDF % #1#2#3%
{\bgroup
\defineMPtoPDFfallbacks
\ifx\pdfdecimaldigits\undefined\else \pdfdecimaldigits=5 \fi % new
\setbox\scratchbox\vbox\bgroup
\xdef\MPheight{0pt}%
\xdef\MPwidth {0pt}%
\forgetall
\offinterlineskip
\startMPresources
\doprocessMPtoPDFfile} %
\def\doprocessMPtoPDFfile#1#2#3% file xscale yscale
{\setMPspecials
\setMPextensions
\the\everyMPtoPDFconversion
\catcode`\^^M=\@@endofline
\startMPscanning
\let\do\empty
\xdef\MPxscale{#2}%
\xdef\MPyscale{#3}%
\xdef\MPxoffset{0}%
\xdef\MPyoffset{0}%
\xdef\MPyshift{0pt}%
\donefalse
\let\handleMPsequence\dohandleMPsequence
\message{[MP to PDF]}% was: [MP to PDF #1] but there is a (#1) anyway
\input#1\relax}
\convertMPtoPDF{test.mps}{0.5}{0.5}
test.mps
将包含按 0.5 倍缩放的纯化 EPS 文件。要构建此命令的内联版本,我需要用包含 EPS 代码定义的宏替换\input#1
它。\doprocessMPtoPDFfile
不幸的是,我不知道如何定义这样的宏,因为我需要保留 EPS 注释(%
)以及换行符。因此,宏定义需要包含逐字(未处理的)EPS 代码。我该怎么做?
答案1
您需要supp-pdf.mkii
,请参阅其注释以了解详情。
困难的部分是将 MPS 文件放入宏(或令牌寄存器)中。宏\savemps
将 MPS 代码保存为宏。需要注意百分号字符,并且应保留行尾。
宏\includemps
非常简单,它调用\convertMPtoPDF
重新定义\input
,通过 e-TeX 将存储在宏中的图像重新读取为文件\scantokens
:
\documentclass{article}
\input{supp-pdf.mkii}
\makeatletter
\newcommand*{\savemps}[1]{%
\begingroup
\@sanitize % verbatim catcodes
\catcode`\ =10 % except space
\catcode`\^^A=14 % new comment char
% keep lines:
\@makeother\^^J% Line feed as character
\endlinechar=`\^^J % end lines with line feed
\savemps@{#1}%
}
\newcommand*{\savemps@}[2]{%
\endgroup
\def#1{#2}%
% catch odd new line
\futurelet\@let@token\savemps@gobbleLF
}
\newcommand*{\savemps@gobbleLF}{%
\ifx\@let@token\includemps@J
\expandafter\@gobble
\fi
}
\begingroup
\lccode`\9=`\^^J %
\lowercase{\endgroup
\let\includemps@J=9%
}
\newcommand*{\includemps}[3]{%
\begingroup
\def\input##1\relax{\scantokens\expandafter{##1}}%
\convertMPtoPDF{#1}{#2}{#3}%
\endgroup
}
\makeatother
\savemps\mympsimage{
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 33 31
%%HiResBoundingBox: 0 0 32.0781 30.9844
%%Creator: MetaPost 1.803
%%CreationDate: 2014.04.30:1514
%%Pages: 1
%%BeginProlog
%%EndProlog
%%Page: 1 1
0 0 0 setrgbcolor
newpath 28.9375 30.1875 moveto
16.0312 7.76563 lineto
3.14063 30.1875 lineto
2.82813 30.6406 2.23438 30.9844 1.64063 30.9844 curveto
0.84375 30.9844 0 30.3906 0 29.5312 curveto
0 1.5 lineto
0 0.64063 0.73438 0 1.64063 0 curveto
2.57813 0 3.28125 0.64063 3.28125 1.5 curveto
3.28125 23.3594 lineto
7.0625 16.8281 10.7969 10.3125 14.5469 3.78125 curveto
14.7969 3.28125 15.3906 2.98438 16.0312 2.98438 curveto
16.7344 2.98438 17.125 3.39063 17.5312 3.78125 curveto
21.2656 10.3125 25 16.8281 28.7812 23.3594 curveto
28.7812 1.5 lineto
28.7812 0.64063 29.4844 0 30.4375 0 curveto
31.3281 0 32.0781 0.64063 32.0781 1.5 curveto
32.0781 29.4844 lineto
32.0781 30.3281 31.2344 30.9844 30.4375 30.9844 curveto
29.8281 30.9844 29.2344 30.7344 28.9375 30.1875 curveto
closepath fill
showpage
%%EOF
}
\begin{document}
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{.1pt}
\fbox{%
\includemps{\mympsimage}{1}{1}%
}
\end{document}