我有四个问题:
- 在“Hello”和“World”之间插入一个类似\sqcup的字符“你好,世界”?
- 我如何改变代码环境以便注释(不在数学模式中)对 Maple 关键字敏感,例如,改变其颜色?
- 有没有办法定义'智能缩进'MATLAB 软件,自动缩进我的代码?如果没有,我该如何定义这样的命令 \maple缩进(用于缩进),这在顶部起作用,而不是我手动插入空格?
- 我怎样才能移动 Fib 算法的下部(下面的最后一个代码环境) 一起到线的中间?我用中央下部,输出格式不太好。
代码是:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage[top=2.5cm,right=3.5cm,bottom=2.5cm,left=2.5cm]{geometry}
%----------------------------------------------------------------------------------------
% MAPLE CODE
%----------------------------------------------------------------------------------------
\tcbuselibrary{listings,skins,theorems}
\lstdefinelanguage{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,
keywordstyle=\color{black},
morecomment=[l][\color{green!50!black}]\#,
morestring=[b]",
morestring=[d]"
aboveskip={0pt},
belowskip={0pt},
}[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]{
skin=bicolor,
colback=white,
colbacklower=white,
colupper=red!40!black,
collower=blue,
listing options={language={Maple}},
fontupper=\ttfamily\bfseries,
boxrule=0mm,
top=0mm,bottom=0mm,middle=0mm,
% center lower,
nobeforeafter,
listing and comment,
comment={ #1},
every listing line={\textcolor{red!40!black}{\ttfamily> }}
}
\newdimen\Tab
\Tab=3ex
\def\mapleIndent#1{\hbox{\hskip#1\Tab\relax}}
\begin{document}
\begin{code}{ F := proc() "Hello World " end proc}
F := proc() # comment
"Hello World"
end proc;
\end{code}
\begin{code}{}
Max := proc()
local i,m;
if nargs = 0 then
return -infinity
end if;
m := args[1];
for i from 2 to nargs do
if args[i] > m then
m := args[i]
end if;
end do;
m;
end proc:
\end{code}
\begin{code}{
Fib := proc(n::nonnegint)\\
option remember;\\
\mapleIndent{1} if $n < 2$ then $n$ else Fib$(n - 1)$ + Fib$(n - 2)$ end if\\
end proc}
Fib := proc( n :: nonnegint )
option remember;
if n<2 then
n
else
Fib(n-1) + Fib(n-2)
end if;
end proc;
\end{code}
\end{document}