![命令“defverbatim”会忘记“minted”中的颜色](https://linux22.com/image/420034/%E5%91%BD%E4%BB%A4%E2%80%9Cdefverbatim%E2%80%9D%E4%BC%9A%E5%BF%98%E8%AE%B0%E2%80%9Cminted%E2%80%9D%E4%B8%AD%E7%9A%84%E9%A2%9C%E8%89%B2.png)
我正在尝试使用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}