当使用 sagetex 时,可以通过 lstlistings 设置轻松更改 sagecommandline 环境的背景。
如何更改 sageblock 环境的背景?
梅威瑟:
\documentclass[]{article}
\usepackage{sagetex}
\usepackage{xcolor}
\lstset{language=Sage,
commentstyle={\ttfamily\color{green}},
keywordstyle={\ttfamily\color{blue}\bfseries},
stringstyle ={\ttfamily\color{dgraycolor}\bfseries},
tabsize = 4,
basicstyle={\small \ttfamily},
backgroundcolor= \color{orange!20},
}
\begin{document}
The following function computes the square of a number:
\begin{sageblock}
def f(x):
return x**2
\end{sageblock}
Testing in the code gives for $x=2$ the value \sage{f(2)}.
Commandline Version:
\begin{sagecommandline}
sage: x = 2
sage: f(2)
\end{sagecommandline}
\end{document}
答案1
您可以使用tcolorbox
包来实现这一点。更改colback
为您想要的背景颜色。tcolorbox
提供更多选项(标题、框架颜色ETC。), 看文档了解这些详细信息
\documentclass{article}
\usepackage{sagetex}
\usepackage{tcolorbox}
\begin{document}
% colback: background colour
\begin{tcolorbox}[colback=orange!20, enhanced, arc=0pt, frame hidden]
\begin{sageblock}
var('x')
f(x) = sin(x) - 1
g(x) = log(x)
h(x) = diff(f(x) * g(x), x)
\end{sageblock}
\end{tcolorbox}
% verify that sageblock works
$h : \sage{h}$
\end{document}