1 2\documentclass[a4paper,12pt]{article} 3 4\usepackage{natbib} 5\usepackage{html} 6\usepackage{latexsym} 7\usepackage{makeidx} 8 9\makeindex 10\citeindextrue 11 12\newcommand{\htm}{{\tt HTML}} 13\newcommand{\lhh}{{\rm \LaTeX2}\htm} 14\newcommand\bef{\begin{figure}} 15 16\begin 17{document} 18\sloppy 19 20\title{Makesegments - a segmentation tool for \lhh} 21\author{Martin Wilck} 22 23\date{Institut f{\"u}r Troposph{\"a}renforschung \\ 24 04303 Leipzig, Germany} 25 26\maketitle 27 28\tableofcontents 29 30\section{Introduction} 31\label{intro} 32 33\lhh\ \index{latex2html@\lhh} is a powerful tool for translating \LaTeX\ documents into a 34hierarchy of linked \htm\ documents suitable for presentation on the 35World Wide Web \cite[]{drakos:l2h}. Users of \lhh\ will encounter 36problems if their \LaTeX\ documents are very large 37\index{document!large} 38--- the translation 39process will eventually fail due to lack of memory. Therefore the 40document segmentation mechanism\index{segmentation}, described in detail by 41\citeauthor{drakos:l2h}, was developed. It serves to split the 42document into peaces called ``segments'', which may be translated by 43\lhh\ seperately. Makesegments is a utility to produce a suitably 44segmented document from a non-segmented \LaTeX\ file. 45 46\subsection{Features} 47\label{features} 48 49Makesegments 50\begin{itemize} 51\item takes care to preserve the \LaTeX\ structure of your document, 52\item reads \verb:\input: files and inserts their 53 contents,\index{input@\verb+\input+}\index{input files} 54\item handles already segmented documents, eventually improving their 55 segment structure or changing the level of it, 56\item Handles \verb:\verb: statements and \verb+verbatim+ environments 57 correctly, 58\item automatically inserts the preamble into all segments, stripping 59 off useless \verb+\internal+ statements and \verb+htmlonly+ environments, 60\item cares for the passing of \lhh\ internal information by inserting 61 appropriate \verb:\internal: statements, 62\item places special sections like \verb:\tableofcontents: or 63 \verb:\bibliography: in the master file (unless the 64 \hyperref{\texttt{ -e} option}{\texttt{-e} option, see }{}{options} 65 is given), 66 \index{special sections} 67\item generates a Makefile for the segmented document, which may be 68 \index{Makefile} 69 edited for customization of \htm\ titles etc. (see \ref{makefile}), 70\item allows for unconventional \LaTeX\ coding, e.~g. sections that 71 are enclosed (or even irregularly devided) by \LaTeX\ blocks (see 72 \ref{caveats} and \ref{blocks}), \index{latex blocks@\LaTeX blocks} 73\item copies (or links) input files to the target directory 74 automatically, \index{input files!copying} 75\item optionally checks if requested \LaTeX\ style files can be found. 76\end{itemize} 77 78\section{Usage} 79\label{usage} 80 81If you have written a long \LaTeX\ document, which you would like to 82translate into \htm, you may use Makesegments to produce a segmented 83version of this document that can be comfortably processed by \lhh. 84It moves the text of each section to a seperate file, leaving only 85the preamble, the \verb:\segment: 86commands\index{segment@\verb+\segment+}, and necessary global 87information in the main file. 88 89\subsection{Arguments and command line options} 90 91Makesegments is called in the following way:\index{usage} 92 93\begin 94{quote} 95 96\begin{verbatim} 97$ makesegments [options] inputfile 98\end{verbatim} 99\end{quote} 100 101Note that you shold change to the directory containig the input file 102before calling Makesegments. 103The \verb:.tex: extension may be ommited from filenames. 104 105\subsubsection{Options} 106\label{options}\index{command line options}\index{invocation}\index{options} 107 108\begin{description} 109\item[\texttt{ -level sectioning-level} (short \texttt{ -l})] 110 \index{options!level@\texttt{ -level/-l}} 111 specifies the level of sectioning commands down to that segmentation is 112 carried out. Possible values are 113 \verb+document+, \verb+part+, \verb+chapter+, \verb+section+, 114 \verb+subsection+, and \verb+subsubsection+. If you specify 115 \verb+-l document+, Makesegments will --- against its usual purpose 116 --- merge all input files and predefined segments into one big file. 117\item[\texttt{ -dir directory} (short \texttt{ -d})] specifies the 118\index{options!dir@\texttt{ -dir/-d}} 119 target directory, where all segments and all other necessary files 120 are going to be written. Default is \verb+./segmented.+ 121\item[\texttt{ -output output-file} (short \texttt{ -o})] 122 \index{options!dir@\texttt{ -dir/-d}} 123 specifies the name of the master file for output (usually without 124 \verb+.tex+ extension). 125\item[\texttt{ -config configuration-file} (short \texttt{ -c})] 126 \index{options!config@\texttt{-config/-c}} 127 is the name of a \hyperref{configuration file}{configuration file 128 (see }{)}{config} for 129 Makesegments. This file may \index{configuration file} 130 define several configuration variables. 131\item[\texttt{ -zero string} (short \texttt{ -z})] 132 \index{options!zero@\texttt{ -zero/-z}} is the name of the ``segment 133 zero''. Makesegments will increment this string in order to obtain 134 segment names. That is, if you specify \texttt{ -z seg00}, the 135 segments will be named \texttt{ seg01.tex}, \texttt{ seg02.tex}, and so 136 forth. If you specify \texttt{ -z master}, the segment names will be 137 \texttt{ mastes}, \texttt{ -mastet}, \ldots, \texttt{ mastez}, 138 \texttt{ mastfa}, \ldots. See the \verb+perlop+ Manpage for details 139 on string incrementation. 140\item[\texttt{ -no\_makefile} (short \texttt{ -n})] suppresses 141 Makefile generation.\index{options!nomakefile@\texttt{ -no\_makefile/-n}}\index{Makefile} 142\item[\texttt{ -check\_latex\_styles} (short \texttt{ -s})] 143 \index{options!check latex@\texttt{ -check\_latex\_styles/-s}} 144 causes Makesegments to look for \LaTeX\ style files. This requires 145 the correct setting of the environment variables for \LaTeX\ input 146 file paths (mainly \texttt{ TEXINPUTS}) or the related 147 \hyperref{configuration variables}{configuration variables 148 (see }{)}{texinputs}. Setting this variable has two side effects: 149 1.~\verb+\usepackage+ commands requesting a \LaTeX\ package that 150 can't be found are deleted; 2.~``local'' style files that are in the 151 current directory are copied or linked to the target directory. 152\item[\texttt{ -ignore\_inputs} (short \texttt{ -i}):] \index{input@\verb+\input+} 153 \index{options!ignore@\texttt{ -ignore\_inputs/-i}} With 154 this option, Makesegments will keep \verb+\input+ and 155 \verb+\include+ statements in their place rather than repacing them 156 with the contents of the input files (of course, sectioning commands 157 inside the input files won't be found!) 158\item[\texttt{ -use\_links} (short \texttt{ -u}):] 159 \index{options!use@\texttt{ -use\_links/-u}} Usually, Makesegments 160 copies input files to the target directory unless it is the same as 161 the current. This holds for files included with \verb+\input+ and 162 \verb+\include+ if the \verb+-i+ option is set, for ``local'' style 163 files if the \verb+-s+ option is set, for bibliography files 164 (\verb+.bib+, \verb+.bst+) and 165 \hyperref{image files}{image files(see }{)}{epsfig} 166 as long as they are given 167 by a path {\em relative to the current directory}\/. The reason is 168 that these input files will not be found by \LaTeX\ or \lhh\ in the 169 target directory. With the \verb+-u+ option, Makesegments creates 170 symbolic links in the target directory instead. 171\item[\texttt{ -dont\_copy} (short \texttt{ -y}):] 172 \index{options!dontcopy@\texttt{ -dont\_copy/-y}} If this flag is set, 173 Makesegments will neither copy nor link the input files to the 174 target directory. 175\item[\texttt{ -specialsegments} (short \texttt{ -e}):] 176 \index{options!specialsegments@\texttt{ -specialsegments/-e}} 177 \index{special sections} 178 Normally Makesegments places all ``special sections'' of \LaTeX in 179 the master segment. With the \verb+-e+ option, it will create extra 180 files for them. If \verb+-e+ is set, the configuration variable 181 \hyperref{\texttt{\%SPECIALNAMES}}{\texttt{\%SPECIALNAMES} (see 182 }{)}{config}\ 183 determines which of the special sections will 184 be treated this way, and which file names they'll get. 185 186 Doing this is 187 useful especially for the table of contents 188 (\verb+\tableofcontents+) and the index (\verb+\printindex+), since 189 in the \htm\ version 190 these may be linked to the other segments by the ``Contents'' and 191 ``Index'' buttons in the navigation panel. If \verb+-e+ is not 192 specified, Makesegments can't figure out the URL's of the contents 193 and index pages, and therefore can't include this information in the 194 Makefile; with \verb+-e+, the URL's are determined before Makefile 195 generation, and Makesegments is able to set the \verb+-contents+ and 196 \verb+-index+ switches for the segments correctly. 197\index{latex2html@\lhh!prev@\verb+-contents+ option} 198\index{latex2html@\lhh!prev@\verb+-index+ option} 199\item[\texttt{ -help} (short \texttt{ -h} or \texttt{ -?}):] 200 \index{options!help@\texttt{ -help/-h/-?}} Display a help message 201 with overview over the options. 202 203\end{description} 204 205\subsection{Caveats} 206\label{caveats} 207 208What you should avoid: 209 210\begin{itemize} 211\item misaligned \LaTeX\ blocks, such as \verb:{\small \begin{figure}...}:. 212 (\LaTeX 213 will also complain about this!)\index{latex blocks@\LaTeX blocks} 214\item use of plain \TeX\ commands such as \verb+\def+. 215\index{tex commands@\TeX\ commands} 216\end{itemize} 217 218The more ``structured'' your \LaTeX\ document, the easier and better 219the outcome of Makesegments will be. 220 221The \verb+\segment+\index{segment@\verb+\segment+} command, that is 222defined in the \lhh\ file \verb+html.sty+, does not account for the 223optional argument to sectioning commands (short version of the section 224title). \index{sectioning commands!optional argument} These arguments are 225therefore discarded by Makesegments. 226 227\subsection{After using Makesegments} 228\label{after} 229 230Ideally, after the segmentation procedure has successfully completed, 231you just need to change to your target directory and type 232\verb:make:.\index{make@\verb+make+} This will produce the complete 233set of \htm\ pages. Type \verb:make all: if you want DVI and 234PostScript output, too.\index{DVI output} 235\index{PostScript output} Then change to the 236subdirectory called \verb:inputfile: (without \verb:.tex: extension), 237and start your \htm\ browser on \verb:inputfile.html:\index{html 238 output@\htm\ output}. In reality, 239you will probably need to edit the \index{Makefile} 240\hyperref{Makefile}{Makefile (see }{)}{makefile} and perhaps even some of 241the segments to obtain the desired \htm\ output. 242 243\section{Internals} 244\label{internals} 245 246Makesegments, as well as \lhh\ itself, is written in Perl. That is, it 247is easy to customize for people with a basic knowledge of Perl. 248\index{Perl} This section gives a brief overview of how Makesegments works. 249 250\subsection{Block structure} 251\label{blocks} 252 253As mentioned in \ref{features}, Makesegment takes special care to 254avoid confusion by intermediate \LaTeX\ blocks. 255Consider the following file: 256\index{latex blocks@\LaTeX blocks} 257 258\begin{verbatim} 259\documentclass{article} 260<preamble> 261{ 262 \begin{document} 263 <leading text> 264 \section{1} 265 <text of 1> 266 {\small 267 <more text of 1> 268 \section{2} 269 <text of 2> 270 \texttt{ 271 <more text of 2> 272 \listoffigures 273 } 274 } 275 \end{document} 276} 277\end{verbatim} 278 279How should this be divided reasonably into segments? Makesegments will 280produce the following master file: 281 282\begin{verbatim} 283\documentclass{article} 284<preamble> 285{ 286 \begin{document} 287 <leading text> 288 \segment{a1}{1} % -> that's where <text of 1> goes 289 {\small 290 <more text of 1> 291 \segment{a2}{2} % -> that's where <text of 2> goes 292 \texttt{ 293 <more text of 2> 294 \listoffigures 295 } 296 } 297 \end{document} 298} 299\end{verbatim} 300 301Note that all blocks that contain a command that is relevant to 302segmentation (\verb+\section+ and \verb+\listoffigures+) have been 303moved to the master segment. This ensures that the \LaTeX\ block 304structure is unharmed and that \LaTeX\ will produce the same DVI output 305from the segmented file as from the original document. \index{DVI output} 306 307But it is also clear that \lhh\ will not see the \verb+\small+ 308command when it processes segment 1. 309Also, the text of both sections is divided between the segments and 310the master file, leading to a strange structure in the \htm\ document. 311 312Thus, even though Makesegments 313can still produce a fairly reasonable segmentation from such a file, 314it is not recommended to write \LaTeX\ code this way (if it is 315supposed to be segmented, at least). 316 317\subsection{Makefile} 318\label{makefile} 319 320The Makefile defines several variables that may be customized. 321For each segment there is a variable that specifies the title of the 322corresponding URL (\verb+A3TITLE+ for segment \verb:a3.tex:) and one 323that determines the command options for \lhh\ when it is invoked on 324this segment (\verb:L2HA3:). Segment titles are derived from the 325section titles they were made of, with all \LaTeX\ commands and their 326arguments stripped, so it's likely that the URL titles are not what 327you desire. 328 329Makesegments tries to guess the correct 330neighbour segments and link them with the \verb+-prev_url+, \verb+-up_url+ and 331\verb+-down_url+ options to \lhh.\index{latex2html@\lhh!down@\verb+-down_url+ option} 332\index{latex2html@\lhh!up@\verb+-up_url+ option} 333\index{latex2html@\lhh!prev@\verb+-prev_url+ option} 334 335This may easily be modified by changing the corresponding variables. 336Note that Makesegments can only set the \verb+-index+ and \verb+-contents+ options 337\index{latex2html@\lhh!prev@\verb+-contents+ option} 338\index{latex2html@\lhh!prev@\verb+-index+ option} 339in the Makefile correctly if the file is processed 340with the \verb+-e+ option. Otherwise, you'll have to find out the 341URL's of these sections ``by hand'' using a \htm\ browser. 342 343\subsection{The configuration file} 344\label{config}\index{configuration file} 345 346Makesegments looks for configuration files in three places: 347\begin{itemize} 348\item in the file specified with the \verb:-c: option, 349\item in the file \verb:.makesegments.cnf: in the current directory, 350\item in \verb:$HOME/.makesegments.cnf:. 351\end{itemize} 352 353If no configuration file is found, Makesegments sets its own defaults. 354 355The files are executed in the order specified above, so if you build a 356configuration file in your home directory, take care that it doesn't 357override settings that have been made before. The same holds for 358system operators that want to change Makesegents' behaviour by editing 359the makesegments script itself. 360 361The easiest way to create a config file is copying the configuration 362part of makesegments (from ``Site configuration'' to ``End of 363configuration options'') to a seperate file and edit. 364 365\subsubsection{Path variables for \LaTeX\ inputs} 366\label{texinputs}\index{path!latex@\LaTeX inputs} 367 368Setting these is very impotant if you want to use the \texttt{ 369 -check\_latex\_styles} command line option. 370 \index{options!check latex@\texttt{ -check\_latex\_styles/-s}} 371Makesegments tries to read the environment variables \verb+TEXINPUTS+ 372(for style files as well as text inluded with \verb+\input+ and 373\verb+\include+ statements), \verb+BIBINPUTS+ (for bibliography 374databases) and \verb+BSTINPUTS+ (for bibliography styles). But on many 375Unix systems these environment variables aren't set, since they have 376been compiled into the \verb+kpathsea+ library, that searches files 377for \TeX. If you work on such a system, set the corresponding Perl 378variables \verb+$TEXINPUTS+ etc. 379 380\subsubsection{Path variables for executables} 381\label{executables}\index{path!executables} 382 383These variables are only needed for Makefile 384generation\index{Makefile}. You should set them if your executables 385for \LaTeX, Bib\TeX, Makeindex, dvips, \lhh, make or touch are 386different then usual. The variable names are \verb+$LATEX+, 387\verb+$BIBTEX+ etc. Additionally, Makesegments defines two variables 388\verb+$TEXENV+ and \verb+$DVIPSENV+ for environment information that should 389be passed explicitly to these programs, e.~g.: 390\begin{verbatim} 391$TEXENV="TEXINPUTS=$TEXINPUTS:/home/myname/mylatex/inputs/ ". 392 "PKFONTS=/home/myname/mylatex//pk//"; 393$LATEX="$TEXENV /home/myname/bin/latex"; 394\end{verbatim} 395This will produce a command line in the Makefile that sets the desired 396environment variables (note that the above example just {\em adds} a 397directory to the Perl variable \verb+$TEXINPUTS+) and calls the special 398executable. 399 400\subsubsection{Variables corresponding to command line options} 401\index{options} 402 403Those settings in the configuration files that correspond to command 404line options are always {\em overriden} by the latter. But be aware 405that some command line options can only switch a feature {\em on}. For 406example, if you specify \verb+$DONTCOPY=1;+ Makesegments will not copy 407any input files and there's no command line option to override this. 408 409\index{options!specialsegments@\texttt{ -specialsegments/-e}} 410The configuration variable \verb+$SPECIAL+ corresponds to the 411\verb+-specialsegments+ option. However, if this is set, you have 412further customization possibilities. The hash table 413\verb+%SPECIALNAMES+ contains the default file names (without 414extension) for the \LaTeX\ commands that you'd like to have a special 415segment for. The Makesegments script defines 416\begin{verbatim} 417%SPECIALNAMES=( 418 "tableofcontents" => "toc", 419 "printindex" => "ind", 420# "listoffigures" => "lof", 421# "listoftables" => "lot", 422# "bibliography" => "bbl", 423# "thebibliography" => "tbl", 424 ); 425\end{verbatim} 426Note that the last four entries are commented out: no entries are set 427here (this is different from setting one of those entries to an empty 428string!). With this (default) setting, Makesegments will only create 429special segments for the index and for the table of contents. 430The hash table \verb+%SPECIALTITLES+ takes the same keys as 431\verb+%SPECIALNAMES+; the values are the URL titles that you'd like 432for these segments. This is mainly intended for language 433customization. 434 435\subsubsection{Adding support for \LaTeX\ commands} 436\label{commands}\index{adding new \LaTeX\ commands} 437 438The ``Experts only'' section of the configuration section in 439Makesegments is intended to help users to add support for special 440\LaTeX\ commands. This may be helpful e.~g. for 441\begin{itemize} 442\item commands that take file arguments that you'd like to have 443 copied; 444\item commands that take weird arguments that should not be parsed 445 (Makesegment parses command arguments with a simpler algorithm than 446 the normal text: commands and environments are not recognized inside 447 these arguments. This is useful for the \verb+\newcommand+ command, 448 for example, because Makesegments would usually complain about a 449 construct like 450\begin{verbatim} 451 \newcommand\beq{\begin{equation}} 452\end{verbatim} 453\index{newcommand@\verb+\newcommand+} 454since it would think that the \verb+equation+ environment wasn't regularly 455closed); 456\item commands that should initiate any special operation by makesegments. 457\end{itemize} 458 459If you want Makesegments to recognize a command, you have to add it to 460the table of known commands. This may be done by adding entries to the 461hash table \verb+%USER_CMDS+. The syntax is as follows: 462\begin{verbatim} 463 %USER_CMDS=( 464 "command1" => [argument-list], 465 "command2" => [argument-list], 466 ... 467 ); 468\end{verbatim} 469\index{usercmds@\verb+%USER_CMDS+} 470The command names should be given without the leading backslash. 471\verb+argument-list+ is a comma-separated list of the two items 472\verb+$m+ for mandatory and \verb+$o+ for optional arguments. 473Example: 474\begin{verbatim} 475 %USER_CMDS=( 476 "parbox" => [$o, $m, $m], 477 "newpage" => [], 478 ); 479\end{verbatim} 480See \htmlref{the next section}{example} for another example. If a command 481takes no arguments, specify an empty array. See also the 482Makesegments script and look at the definition of \verb+%misc_cmds+. 483 484Usually one entry in the hash suffices for both the normal and the 485starred version of the command (if there is one). You only need to add 486an extra entry for the starred version if it takes other arguments (or 487in different order) than the unstarred one. 488 489Adding a command to \verb+%USER_CMDS+ suffices if you just want 490Makesegments to ignore this command's arguments (such as in the 491\verb+\newcommand+ example above). 492 493If you want Makesegments to do anything special when the command is 494encountered, you must define a subroutine called \verb+do_mycommand+ 495(but you {\em always} need the \verb+%USER_CMDS+ entry!). 496 497All routines of the type \verb+do_mycommand+ have access to the 498following local variables: 499\begin{description} 500\item[\texttt{\$command}] contains the command name, without backslash 501 and (eventual) star. 502\item[\texttt{\$star}] contains "\verb+*+" if the command was starred. 503\item[\texttt{@arg}] is the array of arguments in the order given, with 504 brackets. 505\item[\texttt{@mand}] is the array of mandatory arguments in given order, 506 brackets stripped. 507\item[\texttt{@opt}] is the array of optional arguments. 508\end{description} 509 510You may delete the 511command from the text output of Makesegments by setting 512\verb+$command=""; @arg=();+ 513 514\subsubsection{An example}\label{example} 515\label{epsfig} 516\index{adding new \LaTeX\ commands} 517\index{epsfig@\verb+\epsfig+} 518 519As an example, the following code shows how to add support for the 520\verb+\epsfig+ command. The only graphics command that is supported by 521default by Makesgements is \verb+\includegraphics+. But a user might 522wish that Makesegments copy the graphics file specified by an 523\verb+\epsfig+ command to the target directory. 524 525\begin{verbatim} 526# First, add epsfig to %USER_CMDS 527 528 %USER_CMDS=( 529# epsfig takes only one mandatory argument 530 "epsfig" => [$m], 531 ... 532 ); 533 534# Now the subroutine definition 535 sub do_epsfig { 536 537# Check if the epsfig package was loaded 538# If not, do nothing 539 540 if (defined $packages{"epsfig"}) { 541 542# Do a pattern match with the (first and only) mandatory 543# argument to retrieve the filename 544 545 $mand[0] =~ /file=\s*([^\s,]+)\s*,/; 546 my $file=$1; 547 548# Use the &find_texinput routine to look where the file 549# actually is. The routine needs two array references 550# as input: One for the directories to search, 551# one for possible extensions (if ommitted in the text) 552# It returns the full path name or nothing if the 553# file wasn't found. 554 555 $file=&find_texinput 556 ($file,\@graphicsinputs,\@graphicsextensions); 557 if ($file) { 558 559# If the returned filename is a full pathname 560# (i.e. starts with / or ~), it shouldn't be copied 561# (it will be found from the target directory also) 562 563 push @files_to_copy,$file 564 unless file=~ m:^(/|~):; 565 566 } else { 567 568# Complain if the file wasn't found 569 570 print STDERR "epsfig input file not found!\n"; 571 }; 572 }; 573 }; 574\end{verbatim} 575 576\subsection{Support}\label{support} 577 578If you have trouble with makesegments, mail me 579 (\htmladdnormallink{martin@tropos.de}{mailto:martin@tropos.de}). 580 581\section*{Acknowledgements} 582 583The segmentation mechanism of \lhh\ has been invented an programmed by 584Herb Swan and Ross Moore. Thanks to them, to Nikos Drakos and all the 585others who made \lhh. \index{Moore, Ross}\index{Drakos, 586 Nikos}\index{Swan, Herb} 587 588\printindex 589 590\bibliographystyle{plainnat} 591\bibliography{rep,harvard} 592 593\end{document} 594