如何在 Latex 文档源中放置一个小图形?

发布于 2024-08-15 05:43:13 字数 108 浏览 9 评论 0原文

我的文档中有一个小图形。它是 PDF 格式,有 193 行,附言中混有一些二进制数据。我目前正在使用 Graphicx 包并将 pdf 作为单独的文件包含在内。有没有办法可以将它直接内联到我的乳胶源中?

I have a small graphic that is part of my document. It's PDF, is 193 lines, and has some binary data mixed with its postscript. I'm currently using the graphicx package and including the pdf as a separate file. Is there a way I can inline it directly in my latex source?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半仙 2024-08-22 05:43:13

这是我设计的一个解决方案:

  1. 使用 pdftops 将 pdf 转换为 postscript (xpdf 的一部分 包),
  2. 将 postscript 转换为纯 ASCII ,并
  3. 使用 Graphicx 包和 \special 宏嵌入 postscript。

一个缺点是使用 \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}}

我在 github 上做了一个 gist ,提供了一个完整的示例。

Here's a solution I devised:

  1. convert the pdf to postscript using pdftops (part of the xpdf package),
  2. convert the postscript to ASCII-only, and
  3. embed the postscript using the graphicx package and the \special macro.

A drawback is that embedding postscript using \special requires me to emit dvi instead of pdf. It would be nice to improve this solution to allow pdf to be emitted directly.

The latex source will look something like this.

\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.

彩虹直至黑白 2024-08-22 05:43:13

我认为没有办法在 LaTeX 中内联二进制数据。您可以使用各种软件包(例如 lpthnc 推荐的 Asymptote)将图形重新创建为矢量类型图像。如果你真的很聪明,你可以编写一些 TeX 来以数组格式存储数据并重新创建它,但我不认为有一个包可以简单地做到这一点。

I don't think there is a way to inline binary data in LaTeX. You could recreate graphics as vector type images with various packages (such as Asymptote recommended by lpthnc). If you're really clever you could write some TeX to store the data in array format and recreate it, but I don't think there's a package to do it simply.

2024-08-22 05:43:13

您还应该查看 pdfpages 包。在 PDF 文档中包含 PDF 的各种选项。

pdfpages: http://www.ctan.org/ tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf

you should also take a look at the pdfpages package. all kinds of options for including PDFs in your PDF document.

pdfpages: http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages/pdfpages.pdf

合约呢 2024-08-22 05:43:13

好的,我认为这符合您的要求,但除非您确实需要做这样的事情,否则其他解决方案会更好。

为了能够使用此解决方案,您需要:

  • 在 Latex 命令中启用 shell 转义(-shell-escape 命令行选项)。出于安全原因,默认情况下禁用 Shell 转义。
  • 可以访问正在编译文件的 uuencodeuudecode 程序。

假设您的图形是 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

正如我所说,有更好更好的解决方案,除非您确实必须有一个源文件,否则不要做这个。

OK, I think this does what you want, but unless you really need to do something like this, other solutions are better.

To be able to use this solution, you need to:

  • enable shell escape in your Latex command (-shell-escape command line option). Shell escape is disabled by default because of security reasons.
  • have access to uuencode and uudecode programs where you're compiling the file.

Let's say your graphic is graphic.png, and your main document is doc.tex. First, encode graphic.png and append it to the end (the encoded data is all text):

$ cat graphic.png | uuencode graphic.jpg >>doc.tex

Then, make sure you have this before you include the graphic in doc.tex:

\immediate\write18{cat \jobname.tex | uudecode}

For example, here's a document I created:

\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

Then, this will work:

$ pdflatex -shell-escape doc

As I said, there are much nicer and better solutions, and unless you really have to have one source file, don't do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文