Discussion:
Script to export all views from all pages of the IPE drawing
(too old to reply)
Wojciech M. Zabołotny
2018-05-13 15:30:01 UTC
Permalink
To prepare presentations in beamer, I often use IPE editor
( http://ipe.otfried.org ) to prepare animated (i.e., incrementally
displayed on subsequent slides) drawings.
IPE offers the "iperender" tool, that allows to export 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 used to convert
the figures, as shown below:

[...]
.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, I can then include it in my presentation as shown below

\usepackage{xmpmulti}
\graphicspath{{./figures_processed/}}
[...]
\multiinclude[format=pdf,start=1,graphics={width=0.9\linewidth}]{my_figure-p-1-v}

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

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.15.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the '#!/bin/sh' line above, then type 'sh FILE'.
#
lock_dir=_sh05256
# Made on 2018-05-13 17:22 CEST by <***@wzab>.
# Source directory was '/tmp/eav'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1528 -rw-r--r-- expallviews.lua
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
if test "X$1" = "X-c"
then keep_file=''
else keep_file=true
fi
echo=echo
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=
locale_dir=
set_echo=false

for dir in $PATH
do
if test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir
set_echo=true
break ;;
esac
fi
done

if ${set_echo}
then
set_echo=false
for dir in $PATH
do
if test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
set_echo=true
break
fi
done

if ${set_echo}
then
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
fi
IFS="$save_IFS"
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU '\''touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= expallviews.lua ==============
if test -n "${keep_file}" && test -f 'expallviews.lua'
then
${echo} "x - SKIPPING expallviews.lua (file already exists)"

else
${echo} "x - extracting expallviews.lua (text)"
sed 's/^X//' << 'SHAR_EOF' > 'expallviews.lua' &&
-- This is the script for exporting all views from all pages
-- in the IPE drawing.
-- I use it to export animated figures for beamer presentations.
-- Based on the information from
-- http://ipe.otfried.org/manual/luapage.html
-- This script was written by Wojciech M. Zabolotny
-- ( wzab01<at>gmail.com )
-- and is published as Public Domain or under
-- Creative Commons CC0 license, whatever better suits your needs.
--
-- Problems:
-- At the moment I can only epxort figures in PDF 1.4 format.
-- (iperender exports in PDF 1.5, but exportView in PDF 1.4)
if #argv ~= 2 then
X io.stderr:write("Usage: ipescript expallviews <inputfile> <outputdir>\n")
X return
end
fname=argv[1]
print(fname)
doc = ipe.Document(fname)
-- Prepare the base file name for the output files
-- Remove the directory part (if exists)
fbase=fname:reverse()
-- reverse the string. to make searching for last "/" and "." easier
i = fbase:find("/",1,"plain")
if (i) then
X fbase=fbase:sub(1,i-1)
end
i = fbase:find(".",1,"plain")
if (i) then
X fbase=fbase:sub(i+1)
end
fbase=fbase:reverse()
-- Add the output directory to the base filename
fbase=argv[2] .. "/" .. fbase
-- Now we can convert all the views from all pages
np=#doc
--print(fname .. " contains " .. np )
for p=1,np,1
do
X pg=doc[p]
X nv = pg:countViews()
X --print(fname .. " page " .. p .. " contains " .. nv .. " views")
X for v=1,nv,1
X do
X fout=fbase .. "-p-" .. p .. "-v-" .. v .. ".pdf"
X --print("exporting to: " .. fout)
X doc:exportView(fout,nil,nil,p,v)
X end
end
X
SHAR_EOF
(set 20 18 05 13 17 21 35 'expallviews.lua'
eval "${shar_touch}") && \
chmod 0644 'expallviews.lua'
if test $? -ne 0
then ${echo} "restore of expallviews.lua failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'expallviews.lua': 'MD5 check failed'
) << \SHAR_EOF
e042b3f5eddd3df5d54c32e31eb36822 expallviews.lua
SHAR_EOF

else
test `LC_ALL=C wc -c < 'expallviews.lua'` -ne 1528 && \
${echo} "restoration warning: size of 'expallviews.lua' is not 1528"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0
w***@gmail.com
2018-05-13 20:21:40 UTC
Permalink
The first version of my script does not properly export LaTeX objects.
It is necessary to add doc:runLatex right after loading of the IPE drawing:

doc = ipe.Document(fname)
doc:runLatex()

After that modification, LaTeX equations and texts are rendered correctly.
Wojciech M. Zabołotny
2018-06-04 23:07:15 UTC
Permalink
The previous version of my script tends to create huge PDFs
for complex Ipe files with LaTeX texts.
I have found, that exporting the view in the EPS format
and converting it later on into PDF gives better results.
Unfortunately, the ui:renderPage method used by Ipe to
export in EPS format is not available for ipelets.
Therefore, such approach requires calling the external program.
The script below opens the Ipe file and finds the number of pages
and views. Then it calls "iperender" on the same file for each view
to export it to EPS. Afterwards, it calls "epstopdf" to convert it
to PDF, and finally deletes the EPS file.
Opening the same file twice by different programs is a little strange,
but it works.
Of course this is experimental code, published under as Public Domain
or under Creative Commons CC0 license. You use it on your own risk.

Regards,
Wojtek

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.15.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the '#!/bin/sh' line above, then type 'sh FILE'.
#
lock_dir=_sh05437
# Made on 2018-06-05 00:58 CEST by <***@wzab>.
# Source directory was '/tmp/uu'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1767 -rw-r--r-- expallviews2.lua
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
if test "X$1" = "X-c"
then keep_file=''
else keep_file=true
fi
echo=echo
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=
locale_dir=
set_echo=false

for dir in $PATH
do
if test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir
set_echo=true
break ;;
esac
fi
done

if ${set_echo}
then
set_echo=false
for dir in $PATH
do
if test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
set_echo=true
break
fi
done

if ${set_echo}
then
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
fi
IFS="$save_IFS"
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU '\''touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= expallviews2.lua ==============
if test -n "${keep_file}" && test -f 'expallviews2.lua'
then
${echo} "x - SKIPPING expallviews2.lua (file already exists)"

else
${echo} "x - extracting expallviews2.lua (text)"
sed 's/^X//' << 'SHAR_EOF' > 'expallviews2.lua' &&
-- This is the script for exporting all views from all pages
-- in the IPE drawing.
-- I use it to export animated figures for beamer presentations.
-- Based on the information from
-- http://ipe.otfried.org/manual/luapage.html
-- This script was written by Wojciech M. Zabolotny
-- ( wzab01<at>gmail.com )
-- and is published as Public Domain or under
-- Creative Commons CC0 license, whatever better suits your needs.
--
-- Problems:
-- At the moment I can only epxort figures in PDF 1.4 format.
-- (iperender exports in PDF 1.5, but exportView in PDF 1.4)
if #argv ~= 2 then
X io.stderr:write("Usage: ipescript expallviews <inputfile> <outputdir>\n")
X return
end
fname=argv[1]
print(fname)
doc = ipe.Document(fname)
doc:runLatex()
-- Prepare the base file name for the output files
-- Remove the directory part (if exists)
fbase=fname:reverse()
-- reverse the string. to make searching for last "/" and "." easier
i = fbase:find("/",1,"plain")
if (i) then
X fbase=fbase:sub(1,i-1)
end
i = fbase:find(".",1,"plain")
if (i) then
X fbase=fbase:sub(i+1)
end
fbase=fbase:reverse()
-- Add the output directory to the base filename
fbase=argv[2] .. "/" .. fbase
-- Now we can convert all the views from all pages
np=#doc
--print(fname .. " contains " .. np )
flags={}
flags["export"]=false
flags["nozip"]=0
for p=1,np,1
do
X pg=doc[p]
X nv = pg:countViews()
X --print(fname .. " page " .. p .. " contains " .. nv .. " views")
X for v=1,nv,1
X do
X fout=fbase .. "-p-" .. p .. "-v-" .. v
X feps=fout .. ".eps"
X fpdf=fout .. ".pdf"
X --print("exporting to: " .. fout)
X os.execute("iperender -eps -page " .. p .. " -view " .. v .. " " .. fname .. " " .. feps)
X os.execute("epstopdf ".. feps .. " " .. fpdf)
X os.execute("rm " .. feps)
X end
end
X
SHAR_EOF
(set 20 18 06 05 00 44 42 'expallviews2.lua'
eval "${shar_touch}") && \
chmod 0644 'expallviews2.lua'
if test $? -ne 0
then ${echo} "restore of expallviews2.lua failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'expallviews2.lua': 'MD5 check failed'
) << \SHAR_EOF
3f1aff4bec418ad6063bbc44e9403652 expallviews2.lua
SHAR_EOF

else
test `LC_ALL=C wc -c < 'expallviews2.lua'` -ne 1767 && \
${echo} "restoration warning: size of 'expallviews2.lua' is not 1767"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0
Wojciech M. Zabołotny
2018-06-05 12:48:21 UTC
Permalink
This is the optimized version of the script enabling export of all views
from all pages of the Ipe file ( http://ipe.otfried.org/ ).
Now it uses "iperender -pdf", that provides minimal size PDFs with the same
Bounding Box.

If your file is named "myfigure.ipe", and you want to produce PDFs
in the "../figures_out" directory, then you should run:
$ ipescript expallviews myfigure.ipe ../figures_out
Then, if the path "../figures_out" belongs to the \graphicspath in your
LaTeX file, you may create the "animation" based on views of page 1 by:
\multiinclude[<+>][format=pdf,start=1,graphics={width=0.9\linewidth}]{myfigure-p-1-v}

Please remember, that this is experimental code published without any warranty
as Public Domain, or under Creative Commons CC0 license.
It executes remote commands (iperender) and writes to your disk.
You should understand how does it work. You use it on your own risk.

Anyway, it appeared to be very useful for me.
With best regards,
Wojtek

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.15.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the '#!/bin/sh' line above, then type 'sh FILE'.
#
lock_dir=_sh00603
# Made on 2018-06-05 14:37 CEST by <***@wzdell>.
# Source directory was '/tmp/u'.
#
# Existing files will *not* be overwritten, unless '-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 1778 -rw-r--r-- expallviews.lua
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
if test "X$1" = "X-c"
then keep_file=''
else keep_file=true
fi
echo=echo
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=
locale_dir=
set_echo=false

for dir in $PATH
do
if test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir
set_echo=true
break ;;
esac
fi
done

if ${set_echo}
then
set_echo=false
for dir in $PATH
do
if test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
set_echo=true
break
fi
done

if ${set_echo}
then
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
fi
IFS="$save_IFS"
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and
installing GNU '\''touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir} ; then :
else ${echo} "lock directory ${lock_dir} exists"
exit 1
fi
if mkdir ${lock_dir}
then ${echo} "x - created lock directory ${lock_dir}."
else ${echo} "x - failed to create lock directory ${lock_dir}."
exit 1
fi
# ============= expallviews.lua ==============
if test -n "${keep_file}" && test -f 'expallviews.lua'
then
${echo} "x - SKIPPING expallviews.lua (file already exists)"

else
${echo} "x - extracting expallviews.lua (text)"
sed 's/^X//' << 'SHAR_EOF' > 'expallviews.lua' &&
-- This is the script for exporting all views from all pages
-- in the IPE drawing.
-- I use it to export animated figures for beamer presentations.
-- The names of generated files allow to easy inclusion with
-- \multiinclude
-- If your file is named "myfile.ipe", you may prepare animation
-- based on views of page 1 with:
-- \multiinclude[<+>][format=pdf,start=1,graphics={width=0.9\linewidth}]{myfile-p-1-v}
--
-- Based on the information from
-- http://ipe.otfried.org/manual/luapage.html
-- This script was written by Wojciech M. Zabolotny
-- ( wzab01<at>gmail.com )
-- and is published as Public Domain or under
-- Creative Commons CC0 license, whatever better suits your needs.
--
if #argv ~= 2 then
X io.stderr:write("Usage: ipescript expallviews <inputfile> <outputdir>\n")
X return
end
fname=argv[1]
print(fname)
doc = ipe.Document(fname)
doc:runLatex()
-- Prepare the base file name for the output files
-- Remove the directory part (if exists)
fbase=fname:reverse()
-- reverse the string. to make searching for last "/" and "." easier
i = fbase:find("/",1,"plain")
if (i) then
X fbase=fbase:sub(1,i-1)
end
i = fbase:find(".",1,"plain")
if (i) then
X fbase=fbase:sub(i+1)
end
fbase=fbase:reverse()
-- Add the output directory to the base filename
fbase=argv[2] .. "/" .. fbase
-- Now we can convert all the views from all pages
np=#doc
--print(fname .. " contains " .. np )
flags={}
flags["export"]=false
flags["nozip"]=0
for p=1,np,1
do
X pg=doc[p]
X nv = pg:countViews()
X --print(fname .. " page " .. p .. " contains " .. nv .. " views")
X for v=1,nv,1
X do
X fout=fbase .. "-p-" .. p .. "-v-" .. v .. ".pdf"
X --print("exporting to: " .. fout)
X os.execute("iperender -pdf -page " .. p .. " -view " .. v .. " " .. fname .. " " .. fout)
X end
end
X
SHAR_EOF
(set 20 18 06 05 14 33 16 'expallviews.lua'
eval "${shar_touch}") && \
chmod 0644 'expallviews.lua'
if test $? -ne 0
then ${echo} "restore of expallviews.lua failed"
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'expallviews.lua': 'MD5 check failed'
) << \SHAR_EOF
d3425a0d8be2343cc89fd4cf17246e45 expallviews.lua
SHAR_EOF

else
test `LC_ALL=C wc -c < 'expallviews.lua'` -ne 1778 && \
${echo} "restoration warning: size of 'expallviews.lua' is not 1778"
fi
fi
if rm -fr ${lock_dir}
then ${echo} "x - removed lock directory ${lock_dir}."
else ${echo} "x - failed to remove lock directory ${lock_dir}."
exit 1
fi
exit 0
Loading...