[Tex/LaTex] Using htlatex to convert LaTeX to HTML

conversionmiktextex4htwindows

I appear to have htlatex and htxelatex already installed on my computer. However when I try to run them, it comes up with the message, 'I can't write on file 'texput.log''

I am trying to convert a LaTeX file to HTML.

This is on Windows, with MiKTeX.

Best Answer

This may help you. I made a batch script that I use when working with htlatex. You can copy and paste it into a file, and save it with .bat extension, e.g., html.bat.

  1. You need to open a command prompt, you can type in the search bar cmd, or press WndLogo + R and write cmd to execute the command prompt. The command prompt is an application in which you can run different commands. In the top of the window you will see the current directory. For example, C:\Windows\system32\cmd.exe. You can check this tutorial for more information.
  2. Then you just need to move to the directory in which you have your file, using cd path. For example, if you have your LaTeX documents in a folder in the C drive called My Latex, you can move to that folder using cd "C:\My Latex". Note that you have to surround the path with quotes due to the spaces on it.
  3. You can execute the script using html.bat file.tex. That will create a html directory in which you can find your file. (This assumes you have your file in the same directory as your .tex file. However, you can place the script in a folder and add that folder to your environment variables. Then you will be able to call it from anywhere.)
    • If you don't want to use the script you can simple execute htlatex file.tex html "" -dSomeDir "--interaction=nonstopmode". The html option sets the type of output, -dSomeDir sets the output directory to SomeDir (although it is not mandatory, it is a good idea as htlatex produces several files), and the nonstopmode tells the compiler not to stop if it can avoided.

The script looks like this:

@echo off
if [%1]==[] goto usage
set name=%~n1
if exist .\html goto exists
mkdir html
goto process
:exists
echo y | del .\html\*
:process

htlatex %name%.tex html "" -dhtml "--interaction=nonstopmode"

:clean
del %name%.4tc > nul
del %name%.4ct > nul
del %name%.tmp > nul
del %name%.xref > nul
del %name%.idv > nul
del %name%.lg > nul
del %name%.html > nul
del %name%.css > nul
goto end

:usage

echo Usage: %0 file.tex
echo *** Caution *** If there is a html directory it will be deleted.
echo. 
:end