2

I want to do a box like this enter image description here

but the bold text doesn't appear.

Edited:

\documentclass{article}
\usepackage{listings,xcolor,etoolbox,lmodern}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
  % redefine bash prompt:
  \def\prompt{user@linux:\textasciitilde\$\space}%
  \lstset{backgroundcolor=\color{verbgray},
    frame=single,
    framerule=1pt,
    basicstyle=\ttfamily,
    columns=fullflexible,
    escapechar=@
  }%
}{}
\begin{document}
    \begin{sh}
    @\prompt\space\textbf{date}@
    Thu Oct 25 13:51:54 EDT 2007
    \end{sh}
\end{document}
  • A couple pointers, you need a comma after columns=fullflexible. Also, you're misreading the syntax of the escape character, it should be either escapechar=@ or escapechar=\@. – A.Ellett Jan 24 '15 at 22:22
  • Thanks I changed that, but still doesn't seems to work – Arturo Jan 24 '15 at 22:24
  • Because of the indentation I'd add gobble=4 to the setup. And I'd probably use language=bash,keywordstyle=\bfseries,morekeywords=date or something instead of escapechars. (This actually depends if date is the only occurence where you want bold...) – clemens Jan 24 '15 at 22:36
  • no there will be more ocurrences – Arturo Jan 24 '15 at 22:37
4

Here's a slightly modified version of what you wrote:

\documentclass{article}
\usepackage{lmodern}
\usepackage{listings,xcolor,etoolbox}
\definecolor{verbgray}{gray}{0.9}
\newcommand*\prompt{}% empty default
\lstnewenvironment{sh}{%
  % redefine bash prompt:
  \def\prompt{user@linux:\textasciitilde\$\space}%
  \lstset{backgroundcolor=\color{verbgray},
    frame=single,
    framerule=1pt,
    basicstyle=\ttfamily,
    columns=fullflexible,
    escapechar=@
  }%
}{}
% patch \lst@NewLine:
\makeatletter
\patchcmd\lst@NewLine
  {\hbox{}}% search
  {\hbox{}\prompt}% replace
  {}% success
  {}% failure
\makeatother
\begin{document}
    \begin{sh}
    @\textbf{date}@
    Thu Oct 25 13:51:54 EDT 2007
    \end{sh}
\end{document}

enter image description here

You need fonts which will allow bold when creating ttfamily. Hence the loading of

\usepackage{lmodern}
  • why I don't see mine in bold? – Arturo Jan 24 '15 at 22:26
  • @Arturo you need a monospaced font with a bold variant – clemens Jan 24 '15 at 22:33

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.