
このコードを参照してください:
\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}