tcolorbox 패키지로 생성하는 mathmode를 사용하여 주석에 메이플 코드 삽입

tcolorbox 패키지로 생성하는 mathmode를 사용하여 주석에 메이플 코드 삽입

이 코드를 참조하세요:

\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}

출력은 다음과 같습니다

여기에 이미지 설명을 입력하세요

이 출력이 나올 때까지 어떻게 변경합니까?

여기에 이미지 설명을 입력하세요

내 말은암호\begin{code}{} ... \end{code} 환경이 아닙니다.

미리 감사드립니다.

답변1

귀하의 질문을 올바르게 이해했다면 키워드를 갖고 수학적 환경 내에서 자동으로 감지되기를 원할 것 proc입니다 end proc. 여기, align*. 나는 이것이 가능하다고 생각하지 않습니다.

수학적 환경 내에서 직접 키워드를 표시하거나 일부 수학적 내용이 포함된 이스케이프 시퀀스를 listings코드에 삽입할 수 있습니다. 이는 를 listings사용하는 설명서 에 설명되어 있습니다 mathescape.

첫 번째 변형은 기존 코드에 더 가깝습니다. every listing line정의는 의 일부이므로 제거했지만 tcolorbox 2.72 (2014/03/18)이전 버전에서는 그대로 유지할 수 있습니다 tcolorbox. 수학 코드 내에서 수동으로 선택한 키워드를 사용하여 수정된 예는 다음과 같습니다.

\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}

여기에 이미지 설명을 입력하세요

관련 정보