C++ MS Word 文档中的语法突出显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2556862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax highlighting in MS Word document
提问by Arun
I want to insert some C/C++ source code into a Microsoft Word document. I have no problem in copying the code from source file and pasting into Word. I can do fixed-width. But, in Word, I see the code in black-and-white format; I loose the syntax highlighting as I get in the source code editor (for me, gvim). So, my question is, is there any way to do syntax highlighting of C/C++ source code in MS Word?
我想在 Microsoft Word 文档中插入一些 C/C++ 源代码。我从源文件中复制代码并粘贴到 Word 中没有问题。我可以做固定宽度。但是,在 Word 中,我看到的是黑白格式的代码;当我进入源代码编辑器(对我来说,gvim)时,我松开了语法突出显示。所以,我的问题是,有没有办法在 MS Word 中对 C/C++ 源代码进行语法高亮显示?
回答by Ethan Liu
回答by Lukasz Czerwinski
I've found a tool similar to this found by darlinton, but having several different styles of colouring: http://tohtml.com/. I hope it would help.
我找到了一个类似于 darlinton 找到的工具,但有几种不同的着色风格:http://tohtml.com/ 。我希望它会有所帮助。
回答by Vitali Climenco
You can leverage the syntax highlighter that is in use at StackOverflow. I mean the text area where you add the content to be posted to the site :)
您可以利用StackOverflow中使用的语法荧光笔。我的意思是您添加要发布到网站的内容的文本区域:)
But for a more robust and configurable solution you could check out the syntax highlighter developed by Alex Gorbatchov (link). But well, installing it requires some knowledge of HTML and CSS. So, if I needed a quick solution to format my output, I would opt for planet.ca, as darlintonand ArunSaha.
但是对于更健壮和可配置的解决方案,您可以查看由 Alex Gorbatchov 开发的语法高亮器(链接)。但是,安装它需要一些 HTML 和 CSS 知识。所以,如果我需要一个快速的解决方案来格式化我的输出,我会选择planet.ca,因为达林顿和ArunSaha。
回答by RichieHindle
回答by Shiroko
If you have Eclipse CDT or Visual around they do it automatically for you when you paste code to Word (Or similiar). I assume it's not best solution for a gvim guy, but still. Just so you'll know.
如果您有 Eclipse CDT 或 Visual,当您将代码粘贴到 Word(或类似的)时,它们会自动为您执行此操作。我认为这不是 gvim 人的最佳解决方案,但仍然如此。只是为了让你知道。
回答by Arun
After some more searching, I also found Highlight 2.9. But that requires (a) installing an application, and (b) [subjective] aesthetically I like the output of planetb.ca's output (the answer provided by darlinton)
经过一番搜索,我还找到了Highlight 2.9。但这需要 (a) 安装应用程序,并且 (b) [主观] 从美学上讲我喜欢Planetb.ca的输出(由 darlinton 提供的答案)
回答by Jér?me Pouiller
Under Linux, you can use the popular highlightpackage. It can output RTF file. You can copy-paste the result in Word or LibreOffice.
在 Linux 下,您可以使用流行的highlight包。它可以输出RTF文件。您可以在 Word 或 LibreOffice 中复制粘贴结果。