Showing posts with label latex. Show all posts
Showing posts with label latex. Show all posts

16/02/2023

Turning a LaTeX beamer presentation with movies into a portable PPTX via LibreOffice.

Use case: your talk venue insists you use their computer. And PowerPoint.

You'll need pdftoppm (or similar, comes with poppler) and FFMPEG if your movies still need conversion. And a recent Impress (mine was LO 7.4.4.2). Older versions crashed on saving as PPTX if there were embedded media. 

First, create page images, in bash:
pdftoppm mypresentation.pdf img -png -r 250

The output is a series of img-1.png, ...,img-n.png. Resolution is here 250.

If necessary, convert all movies (let's assume they're .avi) to something PowerPoint/Impress will digest. Other containers and codecs might work as well, but my Windows failsafe is WMV2.

ffmpeg -i input.avi -codec:v wmv2 -b:v 2000k output.wmv 

Batch conversion:
for m in *.avi; do ffmpeg -i $m -codec:v wmv2 -b:v 2000k ${m%avi}wmv; done 

Start a new Impress presentation, and add a photo album via the Insert->Media menu (see screenshot).

At this point it's a good idea to protect position and size for all images in the slide (Properties sidebar). This is probably scriptable, but I'm not researching it today. Add the movies on top of the slide images. Note: Videos added via drag and drop from a file browser will get linked and not embedded into the PPTX. To embed, you need to go via the Insert->Audio or Video... dialog. Save as PPTX.

Note: I tried importing PDFs directly into Impress but that only opened them in Draw . 

18/02/2022

How to convert a LaTeX beamer presentation with videos to PPTX using Python

Update: The crash issue appears to be fixed in recent LibreOffice. So there is really no reason to do all of the below any more, hooray. See updated howto.

First, why on earth would you want to do that?

The American Physical Society insists that you upload PPTX slides to their conference server and LibreOffice crashes every time I try to import a movie. The developers on the LO forums say it's not their problem because it works with ODP. Glad you asked.

You'll need pdftoppm (or similar, comes with poppler) and the python-pptx and PIL modules. Also, FFMPEG if your movies still need conversion.

First, create page images, in bash:
pdftoppm mypresentation.pdf img -png -r 250

The output is a series of img-1.png, ...,img-n.png. Resolution is here 250.

If necessary, convert all movies to something PowerPoint will digest. Other containers and codecs might work as well, but my Windows failsafe is WMV2.

ffmpeg -i input.avi -codec:v wmv2 -b:v 2000k output.wmv

Batch conversion:

for m in *.avi; do ffmpeg -i $m -codec:v wmv2 -b:v 2000k ${m%avi}wmv; done

We'll assume that we have movie1.wmv and movie2.wmv on slide 2 and movie3.wmv on slide 5.

Now for the tedious bit - determine the bounding box (left, top, width, height, in px) for each movie on the img-1.png and img-5.png slide images. I just used gwenview's crop tool.

Now for the python script:

from pptx import Presentation
from pptx.util import Inches
from glob import glob
from PIL import Image

prs = Presentation()
prs.slide_width = Inches(16) #assuming 16:9 aspect ratio
prs.slide_height = Inches(9)

blank = prs.slide_layouts[6]

imgs = sorted(glob("img*.png"))
w,h=Image.open(imgs[0]).size
# conversion factor for pixel values to inches.
pxtoin=16./w
slides={}

# did the movie-slide attribution via some kind of messy dictionary/list construction. Use the top,left,width,height values determined above.
movies={4:[['movie3.wmv',[626,323,1263,708]]],
        1:[['movie1.wmv',[155,324,710,710]],['movie2.wmv',[1163,324,710,710]]]}

for i in range(len(imgs)):
   slides[i] = prs.slides.add_slide(blank)
   # add the slide contents as bitmaps
   pic = slides[i].shapes.add_picture(imgs[i], 0, 0, height=prs.slide_height)
   try:
      for it in movies[i]:
         movie = slides[i].shapes.add_movie(it[0],*[Inches(r*pxtoin) for r in it[1]])
   except KeyError: pass

prs.save("test.pptx")



This got me a minimum working presentation when I tested it on a remote Windows machine, apart from the fact that the movies had ugly speaker icons instead of poster images. There's a poster_frame_image keyword in add_movie where you can provide an image filename, but it didn't seem to change anything.

Sources:

The python-pptx documentation has a lot of basic use cases. https://python-pptx.readthedocs.io/










11/04/2019

articletitle, article-title, gnah!

Joseph Wright is an awesome person who provides handy biblatex styles for numerous journals.
Some of those require article titles in the submission reference list which are later removed for publication, so it makes sense to put in a switch when you load the package:
\usepackage[style=science,articletitle=true]{biblatex}
(the switch is defined in the science.bbx file, btw.) All hunky dory,  except for the fact that the most recent texlive shipping with ubuntu (TeXLive 2018.20180824) still provides biblatex-science from 2016, where the switch is called article-title. I hope the newest versions get into TexLive soon, apparently he's done quite a bit of cleanup.
https://github.com/josephwright/biblatex-science/issues/1
Update: Fixed in the TeXlive 2018.20190227 that came with the Dingo upgrade. Gnah. Now my work desktop and laptop have different versions of the script.

25/03/2019

Help! Kile is stuck!

"The file x.kilepr cannot be opened as it does not appear to be a project file." Which didn't stop Kile from "scanning project files", which in turn blocked the entire interface. All in vain, I might add, since the project file had moved anyway, so there was nothing to scan in a folder that didn't exist any more. An existential crisis ensued: it is almost midnight, after all, and I'm in mid deadline panic.
Ah well, let's find kilerc, which happens to be in ~/.config/ (if there is a method to KDE's config folder organisation's madness I haven't found it yet). The culprit was in the FilesOpenOnStart section:

[FilesOpenOnStart]
DocsOpenOnStart0[$e]=/path/to/file1.tex
DocsOpenOnStart1[$e]=/path/to/file2.tex
EncodingsOfDocsOpenOnStart0[$e]=UTF-8
EncodingsOfDocsOpenOnStart1[$e]=UTF-8
NoDOOS=2
NoPOOS=1
ProjectsOpenOnStart0[$e]=/this/path/is/invalid.kilepr

I just had to adapt the numbers and paths of docs and projects open on start after all. 

08/09/2017

How to get okular to play nice with pretty much all embedded movies

The trick is to have VLC play them, because vlc plays basically everything.
Install via apt-get either phonon4qt5-backend-vlc or phonon-backend-vlc or both.
In System Settings -> Audio and Video, prefer 'Phonon VLC' in the backend tab. If in doubt, restart Okular.

13/04/2017

Beamer to pptx via LibreOffice.

Notes on getting your beamer slides into PowerPoint via LibreOffice without too much postediting. (AKA boss asks you for a few quick slides from a recent presentation. Gah, I wish I'd figured out the tricks below last Monday)

Standard procedure:
  • Open PDF in LibreOffice Draw. 
  • Save as ODP (or as odg and rename the extension to odp).
  • Open in Impress. Fix display issues. Save as PPTX. Pray.

How to prepare your LaTeX source in order to minimise postediting:
  • Use a recent libreoffice. There were some improvements of the PDF import with regard to text spacing in 2014 which should have been implemented by version 5.x.
  • Speaking of text spacing: avoid justification. Best switch it off globally with the ragged2e package.
  • Don't use PDF figures. Convert to PNG if necessary.
  • Forget about conversion-proofing equations, take screenshots and add them afterwards as pictures. They will get screwed up during PDF import and then there's the issue of LibreOffice vs. PowerPoint math editors.
  • Use LuaLaTeX with a Microsoft system TTF font and switch off ligatures. (note setsansfont vs. setmainfont for beamer!)
  • Don't worry about advanced figure/text block positioning with columns or tikz pictures.  That stuff transferred surprisingly well.

Minimum example:

\documentclass{beamer}
\usepackage[document]{ragged2e}
\usepackage{fontspec}
\setsansfont[Ligatures = {NoRequired, NoCommon, NoContextual}]{Arial}
\usepackage{lipsum}
\begin{document}
 \frame{\frametitle{Lorem Ipsum}\lipsum[1]}
\end{document}



24/01/2017

LuaLaTeX, TeXlive, beamer and multimedia

 


Sometimes you need beamer to be a bit more, er, powerpointy. E.g., use a TTF font, have a more or less blank page and cram some text, images and movies on there. LuaLaTeX to the rescue. I installed texlive-xetex and texlive-luatex, got myself a minimal beamer template, started to dump objects into tikzpictures and compiled with lualatex instead of pdflatex. Sadly, what worked fine on TeXLive 2012 at work failed at home with a lot of nasty PDF specific error messages due to some bug in TeXLive 2016. Apparently, to get beamer, multimedia and LuaLaTeX to play nicely together, you need to add a \RequirePackage{luatex85} as the first line in your document. So here's a minimal example in very bad taste.

%\RequirePackage{luatex85} %uncomment for texlive 2016
\documentclass[gray]{beamer}
\usepackage[english]{babel}
\usepackage{fontspec}
\setsansfont[Path = fonts/,
    Extension = .ttf,
    Ligatures = TeX,
    BoldFont = comicbd ]
{comic}%use \setmainfont for non-beamer
\usepackage{amsmath}
\usepackage{multimedia}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}{}
\setbeamertemplate{itemize items}[circle]
\begin{document}
\begin{frame}[plain]
\frametitle{Science is fun!}
\begin{columns} \begin{column}{.5\textwidth}
\begin{itemize} \item random equation! \end{itemize}
\begin{align*} \rho\left(\frac{\partial}{\partial t}+\vec{u}\cdot\vec{\nabla}\right)\vec{u} &= -\vec{\nabla} p + \eta \nabla^2\vec{u}\\
\vec{\nabla}\cdot\vec{u} &=0 \end{align*}
\end{column} \begin{column}{.5\textwidth} \movie{\includegraphics[width=\textwidth]{movieposter}}{demomovie.avi} \begin{itemize} \item random animation! \end{itemize}
\end{column} \end{columns}
\end{frame}
\end{document}
Notes: I kept the TTF fonts in a subfolder 'fonts' next to the .tex source file. Font names correspond to the ttf file names without extensions (i.e. comic.ttf, comicbd.ttf). LuaLaTeX also works with system fonts, but then you're at the mercy of your font manager. In that case, just \setsansfont{comic} should work as well.
Beamer's default font style is sans serif. For serif font styles, use \setmainfont instead.

20/02/2014

Kile, biber and path issues on Precise

I've grown to like biber as a bibTeX backend, as it's highly configurable. However, it was a bit of a stretch to get it to work on my work computer, which is on Kubuntu Precise LTS.

04/02/2013

Okular inverse search for multiple editors (e.g. Kile)

Setting up inverse search for Kile/Okular is well documented, e.g. in the official Kile docs. What has always bugged me, though, is that the inverse search editor is set globally in the okularpartrc config file, which means that you can't set up inverse search with different editors for different source code types.
I put together a workaround that changes Okular's editor choice to Kile when Okular is called from Kile by temporarily overwriting the okularpartrc file.

02/03/2012

Movie playback in Latex/Beamer: the current situation with Adobe Reader, Okular and Impress

A few years ago, the only option to include multimedia content in Linux presentations was linking to an external player. While the situation is still far from ideal, we have a few options now:
  • Okular has been able to play back movies via mplayer for quite some time now. Features: pause and seek. Downside: poster images appear all black (fixed in KDE 4.10), control bar spacing.
  • Adobe Reader can embed external flash players and videos. Features: pause. Downside: Flash, works only with old acroread.
  • Open/Libre Office Impress movie playback finally works. Features: presenter console. Downside: plays immediately, pause and seek only outside presentation mode. Also, the LaTeX PDF has to be converted into page images.

24/02/2012

A fairly decent poster in Inkscape

Input: nicely polished LaTeX/Beamer slides from the last conference presentation. No concept at all yet. The poster is due in 5 days.
I used to do posters with LaTeX/geometry, but that only works if you have lots of text and a plan. Trying this approach with throwing lots of figures on your empty canvas and shuffling them around is a nightmare.

23/02/2012

HTML directory of PDF files

The file names for my PDF presentations contain only my name and the presentation date. Having to sort through a hundred meeting write-ups when looking for a specific bit of data is annoying, so I wrote a python script to put title, author, modification date and a link to the file into a HTML table.

31/01/2011

Kile, KDE 4.6 and autocompletion

After installing KDE 4.6 (from Kubuntu backports), LaTeX autocompletion was gone in Kile 2.1 β4. It worked on β5, which can be downloaded as a source tarball from the Kile homepage.
I followed the README instructions, but used sudo checkinstall instead of sudo make install to get a .deb package (source ubuntuforums). The kile executable didn't end up in a PATH directory, so I linked it into /usr/bin via cd /usr/bin; sudo ln -s ~/kile-install/bin/kile 
The package system tried to 'update' to β4, so I had to protect the newer version with e.g. sudo aptitude hold kile.

Note on a second install: with just cmake . / make / sudo checkinstall instead of the README approach I ended up with the kile executable in /usr/local/bin. I prefer that to the version in /home, as kile is integrated into the package system via checkinstall anyway.

22/12/2009

Frescobaldi opening Kile

Today frescobaldi surprised me by opening source code references from PDF annotations in Kile. Hey, I love Kile! Still, not very practical.
Solution: open an external instance of Okular, go to Settings->Configure Okular…->Editor, choose Custom Text Editor instead of Kile (the command should read frescobaldi --smart --line %l --column %c), apply, restart frescobaldi and you should be good to go again. Apart from the fact that now your LaTeX source code annotations will be opened in frescobaldi…

05/08/2009

Texlive 2007 and inkscape 0.46 on openSuSE 10.3

I hadn't thought this would be a problem, but I fiddled quite a while with inkscape's and texlive's alternating complaints about missing poppler libraries.
Poppler is a pdf rendering library (xpdf fork), of which texlive 2007 needs version 1 (provided by the poppler package), while inkscape 0.46 (yes, the new version with built-in pdf import) needs libpoppler2. For some reason YaST apparently deleted one of them :-(
Well, I learnt quite a bit about library linking conventions.
Altogether, it has to be some problem of the expiring support for SuSE 10.3; texlive 2008 probably already depends on a newer poppler version (cf. the 'PageGroup detected' error, which is fixed by now), but it's packaged only for 11.0 and higher. Still, Archimedes is stuck with 10.3 until I've got my PhD at least - or so I thought.

17/07/2009

On Kile forgetting shortcuts

The Kile-KDE4 version installed on Archimedes (SuSE 10.3) kept forgetting user-defined shortcuts when restarted. This was a bug, which has been fixed in newer svn versions (like this one).

09/07/2009

Brute force presentation clock


Prerequisites: KDE 4.2, Superkaramba, Acrobat reader.
The idea is to force the relative placement of the Adobe Reader and a Karamba clock widget. This doesn't work with Plasma widgets and the Okular presentation mode, as both seem to override Kwin placement rules (plasma is desktop-integrated anyway).
Get a suitable Karamba clock or countdown widget from kde-look.org (small and preferably with transparency) and put it onto your dektop.
Back up your present window rules:

06/07/2009

How to fake footnotes…

…at the bottom of a LaTeX figure page. Not very elegant, but here goes:

\usepackage{eso-pic}
...
\begin{figure}[p]
\includegraphics[width=\textwidth]{bigimage.jpg}
\caption{Some really important figure.\protect\footnotemark[1]}
\AtPageLowerLeft{\begin{minipage}{0.9\textwidth}
\vspace{0.8em}\rule{14em}{0.5px}\\
\hspace*{1em}\footnotesize{$^1$Ceci n'est pas une annotation.}
\end{minipage}}
\end{figure}
\addtocounter{footnote}{1}

Adjust the number by hand and fiddle with the spacing until it looks like a footnote.

15/06/2009

Microsoft Research publishes in LaTeX

…as witnessed by this paper (and many more) I found linked on Heise Security.
It's declared a tech report and not published in a specific journal, so I imagine they could have used Word. We have to ask ourselves: are the Microsoft Research employees a bunch of faithless renegades?
I think not - because this is a pretty appalling example of LaTeX layout: A strange mixture of Computer Modern in the document body and Helvetica (?) in the section headings, capitalised headings, crowded pages, orphaned lines, horrendous bad boxes…
If this is an informal pre-print, I concede the orphans and bad boxes, but deliberately choosing a document style this ugly?
Now that's what I call partisanship.

07/05/2009

matplotlib and PDF bounding boxes

python-matplotlib can be a bit temperamental sometimes (at least 0.91). At the moment, I am preparing some figures to be included in a (PDF)LaTeX document, which should use correct fonts, math typesetting in the axis labels and a rather small figure size, so that I don't have to scale down in LaTeX, which would give me thin lines and tiny fonts. There is a very handy example in the SciPy Cookbook for all of that, which uses EPS output. No matter, pylab.savefig() also generates PDF when asked to do so - however, with little regard for the actual figure size, so usually the labels are cut off somewhere at the page border.
OK. EPS output and convert to PDF afterwards:
pylab.savefig('myfig.eps')
dum,my=os.popen('epstopdf myfig.eps')
A bit cumbersome; the converted eps figs look murky on some pdf viewers, but they print out OK.
Edit (02/2012): Being less ignorant about the matplotlib by now, I'd also recommend tweaking the figure's default parameter set, e.g.:
from matplotlib import pyplot as pl
import matplotlib
para = { 'axes.labelsize': 14, 'text.fontsize': 8, 'legend.fontsize': 11, 'xtick.labelsize': 10, 'ytick.labelsize': 10,  'figure.subplot.left' : 0.12, 'figure.subplot.right' : 0.98, 'figure.subplot.bottom' : 0.11, 'figure.subplot.top' : 0.97}
pl.rcParams.update(para)
Or, even easier, use the pyplot.subplots_adjust() method for on-the-fly modification. Savefig to PDF should  yield decent results without the EPS workaround.