I want to use tex to generate a html page with an embedded video. I know that I can use latex2html to convert tex to html. I also know about media9 but I think it can only be used to render videos in pdf. I think that if javascript can be embedded in tex and rendered as html then I could use a javascript based video player to show the video in the html page. So is it possible?

Why do I want to do this? : I want videos in my document and I am frustrated with the intermittent support of this in the pdf standard and its associated viewers.

  • You should be able to use any tex to html converter latex2html or tex4ht (or latexml which just got updtated yesterday) if video isn't supported out of the box just pre-process the document to replace the video by [[video here]] convert it then process the resulting html to replace [[video here]] by <video> or flash or whatever you want to use. – David Carlisle May 9 '14 at 9:28
  • @David Thanks for your answer. To clarify, I dont want a link to a video, I want an embedded player that plays my video on the page. If possible, then what latex code can I use to accomplish this? – Kirillvh May 9 '14 at 9:44
  • yes that's what the html video does. You don't need latex code if your target is html just write literally [[video here]] or ljsacchasljcalj anything at all, and then convert to html and replace that string using any editing tool you like by <video src="myvideo.mov"> or whatever you want the html video markup to be. – David Carlisle May 9 '14 at 9:47
  • @david Oh ok, now I get it! Thank you. Now I have to go ahead and implement such a setup. – Kirillvh May 9 '14 at 9:52
  • Once you get that simplistic scheme working and you know exactly what you generate, most latex to html convertors allow you to define a custom command such as \myvideo{filename} and then define what that command does in latex and in the html conversion that would automate the editing step but I'd leave that until you get it working – David Carlisle May 9 '14 at 9:57

Solution using tex4ht. Sample document:


command \myvideo is introduced, with three parameters, width, height and video file. media9 command \includemedia is used to include the video. I cannot test if that works, as video playing isn't supported on Linux.

Now we need to make config file for tex4ht, named media.cfg , in which we will rewrite \myvideo command to produce video html tags.

<embed src="#3" type="video/mp4" WIDTH="\the\dimexpr#1\relax" HEIGHT="\the\dimexpr#2\relax" AUTOPLAY="TRUE" LOOP="TRUE" PLAYEVERYFRAME="TRUE" />

<embed> element is used, as it is widely supported. Note that type parameter is hardcoded to video/mp4, you will need to change it if your videos are of different type. \dimexpr is used to calculate dimensions.

Now you can compile the document with:

htlatex sample.tex media

and produced html:

<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"  
<head> <title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<!-- charset=utf-8,html,xhtml --> 
<meta name="src" content="sample.tex" /> 
<meta name="date" content="2014-05-09 13:45:00" /> 
<link rel="stylesheet" type="text/css" href="sample.css" /> 
<!--l. 12--><p class="noindent" ><embed src="circle.mp4" type="video/mp4" WIDTH="172.5pt" HEIGHT="172.5pt" AUTOPLAY="TRUE" LOOP="TRUE" PLAYEVERYFRAME="TRUE" />  </p> 
  • Thank you, I came up with a similar solution using latex2html and the html5 video tags. I posted my answer for reference but I will be accepting your answer. – Kirillvh May 9 '14 at 12:47

Thanks to David Carlisle to the suggestion and to michal.h21 for a solution using tex4ht. Here follows a solution for latex2html.

I used the rawhtml environment of latex2html for writing an environment that places a html5 video file (it tries mp4 and ogg formats)

\newcommand{\vid}[1] {   
<video width="320" height="240" controls>   
<source src="
.ogg" type="video/ogg"> 
<source src="
.mp4" type="video/mp4"> 
Your browser does not support the video tag. </video>
%now use the environment defined above to place 
%a video called myVidName.mp4 or myVidName.ogg

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.