52

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

Community
  • 1
  • 1
DrBeco
  • 11,237
  • 9
  • 59
  • 76
  • There are a bunch of tools that make it easy to create presentations which are specific to programming (code snippets etc.) but as far as I know, none are WYSIWYG. Would you consider any of those? – Noufal Ibrahim Apr 08 '11 at 14:22
  • Dear @Noufal, I could accept such an answer if the question proves unfruitful with a WYSIWYG tool, yes, thank you. I'm familiar with LaTeX as a book tool (I've written my phd thesis using it, so I'm ok with that), but I know very little about it when related to presentations. – DrBeco Apr 08 '11 at 16:30
  • @Ira thanks for helping. May be too basic, but: how do you make a text box? I only know when creating a new slide with a template that already has one (right side pane). Is it the same? Thanks – DrBeco Apr 10 '11 at 06:08
  • I converted my comments into an official answer. – Ira Baxter Apr 11 '11 at 00:33
  • Is it just me, or is all the bolding in this question hard on the eyes? – allyourcode Apr 06 '13 at 00:37
  • odpdown is awesome and makes this trivial: https://github.com/thorstenb/odpdown – Sweetshark Nov 28 '15 at 12:51

9 Answers9

33

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.

Francisco Alvarado
  • 2,815
  • 2
  • 26
  • 51
  • Thanks @nihcap. I'll give it a try. About the first option, how does it works? Just copy/paste, plain and simple? Paste to a text-box? And the second option, opening RTF with OOO will open ooo-writer or ooo-presentation? Thanks for your time here! – DrBeco Apr 13 '11 at 06:36
  • With eclipse people says that just copy/paste, plain and simple. And with Highlight option, I'd first open Writer and then I'd open RTF file from there – Francisco Alvarado Apr 13 '11 at 06:45
  • Feedback: The eclipse think, just balones! The LibreOffice, although it may work, it is not my intent. Now, the HighLight, installed directly from 'synaptic' (or apt-get if you will), works as a charm! Thanks! You did it! ;) Please, update your answer if this info. – DrBeco Apr 13 '11 at 06:58
  • @Dr Beco: OK, answer updated... please don't forget to check it as accepted. Thank you. – Francisco Alvarado Apr 13 '11 at 07:03
  • Not only checked as accepted. You also just earned yourself a +50 bonus! Congratulations! – DrBeco Apr 13 '11 at 07:08
  • Thank you very much! It's my first bounty earned at SO. – Francisco Alvarado Apr 13 '11 at 07:09
  • :) My pleasure. Now, if you don't mind, my hightlight only works at command line. What is the name of the program to launch it as GUI? – DrBeco Apr 13 '11 at 07:23
  • If you call it from menu, you still can see the name by right-clicking the menu entry and looking into its properties, what the command is used to start the application. Maybe the GUI is only for KDE. I'm on GNOME here, but I'm installing KDE right now. Thanks! – DrBeco Apr 13 '11 at 07:41
  • Highlight GUI is a Qt 4.x based UI (http://www.andre-simon.de/dokuwiki/doku.php?id=en:installation_linux), so it seems to be only compatible with KDE. Although it there may be some compatibility package from Qt for Gnome... – Francisco Alvarado Apr 13 '11 at 13:11
  • @nihcap Don't you have it installed? Because I googled a lot and searched for the application name. I've already read this site of andre-simon. Unfortunately all sites I came across do not tell this simple information: what is the application name? (What do I type at the command line to start it?). I've installed KDE also. In any case, the console application is working here. I just type `hig` and `TAB` key, it auto-completes to the application name. There is no auto-completion for starting the name with upper-case `Hig`. Thanks. – DrBeco Apr 13 '11 at 16:53
  • The "Highlight" link in this answer is broken. Does anyone know where to find it now? I've been searching Google for things like "highlight 3.1". – David Grayson Oct 07 '12 at 21:26
  • 1
    The original link is indeed broken. This one works: http://www.andre-simon.de/doku/highlight/en/highlight.html But simpler yet, if you're on ubuntu, just run 'sudo apt-get install highlight'. – Eitan Feb 22 '13 at 19:34
29

This answer is perfect for the job:

Community
  • 1
  • 1
Daniel Reis
  • 12,944
  • 6
  • 43
  • 71
5

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

Gobinath
  • 904
  • 1
  • 15
  • 23
4

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.

Sandro L
  • 1,140
  • 18
  • 32
4

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.

trampgeek
  • 41
  • 1
3

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.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
  • Thanks! I'll take a look as an alternative. But I still *really* want for someone who can solve the **open office** mystery. – DrBeco Apr 08 '11 at 17:49
1

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.

1

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.

Andreas Abel
  • 190
  • 1
  • 11
0

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.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Thanks Ira. I tried this box and it worked, but no highlight came together. I can use this at least in the urgency. – DrBeco Apr 11 '11 at 01:29