4

I use texttt{} to write names of software, commands etc. within the text. Sometimes the texttt text is longer and there is a line break within it. It works well, no problem here.

I wish to add background to that text. I modified the texttt command:

\renewcommand{\texttt}[1]{\colorbox{Ivory}{{\ttfamily #1}}}

The only problem with this solution is that it doesn't allow line breaks.

Minimal working example

\documentclass[a4paper, 11pt, twoside]{article}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{polyglossia}
\usepackage[svgnames]{xcolor}
% Modify page margins
\usepackage[a4paper, text={160mm, 250mm}]{geometry}
% Add background for \texttt{}
\renewcommand{\texttt}[1]{\colorbox{Ivory}{{\ttfamily #1}}}
\setdefaultlanguage{english}
\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec quis
nibh at felis congue commodo. Fusce wisi. Nullam feugiat, turpis at 
pulvinar vulputate, erat libero tristique tellus, nec bibendum odio 
risus sit amet ante. Nullam sit amet magna in magna gravida vehicula. 
Fusce dui leo, imperdiet in, aliquam sit amet, \texttt{feugiat eu, 
in lorem sit amet leo accumsan lacinia. Etiam egestas wisi a erat. 
Praesent vitae arcu tempor neque lacinia pretium. Nullam lectus justo, 
vulputate eget mollis sed, tempor sed magna. Integer vulputate sem a 
nibh rutrum consequat. Pellentesque ipsum. Etiam posuere lacus quis 
dolor. Aenean vel massa quis mauris vehicula lacinia. Vestibulum erat 
nulla, ullamcorper nec, rutrum non, nonummy ac, erat. Proin pede metus, 
vulputate nec, fermentum fringilla, vehicula vitae, justo. Nullam at} 
arcu a est sollicitudin euismod. Nam libero tempore, cum soluta nobis 
est eligendi optio cumque nihil impedit quo minus id quod maxime placeat 
facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. 
Maecenas lorem. Sed ut perspiciatis unde omnis iste natus error sit
voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque 
ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae 
dicta sunt explicabo.
\end{document}

doesn't work as expected...

5

You can use the package soul and its highlighting feature.

\usepackage{soul}
\sethlcolor{Ivory}
\renewcommand{\texttt}[1]{\hl{\ttfamily #1}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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