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
.
- 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.
- 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.
- 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
The env
file is stored in %texmf-home%/texmf-dist/tex4ht/base/unix
or %texmf-home%/texmf-dist/tex4ht/base/win32
, depending on your operating system. For testing purposes, it is best to make copy of that file in your working directory.
The structure of this file is little bit strange:
<tag>
Gsome command and the parameters
Ganother command
</tag>
<anothertag>
GNext command
Gcommand again
</anothertag>
Spaces are important. All lines with space at the beginning are ignored. Tagged sections are sometimes ignored. Quoting tex4ht.env
itself:
Tagged script segments ... are scanned only if their names are specified within -ctag switches of tex4ht.c and t4ht.c. When -c switches are not supplied, a -cdefault is implicitly assumed.
In the example, only GNext command
is actually executed. If you look at actual tex4ht.env
file, you can see that there are several configurations for output of images. Default is
<convert>
G.png
Gdvips -E -q -Ppdf -f %%1 -pp %%2 > zz%%4.ps
Ggs -sDEVICE=pngalpha -sOutputFile=%%3 -r110x110 -dEPSCrop -dBackgroundColor=16#ffffff -dTextAlphaBits=2 -dGraphicsAlphaBits=2 -q -dbatch -dNOPAUSE zz%%4.ps -c quit
Grm zz%%4.ps
G.svg
Gdvips -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.eps
Gpstoedit -f svg zz%%4.eps %%3
G.
Gdvips -E -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.ps
Gconvert -trim +repage -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3
</convert>
lines
G.
Gdvips -E -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.ps
Gconvert -trim +repage -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3
means, that default conversion uses dvips
command to convert picture to the eps file and then using convert to the final output format.
There is also section
<dvipng>
G.png
Gdvipng -T tight -x 1440 -D 96 -bg Transparent -pp %%2:%%2 %%1 -o %%3
G.gif
Gdvipng -T tight -x 1440 -D 96 -bg Transparent -gif -pp %%2:%%2 %%1 -o %%3
G.
Gdvips -Ppdf -mode ibmvga -D 110 -f %%1 -pp %%2 > zz%%4.ps
Gconvert -crop 0x0 -density 110x110 -transparent '#FFFFFF' zz%%4.ps %%3
Grm zz%%4.ps
</dvipng>
Which uses dvipng
instead of convert
and dvips
and in my opinion the output is better. So to use this configuration, just erase spaces before <convert>
and </convert>
, and add space at the beginning of <dvipng>
and </dvipng>
Another opinion is to use svg
images instead of the png
. Just add :
G.svg
Gdvisvgm -n -p %%2 -c 1.2,1.2 -s %%1 > %%3
Create the file myconfig.cfg
:
\Preamble{xhtml}
\Configure{Picture}{.svg}
\begin{document}
\EndPreamble
and call:
htlatex file "myconfig"
Edit:
Another option is to to use make4ht build system. You can specify image conversion command in the build file, see the chapter on that matter
Best Answer
You need to change to the folder containing
filename.tex
before executinghtlatex filename.tex
. Under Windows, this can be achieved usingYou can either use backslashes
\
or forward slashes/
. If your path contains spaces, you can either use TAB to let Windows auto-complete a partially completed folder name (that is, you typecd Docu
and press TAB and Windows will auto-complete this tocd "Documents and Settings"
), or use quotes to denote the folder names, for exampleOnce in the correct folder, use