147

Is it possible to embed programming source code to Powerpoint slide, and keep code highlighting/coloring?

3
  • what application are you copying from?
    – user1931
    Dec 21, 2009 at 4:26
  • I use textmate, e-texteditor and eclipse the most.
    – Yousui
    Dec 21, 2009 at 4:58
  • 2
    Please copy your code to VC Code, and then paset to ppt Oct 12, 2023 at 17:13

11 Answers 11

67

After pasting, a small "Paste Options" icon appears below the pasted text.

Click this icon and choose "Keep Source Formatting" :

enter image description here

2
  • 3
    I don't see such a Paste Options icon. I don't see a button to give me these options. I'm using PowerPoint:mac 2011. I think I have seen it in Windows versions, however.
    – Asclepius
    Jul 19, 2013 at 21:49
  • I tried different suggested methods and tools to copy from, but was actually missing that word/powerpoint was messing up the format by using "Destination Theme". Thanks!
    – Tim Büthe
    Jan 22, 2014 at 11:23
58

Use Notepad++ with add-on NppExport.

  • Select the source code

  • Use Copy RTF to clipboard of NppExport

  • Paste into empty PPT slide (do not select any textfiled)

4
  • 8
    With version 6.9.2 or higher it's working without NppExport plugin. Just make right-click on the selected text -> Plugin commands -> Copy Text with Syntax Highlighting. Aug 7, 2016 at 19:00
  • 2
    Current version of Notepad++ already comes with this plugin :) Nov 27, 2016 at 17:53
  • 1
    Still working in NPP v8.2.1, Power Point 2016
    – iroiroys
    Mar 16, 2022 at 6:08
  • Direct copy to PowerPoint did not worked well, I paste the code to Word and copy it from word to PowerPoint Aug 28, 2023 at 4:45
32

Pygments can format almost every format to rtf:

pygmentize -f rtf -o code.rtf code.py
4
  • 3
    An online translator is available at pygments.org/demo
    – koppor
    Nov 25, 2015 at 11:48
  • 6
    Same idea, straight to the OS X clipboard pygmentize -f rtf code.py | pbcopy. Mar 14, 2016 at 14:28
  • Thanks for this. I got very favorable results with pygmentize -O style=paraiso-dark -f rtf -l aspx-cs Index.cshtml | pbcopy for syntax highlighting of a Razor view for use in a presentation. Jun 20, 2019 at 20:42
  • Adding to what @ChristianLong suggested, but for Linux: pygmentize -f rtf code.py | xclip -sel clip. Note that you will probably have to install xclip. Nov 19, 2019 at 23:16
6

If the source code does not need to be copied and pasted out of the presentation, a quick and dirty solution could be to simply take screenshots of the source code.

4
  • 12
    Image can be fuzzy when zoom in.
    – Yousui
    Dec 21, 2009 at 4:58
  • Use the magnifier and then take a screenshot of that.
    – wbeard52
    May 17, 2015 at 0:57
  • 4
    Doing so can increase the size of the presentation file significantly.
    – Rufflewind
    Nov 10, 2016 at 17:39
  • 1
    This also has the drawback that once screenshot, it is no longer possible to resize the column width. This becomes a problem if you try to fit a 80 column printout into a 2x1 horizontal slide layout, a 132 column source into a 1x2 vertical layout, for example. The pygmentize answer above doesn't suffer from this. Nov 19, 2019 at 22:55
3
  1. Click on Insert → Object → OpenDocument Text
  2. Paste on opened panel
  3. Click outside.

Note: Copying from Notepad++ will preserve colors and styling.

2
  • 1
    Doesn't work for power point 2010. I copied text from Notepad++ to Power point presentation but it looses colors and styling.
    – ART
    Jan 4, 2016 at 5:11
  • 2
    If I use NPPExport pluging and use "copy RTF to clipboard" and then paste it works.
    – ART
    Jan 4, 2016 at 5:13
2

Copy the code and first paste that code into Microsoft word

enter image description here

Then do the formatting if necessary and then copy from word and paste back to powerpoint by right clicking and choosing use destination theme

enter image description here

3
  • Either way,  what does “Then do the formatting if necessary” mean? Apr 26, 2017 at 19:10
  • It means if you want to do some changes of your own like aligning or indentation of code Apr 26, 2017 at 19:17
  • This was the only way that I could copy and paste code from IntelliJ (a special program used for writing code)
    – robert
    Nov 14, 2019 at 4:15
2

Here's another approach:

  1. Find an online source code syntax highlighting service.
  2. Paste the code to highlight into the web site.
  3. Copy the highlighted version.
  4. Create a new Word document.
  5. Paste the code into Word (note the background colours may be lost).
  6. Copy the code from Word.
  7. Create a new text area in PowerPoint.
  8. Click the Home menu option.
  9. Open Paste on the ribbon.
  10. Select Keep source formatting.
  11. Optionally, change the text area background colour to taste.

Adjust the font using Inconsolata or other monospace font.

1

Online syntax highlighter like TextMate seems good as well, http://markup.su/highlighter/

But after pasting into PowerPoint presentation new lines and line spacing is lost, so we can take a screen shot of the preview and paste it in our PowerPoint presentation

1
  • Pasting into ppt does not quite work here on Windows 10: The new lines are not pasted.
    – koppor
    Nov 24, 2015 at 15:22
1

Using Notepad++ and Npp Export works great, but your text will end up with a white background.

To remove it, paste first the text in word with the "preserve source formatting" option. Then, select the text and in Home > Font, remove the background with the Text Highlight Color option.

Then, copy again the text from word, and paste it in powerpoint with the "preserve source formatting" option.

0

Pasting from Eclipse should retain formatting if the app supports it. I know Word does... not sure about PPT.

1
  • 1
    Works from Eclipse Juno to Word 2010, but not to Powerpoint 2010 - it loses the colours and converts some of them to bold text
    – DNA
    Sep 4, 2013 at 17:21
0

I've had no success pasting into Powerpoint 2010 on Windows.

However, pasting from Eclipse into Word 2010 works.

You can then save this formatted text as an RTF file, then embed the RTF into a Powerpoint 2010 slide using Insert Object (and optionally select 'link' so you can edit and update the text in Word).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .