insert Maple code in comment with mathmode create with tcolorbox package

see this code:

\documentclass[svgnames,12pt]{report}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins,theorems}

\lstdefinelanguage{Maple}%
{aboveskip={0pt},belowskip={0pt},basicstyle=\bfseries,
morekeywords={and,assuming,break,by,catch,description,do,done,%
elif,else,end,error,export,fi,finally,for,from,global,if,%
implies,in,intersect,local,minus,mod,module,next,not,od,%
option,options,or,proc,quit,read,return,save,stop,subset,then,%
to,try,union,use,uses,while,xor},%
sensitive=true,%
morecomment=[l]\#,%
morestring=[b]",%
morestring=[d]"%
}[keywords,comments,strings]%

\makeatletter
\tcbset{every listing line/.code={%
\def\lst@NewLine{%
\ifx\lst@OutputBox\@gobble\else
\par\noindent \hbox{}#1%
\fi
\global\advance\lst@newlines\m@ne
\lst@newlinetrue}}}
\makeatother

\newtcblisting{code}[1]{
colback=white,
skin=bicolor,
colbacklower=white,
colupper=red!40!black,
collower=blue,
frame style={draw=white,left color=white,right color=white},
fontupper=\bfseries,
fontlower=\bfseries,
width=\linewidth,
boxrule=0mm,
outer arc=1mm,arc=1mm,
leftupper=0cm,leftlower=0cm,rightupper=0cm,rightlower=0cm,
top=0mm,bottom=0mm,middle=0mm,
center lower,
nobeforeafter,
listing and comment,
ams nodisplayskip lower,
%           comment={#1},
comment={\begin{align*}#1\end{align*}},
every listing line={\textcolor{red!40!black}{\ttfamily> }}
}

\begin{document}

\begin{code}{h := proc(t) t * (t-1) end proc}
h := proc(t) t*(t-1) end proc;
\end{code}

\end{document}

output is:

How do i change that until i have this output?

I mean in the main definition of code environment, not in the \begin{code}{} ... \end{code}.

Thanks in advance.

1 Answer

If I understand your question correctly, you want to have the keywords proc and end proc automatically detected inside a mathematical environment; here, align*. I do not think that this is possible.

You could mark the keywords by hand inside a mathematical environment or you could insert escape sequences with some math stuff into listings code. This is documented in the listings documentation using mathescape.

The first variant is nearer to your existing code. I removed the every listing line definition, because it is part of tcolorbox 2.72 (2014/03/18), but you could keep it with an older tcolorbox version. The modified example with manually selected keywords inside math code is:

\documentclass[svgnames,12pt]{report}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{listings,skins,theorems}

\lstdefinelanguage{Maple}%
{aboveskip={0pt},belowskip={0pt},basicstyle=\bfseries,
morekeywords={and,assuming,break,by,catch,description,do,done,%
elif,else,end,error,export,fi,finally,for,from,global,if,%
implies,in,intersect,local,minus,mod,module,next,not,od,%
option,options,or,proc,quit,read,return,save,stop,subset,then,%
to,try,union,use,uses,while,xor},%
sensitive=true,%
morecomment=[l]\#,%
morestring=[b]",%
morestring=[d]"%
}[keywords,comments,strings]%

\newtcblisting{code}[1]{
listing and comment,
blank,nobeforeafter,
colupper=red!40!black,collower=blue,
fontupper=\bfseries,fontlower=\bfseries,
center lower,
listing options={language=Maple},
ams nodisplayskip lower,
comment={\begin{align*}#1\end{align*}},
every listing line={\textcolor{red!40!black}{\ttfamily> }}
}

\begin{document}

\begin{code}{h := \text{\bfseries proc}(t) t * (t-1)\,\text{\bfseries end proc}}
h := proc(t) t*(t-1) end proc;
\end{code}

\end{document}

• "I do not think that this is possible." #Dr Sturm, I thank you very much, because i'm sure now, no need to find a solution, I think. but, "mark the keywords by hand inside a mathematical environment" is very time consuming. – niksirat Mar 23 '14 at 18:10