5

I want to highlight some code~ish thing in a report like this:

blahblahblah...Then you should use ./runprog to start up the program etc etc...

How can I do this?

jak123
  • 4,252
  • 5
  • 26
  • 49

1 Answers1

11

Use the colorbox command from xcolor package:

\documentclass{article}

\usepackage{xcolor}
    \newcommand{\SEBox}[1]{\texttt{\colorbox{gray!14}{#1}}}

\begin{document}
     \SEBox{blahblah}
\end{document}

monospaced example text on a gray background

Luc
  • 214
jak123
  • 4,252
  • 5
  • 26
  • 49
  • It works! Thank you! Could you kindly explain for me what is this command doing? – anetworknoobie Jun 08 '15 at 06:40
  • 1
    \texttt changes font to typewriter style; \colorbox changes the text background color to 10% transparent gray (gray!10). – jak123 Jun 08 '15 at 06:42
  • 1
    What are [1] and {#1}? – anetworknoobie Jun 08 '15 at 06:44
  • 1
    [1] number of arguments passed to the command, and #1 means use argument #1 here. For example, you can write \newcommand{\SEBox}[2][gray!10]{\texttt{\colorbox{#2}{#1}}} to be able to change the background color. Check this out: http://www.emerson.emory.edu/services/latex/latex_19.html – jak123 Jun 08 '15 at 06:46
  • BTW, it is typically recommended to wait for sometime before accepting answers, you might get better ones. – jak123 Jun 08 '15 at 06:48
  • Thanks for the advice, but your answer just works and is suitable for my use and most importantly is simplicity which I really appreciate as a LaTeX newbie. – anetworknoobie Jun 08 '15 at 06:52
  • 1
    @anetworknoobie You ought to read about command definitions etc. Just search things like "newcommand latex" on google and on this site and you'll find tons of resources about that. If you are using linux or mac be aware that you probably have texdoc installed. So if you want to learn about a certain package you can just launch from the terminal texdoc package-name to see its documentation (e.g. texdoc mathtools). – Bakuriu Jun 08 '15 at 09:43