5

I want define an environment in tcolorbox.

6 questions:

  1. Why when i want use math lower and ams align* ‎lower‎ for set the lower part to mathematical mode with font \displaystyle, i have error?
  2. Why declaration \bfseries in ‎fontupper=‎\bfseries‎ is not work?
  3. How can define Maple code in listings package? I want put maple code in upper part and i have to define that style myself.
  4. I want put > character ‎before any line in upper part, how can do that?
  5. Why when use before upper=‎{‎\texttt{>}‎‎‎‎}‎‎, code appear in a newline after > char?
  6. I use ‎center lower‎, but lower part doesn't shift in center.

see this code:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}
%\usepackage{maplestd2e}

\tcbuselibrary{listings}
\tcbuselibrary{skins}
\tcbuselibrary{theorems}

\definecolor{ocre}{RGB}{243,102,25}

%\lst@definelanguage{Maple}%
%{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]{
           lowerbox=visible, % visible,invisible,ignored,
%          colback=black,
           skin=bicolor,
%          colbacklower=white,
%          colupper=white,
%          collower=black,
           overlay={\draw[dashed,black] (segmentation.west)--(segmentation.east);},
%          listing options={language={Maple}},
%          frame style={draw=black,left color=Gold,right color=Goldenrod!50!Gold},
           fontupper=\bfseries,
           fontlower=\sffamily\bfseries,
           width=\linewidth,
%          toprule=1mm,bottomrule=.3mm,rightrule=.3mm,leftrule=3mm,
           boxrule=0.5mm,
           outer arc=1mm,arc=1mm,
%          leftupper=3cm,leftlower=3cm,rightupper=4cm,rightlower=3cm,
           top=1mm,bottom=1mm,middle=1mm,
%          height=,
           valign=center,
           valign lower=center,
           before=\begin{center},after=\end{center},
           before upper={\texttt{>}},
           before lower={\begin{center}},
           after lower={\end{center}},
           center lower, % center upper,
%          flushright upper,
           nobeforeafter, 
           math lower,
%          ams align* lower,
           listing and comment,
           comment={#1}
           }

\begin{document}


\begin{code}{\frac{n}{n+1}}
2+3;
\end{code}

\end{document}

output:

enter image description here

5
  • I tried to copy your MWE into an editor -- there are a lot of special characters add the end of the lines.
    – user31729
    Commented Mar 8, 2014 at 16:54
  • I removed those special characters but your document is not compilable at all, it refuses to load Maple as language.
    – user31729
    Commented Mar 8, 2014 at 17:10
  • @user626 Your editor adds several spurious characters (U+200E) that make the example not to compile.
    – egreg
    Commented Mar 8, 2014 at 17:41
  • Sorry everyone, delete all spurious characters with vim editor now.
    – niksirat
    Commented Mar 8, 2014 at 18:14
  • Remove the @ character in \lst@definelanguage -- this will solve automatically question/problem number 2 and 3, since \bfseries is only applied if listings is used, so listings, i.e. the 'programming' language must be correctly defined.
    – user31729
    Commented Mar 8, 2014 at 23:13

1 Answer 1

4

As you wrote yourself, you ask 6 questions. I try to give one answer, but your questions addresses different problems.

  1. There is a problem when mixing user created environments based on \tcblisting together with some specific hacks for the amsmath align environment. I have an idea for a solution, but in your case there is a much easier way (see example below). UPDATE: A general solution will be part of tcolorbox v2.72 (in the future).
  2. Listings are formatted by listings settings. Therefore, use basicstyle to set the listings font.
  3. @Christian H. answered this in his comment. Remove the @ character.
  4. UPDATE: This is a question of its own. I see this as an listings package question: How to insert a text before every line of a listing? You will find an answer (a hack) as second example below.
  5. You inserted a > before a lstlisting which starts with a new paragraph.
  6. You overruled center lower by a following math lower. The same way. nobeforeafter overrules before and after.

The following code example tries to fulfill your requests with exception of >:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}

\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]{
           skin=bicolor,
           overlay={\draw[dashed,black] (segmentation.west)--(segmentation.east);},
           listing options={language={Maple}},
           boxrule=0.5mm,arc=1mm,
           top=1mm,bottom=1mm,middle=1mm,
           listing and comment,
           ams nodisplayskip lower,
           comment={\begin{align*}#1\end{align*}}
           }

\begin{document}

\begin{code}{\frac{n}{n+1}}
2+3;
\end{code}

\end{document}

enter image description here

UPDATE: The following hack allows to insert a text before every line of a listing. Here, a red > is inserted:

\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{lipsum}

\tcbuselibrary{listings,skins,theorems}

\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


\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]{
           skin=bicolor,
           overlay={\draw[dashed,black] (segmentation.west)--(segmentation.east);},
           listing options={language={Maple}},
           boxrule=0.5mm,arc=1mm,
           top=1mm,bottom=1mm,middle=1mm,
           listing and comment,
           ams nodisplayskip lower,
           comment={\begin{align*}#1\end{align*}},
           every listing line={\textcolor{red}{\ttfamily>}}
           }

\begin{document}

\begin{code}{\frac{n}{n+1}}
2+3;
4+5;
\end{code}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .