2

I needed to create an animated code sample presentation, so I decided to use beamer + minted. That's what I could finally come up with:

\documentclass{beamer}

\usepackage{ifthen}
\usepackage{minted}

\newcommand<>{\iterdemo}[3]{%
  \begin{onlyenv}#4
    \begin{columns}
      \begin{column}{0.4\textwidth}
        \ifthenelse{#3 = 1}
        {\inputminted[highlightlines=#1,highlightcolor=structure!50!white]{Delphi}{iterdemo1.pas}}
        {\inputminted[highlightlines=#1,highlightcolor=structure!20!white]{Delphi}{iterdemo1.pas}}
      \end{column}
      \begin{column}{0.4\textwidth}
        \begin{onlyenv}<4-44>
          \ifthenelse{#3 = 2}
          {\inputminted[highlightlines=#2,highlightcolor=structure!50!white]{Delphi}{iterdemo2.pas}}
          {\inputminted[highlightlines=#2,highlightcolor=structure!20!white]{Delphi}{iterdemo2.pas}}
        \end{onlyenv}
      \end{column}
    \end{columns}
  \end{onlyenv}
}

\begin{document}

\begin{frame}
  \iterdemo<1>{0}{0}{1}
  \iterdemo<2>{5}{0}{1}
  \iterdemo<3>{6}{0}{1}
  \iterdemo<4>{6}{0}{1}
  \iterdemo<5>{8}{0}{1}
  \iterdemo<6>{8}{2}{2}
  \iterdemo<7>{8}{3}{2}
  \iterdemo<8>{8}{3}{1}

  \iterdemo<9>{9}{3}{1}
  \iterdemo<10>{10}{3}{1}
  \iterdemo<11>{10}{3}{2}
  \iterdemo<12>{10}{4}{2}
  \iterdemo<13>{10}{4}{1}

  \iterdemo<14>{11}{4}{1}
  \iterdemo<15>{12}{4}{1}
  \iterdemo<16>{12}{4}{2}
  \iterdemo<17>{12}{5}{2}
  \iterdemo<18>{12}{5}{1}

  \iterdemo<19>{13}{5}{1}
  \iterdemo<20>{14}{5}{1}
  \iterdemo<21>{14}{5}{2}
  \iterdemo<22>{14}{6}{2}
  \iterdemo<23>{14}{6}{1}

  \iterdemo<24>{15}{6}{1}
  \iterdemo<25>{16}{6}{1}
  \iterdemo<26>{16}{6}{2}
  \iterdemo<27>{16}{7}{2}
  \iterdemo<28>{16}{7}{1}

  \iterdemo<29>{17}{7}{1}
  \iterdemo<30>{18}{7}{1}
  \iterdemo<31>{18}{7}{2}
  \iterdemo<32>{18}{8}{2}
  \iterdemo<33>{18}{8}{1}

  \iterdemo<34>{19}{8}{1}
  \iterdemo<35>{20}{8}{1}
  \iterdemo<36>{20}{8}{2}
  \iterdemo<37>{20}{9}{2}
  \iterdemo<38>{20}{9}{1}

  \iterdemo<39>{21}{9}{1}
  \iterdemo<40>{22}{9}{1}
  \iterdemo<41>{22}{9}{2}
  \iterdemo<42>{22}{10}{2}
  \iterdemo<43>{22}{0}{1}
  \iterdemo<44>{24}{0}{1}
  \iterdemo<45>{24}{0}{1}
  \iterdemo<46>{26}{0}{1}
\end{frame}

\end{document}

The code is obviously suboptimal due to heavy duplication (and it was pain to create it!). However, the following approaches to fight the hand-work didn't play for me:

  1. Using <+-> overlay specification instead of hard-coded numbers doesn't have effect: the content appears on every page.

  2. It seemed that \foreach loop would easily remove a lot of duplication in the central part of code, but I couldn't find a way to pass expanded value as a minted option highlightlines. This is probably due to pgfkeys nature of minted options.

Is it possible to simplify the above code, e.g. by using a loop?

2
  • Welcome to TeX.Stackexchange! Can you please make your MWE compilable? We don't have iterdemo1.pas thus cannot test your code. What is the intended result of your code? Jul 20, 2017 at 13:50
  • @samcarter: they're just arbitrary pascal files.
    – JPi
    Jul 20, 2017 at 13:54

1 Answer 1

2

I'm not sure what you have in mind re 2, but this works...

\documentclass{beamer}

\usepackage{ifthen}
\usepackage{minted}
\usepackage{pgffor}

\newcommand<>{\iterdemo}[3]{%
  \begin{onlyenv}#4
    \begin{columns}
      \begin{column}{0.4\textwidth}
        \ifthenelse{#3 = 1}
        {\inputminted[highlightlines=#1,highlightcolor=structure!50!white]{Delphi}{iterdemo1.pas}}
        {\inputminted[highlightlines=#1,highlightcolor=structure!20!white]{Delphi}{iterdemo1.pas}}
      \end{column}
      \begin{column}{0.4\textwidth}
        \begin{onlyenv}<4-44>
          \ifthenelse{#3 = 2}
          {\inputminted[highlightlines=#2,highlightcolor=structure!50!white]{Delphi}{iterdemo2.pas}}
          {\inputminted[highlightlines=#2,highlightcolor=structure!20!white]{Delphi}{iterdemo2.pas}}
        \end{onlyenv}
      \end{column}
    \end{columns}
  \end{onlyenv}
}

\begin{document}

\begin{frame}
\foreach \x / \y / \z / \a in {1/0/0/1,2/5/0/1,3/6/0/1,4/6/0/1,5/8/0/1,6/8/2/2,7/8/3/2,8/8/3/1,9/9/3/1,10/10/3/1,11/10/3/2,12/10/4/2,13/10/4/1}
{

    \iterdemo<\x>{\y}{\z}{\a}
   }

  \iterdemo<14>{11}{4}{1}
  \iterdemo<15>{12}{4}{1}
  \iterdemo<16>{12}{4}{2}
  \iterdemo<17>{12}{5}{2}
  \iterdemo<18>{12}{5}{1}

  \iterdemo<19>{13}{5}{1}
  \iterdemo<20>{14}{5}{1}
  \iterdemo<21>{14}{5}{2}
  \iterdemo<22>{14}{6}{2}
  \iterdemo<23>{14}{6}{1}

  \iterdemo<24>{15}{6}{1}
  \iterdemo<25>{16}{6}{1}
  \iterdemo<26>{16}{6}{2}
  \iterdemo<27>{16}{7}{2}
  \iterdemo<28>{16}{7}{1}

  \iterdemo<29>{17}{7}{1}
  \iterdemo<30>{18}{7}{1}
  \iterdemo<31>{18}{7}{2}
  \iterdemo<32>{18}{8}{2}
  \iterdemo<33>{18}{8}{1}

  \iterdemo<34>{19}{8}{1}
  \iterdemo<35>{20}{8}{1}
  \iterdemo<36>{20}{8}{2}
  \iterdemo<37>{20}{9}{2}
  \iterdemo<38>{20}{9}{1}

  \iterdemo<39>{21}{9}{1}
  \iterdemo<40>{22}{9}{1}
  \iterdemo<41>{22}{9}{2}
  \iterdemo<42>{22}{10}{2}
  \iterdemo<43>{22}{0}{1}
  \iterdemo<44>{24}{0}{1}
  \iterdemo<45>{24}{0}{1}
  \iterdemo<46>{26}{0}{1}
\end{frame}

\end{document}
1
  • This works but doesn't remove the duplication :-( The slide numbers are still specified manually in spite of they are a just a natural numbers sequence. I would also expect that slide groups 2..6 (slides 9-38) could be united into one foreach body, as the \iterdemo arguments between these groups differ only by slide number offset. Jul 20, 2017 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .