
Tengo un directorio de imágenes con varias imágenes:
p1.jpg
p2.jpg
p3.jpg
p4.jpg
También tengo el siguiente entorno que establece la imagen de fondo en un marco:
\newenvironment{imageframe}[1]
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]%
\node[inner sep=0] at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{#1}};%
\end{tikzpicture}%
}%
\begin{frame}%
}
{
\end{frame}%
}
Se usa así:
\begin{imageframe}{p1.jpg}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{imageframe}
Me gustaría crear una variable (o comando) que contenga la lista de imágenes de fondo válidas (p1.jpg, ..., p4.jpg) y luego no especificar la ruta de la imagen explícitamente cuando se llama al entorno. En cambio, la primera imagen (p1.jpg) debe seleccionarse la primera vez que se invoca el marco de imagen, la segunda imagen (p2.jpg) debe llamarse la segunda vez, y así sucesivamente. El desbordamiento debería volver a p1.jpg.
Respuesta1
Sin contadores y sin necesidad de indicar previamente el número de imágenes: simplemente define la lista de imágenes de la forma mostrada y listo.
\documentclass{beamer}
\usepackage{tikz}
\newenvironment{autoimageframe}
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]
\node[inner sep=0] at (current page.center) {%
\includegraphics[width=\paperwidth,height=\paperheight]{\currentbgimage}%
};
\end{tikzpicture}%
\expandafter\swapbgimage\bgimagelist
}%
\begin{frame}}
{\end{frame}}
\newcommand\currentbgimage{\expandafter\usebgimage\bgimagelist}
\newcommand{\usebgimage}{}
\def\usebgimage#1#2\bgimagelist{#1}
\newcommand{\swapbgimage}{}
\def\swapbgimage#1#2\bgimagelist{%
\gdef\bgimagelist{#2{#1}\bgimagelist}%
}
% Define here the list of images
% Each image is in a braced group
% REMEMBER to have \bgimagelist at the end
\newcommand\bgimagelist{
{example-image}
{example-image-a}
{example-image-b}
{example-image-c}
\bgimagelist
}
\begin{document}
% Thanks to Percusse for the code here
\foreach\x in{1,...,9}{
\begin{autoimageframe}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{autoimageframe}
}
\end{document}
La \currentbgimage
macro utiliza el primer elemento de la lista; luego \swapbgimage
coloca el primer elemento al final.
Respuesta2
Puede generar algunas macros y una lista de nombres y recorrerlas mediante una mod
operación.
\documentclass{beamer}
\usepackage{tikz,mwe}% For dummy images
\newcounter{backgroundimagecounter}
\setcounter{backgroundimagecounter}{0}
\newenvironment{autoimageframe}
{% Set background image
\usebackgroundtemplate{%
\begin{tikzpicture}[remember picture,overlay]%
\pgfmathsetmacro\currentbackgroundimage{\backgroundimagenamelist[int(Mod(\value{backgroundimagecounter},\numberofbackgroundimages))]}%
\node[inner sep=0] at (current page.center) {\includegraphics[width=\paperwidth,height=\paperheight]{\currentbackgroundimage}};%
\end{tikzpicture}%
\stepcounter{backgroundimagecounter}%
}%
\begin{frame}%
}
{
\end{frame}%
}
\def\backgroundimagenamelist{{
"example-image",
"example-image-a",
"example-image-b",
"example-image-c"}}
\def\numberofbackgroundimages{4}
\begin{document}
\foreach\x in{1,...,9}{
\begin{autoimageframe}
\frametitle{Nothing was the same.}
Always felt like my vision been bigger than the bigger picture.
\end{autoimageframe}
}
\end{document}