Format text as code snippet in any word processor, like we do in Stackexchange sites
Solution 1
Create a new style that formats the text the way you want. The style will likely need to include:
- setting the font to a monospaced font like Courier New
- setting the language to No Proofing (Word 2003 and older) or Do Not Check Spelling or Grammar (Word 2007 and newer)
- setting the font size to something smaller; often code won't fit well on a page unless you make it smaller
To use this, select the text and change the style. All the formatting attributes will be applied at once.
Save the style in the normal.dot template (the default) so that it's available in all documents.
If you need to do this often, you can assign a keyboard shortcut to the text so you don't have to select the style from the style menu. You don't need a separate program to do this. In Word 2007
- Click the Office button.
- Click the Word Options button (at the bottom of the menu)
- Select Customize from the menu on the left.
- Click the Keyboard Shortcuts: Customize button at the bottom.
- In the Categories list, scroll down until you find Styles (second from the bottom) and select it.
- In the Styles list, select the style you created.
- Click in the Press New Shortcut key box.
- Type the key combination you wish to use (e.g. Alt 1)
- Click the Assign button
- Click Close
When you close Word it may ask if you want to save the normal template. Answer Yes.
Solution 2
While the syntax differs from that of markdown, LaTeX offers a proper what-you-mean semantic markup environment for document preparation.
Of course, you'll have to give up your word-processing ways and join the light side.
Related videos on Youtube
![Kushal](https://i.stack.imgur.com/lnrbk.jpg?s=256&g=1)
Comments
-
Kushal almost 2 years
Its been more than six months since I'm using stackexchange, so everyone out there knows that we're speechless about how much it has been helpful to us. But a small thing about the these sites that I'm in love with is that the way we can format our questions, I'm pointing particularly to the way we format code snippets, i.e. either keeping them in single quotes (I don't know if they're actually called quotes or something else)
LikeThis.Code()
or by prefixing four spaces.I need to write most of my college work in Microsoft Word or OneNote, where I have large chunk of code to be placed, I like my writing organized, like everyone do, so I format those code snippets with mono fonts manually. But after coming to stack... sites, I was wondering if I can automate similar behaviour in Word through some third party program, like AutoHotkey or something else. While I know AutoHotkey deals a lot with keyboard, but I was looking for a more fast and efficient way to format block of words into mono fonts (its ok, I'm not expecting them to hightlight syntax). Before a few months, I read an article on HowToGeek about an application that automatically replaces short-forms of words that we often type to the full word, basically converting informal English to formal (I can't remember now what was that application). So with the same way, can I format text in mono fonts, using single quotes or something else? so that I don't have to manually select text and change fonts to mono.
-
Cajunluke over 13 yearsSingle quotes are similar to apostrophes, and generally use the same key
'
. (Double quotes are, of course,"
.) The term for the code-quote character you're looking for is "backtick"`
. -
E. Jaep almost 12 yearsyou may consider the below answer on Stackoverflow: stackoverflow.com/questions/387453/…
-
-
Kushal over 13 yearsOk, that would be more helpful if I can select text and use hotkey to convert the fonts to the one I prefer (Droid Sans Mono, or anything), instead of opening the list and scroll through fonts.
-
uxout over 13 yearsI was about to post "Why do you HAVE to use Word? If you're in an academic discipline that's going to require that much code in papers, LaTeX should be standard!"
-
Kushal over 13 yearsWorks like a charm!!! Thanks a trillion....... :-)