I'd like to include inline images in my org-mode documents, but I really need a png for HTML export and a pdf for LaTeX export for it to look decent. Is there a way to express this?
我想在我的组织模式文档中包含内联图像,但我真的需要一个用于HTML导出的png和用于LaTeX导出的pdf,这样它才会看起来不错。有什么表达方式吗?
更多回答
优秀答案推荐
I got an answer in irc that worked well for me.
我在irc得到了一个对我很有效的答案。
#+ATTR_LaTeX: width=0.38\textwidth wrap placement={r}{0.4\textwidth}
#+ATTR_HTML: alt="old index mech" title="Old index mech" align="right"
#+begin_src emacs-lisp :exports results :results value raw
(case (and (boundp 'backend) backend)
(nil "")
(latex "[[file:img/indexing-old.pdf]]")
(html "[[file:img/indexing-old.png]]"))
#+end_src
This selects the link based on the backend at export time while still giving me HTML and LaTeX attributes. Seems pretty straightforward.
这将在导出时基于后端选择链接,同时仍然为我提供HTML和LaTeX属性。看起来很简单。
The elisp code below with conditionals works for me without any additional settings. When exporting to html, it exports an interactive iframe as an image. When exporting to odt or docx via pandoc, it exports a png version of it.
下面带有条件语句的elisp代码在没有任何额外设置的情况下对我有效。当导出到html时,它将交互式iframe导出为图像。当通过pandoc导出到odt或docx时,它会导出它的png版本。
#+BEGIN_SRC emacs-lisp :exports results :results raw
(cond
((org-export-derived-backend-p org-export-current-backend 'html)
"#+HTML: <iframe src='./media/image.html' width='100%' height='400px' frameborder='0'></iframe>")
((org-export-derived-backend-p org-export-current-backend 'odt)
"[[file:./media/image.png]]")
(t "[[file:./media/image.png]]"))
#+END_SRC
If you want to keep the org export caption and cross-referencing functionality, you can add a dummy image (small transparent png):
如果你想保留组织导出标题和交叉引用功能,你可以添加一个伪图像(小透明png):
#+CAPTION: Legend of image.
#+NAME: fig:image
[[./media/dummy.png]]
#+BEGIN_SRC emacs-lisp :exports results :results raw
(cond
((org-export-derived-backend-p org-export-current-backend 'html)
"#+HTML: <iframe src='./media/image.html' width='100%' height='400px' frameborder='0'></iframe>")
((org-export-derived-backend-p org-export-current-backend 'odt)
"[[file:./media/image.png]]")
(t "[[file:./media/image.png]]"))
#+END_SRC
更多回答
Does it require additional setting? For me, this only prints « nil » in the exported documents.
是否需要额外设置?对我来说,这只会在导出的文档中打印“nil”。
我是一名优秀的程序员,十分优秀!