예를 들어 매달린 포인터에서 어떤 일이 일어나는지 보여주기 위해 "단일 단계"로 수행하고 싶은 C 포인터 코드가 있습니다. 구문 강조를 위해 사용하는데 minted
이것이 문제를 일으키는 것 같습니다.
아래 코드는 (를 사용하여 -shell-escape
) 컴파일되지만 이스케이프되어야 하는 코드는 그렇지 않습니다. 그 이유는 버그인 것 같습니다 pygments
(참조:https://github.com/gpoore/minted/issues/70). 또한 marvin2k
재정의된 문제 를 해결하려고 시도했지만 !
해당 코드가 작동하도록 하는 데 실패했습니다. 또한 다양한 조합을 시도했지만 \begin{minted}[highlightlines=\only<1>{3}\only<2>{5}]{c}
소용이 없었습니다.
누구든지 해결책이 있습니까? 편집: 내 플랫폼은 우분투 14.04, pygmentize 1.6, minted 2.4.1입니다.
\documentclass{beamer}
\usepackage{minted,tikz}
\begin{document}
\begin{frame}[fragile]{Pointers}
\begin{minted}[linenos,escapeinside=||]{c}
int main(void) {
char *p;
p=(char *)malloc(5); |\only<1>{$\Leftarrow$}|
/* do stuff */
p=(char *)malloc(7); |\only<2>{$\Leftarrow$}|
free(p);
return 0;
}
\end{minted}
\begin{tikzpicture}
\node<1->[rectangle,draw] (p) {p};
\node<1->[rectangle,draw,right of=p] (q1) {q1};
\draw<1>[->] (p) -- (q1);
\uncover<2->{\node[rectangle,draw,below right of=p] (q2) {q2};};
\draw<2->[->] (p) -- (q2);
\end{tikzpicture}
\end{frame}
\end{document}
답변1
<
및 >
에는 문제가 있으므로 다음 명령 minted
을 정의할 수 있습니다 \myonly
.
\newcommand\myonly[2]{\only<#1>{#2}}
MWE:
\documentclass{beamer}
\usepackage{minted,tikz}
\newcommand\myonly[2]{\only<#1>{#2}}
\begin{document}
\begin{frame}[fragile]{Pointers}
\begin{minted}[linenos,escapeinside=||]{c}
int main(void) {
char *p;
p=(char *)malloc(5); |\myonly{1}{$\Leftarrow$}|
/* do stuff */
p=(char *)malloc(7); |\myonly{2}{$\Leftarrow$}|
free(p);
return 0;
}
\end{minted}
\begin{tikzpicture}
\node<1->[rectangle,draw] (p) {p};
\node<1->[rectangle,draw,right of=p] (q1) {q1};
\draw<1>[->] (p) -- (q1);
\uncover<2->{\node[rectangle,draw,below right of=p] (q2) {q2};};
\draw<2->[->] (p) -- (q2);
\end{tikzpicture}
\end{frame}
\end{document}
답변2
지금까지 제가 가지고 있는 최고의 솔루션은 @VZ.의 overprint
솔루션(https://tex.stackexchange.com/a/51618/35602). 하지만 C 코드를 반복할 필요가 없는 솔루션이라면 좋을 것 같습니다...
\documentclass{beamer}
\usepackage{minted}
\usepackage{tikz}
\begin{document}
\begin{frame}[fragile]{Foo}
\begin{overprint}
\onslide<1>
\begin{minted}[linenos,highlightlines={3}]{c}
int main(void) {
char *p;
p=(char *)malloc(5);
/* do stuff */
p=(char *)malloc(7);
free(p);
return 0;
}
\end{minted}
\onslide<2>
\begin{minted}[linenos,highlightlines={5}]{c}
int main(void) {
char *p;
p=(char *)malloc(5);
/* do stuff */
p=(char *)malloc(7);
free(p);
return 0;
}
\end{minted}
\end{overprint}
\begin{tikzpicture}
\node<1->[rectangle,draw] (p) {p};
\node<1->[rectangle,draw,right of=p] (q1) {q1};
\draw<1>[->] (p) -- (q1);
\uncover<2->{\node[rectangle,draw,below right of=p] (q2) {q2};};
\draw<2->[->] (p) -- (q2);
\end{tikzpicture}
\end{frame}
\end{document}