14

This year in my field we have a large conference overlapping with the European soccer championship. Luckily my talk does not overlap with any match, but in case it will happen in the future I was wondering if it is possible to include in a beamer presentation some Javascript magic that fetches the live results from the internet and displays them in the bottom bar.

I have researched and seen some examples of embedding JS in TeX, but everything seems to be only functions that do some simple stuff when the document is opened or when a PDF form is submitted. In particular, my questions at this point are:

  1. can I run AJAX requests inside a PDF, or are the security restrictions too tight?

  2. how do I embed code that gets called every X seconds, or whenever a new slide is presented?

  3. which packages would make my life easier in programming this?

14

Package media9 is an option.

This example displays latest FIFA news in a Flash-based RSS-Reader I found on the web. It is embedded in the footline of every slide in a beamer presentation. It doesn't seem to update the content, though. However, it is reloaded (with updated content) when moving to the next presentation slide (Acrobat Reader required).

\documentclass{beamer}
\usepackage{media9}

\setbeamertemplate{footline}{
\includemedia[
  width=\paperwidth,height=0.1\linewidth,
  activate=pageopen, deactivate=pageclose,
  flashvars={rss=http://www.fifa.com/rss/index.xml},
  url
]{}{http://rsstool.sanriotown.com/rssReader.swf}%
}

\begin{document}
\begin{frame}{Frame title}
Please concentrate on the slide content!
\end{frame}
\end{document}

↗Another example, uses SlideShow.swf (also media9) to display a life image loaded from the web.

7

One option is to use Lua to fetch data when the file is compiled. Then, set a batch script to recompile the TeX file every 30 seconds or so, and use a pdf reader that auto-refreshes the pdf file.

Here is an example (in ConTeXt) that fetches the current date and time at a specific location from a webserver, parses the returned XML file, and displays the result.

\enabledirectives[schemes.threshold=10] % Don't cache downloaded file for more than 10 sec

% I use earth tools as an example, which returns data in XML format.
\startluacode
  thirddata = thirddata or {}
  thirddata.url = "http://www.earthtools.org/timezone-1.1/40.71417/-74.00639"

  function thirddata.getcurrenttime()
      -- Fetch remote url and store it in a file. ConTeXt automatically caches the
      -- file for a duration given by `schemes.threshold`
      local filename = resolvers.getreadfilename("loc",".", thirddata.url)

      -- Read the file for data
      local xmldata  = xml.load (filename)

      -- Parse XML data.to find localtime
      local time = xml.text(xmldata, "xml://timezone/localtime")
      print("DEBIG:", time)

      return time
  end
\stopluacode

\def\getCurrentTime{\ctxlua{context(thirddata.getcurrenttime())}}

\starttext
The current time is New York is \getCurrentTime.

\stoptext

Of course, if you are running a batch script to compile the file, you could as well get the data using any programming language of your choice, but where is the fun in that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.