Re: Script to export all views from all pages of the Ipe drawing

Otfried Cheong via Ipe-discuss <ipe-discuss-rGrgPyRx506NN8uzcEdRPYRWq/[email protected]> Mon, 17 Sep 2018 01:17:14 +0900
Newsgroups gmane.comp.graphics.ipe.general
Message-ID <1537114634.2960605.1509847104.177B288C@webmail.messagingengine.com>
My apologies for not looking into this earlier, I was very busy (moving to Europe) during the last few months.

It seems quite wasteful that we first need to decompose the Ipe animation into one file per view, before we can then include those into the presentation.   After all, pdflatex and the \includegraphics command already have the ability to include a given page from a PDF file.

The problem here was that the xmpmulti.sty package and the \multiinclude command that it defines cannot do this, it really needs the animation split over 30 files.

I think the most elegant solution to this issue is to make an alternative \multiinclude command that will include a sequence of pages from a  single PDF file.    I'm attaching a file "pdfmulti.sty" that does exactly this.   Instead of including abc-1.pdf, abc-2.pdf, etc., it will include page 1, page 2, etc from file abc.pdf.

I'm also attaching a small example presentation that includes Wojciech's nice Heapsort animation.

-----

As to the question why the PDF files exported by Ipe are so large, this is caused by the PDF resources that Ipe copies from the pdflatex run on the text objects into the output PDF file.   In the current version,  Ipe simply includes ALL such resources, even if they are not used on the view being exported.    I need to investigate how this can be fixed (as resources form a dag of dependencies).

Cheers,
  Otfried



On Mon, May 14, 2018, at 01:11, Wojciech Zabolotny via Ipe-discuss wrote:
> I often use Ipe to prepare animated (i.e., incrementally displayed on
> subsequent slides)
> drawings for my presentations in beamer.
> The "iperender" tool allows exporting a single view.
> However, I need an automatic tool, that is able to export all the
> views in the separate files,
> located in another directory. That allows me to use it in a Makefile
> prepared for conversion
> of the figures, as shown below:
> 
> In the Makefile:
> [...]
> .ipe.pdf: *.ipe
>         ipescript expallviews $*.ipe ../figures_processed
> [...]
> 
> If I have a figure "my_figure.ipe", that contains a few views in the
> page 1, then I can include it in my presentation as shown below
> 
> In the presentation.tex file:
> 
> \usepackage{xmpmulti}
> \graphicspath{{./figures_processed/}}
> [...]
> 
> \multiinclude[format=pdf,start=1,graphics={width=0.9\linewidth}]
> {my_figure-p-1-v}
> 
> At the end of that message I attach the source code of my
> "expallviews.lua" script.
> 
> The code is published as PUBLIC DOMAIN or under Creative Commons
> CC0 license, whatever better suits your needs.
> The code is published without any warranty. You use it on your own risk.
> 
> -- 
> With best regards,
> Wojtek

_______________________________________________
Ipe-discuss mailing list
Ipe-discuss-rGrgPyRx506NN8uzcEdRPYRWq/[email protected]
https://mailman.science.uu.nl/mailman/listinfo/ipe-discuss
pdfmulti.sty (text/x-tex, 6.1 KB)
% Copyright 2000 by Klaus Guntermann
% Copyright 2004 by Till Tantau <[email protected]>.
% Copyright 2015 by Vedran Mileti\'c, Joseph Wright
% PDF multi-page version by Otfried Cheong, 2018
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.

%
% This is "pdfmulti.sty", a modified version of "xmpmulti.sty":
% Instead of including images from several files names abc-1, abc-2,
% abc-3, etc.,  it includes pages from a single PDF file, using the
% page=# option to \includegraphics.
% The check to stop at the last page of a PDF file uses the 
% \pdflastximagepages command, it may not work on engines other than
% pdftex.
%

%
% Copyright notices: Large parts of this file are identical to the
% file mpmulti.sty from the ppower4 distribution. Unfortunately, no
% clear copyright notice is given in the original file nor is even the
% author indicated. The author appears to be Klaus Guntermann and the
% license appears to be GPL, at least the whole package is distributed
% under GPL, so I assume that also applies to the individual
% files.
%

%
% This file does the same as the original mpmulti.sty. The only
% differences are that a) the package pause is not loaded (it's
% provided automatically by beamer and it should be loaded ``by hand''
% when using ppower4) and b) a default overlay specification can be
% given (as in \multiinclude[<+->][...]{...}), which will be the
% argument to an actionenv that is put around each image.
%


%% mpmulti.sty                                     09 Sep 2002
%%------------------------------------------------------------
%% History:
%%   Initial version                               14 Apr 2000
%%   Introduced keyword parameters                 12 Jun 2000
%%   Introduced new parameters (start,format), changed the
%%     global code to take several file counting strings (eg
%%     bla-*.mps, foo-*.jpg, etc.), added compatibility with
%%     \graphicspath (Jean-Christophe Dubacq)      06 Dec 2001
%%   Generalized the format option, added the end
%%   handling and documented extended features in here
%%                                                 09 Sep 2002
%%
%% Purpose:
%%     include pictures from PDF file and overlay them,
%%     inserting a transition effect between them
%%
%% Synopsis:
%%
%% \multiinclude[defaultoverlayspecification]%
%%              [pause=transitioncommand,
%%               graphics={option for includegraphics},
%%               start=number,
%%               end=number]{basefilename}
%%
%%     Include several graphics found in the single PDF file "filename".
%%     Insert the transitioncommand between the images (defaults
%%     to \pause).
%%     Further options allow to specify additional specifications
%%     for includegraphics, can change the page number to start with
%%     (default 1) or the number to end with (default 1000000).
%%
%%     If a defaultoverlayspecification is given, each image is
%%     surrounded by an actionenv environment (defined by the beamer
%%     class) with this option as argument. An example usage might be
%%
%%     \multiinclude[<alert@+| +->][graphics={height=4cm}]{myimage}
%%
%% Requires:
%%     The keyval package for options processing.
%%
%%
%\RequirePackage{pause}
\RequirePackage{keyval}
%%
%% The command should process the optional arguments.
%%
\def\multiinclude{%
  \def\@mpm@pause{\pause}\def\@mpm@ospec{}\def\@mpm@endospec{}%
  \@ifnextchar [\@mpmulti{\@@@mpmulti[]}}
%%
\newif\if@mpm@groptions\@mpm@groptionsfalse
%% We describe the keys and their default values
\define@key{mpm}{start}[1]{\global\def\@mpm@start{#1}\relax}
\define@key{mpm}{end}[1000000]{\global\def\@mpm@end{#1}\relax}
\define@key{mpm}{pause}[\pause]{\global\def\@mpm@pause{#1}\relax}
\define@key{mpm}{graphics}{\@mpm@groptionstrue
  \global\def\@mpm@graphics{\string#1}}
%%
%% We need a local counter
%%
\newcount\@mpm@count
%%
%% Implement the basic functionality.
%% Try to include the first file unconditionally.
%% This will produce an error message, if no such file can be found.
%% Afterwards we are going to check for more files and stop, when we
%% do not find another file. As long as we find files, these are
%% overlapped to the previous parts.
%%
\def\@mpmulti[{\@ifnextchar<{\@@mpmulti[}{\@@@mpmulti[}}
\def\@@mpmulti[#1]{%
  \def\@mpm@pause{\relax}%
  \def\@mpm@ospec{\begin{actionenv}#1}%
  \def\@mpm@endospec{\end{actionenv}}%
  \@ifnextchar[{\@@@mpmulti}{\@@@mpmulti[]}}
\def\@@@mpmulti[#1]#2{%
  %% reset the options
  \global\def\@mpm@graphics{}%
  \global\def\@mpm@start{1}%
  \global\def\@mpm@end{1000000}%
  %% get the arguments
  \setkeys{mpm}{#1}%
  %% Insert the first part of the figure
  %% and make sure we look also in other places according to path.
  \let\@mpm@oldinp@th\input@path\let\input@path\Ginput@path
  \@mpm@count=\@mpm@start
  \@mpm@ospec%
  \if@mpm@groptions%
  \edef\@mpm@do@include{\noexpand\includegraphics[page=\@mpm@count,\@mpm@graphics]{#2}}%
  \else%
  \edef\@mpm@do@include{\noexpand\includegraphics[page=\@mpm@count]{#2}}%
  \fi%
  \@mpm@do@include%
  \@mpm@endospec%
  \def\@mpmdoit{% Do it by conditional tail recursion.
  \edef\@mpmfilename{#2}%
    %% insert the user defined transition (or the default),
    \@mpm@pause
    %% then process the next part and set up to try again.
    \llap{%
      \@mpm@ospec%
      \if@mpm@groptions
      \edef\@mpm@do@include{\noexpand
        \includegraphics[page=\@mpm@count,\@mpm@graphics]{\@mpmfilename}}%
      \else
      \edef\@mpm@do@include{\noexpand
        \includegraphics[page=\@mpm@count]{\@mpmfilename}}%
      \fi%
      \@mpm@do@include
      \@mpm@endospec%
      }%
    \ifnum\@mpm@count<\@mpm@end\relax
      \ifnum\@mpm@count<\pdflastximagepages\relax
        \advance\@mpm@count by 1\relax
        \let\@mpmnext\@mpmdoit
      \else
        \let\@mpmnext\relax
      \fi
    \else
      \let\@mpmnext\relax
    \fi
  %% Whatever we had to do
  \@mpmnext
  }%
  %% Finally we must start it once, if there is more than one file
  %% supposed to be available.
  \ifnum\@mpm@count<\@mpm@end\relax
    \advance\@mpm@count by 1\relax   % start counting
    \@mpmdoit % and run the show
  \fi
  %% and reset the input path after all
  \let\input@path\@mpm@oldinp@th
}%
sort-with-heap.tex (text/x-tex, 420 B)
\documentclass{beamer}
\usepackage{pdfmulti}

\setbeamertemplate{background canvas}[vertical shading][bottom=white,top=structure.fg!25]

\usetheme{Warsaw}
\setbeamertemplate{headline}{}
\setbeamertemplate{footline}{}
\setbeamersize{text margin left=0.5cm}
  
\begin{document}

\begin{frame}{HeapSort}{A Heapsort Animation}

  \multiinclude[<+>][graphics={width=0.7\linewidth}]{heapsort}
  
\end{frame}

\end{document}