将源代码示例插入Microsoft Word文档的最佳方法是什么? [英] What is the best way to insert source code examples into a Microsoft Word document?

查看:478
本文介绍了将源代码示例插入Microsoft Word文档的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须写一些包含源代码示例的文档.其中一些示例将从IDE中编写,而其他示例将在适当位置编写.我的示例主要是在Java中.

I have to write some documents that will include source code examples. Some of the examples will be written from the IDE, and others would be written in place. My examples are primarily in Java.

作为习惯于LaTeX的人,在Word中执行此操作非常痛苦.但是,我为此必须遵守Word.我看到的唯一选择是:

As someone who is used to LaTeX, doing this in Word is extremely painful. However, I am bound to Word for this. The only options I have seen are:

  1. 写入或复制到文档中, 然后使用固定字体, 格式化并希望Word不会 大写的东西给你.不用了 例如,这看起来像胡扯.
  2. 复制并粘贴源屏幕截图 IDE中的代码.至少我坚持 颜色.但是,如果我更改字体 大小,我搞砸了.我也搞砸了 跨页面边界.然后让我们 承认,Word并不擅长 管理一个上的多个图像 文档.
  3. 编写HTML(实际上不是一种选择) 在这里)
  1. Write or copy into the document, then use a fixed type font, arrange formatting and hope that Word didn't uppercase stuff for you. Needless to say, this looks like crap.
  2. Copy and paste screenshots of source code from the IDE. At least I keep colors. However, if I change my font size, I'm screwed. I'm also screwed across page boundaries. And let's admit it, Word is not great at managing multiple images on a document.
  3. Write HTML (not really an option here)

是否有更好的(最好是便携式的)方法来做到这一点?至少有某种类似于LaTeX环境的逐字记录样式吗?至少有一些漂亮的打印机可以复制并粘贴为RTF吗?

Is there some better (and ideally portable) way to do this? Is there at least some sort of verbatim style similar to the LaTeX environment? Is there at least some pretty printer that I could copy-and-paste as RTF?

推荐答案

我绝对讨厌并鄙视免费为Microsoft工作,因为毕竟他们数十亿美元仍然没有适当的指南,如屏幕快照在他们该死的网站上.

I absolutely hate and despise working for free for Microsoft, given how after all those billions of dollars they STILL do not to have proper guides about stuff like this with screenshots on their damn website.

无论如何,这是Word 2010中的快速指南,使用Notepad ++进行语法着色,并使用可带字幕的TextBox:

Anyways, here is a quick guide in Word 2010, using Notepad++ for syntax coloring, and a TextBox which can be captioned:

  1. 选择插入/文本框/简单文本框
  2. 已插入默认文本框
  3. 切换到NPP,选择用于代码语法着色的语言,转到插件"/"NPPExport"/将RTF复制到剪贴板"
  4. 切换回单词,然后粘贴到文本框中-可能太小...
  5. ...因此您可能必须更改其大小
  6. 已选择文本框,右键单击它,然后选择插入标题" ...
  7. 在标题"菜单中,如果您还没有一个,请单击新建标签",然后将新标签设置为代码",然后单击确定" ...
  8. ...,然后在标题"对话框中,将标签切换为代码",然后单击确定".
  9. 最后,在新创建的标题框中输入标题

这篇关于将源代码示例插入Microsoft Word文档的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆