如何在不使用屏幕截图的情况下在 Open Office Org 演示文稿中嵌入源代码或 HTML?

发布于 2024-10-28 23:34:48 字数 1812 浏览 8 评论 0原文

我需要为我的编程课编写很多课程演示文稿,并且经常需要展示源代码(主要是C代码)。

在此处输入图像描述

我找不到简单的方法:

  1. 从以下位置复制我的源代码我的编辑器 (kate) 并将
  2. 其格式化并突出显示源代码粘贴到 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 文本,您可以使用菜单 insertfilertf(或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).

enter image description here

I don't find a easy way to:

  1. Copy my source code from my editor (kate) and
  2. 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 技术交流群。

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

发布评论

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

评论(9

画尸师 2024-11-04 23:34:48

有些人说从 Eclipse 编辑器复制代码效果很好(更新:事实证明FALSE)。另一种选择是从 突出显示,然后在 OpenOffice.org 中打开/粘贴它。 (更新:已证明正确

以下是​​突出显示 GUI 屏幕截图:
Highlight GUI (KDE)

您还可以从 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:
Highlight GUI (KDE)

You can also switch from OpenOffice.org to LibreOffice, and get COOoder from here.

迷爱 2024-11-04 23:34:48

这个答案非常适合这项工作:

This answer is perfect for the job:

冰雪梦之恋 2024-11-04 23:34:48

更新:我已将此宏作为 LibreOffice 扩展发布。您可以从官方网站安装它: 代码荧光笔


我也遇到了同样的问题,但是对于Java,最后我找到了一个使用 Python 宏的本机解决方案,该解决方案在 LibreOffice 5 中进行了测试。

安装

第 1 步: 安装 libreoffice-script-provider-python:

sudo apt-get install libreoffice-script-provider-python

第 2 步: 安装 pygments对于Python 3:

sudo pip3 install python3-pygments

第3步:下载Highlight.py

第4步:将Highlight.py复制到/usr/lib/libreoffice/share/Scripts/python/

sudo cp Highlight.py /usr/lib/libreoffice/share/Scripts/python/

第5步: 设置脚本的只读权限。

sudo chmod 0444 /usr/lib/libreoffice/share/Scripts/python/Highlight.py

第 6 步: 打开 LibreOffice Writer 并转到“工具”->“定制->键盘

  • 选择 LibreOffice 选项按钮(位于左上角)
  • 选择任何所需的快捷方式
  • 在功能类别下选择共享/突出显示/Highlight_source_code
  • 单击“修改”按钮以设置快捷方式

使用

LibreOffice Impress

  • 打开 LibreOffice Impress。
  • 插入文本框(插入 -> 文本框)。
  • 将任何代码片段复制并粘贴到该文本框中。
  • 创建新样式(右键单击现有样式 -> 新建...)
  • 将样式命名为 code-
  • 将样式应用到代码片段文本框。
  • 选择文本框。
  • 使用快捷键来执行宏。

LibreOffice Writer/Calc

  • 打开 LibreOffice Writer/Calc。
  • 插入文本框(插入 -> 文本框)。
  • 将任何代码片段复制并粘贴到该文本框中。
  • 右键单击文本框并选择“说明”。
  • 按以下格式添加说明:code-<语言>
  • 选择文本框
  • 使用快捷键执行宏。

更新:

我已为此扩展添加了自定义样式支持。使用 code- 作为默认样式,使用 code--

例如,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:

sudo apt-get install libreoffice-script-provider-python

Step 2: Install pygments for Python 3:

sudo pip3 install python3-pygments

Step 3: Download Highlight.py

Step 4: Copy the Highlight.py to /usr/lib/libreoffice/share/Scripts/python/

sudo cp Highlight.py /usr/lib/libreoffice/share/Scripts/python/

Step 5: Set the Read-Only permission to the script.

sudo chmod 0444 /usr/lib/libreoffice/share/Scripts/python/Highlight.py

Step 6: Open the LibreOffice Writer and goto Tools -> Customize -> Keyboard

  • Select the LibreOffice option button (Available on top left corner)
  • Select any desired shortcut
  • Select share/Highlight/Highlight_source_code under the Functions Category
  • Click on the Modify button to set the shortcut

Usage

LibreOffice Impress

  • Open LibreOffice Impress.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Create a new Style (Right click on an existing style -> New...)
  • Name the Style as code-<language>
  • Apply the style to your code snippet Text Box.
  • Select the Text Box.
  • Use your shortcut keys to execute the macro.

LibreOffice Writer/Calc

  • Open LibreOffice Writer/Calc.
  • Insert a Text Box (Insert -> Text Box).
  • Copy and paste any code snippet into that Text Box.
  • Right click on the Text Box and select 'Description'.
  • Add a description in the following format: code-<language>
  • Select the Text Box
  • Use your shortcut keys to execute the macro.

UPDATE:

I have added custom style support to this extension. Use code-<language> for default style and code-<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

萌辣 2024-11-04 23:34:48

我有完全相同的问题,但使用 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.

酒几许 2024-11-04 23:34:48

您可以轻松地

  • 从您喜欢的编辑器中复制文本
  • 以留下深刻印象,创建一个新文本字段
  • ,按CTRL + SHIFT + V(或编辑→粘贴内容),
  • 然后选择富文本格式(RTF)

我已经在 Ubuntu 下使用 LibreOffice 4.2.8 进行了测试。

You can do this easily

  • copy the text from you favorite editor
  • go to impress, make a new text field
  • press CTRL + SHIFT + V (or Edit → Paste Contents)
  • and then choose Rich Text Format (RTF).

I have tested this with LibreOffice 4.2.8 under Ubuntu.

下雨或天晴 2024-11-04 23:34:48

如果您熟悉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.

何止钟意 2024-11-04 23:34:48

您可以轻松地使用 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.

千と千尋 2024-11-04 23:34:48

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

柏拉图鍀咏恒 2024-11-04 23:34:48

我一直在 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.

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