如何在不使用屏幕截图的情况下在 Open Office Org 演示文稿中嵌入源代码或 HTML?
我需要为我的编程课编写很多课程演示文稿,并且经常需要展示源代码(主要是C代码)。
我找不到简单的方法:
- 从以下位置复制我的源代码我的编辑器 (kate) 并将
- 其格式化并突出显示源代码粘贴到 Open Office 演示文稿 (OOP)。
如果代码很小,我用来做的是快照,或者如果代码太大,则停止演示并在数据显示中打开 Kate。
在此其他问题中,一些建议嵌入HTML 代码。因此,我安装了QSource-Highlight,它可以轻松将 C 代码转换为 HTML(还有 gnu source-highlight、code2html 等)。他们都无法将源代码转换为突出显示的 RTF(富文本格式)版本,这将是另一种方法。
拥有 HTML 并没有帮助,因为我也找不到将 HTML 插入演示文稿的简单方法。该网站展示了一个非常巧妙的 Windows 解决方案。它需要使用特定的 Windows 程序将 C 代码转换为 HTML,该程序可以选择将 HTML 复制为 RTF,然后您需要将 RTF 复制到 Word 或 Wordpad 中,然后将 RTF 复制到 PowerPoint。一切都很好,但我是一个 linux 用户,我认为可能有更好的方法。
另外,还有另一种可能的解决方案,即为 openoffice 安装 coooder 扩展。我不知道为什么,但尝试在我的系统中安装此扩展会出现错误。 Synaptic 告诉我 openoffice.org-core 和许多其他内容应该被标记。我单击“下一步”,它告诉我它想要删除所有软件包,并且 coooder 需要这些软件包才能工作,因此不会安装它。嗯...
我正在使用 linux UBUNTU 10.04 和 Open Office 3.2
谢谢! 贝科。
附: 这个问题在 meta-so 中进行了争论,因为该问题可能重复上面引用过。但据我了解,旧问题并不能解决这个特定问题。
PPS.:关于 coooder 错误,我发布了错误报告 此处
编辑 (2015-08-19)
要在 LibreOffice 演示文稿中插入 RTF 文本,您可以使用菜单 insert
、file
和 rtf
(或HTML
)。
I need to write a lot of class courses presentations to my programming class, and I constantly need to show source code (mainly C code).
I don't find a easy way to:
- Copy my source code from my editor (kate) and
- Paste it formated and with source highlighted to an Open Office Presentation (OOP).
What I use to do is a snapshot if the code is small, or to stop presentation and open Kate in the datashow if it is too big.
In this other question some suggest to embed HTML code. So I installed QSource-Highlight that easily convert C code to HTML (also gnu source-highlight, code2html, and so on). None of them can convert source code to a version of a highlighted RTF (rich text format), that would be another way to go.
Having HTML doesn't help, because I can't find a easy way to insert HTML into a presentation either. This site show a very trick windows solution. It needs to convert c code to HTML using an specific windows program that has an option to copy the HTML as RTF, after that you need to past the RTF in Word or Wordpad, and after that you special past RTF to PowerPoint. All good, but I'm a linux user, and I think there might be a better way.
Also, there is another possible solution, installing coooder extension to openoffice. I don't know why, but trying to install this extension in my system gives me an error. Synaptic tell's me that openoffice.org-core and a lot of other should be marked. I click next, and it tells me it wants to remove all the packages, and that coooder needs this packages to work, and so it is not going to be installed. Well...
I'm using linux UBUNTU 10.04, and Open Office 3.2
Thanks!
Beco.
PS.:
This question is debated in meta-so as possible duplication of the question cited above. But it is my understanding that the older question doesn't solve this specific problem.
PPS.: About the coooder bug, I've launched a bug report here
Edit (2015-08-19)
To insert a RTF text to presentation LibreOffice you can use menu insert
, file
, and rtf
(or HTML
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
有些人说从 Eclipse 编辑器复制代码效果很好(更新:事实证明FALSE)。另一种选择是从 突出显示,然后在 OpenOffice.org 中打开/粘贴它。 (更新:已证明正确)
以下是突出显示 GUI 屏幕截图:
您还可以从 OpenOffice.org 切换到 LibreOffice,并从 此处。
Some people says that copying code from Eclipse editor works well (UPDATE: Proven FALSE). Another alternative is exporting to RTF (can also export line numbers), or to clipboard, from Highlight and then opening/pasting it in OpenOffice.org. (UPDATE: Proven TRUE)
Here is a Highlight GUI screen shot:
You can also switch from OpenOffice.org to LibreOffice, and get COOoder from here.
这个答案非常适合这项工作:
This answer is perfect for the job:
更新:我已将此宏作为 LibreOffice 扩展发布。您可以从官方网站安装它: 代码荧光笔
我也遇到了同样的问题,但是对于Java,最后我找到了一个使用 Python 宏的本机解决方案,该解决方案在 LibreOffice 5 中进行了测试。
安装
第 1 步: 安装 libreoffice-script-provider-python:
第 2 步: 安装 pygments对于Python 3:
第3步:下载Highlight.py
第4步:将Highlight.py复制到/usr/lib/libreoffice/share/Scripts/python/
第5步: 设置脚本的只读权限。
第 6 步: 打开 LibreOffice Writer 并转到“工具”->“定制->键盘
使用
LibreOffice Impress
code-
LibreOffice Writer/Calc
code-<语言>
更新:
我已为此扩展添加了自定义样式支持。使用
code-
作为默认样式,使用code--
作为自定义样式。我的 Git Hub 页面中列出了可用的样式。
例如,
Code-Java-Emacs
将使用 Emacs 风格对 Java 代码进行着色。有关更多详细信息,请访问 Git Hub 链接:libreoffice-code-highlighter
Update: I have released this macro as a LibreOffice extension. You can install it from the official site: Code Highlighter
I had the same problem but for Java and finally I found a native solution using Python macro which is tested in LibreOffice 5.
Installation
Step 1: Install libreoffice-script-provider-python:
Step 2: Install pygments for Python 3:
Step 3: Download Highlight.py
Step 4: Copy the Highlight.py to /usr/lib/libreoffice/share/Scripts/python/
Step 5: Set the Read-Only permission to the script.
Step 6: Open the LibreOffice Writer and goto Tools -> Customize -> Keyboard
Usage
LibreOffice Impress
code-<language>
LibreOffice Writer/Calc
code-<language>
UPDATE:
I have added custom style support to this extension. Use
code-<language>
for default style andcode-<language>-<style>
for custom style. Available styles are listed in my Git Hub page.For example
Code-Java-Emacs
will colorize the Java code using Emacs style.For more details, visit to the Git Hub link: libreoffice-code-highlighter
我有完全相同的问题,但使用 PHP 代码而不是 C。我的几乎解决方案是将代码复制为 Kate 中的 HTML 并将其粘贴到临时 Open Office Writer 文档中。这会将其转换为 Open Office 自己的样式文本格式,然后您可以将其复制并粘贴到 Impress 中。除了有点烦人的双步复制粘贴之外,这基本上工作正常除了,完全粗体的行失去了勇气,我必须手动修复它们。其他一些奇怪的错误也可能发生 - Impress 从 OOWriter 导入样式文本似乎有点错误。
I have exactly the same problem, but with PHP code rather than C. My almost-solution is to copy the code as HTML in Kate and paste it into a temporary Open Office Writer document. That converts it to Open Office's own styled text format, and from there you can copy and paste it into Impress. Aside from the slightly annoying double-step copy-and-paste, this mostly works fine except that lines that were entirely in bold lose their emboldening and I have to manually fix them. A few other strange bugs can occur too - Impress's import of styled text from OOWriter appears to be a bit buggy.
您可以轻松地
我已经在 Ubuntu 下使用 LibreOffice 4.2.8 进行了测试。
You can do this easily
I have tested this with LibreOffice 4.2.8 under Ubuntu.
如果您熟悉LaTeX,则应该考虑使用beamer创建您的演示文稿。 wikipedia 页面 包含许多教程和文档的指针。 用户指南可能是我最好的指南已经找到了。
这可以为您提供 LaTeX 源代码片段(列表包或您喜欢的任何其他包)的所有功能以及您习惯的 LaTeX 的其余常用功能。它捆绑了许多非常好的主题。
If you are familiar with LaTeX, you should consider using beamer to create your presentation. The wikipedia page has pointers to many tutorials and documents. The user guide is probably the best one I've found.
This can give you all the power of LaTeX for source code snippets (listings package or any other you prefer) along with the rest of the usual features of LaTeX that you're used to. It comes bundled with a score of really nice themes.
您可以轻松地使用 1 行 1 列的表格,从您喜欢的 IDE 复制并粘贴您的代码,开放式办公室将保留您的代码风格。
You can easly use a table with 1 line and 1 column, copy and past your code from your favorit IDE, open office will preserve your code style.
从 Eclipse 直接粘贴到 OpenOffice Impress 似乎失去了色彩。
然而,首先粘贴到 OO Writer 中,然后再粘贴到 OO Impress 中是可行的。
Pasting from Eclipse into OpenOffice Impress directly seems to lose the coloring.
However, first pasting into OO Writer and from there into OO Impress does work.
我一直在 Windows 下使用带有源代码的开放式 Office 来执行此操作。在您最喜欢的编辑器(emacs、记事本等)中查看代码,然后选择/复制感兴趣的文本。在打开的office中制作一个文本框,然后粘贴。这是可行的,因为所有 Windows 工具共享一个全局剪切缓冲区。我对Linux的使用还不够多,不知道它是否有这样的共享剪切缓冲区,如果没有,我有点理解你的问题。(如果有,我真的不明白你的问题)。当然,我的解决方案本身并不能获得格式良好/突出显示的代码。
具体步骤:
在打开幻灯片的“Open Office Impress”(“演示文稿”)中,单击下部工具栏上标有“T”的框(或按 F2)。然后在幻灯片上大致单击所需文本的位置,然后拖动以使框大小合适。单击框中,您可以输入文本。对于代码,我从某个编辑器窗口中剪切,然后在选择文本框后粘贴。如果单击文本框的轮廓,则可以更改字体(courier new 对于代码有好处)和打印尺寸。
获得正确大小的文本后,您可以重新访问特定的子字符串,如果您想要精美的文本,请选择/粗体或选择/颜色。
您可以考虑从 JavaDoc 或 Doxygen 输出中剪切和粘贴;您可能会随文本一起获得格式数据。
I do this all the time with open office with source code under Windows. View the code in your favorite editor (emacs, notepad, ...), and select/copy the text of interest. Make a text box in open office, and paste. This works because all of Windows tools share a global cut buffer. I don't use Linux enough to know if it has such a shared cut-buffer, if it doesn't, I kind of understand your problem.( If it does, I really don't understand your problem). My solution of course doesn't get nicely formatted/highlighted code by itself.
Specific steps:
In Open Office Impress ("Presentation") with a slide open, click the box labelled "T" on the lower tool bar (or push F2). Then click on the slide roughly where you want the the text, and drag to make the box about the right size. Click in box and you can enter text. For code, I cut from some editor window, and paste after selecting the text box. If you click on the outline of the text box, you can change the font (courier new is good for code) and print size.
After you get the text sized right, you can revisit specific substrings, and select/bold or select/color if you want fancy text.
You might consider cutting and pasting from JavaDoc or Doxygen output; you are likely to get the formatting data along with the text.