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

查看:80
本文介绍了将源代码示例插入 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(不是真正的选项在这里)

有没有更好的(并且最好是便携的)方法来做到这一点?是否至少有某种类似于 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. 切换回 word,然后粘贴到文本框中 - 它可能太小了...
  5. ...所以你可能需要改变它的大小
  6. 选择文本框后,右键单击它,然后选择插入标题...
  7. 在 Caption 菜单中,如果您还没有,请单击 New Label,并将新标签设置为Code",单击 OK ...
  8. ...然后在 Caption 对话框中,将标签切换为 Code,然后点击 OK
  9. 最后,在新创建的标题框中输入您的标题

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

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