Question

Hi I'm trying to create an environment in Latex that recreates the effect of the following.

\colorbox{bg}{\ttfamily{\color[RGB]{222,222,222}
Hello
Whats up
}
}

I want to be able to say.

\begin{bashcommands}
Hello
Whats Up
\end{bashcommands}
Was it helpful?

Solution

This works for me:

\makeatletter\newenvironment{bc_box}{%
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
   \colorbox{bg}{\usebox{\@tempboxa}}
}\makeatother

\newenvironment{bashcommands}{
    \begin{bc_box}\ttfamily\color[RGB]{222,222,222}
}{                                    
    \end{bc_box}
}

See this, as well.

OTHER TIPS

Using Donald Arseneau's framed.sty, you can do this, which would also work nicely if you need to span multiple pages.

\newenvironment{bashcommands}{%
  \definecolor{shadecolor}{named}{bg}%
  \begin{shaded}\ttfamily\color[RGB]{222,222,222}%
}{%
  \end{shaded}%
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top