<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>Copy formatted org-mode text from Emacs to other applications</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/06/16/Copy-formatted-org-mode-text-from-Emacs-to-other-applications</link>
      <pubDate>Thu, 16 Jun 2016 11:46:39 EDT</pubDate>
      <category><![CDATA[rtf]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">8BfFihQxeSpGlD1tGvKAFPysQFM=</guid>
      <description>Copy formatted org-mode text from Emacs to other applications</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I do a lot of writing in org-mode and I thought it would be great if I could copy text from an org-file and paste it &lt;i&gt;with formatting&lt;/i&gt; into other applications, e.g. Word, Gmail, etc&amp;#x2026;.  Curiosity got the better of me and I wondered how this is done in other applications. It works by creating a &lt;a href="https://www.safaribooksonline.com/library/view/rtf-pocket-guide/9781449302047/ch01.html"&gt;Rich Text Format&lt;/a&gt; version of what you want to copy and then putting that on the clipboard. It isn't quite enough to just copy it, it needs to go in the clipboard as an RTF datatype. On Mac OSX I used &lt;a href="http://osxdaily.com/2007/03/05/manipulating-the-clipboard-from-the-command-line/"&gt;pbcopy&lt;/a&gt; to make that happen.
&lt;/p&gt;

&lt;p&gt;
Check out this video of this post in action: &lt;a href="https://www.youtube.com/watch?v=irkmQnggVpE"&gt;https://www.youtube.com/watch?v=irkmQnggVpE&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
One simple strategy to do this from org-mode is to generate HTML by export, and then convert it to RTF with a utility, e.g. textutil. For example like this.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;formatted-copy&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Export region to HTML, and copy it to the clipboard."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;save-window-excursion&lt;/span&gt;
    (&lt;span style="color: #0000FF;"&gt;let*&lt;/span&gt; ((buf (org-export-to-buffer 'html &lt;span style="color: #008000;"&gt;"*Formatted Copy*"&lt;/span&gt; nil nil t t))
           (html (&lt;span style="color: #0000FF;"&gt;with-current-buffer&lt;/span&gt; buf (buffer-string))))
      (&lt;span style="color: #0000FF;"&gt;with-current-buffer&lt;/span&gt; buf
        (shell-command-on-region
         (point-min)
         (point-max)
         &lt;span style="color: #008000;"&gt;"textutil -stdin -format html -convert rtf -stdout | pbcopy"&lt;/span&gt;))
      (kill-buffer buf))))

(global-set-key (kbd &lt;span style="color: #008000;"&gt;"H-w"&lt;/span&gt;) 'formatted-copy)
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
This works well for everything but equations and images. Citations leave a bit to be desired, but improving this is still a challenge.
&lt;/p&gt;

&lt;p&gt;
Let us try this on some text. Some &lt;b&gt;bold&lt;/b&gt;, &lt;i&gt;italic&lt;/i&gt;, &lt;span class="underline"&gt;underline&lt;/span&gt;, &lt;del&gt;struck&lt;/del&gt; and &lt;code&gt;verbatim&lt;/code&gt; text to copy. Here are some example Formulas: H&lt;sub&gt;2&lt;/sub&gt;O ionizes to form H&lt;sup&gt;+&lt;/sup&gt;. We simply must have an equation: \(e^{i\pi} + 1 = 0\) &lt;sup&gt;&lt;a id="fnr.1" class="footref" href="#fn.1"&gt;1&lt;/a&gt;&lt;/sup&gt;. We should also have a citation &lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt; and multiple citations &lt;a class='org-ref-reference' href="#kitchin-2016-autom-data"&gt;kitchin-2016-autom-data&lt;/a&gt;,&lt;a class='org-ref-reference' href="#kitchin-2015-data-surfac-scien"&gt;kitchin-2015-data-surfac-scien&lt;/a&gt; &lt;sup&gt;&lt;a id="fnr.2" class="footref" href="#fn.2"&gt;2&lt;/a&gt;&lt;/sup&gt;.
&lt;/p&gt;

&lt;p&gt;
A code block:
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; pycse.orgmode &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; org
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; np
&lt;span style="color: #0000FF;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #0000FF;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #BA36A5;"&gt;x&lt;/span&gt; = np.linspace(0, 60, 500)
plt.figure(figsize=(4, 2))
plt.plot(np.exp(-0.1 * x) * np.cos(x),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;np.exp(-0.1 * x) * np.sin(x))
org.figure(plt.savefig(&lt;span style="color: #008000;"&gt;'spiral.png'&lt;/span&gt;),
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  caption=&lt;span style="color: #008000;"&gt;'A spiral.'&lt;/span&gt;,
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;  attributes=[[&lt;span style="color: #008000;"&gt;'org'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;':width 100'&lt;/span&gt;]])
&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt;(&lt;span style="color: #008000;"&gt;''&lt;/span&gt;)
org.table([[&lt;span style="color: #008000;"&gt;'H1'&lt;/span&gt;, &lt;span style="color: #008000;"&gt;'H2'&lt;/span&gt;], &lt;span style="color: #D0372D;"&gt;None&lt;/span&gt;, [1, 2], [2, 4]],
&lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt;   &lt;span style="color: #9B9B9B; background-color: #EDEDED;"&gt; &lt;/span&gt; caption=&lt;span style="color: #008000;"&gt;'A simple table'&lt;/span&gt;)
&lt;span style="color: #0000FF;"&gt;print&lt;/span&gt;(&lt;span style="color: #008000;"&gt;''&lt;/span&gt;)
org.result(6 * 7)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2016-06-16-Copy-formatted-org-mode-text-from-Emacs-to-other-applications/spiral.png"&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span class="figure-number"&gt;Figure 1:&lt;/span&gt; A spiral.&lt;/p&gt;
&lt;/div&gt;

&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;
&lt;caption class="t-above"&gt;&lt;span class="table-number"&gt;Table 1:&lt;/span&gt; A simple table&lt;/caption&gt;

&lt;colgroup&gt;
&lt;col  class="org-right" /&gt;

&lt;col  class="org-right" /&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th scope="col" class="org-right"&gt;H1&lt;/th&gt;
&lt;th scope="col" class="org-right"&gt;H2&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="org-right"&gt;1&lt;/td&gt;
&lt;td class="org-right"&gt;2&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td class="org-right"&gt;2&lt;/td&gt;
&lt;td class="org-right"&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;pre class="example"&gt;
42
&lt;/pre&gt;

&lt;p&gt;
In summary, this simple approach to generating RTF from exported HTML works really well for the simplest markups. To improve on getting figures in, getting cross-references, captions, proper references, etc&amp;#x2026; will require a more sophisticated export approach, and probably one that exports RTF directly. That is a big challenge for another day!
&lt;/p&gt;

&lt;p&gt;
&lt;h1 class='org-ref-bib-h1'&gt;Bibliography&lt;/h1&gt;
&lt;ul class='org-ref-bib'&gt;&lt;li&gt;&lt;a id="kitchin-2015-examp"&gt;[kitchin-2015-examp] Kitchin, Examples of Effective Data Sharing in Scientific Publishing, &lt;i&gt;ACS Catalysis&lt;/i&gt;, &lt;b&gt;5(6)&lt;/b&gt;, 3894-3899 (2015). https://doi.org/10.1021/acscatal.5b00538&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a id="kitchin-2016-autom-data"&gt;[kitchin-2016-autom-data] "Kitchin, Van Gulick &amp; Zilinski, Automating Data Sharing Through Authoring Tools, &lt;i&gt;"International Journal on Digital Libraries"&lt;/i&gt;, &lt;b&gt;&lt;/b&gt;, 1-6 (2016). https://doi.org/10.1007/s00799-016-0173-7&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a id="kitchin-2015-data-surfac-scien"&gt;[kitchin-2015-data-surfac-scien] "John Kitchin", Data Sharing in Surface Science, &lt;i&gt;"Surface Science "&lt;/i&gt;, &lt;b&gt;N/A&lt;/b&gt;, in press (2015). https://doi.org/10.1016/j.susc.2015.05.007&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;div id="footnotes"&gt;
&lt;h2 class="footnotes"&gt;Footnotes: &lt;/h2&gt;
&lt;div id="text-footnotes"&gt;

&lt;div class="footdef"&gt;&lt;sup&gt;&lt;a id="fn.1" class="footnum" href="#fnr.1"&gt;1&lt;/a&gt;&lt;/sup&gt; &lt;div class="footpara"&gt;&lt;p class="footpara"&gt;
There are probably some ways to get better images for equations. To get equation numbers and references to them will probably require a two pass build process.
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class="footdef"&gt;&lt;sup&gt;&lt;a id="fn.2" class="footnum" href="#fnr.2"&gt;2&lt;/a&gt;&lt;/sup&gt; &lt;div class="footpara"&gt;&lt;p class="footpara"&gt;
This is another place where configuration will be required for bibliography style. Also, some checks to join neighboring footnotes.
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;


&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2016/06/16/Copy-formatted-org-mode-text-from-Emacs-to-other-applications.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 8.3.4&lt;/p&gt;
]]></content:encoded>
    </item>
  </channel>
</rss>
