# MATLAB like command box

hello i am trying to set up style for script box.

so far i got \begin{script*} >> help \end{script*} working and displaying

i want final version to look some what similar to this picture

and have second comment that will use more or less same environment

for example

i'm sure that it can be done with latex, but i don't have enough experience and knowledge.

any help will be appreciated thank you!

[UPDATE] HERE is the final version that i have decide to stay with, it uses tikz and mdframed

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{listings}
\definecolor{topBlue}{RGB}{42,93,147}
\definecolor{bottomBlue}{RGB}{10,60,113}
\definecolor{sideline}{RGB}{235,235,237}
\definecolor{frameBlue}{RGB}{17,74,135}
\usepackage{tikz}

\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}

\newcommand{\triangcirc}{\tikz{
\node[draw=frameBlue,inner ysep=4pt,
color=frameBlue,
top color=topBlue,
bottom color=bottomBlue,
text=white,
align=flush left,
font=\textbf\textsf,
text width=\textwidth] (a) {Command Window};
\node[circle,white,draw,inner sep=3pt] (c) at ([xshift=-3mm]a.east) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.2pt] (t) at ([yshift=1.5pt]c.south) {};}}

\mdfdefinestyle{commandline}
{leftmargin=0pt, rightmargin=0pt,innerleftmargin=-0.5pt,innerrightmargin=7.5pt,
middlelinecolor=frameBlue,
middlelinewidth=1.2pt,
frametitlerule=false,
backgroundcolor=white,
frametitle={\triangcirc},
frametitleaboveskip=-0.5pt,
frametitlebelowskip=0pt,
singleextra={\draw[sideline,line width=12pt]
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight)-(0,1pt)$);
\node[inner sep=0pt,color=black]at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}; }
}

\lstnewenvironment{script} {\lstset{language=Matlab,xleftmargin=5mm,basicstyle=\footnotesize,,breaklines=true,aboveskip=-2pt,belowskip=0pt}} {}
\surroundwithmdframed[style=commandline]{script}

\begin{document}
\begin{script}
>> help sin
sin    Sine of argument in radians.
sin(X) is the sine of the elements of X.

sdpvar/sin
codistributed/sin
gpuArray/sin

Reference page in Help browser
doc sin

>>
\end{script}

\end{document}


-
Have a look at the mdframed package. I don't know it very well, but IIRC it provides a lot of nice frames. You could try to combine it with e.g. the listings package. –  Uwe Ziegenhagen May 19 at 21:35
@Uhh. That can be very easily done with PythonTeX for Python command shell. Maybe you can e-mail the author to see how is done. –  Predrag Punosevac May 19 at 21:38
Incase you want exactly "MATLAB like command box" a good screenshot capture in .png might be one of many ways. –  texenthusiast May 19 at 22:06
have a look at the tcolorbox package too... –  cmhughes May 19 at 22:22
Please see the edit of Alan's answer. –  Marco Daniel May 20 at 8:27

Here's a version using mdframed.

Revised version

I've updated the answer to include the grey bar that was missing from the earlier answer, and I've removed the dependency on an Apple font by using percusse's code for the circled triangle. Because mdframed allows breaks across pages, this solution will be slightly more flexible than a solution that puts the code in a TikZ node.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\definecolor{DarkBlue}{rgb}{.11,.23,.60}

\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}

\newcommand{\triangcirc}{\tikz{
\node[circle,white,draw,inner sep=3pt] (c) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.5pt] (t) at ([yshift=0.5pt]c.south) {};}}

\mdfdefinestyle{commandline}
{leftmargin=5pt, rightmargin=10pt,innerleftmargin=15pt,
middlelinecolor=DarkBlue,
middlelinewidth=2pt,
backgroundcolor=white,
frametitle={Command Window\hfill\triangcirc},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1.25em}},
frametitlebackgroundcolor=DarkBlue,
singleextra={\draw[black!20,line width=12pt] node[inner sep=0pt,color=black]
at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight-1pt)$);}}

\newmdenv[style=commandline]{cmdline}
\usepackage{listings}
\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true}
\begin{document}
\begin{cmdline}
\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
>> help sin
sin    Sine of argument in radians.
sin(X) is the sine of the elements of X.

sdpvar/sin
codistributed/sin
gpuArray/sin

Reference page in Help browser
doc sin

>>
\end{lstlisting}%
\end{cmdline}
\end{document}


The following code simplify the complete method by defining on environment script which results in your required output:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\definecolor{DarkBlue}{rgb}{.11,.23,.60}

\usepackage[framemethod=TikZ]{mdframed}
\usetikzlibrary{calc,shapes.geometric}

\newcommand{\triangcirc}{\tikz{
\node[circle,white,draw,inner sep=3pt] (c) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=1.5pt] (t) at ([yshift=0.5pt]c.south) {};}}

\mdfdefinestyle{commandline}
{leftmargin=5pt, rightmargin=10pt,innerleftmargin=15pt,
middlelinecolor=DarkBlue,
middlelinewidth=2pt,
frametitlerule=false,
backgroundcolor=black!10!white,
frametitle={Command Window\hfill\triangcirc},
frametitlefont={\normalfont\sffamily\color{white}\hspace{-1.25em}},
frametitlebackgroundcolor=DarkBlue,
singleextra={\draw[black!20,line width=12pt]
($(O)+(7pt,1pt)$) -- ($(O|-P)+(7pt,-\mdfframetitleboxtotalheight)-(0,1pt)$);
\node[inner sep=0pt,color=black]at ($(O)+(7pt,9pt)$) {$\scriptstyle f\!x$}; }
}

\usepackage{listings}
\lstnewenvironment{script} {\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true,aboveskip=0pt,belowskip=0pt}} {}
\surroundwithmdframed[style=commandline]{script}

\begin{document}
\begin{script}
>> help sin
sin    Sine of argument in radians.
sin(X) is the sine of the elements of X.

sdpvar/sin
codistributed/sin
gpuArray/sin

Reference page in Help browser
doc sin

>>
\end{script}

\end{document}


-
this code does look smaller and more simpler, but i was not able to compile it due to "Apple Symbols". And another think that i'm not sure how to add left side line (grey with fx inside.) –  vveliev May 20 at 2:04
@texenthusiast Yes, mdframed can break across pages, which might be useful for longer listings. –  Alan Munn May 20 at 4:13
@vveliev: The background color is controlled by the option backgroundcolor. Where do you have an offset? –  Marco Daniel May 20 at 8:00
@vveliev: Fixed the dimension in the example. –  Marco Daniel May 20 at 8:36
@vveliev I think it's fair to accept this answer instead of mine. It's great and also involves the author of mdframed who confirmed to include these in the manual for a future release. Note that mdframed has the option to use TikZ as the underlying graphics engine hence it's not quite a choice between TikZ and mdframed. –  percusse May 21 at 11:16

Just a quick cook-up if mdframed doesn't have a direct support for this (I doubt that it doesn't though). The basic functionality is there such as shrinking via depending on the vertical size etc. but I didn't test it extensively and I got lazy for the triangle of the $fx$ part. Probably a better font would make it look way nicer.

\documentclass{article}
\usepackage{tikz,listings,amssymb}
\lstset{language=Matlab,basicstyle=\tiny\ttfamily,breaklines=true}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
\node[draw,inner ysep=3pt,
top color=blue!60!black,
bottom color=blue,
text=white,
align=flush left,
font=\tiny\ttfamily,
text width=\textwidth] (a) {Command Window};
\node[circle,white,draw,inner sep=1.9pt] (c) at ([xshift=-3mm]a.east) {};
\node[isosceles triangle,
white,
fill,
rotate=-90,
anchor=apex,
isosceles triangle apex angle=60,
inner sep=0.8pt] (t) at ([yshift=0.5pt]c.south) {};

\node[
anchor=north west,
minimum width=\textwidth-3mm,
align=flush left,
font=\tiny\ttfamily,
text width=\textwidth-3mm,
inner sep=0
] (l) at ([xshift=3mm]a.south west)
{%
\begin{lstlisting}[aboveskip=0pt,belowskip=0pt]
>> help sin
sin    Sine of argument in radians.
sin(X) is the sine of the elements of X.

sdpvar/sin
codistributed/sin
gpuArray/sin

Reference page in Help browser
doc sin

>>
\end{lstlisting}%
};

\filldraw[fill=blue!10,draw=white] ([yshift=-0.3pt]a.south west) rectangle (l.south west);
\draw ([xshift=0.3pt]a.south west) rectangle ([xshift=2mm+0.7pt]l.south east);
\node[anchor=south east,inner xsep=0.5pt,inner ysep=1pt] (f) at (l.south west) {$\scriptstyle f\!x$};
\end{tikzpicture}

\end{document}


-