我有一个小图形,它是我文档的一部分。它是 PDF,有 193 行,并且有一些二进制数据与它的后记混合。我目前正在使用 graphicsx 包并将 pdf 作为单独的文件包含在内。有没有办法可以直接在我的乳胶源中内联它?
5 回答
这是我设计的解决方案:
pdftops
使用(xpdf包的一部分)将 pdf 转换为 postscript ,- 将 postscript 转换为 ASCII-only,和
- 使用 graphicsx 包和宏嵌入 postscript
\special
。
一个缺点是使用 \special 嵌入 postscript 需要我发出 dvi 而不是 pdf。改进此解决方案以允许直接发出 pdf 会很好。
乳胶源看起来像这样。
\noindent\vbox to 112pt{\vfil\hbox to 248pt{\special{" gsave
currentfile /ASCIIHexDecode filter cvx exec
25 21 50 53 2d 41 64 6f 62 65 2d 33 2e 30 20 45
50 53 46 2d 33 2e 30 0a 25 20 50 72 6f 64 75 63
65 64 20 62 79 20 78 70 64 66 2f 70 64 66 74 6f
70 73 20 33 2e 30 32 0a 25 25 43 72 65 61 74 6f
...
65 72 0a 65 6e 64 0a 25 25 44 6f 63 75 6d 65 6e
74 53 75 70 70 6c 69 65 64 52 65 73 6f 75 72 63
65 73 3a 0a 25 25 45 4f 46 0a
>
grestore
}
\hfil}}
I made a gist at github that provides a complete example.
我认为没有办法在 LaTeX 中内联二进制数据。您可以使用各种包(例如 lpthnc 推荐的 Asymptote)将图形重新创建为矢量类型的图像。如果你真的很聪明,你可以编写一些 TeX 来以数组格式存储数据并重新创建它,但我认为没有一个包可以简单地做到这一点。
你也应该看看pdfpages
包裹。用于在 PDF 文档中包含 PDF 的各种选项。
pdfpages:http ://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf
好的,我认为这可以满足您的需求,但除非您真的需要这样做,否则其他解决方案会更好。
为了能够使用此解决方案,您需要:
-shell-escape
在您的 Latex 命令(命令行选项)中启用 shell 转义。由于安全原因,默认情况下禁用 Shell 转义。- 可以访问您正在编译文件的程序
uuencode
。uudecode
假设您的图形是graphic.png
,而您的主文档是doc.tex
. 首先,编码graphic.png
并附加到末尾(编码后的数据都是文本):
$ cat graphic.png | uuencode graphic.jpg >>doc.tex
然后,确保在将图形包含在之前有这个doc.tex
:
\immediate\write18{cat \jobname.tex | uudecode}
例如,这是我创建的一个文档:
\documentclass{article}
\immediate\write18{cat \jobname.tex | uudecode}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{graphic}
\end{document}
%%% Do not touch the data below, this is added by uuencode.
begin 644 graphic.png
..... (stripped a lot of lines) ...
`
end
然后,这将起作用:
$ pdflatex -shell-escape doc
正如我所说,有更好更好的解决方案,除非你真的必须有一个源文件,否则不要这样做。