Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to be able to make a single word in a text look like a coded word. Is there any command such as \code{...} which allows me to do so?

(basically, I want to produce something like above for the "\code{...}" part)

share|improve this question
2  
Do you want it to change the background to grey too? –  N.N. Nov 24 '11 at 11:15
    
@N.N : it could have been even better yeah, but it's not extremely important. –  SRKX Nov 24 '11 at 12:46

2 Answers 2

up vote 16 down vote accepted

Normally a monospaced font is used for this. This is accomplished with \texttt{...}. If you want to use code, you can use \def\code#1{\texttt{#1}}. From that point on you can write \code{...} to get monospaced output.

share|improve this answer
    
Yes, that's the way to go. Put it semantically correct (by calling it code) and use texttt inside this until you come across a better formatting. –  wal-o-mat Nov 24 '11 at 11:15
4  
I'd prefer \newcommand{\code}[1]{\texttt{#1}} as you're dealing with LaTeX. Even better \newcommand{\code}{\texttt}, but this is quite advanced. –  egreg Nov 24 '11 at 11:40
    
@egreg I'm not so sure about the last approach (yes, I know why you're doing it, but from an interface POV I prefer macros where the arguments required are clear). –  Joseph Wright Nov 24 '11 at 11:41
    
@JosephWright That's why I wrote that it's advanced. :) –  egreg Nov 24 '11 at 11:50
1  
I would also wrap a \mbox around the \texttt, to avoid the word being hyphenated if it happens to fall near the end of a line. –  Karl Ove Hufthammer Nov 24 '11 at 11:51

\verb|code| or \verb#code# also works. It creates characters in monospace, although its primary utility to enter commands that the compiler wont confuse as tex commands.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.