命令“defverbatim”会忘记“minted”中的颜色

命令“defverbatim”会忘记“minted”中的颜色

我正在尝试使用mintedinside 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 页

第 2 页

答案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}

在此处输入图片描述

相关内容