Latex to Word via HTML using Vim

One of the best ways to convert a Latex file to a word document is to first convert it to html using latex2html and then open the html file using word. Although there are other programs (such as latex2rtf) that can do the same job, I find that latex2html is slightly better at keeping most of the formatting.

This post will therefore teach you how to turn a Latex document into html without leaving Vim.

It sounds complicated, but it isn’t – honest.

First step is to install latex2html.

Installing Latex2html

I use a Mac with macports installed, which means that all I need to do to install latex2html is run the following command in the terminal

sudo port install latex2html

and that is pretty much it.

Using latex2html

You run latex2html through the terminal by first changing directory to where your latex file is, then calling the program and naming the file. For example

latex2html thesis.tex

Here we are changing a latex file called ‘thesis.tex’ into html.

Once you run it, the program will create a new folder with all the relevant html files on it. The index file will contain the starting page, as is the norm.

The main problem is that this html file cannot be turned into a document because all the sections in the latex document are placed into different html files.

To put all the contents into one single html file we need to add the following option

-split 0

so the command will now look like this

latex2html thesis.tex -split 0

Now we end up with a single html file (index.html) with the contents in one place, so we can now open it with word.

As soon as you open the html file in word you will see that there are a few things that are not right with the document.

First, the section numbers are lost. Second, we get some crappy navigation stuff (okay for websites, not cool for word documents). Lastly, we end up with a document info section at the end, not cool.

The good news is that we can solve all these problems by first adding the section numbers with the following option


We can also get rid of the navigation part with this option


and we can get rid of the document info with this option

-info 0

Now, the final command should look something like this

latex2html thesis.tex -split 0 -show_section_numbers -no_navigation -info 0

Using latex2html through vim

Instead of having to open the terminal and type all that stuff in, we can just add the command to Vim so that it does it for us.

This we can do by adding the following line in our .vimrc file

command Tohtml execute "!latex2html % -split 0 -show_section_numbers -no_navigation -info 0"

then restart Vim so it takes effect.

With the above command, we can convert the tex file to html by simply typing in vim


But remember, first compile the tex file to pdf, THEN convert it to html. Otherwise it won’t work.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s