# Specify output directory for htlatex

I would like to know how I can specifiy the output directory for the html/css generated by htlatex.

My call is as follows:

htlatex main.tex


The files are generated in the same directory where main.tex is located. But I would rather like to write it to a folder named html contained in the current directory (./html).

I read about adding "" "-d/mypath/" args but it didn't work out.

Can someone help me? I also have some problems to get documentation as calling htlatex with -h or --help doesn't work out.

http://tug.org/applications/tex4ht/mn.html was not useful either.

-

## migrated from stackoverflow.comJul 9 '12 at 15:28

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Jul 9 '12 at 16:05

A little investigation reveals that htlatex is indeed a sh script file, at least in my system:

$which htlatex /usr/texbin/htlatex$ file /usr/texbin/htlatex
/usr/texbin/htlatex: symbolic link to ../../texmf-dist/scripts/tex4ht/htlatex.sh'


And the contents of that script are:

$cat /usr/texbin/htlatex #!/bin/sh latex$5 '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode '$2'.a.b.c.\input '$1
latex $5 '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode '$2'.a.b.c.\input ' $1 latex$5 '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode '$2'.a.b.c.\input '$1
tex4ht -f/$1 -i~/tex4ht.dir/texmf/tex4ht/ht-fonts/$3
t4ht -f/$1$4 ## -d~/WWW/temp/ -m644


So it consists of a sequence of calls to latex, tex4ht and finally t4ht. Apparently the script expects 5 parameters ($1 to $5) and from their use we can deduce, more or less, their function:

• $1 is the name of the file containing the latex source. It is passed to all the tools in the chain. • $2 is part of a parameter passed to a mysterious command \HCode defined in place for the latex command, and whose mission I didn't try to understand. I will ignore this parameter until someone better equiped than me can discover its function
• $3 is passed to tex4ht as part of the -i option, and thus serve to specify a folder for fonts. • $4 is passed to t4ht so looks like a place where we can specify additional switches for t4ht.
• $5 is passed to latex, so it looks like a place where we can specify additional switches for latex. Using t4ht --help we discover that the -d option can be used here to specify the destination directory, so I tried: $ htlatex Example.tex "" "" -d/tmp/


And it worked. The result goes to /tmp/`, but note that this affects only to the final step. The first steps still use the current directory, so all intermediate and auxiliary files are still there. I guess you cannot get ride of them with a switch.

-
Thank you very much! It worked. Is there the possibility to add a usage message to this shell script? Shall I make a proposition to tug.org? –  Tobi Jul 11 '12 at 7:26