我正在尝试使用minted
inside uncover
。看起来环境minted
具有逐字环境的属性,因此需要 hack defverbatim
。问题是这个 hack 会忘记颜色。如何解决这个问题?
演示示例:
\documentclass[aspectratio=169
, xcolor={svgnames}
]{beamer}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}
\usepackage[cache=true]{minted}
\begin{document}
\defverbatim{\exampleTailRec}{
\begin{minted}{ocaml}
(* make2 : 'a -> int -> 'a list *)
let make2 x n =
let rec helper acc n =
if n<1 then acc
else helper (x :: acc) (n-1)
in
helper [] n
\end{minted}
}
\begin{frame}[fragile]
\begin{minipage}[t]{0.45\linewidth}
\begin{minted}{ocaml}
(* make : 'a -> int -> 'a list *)
let rec make x n =
if n<1 then []
else x :: (make x (n-1))
\end{minted}
\uncover<2->{
\begin{minipage}{7cm}
%\begin{minted}{ocaml}
%(* make2 : 'a -> int -> 'a list *)
%let make2 x n =
% let rec helper acc n =
% if n<1 then acc
% else helper (x :: acc) (n-1)
% in
% helper [] n
%\end{minted}
\exampleTailRec
\end{minipage}
}
\end{minipage}\hspace{1cm}
\begin{minipage}[t]{0.45\linewidth}
\lipsum[2]
\end{minipage}
\end{frame}
\end{document}
答案1
(第 18 页)的手册beamer
说,为了保存lstlisting
环境中的彩色列表,必须使用\defverbatim[colored]
。
它也适用于minted
。
\documentclass[aspectratio=169
, xcolor={svgnames}
]{beamer}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{russian}
\usepackage[cache=true]{minted}
\begin{document}
\defverbatim[colored]{\exampleTailRec}{
\begin{minted}{ocaml}
(* make2 : 'a -> int -> 'a list *)
let make2 x n =
let rec helper acc n =
if n<1 then acc
else helper (x :: acc) (n-1)
in
helper [] n
\end{minted}
}
\begin{frame}[fragile]
\begin{minipage}[t]{0.45\linewidth}
\begin{minted}{ocaml}
(* make : 'a -> int -> 'a list *)
let rec make x n =
if n<1 then []
else x :: (make x (n-1))
\end{minted}
\uncover<2->{
\begin{minipage}{7cm}
%\begin{minted}{ocaml}
%(* make2 : 'a -> int -> 'a list *)
%let make2 x n =
% let rec helper acc n =
% if n<1 then acc
% else helper (x :: acc) (n-1)
% in
% helper [] n
%\end{minted}
\exampleTailRec
\end{minipage}
}
\end{minipage}\hspace{1cm}
\begin{minipage}[t]{0.45\linewidth}
\lipsum[2]
\end{minipage}
\end{frame}
\end{document}