hyper-literate/collects/slatex/slatex-code/tex2html.tex
Robby Findler 9e5d391dfb ...
original commit: 66a62c2f50bd2b8c85867be3e415c6a0b3881f20
2000-05-25 15:55:50 +00:00

811 lines
19 KiB
TeX

% tex2html.tex
% Dorai Sitaram, Apr 1997
\message{version 3p}
% TeX files using these macros
% can be converted by the program
% tex2html into HTML
\let\texonly\relax
\let\endtexonly\relax
\texonly
\ifx\slatexignorecurrentfile\UNDEFINED\relax\fi
\def\defcsactive#1{\defnumactive{`#1}}
\def\defnumactive#1#2{\catcode#1\active
\begingroup\lccode`\~#1%
\lowercase{\endgroup\def~{#2}}}
% gobblegobblegobble
\def\gobblegroup{\bgroup
\def\do##1{\catcode`##1=9 }\dospecials
\catcode`\{1 \catcode`\}2 \catcode`\^^M=9
\gobblegroupI}
\def\gobblegroupI#1{\egroup}
\def\gobbleencl{\bgroup
\def\do##1{\catcode`##1=12 }\dospecials
\catcode`\{1 \catcode`\}2 \catcode`\^^M=9
\futurelet\gobbleenclnext\gobbleenclI}
\def\gobbleenclI{\ifx\gobbleenclnext\bgroup
\let\gobbleenclnext\gobblegroupI
\else\let\gobbleenclnext\gobbleenclII\fi
\gobbleenclnext}
\def\gobbleenclII#1{%
\def\gobbleenclIII##1#1{\egroup}%
\gobbleenclIII}
% \verb
% Usage: \verb{...lines...} or \verb|...lines...|
% In the former case, | can be used as escape char within
% the verbatim text
\let\verbhook\relax
\def\verbfont{\tt}
%\hyphenchar\tentt-1
\def\verbsetup{\frenchspacing
\def\do##1{\catcode`##1=12 }\dospecials
\catcode`\|=12 % needed?
\verbfont}
% The current font is cmtt iff fontdimen3 = 0 _and_
% fontdimen7 != 0
\def\checkifusingcmtt{\let\usingcmtt n%
\ifdim\the\fontdimen3\the\font=0.0pt
\ifdim\the\fontdimen7\the\font=0.0pt
\else\let\usingcmtt y\fi\fi}
% In a nonmonospaced font, - followed by a letter
% is a regular hyphen. Followed by anything else, it is a
% typewriter hyphen.
\def\variablelengthhyphen{\futurelet\variablelengthhyphenI
\variablelengthhyphenII}
\def\variablelengthhyphenII{\ifcat\noexpand\variablelengthhyphenI
a-\else{\tt\char`\-}\fi}
\def\verbavoidligs{% avoid ligatures
\defcsactive\`{\relax\lq}%
\defcsactive\ {\leavevmode\ }%
\defcsactive\^^I{\leavevmode\ \ \ \ \ \ \ \ }%
\defcsactive\^^M{\leavevmode\endgraf}%
\checkifusingcmtt
\ifx\usingcmtt n%
\defcsactive\<{\relax\char`\<}%
\defcsactive\>{\relax\char`\>}%
\defcsactive\-{\variablelengthhyphen}%
\fi}
\def\verbinsertskip{%
\let\firstpar y%
\defcsactive\^^M{\ifx\firstpar y%
\let\firstpar n%
\verbdisplayskip
\aftergroup\verbdisplayskip
\else\leavevmode\fi\endgraf}%
\verbhook}
\def\verb{\begingroup
\verbsetup\verbI}
\newcount\verbbracebalancecount
\def\verblbrace{\char`\{}
\def\verbrbrace{\char`\}}
\def\verbescapechar#1{%
\def\escapifyverbescapechar{\catcode`#1=0 }}
\verbescapechar\|
{\catcode`\[1 \catcode`\]2
\catcode`\{12 \catcode`\}12
\gdef\verbI#1[\verbavoidligs
\verbinsertskip\verbhook
\if#1{\escapifyverbescapechar
\def\{[\char`\{]%
\def\}[\char`\}]%
\def\|[\char`\|]%
\verbbracebalancecount0
\defcsactive\{[\advance\verbbracebalancecount by 1
\verblbrace]%
\defcsactive\}[\ifnum\verbbracebalancecount=0
\let\verbrbracenext\endgroup\else
\advance\verbbracebalancecount by -1
\let\verbrbracenext\verbrbrace\fi
\verbrbracenext]\else
\defcsactive#1[\endgroup]\fi
\verbII
]]
\def\verbII{\futurelet\verbIInext\verbIII}
{\catcode`\^^M\active%
\gdef\verbIII{\ifx\verbIInext^^M\else%
\defcsactive\^^M{\leavevmode\ }\fi}}
\let\verbdisplayskip\medbreak
% \verbinput FILENAME
% displays contents of file FILENAME verbatim.
\def\verbinput#1 {{\verbsetup\verbavoidligs\verbhook
\input #1 }}
\def\verbfilename#1 {\relax}
\let\verbwrite\gobbleencl
% \path is like \verb except that its argument
% can break across lines at `.' and `/'.
\def\path{\begingroup\verbsetup
\pathfont
\defcsactive\.{\discretionary{\char`\.}{}{\char`\.}}%
\defcsactive\/{\discretionary{\char`\/}{}{\char`\/}}%
\verbI}
\let\pathfont\relax
% \url{URL} becomes
% <a href="URL">URL</a> in HTML, and
% URL in DVI.
% A-VERY-VERY-LONG-URL in a .bib file
% could be split by BibTeX
% across a linebreak, with % before the newline.
% To accommodate this, %-followed-by-newline will
% be ignored in the URL argument of \url and related
% macros.
\def\url{\bgroup\urlsetup\let\dummy=}
\def\urlsetup{\verbsetup\urlfont\verbavoidligs
\catcode`\{1 \catcode`\}2
\defcsactive\%{\urlpacifybibtex}%
\defcsactive\ {\relax}%
\defcsactive\^^M{\relax}%
\defcsactive\.{\discretionary{\char`\.}{}{\char`\.}}%
\defcsactive\/{\discretionary{\char`\/}{}{\char`\/}}%
\defcsactive\`{\relax\lq}}
\let\urlfont\relax
\def\urlpacifybibtex{\futurelet\urlpacifybibtexnext\urlpacifybibtexI}
\def\urlpacifybibtexI{\ifx\urlpacifybibtexnext^^M%
\else\%\fi}
% \mailto{ADDRESS} becomes
% <a href="mailto:ADDRESS">ADDRESS</a> in HTML, and
% ADDRESS in DVI.
\let\mailto\url
% \urlh{URL}{TEXT} becomes
% <a href="URL">TEXT</a> in HTML, and
% TEXT in DVI.
% If TEXT contains \\, the part after \\ appears in
% the DVI only. If, further, this part contains \1,
% the latter is replaced by a fixed-width representation
% of URL.
\def\urlh{\bgroup\urlsetup
\afterassignment\urlhI
\gdef\urlII}
\def\urlhI{\egroup
\bgroup
\let\\\relax
\def\1{{\urlsetup\urlII}}%
\let\dummy=}
% \urlhd{URL}{HTML-TEXT}{DVI-TEXT} becomes
% <a href="URL">HTML-TEXT</a> in HTML, and
% DVI-TEXT in DVI
\def\urlhd{\bgroup
\def\do##1{\catcode`##1=12 }\dospecials
\catcode`\{1 \catcode`\}2
\urlhdI}
\def\urlhdI#1#2{\egroup}
%
\let\ignorenextinputtimestamp\relax
%
\let\htmlonly\iffalse
\let\endhtmlonly\fi
\def\rawhtml{\errmessage{Can't occur except inside
\string\htmlonly}}
\def\endrawhtml{\errmessage{Can't occur except inside
\string\htmlonly}}
\let\htmlheadonly\iffalse
\let\endhtmlheadonly\fi
\let\htmlstylesheet\gobblegroup
% color (deprecated)
\let\rgb\gobblegroup
\let\color\gobblegroup
% Scheme
\let\scm\verb
\let\scminput\verbatiminput
\def\scmfilename#1 {\relax}
\let\scmdribble\scm
\let\scmwrite\gobbleencl
\let\scmkeyword\gobblegroup
\let\setkeyword\gobblegroup % SLaTeX compat
\ifx\slatexversion\UNDEFINED
\def\schemedisplay{\begingroup
\verbsetup\verbavoidligs
\verbinsertskip
\schemedisplayI}%
\fi
{\catcode`\|0 |catcode`|\12
|long|gdef|schemedisplayI#1\endschemedisplay{%
#1|endgroup}}
% GIFs
\let\gifdef\def
\def\gifpreamble{\let\magnificationoutsidegifpreamble\magnification
\def\magnification{\count255=}}
\def\endgifpreamble{\let\magnification\magnificationoutsidegifpreamble}
\let\htmlgif\relax
\let\endhtmlgif\relax
% Cheap count registers: doesn't use up TeX's limited
% number of real count registers.
% A cheap count register is simply a macro that expands to the
% contents of the count register. Thus \def\kount{0} defines a
% count register \kount that currently contains 0.
% \advancecheapcount\kount num increments \kount by n.
% \globaladvancecheapcount increments the global \kount.
% If \kount is not defined, the \[global]advancecheapcount
% macros define it to be 0 before proceeding with the
% incrementation.
\def\newcheapcount#1{\edef#1{0}}
\def\advancecheapcounthelper#1#2#3{%
\ifx#2\UNDEFINED
#1\edef#2{0}\fi
\edef\setcountCCLV{\count255=#2 }%
\setcountCCLV
\advance\count255 by #3
#1\edef#2{\the\count255 }}
\def\advancecheapcount{\advancecheapcounthelper\relax}
\def\globaladvancecheapcount{\advancecheapcounthelper\global}
% title
\let\title\gobblegroup
\def\subject#1{\centerline{\bf#1}\medskip}
% plain's \beginsection splits pages too easily
%\def\beginsection#1\par{\sectionwithnumber{1}{}{#1}}
\def\beginsection{\vskip-\lastskip
\bigbreak\noindent
\bgroup\bf
\let\par\sectionafterskip}
\def\beginsectionstar*{\beginsection}
% plain's \{left,center,right}line can't handle catcode change
% within their argument
\def\leftline{\line\bgroup\bgroup
\aftergroup\leftlinefinish
\let\dummy=}
\def\leftlinefinish{\hss\egroup}
\def\centerline{\line\bgroup\bgroup
\aftergroup\leftlinefinish
\hss\let\dummy=}
\def\rightline{\line\bgroup\hss\let\dummy=}
%
\let\strike\fiverm % can be much better!
%
\let\htmlpagebreak\relax
\let\htmlpagelabel\gobblegroup
\def\htmlpageref{\errmessage{Can't occur except inside
\string\htmlonly}}
% Miscellaneous stuff
\def\hr{$$\hbox{---}$$}
\def\hr{\medbreak\centerline{---}\medbreak}
%\def\hr{\par\centerline{$*$}\par}
%\def\hr{\smallskip\line{\leaders\hbox{~.~}\hfill}\smallskip}
%Commonplace math that doesn't require GIF. (Avoiding $
%here because $ triggers GIF generation.)
\def\mathg{$\bgroup\aftergroup\closemathg\let\dummy=}
\def\closemathg{$}
\def\mathdg{$$\bgroup\aftergroup\closemathdg\let\dummy=}
\def\closemathdg{$$}
\def\frac#1/#2{{#1\over#2}}
%
% Backward compatible stuff
\let\p\verb
\let\verbatim\verb
\let\verbatimfile\verbinput
\let\setverbatimescapechar\verbescapechar
\let\scmp\scm
\let\scmverbatim\scm
\let\scmverbatimfile\scminput
\let\scmfile\scmdribble
\let\scmfileonly\scmwrite
\let\href\urlhd
\endtexonly
\ifx\newenvironment\UNDEFINED\else
% we're in LaTeX and so won't load rest of file
\endinput\fi
\texonly
\input btxmac
% Sections
\def\tracksectionchangeatlevel#1{%
\expandafter\let\expandafter\thiscount\csname
sectionnumber#1\endcsname
\ifx\thiscount\relax
\expandafter\edef\csname sectionnumber#1\endcsname{0}%
\fi
\expandafter\advancecheapcount
\csname sectionnumber#1\endcsname 1%
\ifx\doingappendix0%
\edef\recentlabel{\csname sectionnumber1\endcsname}%
\else
%\count255=\expandafter\csname sectionnumber1\endcsname
\edef\recentlabel{\char\csname sectionnumber1\endcsname}%
\fi
\count255=0
\loop
\advance\count255 by 1
\ifnum\count255=1
\else\edef\recentlabel{\recentlabel.\csname
sectionnumber\the\count255\endcsname}\fi
\ifnum\count255<#1%
\repeat
\loop
\advance\count255 by 1
\expandafter\let\expandafter\nextcount\csname
sectionnumber\the\count255\endcsname
\ifx\nextcount\relax
\let\continue0%
\else
\expandafter\edef\csname
sectionnumber\the\count255\endcsname{0}%
\let\continue1\fi
\ifx\continue1%
\repeat}
% Vanilla section-header look -- change this macro for new look
\def\sectionstar#1*#2{\vskip-\lastskip
% #1=depth #2=heading-text
\tocactivate
{\let\folio0%
\edef\temp{\write\tocout{\string\tocentry{#1}{}{#2}{\folio}}}%
\temp}%
\goodbreak
\vskip1.5\bigskipamount
\noindent
\hbox{\bf\vtop{\hsize=.7\hsize
\pretolerance 10000
\noindent\raggedright#2}}%
\bgroup\let\par\sectionafterskip}
\def\sectionwithnumber#1#2#3{\vskip-\lastskip
% #1=depth #2=dotted-number #3=heading-text
\tocactivate
{\let\folio0%
\edef\temp{\write\tocout{\string\tocentry{#1}{#2}{#3}{\folio}}}%
\temp}
\goodbreak
\vskip1.5\bigskipamount
\noindent
\hbox{\bf#2\vtop{\hsize=.7\hsize
\pretolerance 10000
\noindent\raggedright#3}}%
\bgroup\let\par\sectionafterskip}
% \edef\temp{\write\tocout{\string\hskip#1\space em\string\relax\space #2%
% \string\vtop{\string\hsize=.7\string\hsize
% \string\noindent\string\raggedright\space #3}\string\par}}\temp
\def\sectionafterskip{\egroup\nobreak\medskip\noindent}
\def\sectiond#1{\count255=#1%
\ifx\usingchapters1\advance\count255 by 1 \fi
\edef\sectiondlvl{\the\count255 }%
\futurelet\sectionnextchar\sectiondispatch}
\def\sectiondispatch{\ifx\sectionnextchar*%
\def\sectioncontinue{\sectionstar{\sectiondlvl}}\else
\tracksectionchangeatlevel{\sectiondlvl}
\def\sectioncontinue{\sectionwithnumber{\sectiondlvl}%
{\recentlabel\enspace}}\fi
\sectioncontinue}
\def\section{\sectiond1}
\def\subsection{\sectiond2}
\def\subsubsection{\sectiond3}
\def\paragraph{\sectiond4}
\def\subparagraph{\sectiond5}
\let\usingchapters0
\def\chapter{\global\let\usingchapters1%
\futurelet\chapternextchar\chapterdispatch}
\def\chapterdispatch{\ifx\chapternextchar*%
\let\chaptercontinue\chapterstar\else
\tracksectionchangeatlevel{1}%
\def\chaptercontinue{\chapterhelp{\recentlabel}}\fi
\chaptercontinue}
\def\chapterstar*#1{%
% #1=heading-text
\tocactivate
{\let\folio0%
\edef\temp{\write\tocout{\string\tocentry{1}{}{#1}{\folio}}}%
\temp}%
\vfill\eject
\null\vskip3em
\noindent
\hbox{\bf\vtop{\hsize=.7\hsize
\pretolerance 10000
\noindent\raggedright#1}}%
\bgroup\let\par\chapterafterskip}
\def\chapterhelp#1#2{%
% #1=number #2=heading-text
\tocactivate
{\let\folio0%
\edef\temp{\write\tocout{\string\tocentry{1}{#1\enspace}{#2}{\folio}}}%
\temp}%
\vfill\eject
\null\vskip3em
\noindent
\ifx\doingappendix0%
\hbox{\bf Chapter #1}\else
\hbox{\bf Appendix #1}\fi
\vskip 1em
\noindent
\hbox{\bf\vtop{\hsize=.7\hsize
\pretolerance 10000
\noindent\raggedright#2}}%
\bgroup\let\par\chapterafterskip}
\def\chapterafterskip{\egroup\nobreak\vskip3em \noindent}
\let\doingappendix=0
\def\appendix{\let\doingappendix=1%
\count255=`\A%
\advance\count255 by -1
\expandafter\edef\csname
sectionnumber1\endcsname{\the\count255 }}
% toc
\let\tocactive0
\def\tocoutensure{\ifx\tocout\UNDEFINED
\csname newwrite\endcsname\tocout\fi}
\def\tocactivate{\ifx\tocactive0%
\tocoutensure
\tocsave
\openout\tocout \jobname.toc
\global\let\tocactive1\fi}
\def\tocspecials{\def\do##1{\catcode`##1=12 }\dospecials}
\def\tocsave{\openin0=\jobname.toc
\ifeof0 \closein0 \else
\openout\tocout Z-T-\jobname.tex
\let\tocsaved 0%
\loop
\ifeof0 \closeout\tocout
\let\tocsaved1%
\else{\tocspecials
\read0 to \tocsaveline
\edef\temp{\write\tocout{\tocsaveline}}\temp}%
\fi
\ifx\tocsaved0%
\repeat
\fi
\closein0 }
\def\tocentry#1#2#3#4{%
%#1=depth #2=secnum #3=sectitle #4=secpage
\ifnum#1=1\medbreak\begingroup\bf
\else\begingroup\fi
\noindent\hskip #1 em
#2%
\vtop{\hsize=.7\hsize
\raggedright
\noindent {#3},
#4\strut}\endgroup\par}
\def\tableofcontents{%
\ifx\tocactive0%
\openin0 \jobname.toc
\ifeof0 \closein0 \else
\closein0 \input \jobname.toc
\fi
\tocoutensure
\openout\tocout \jobname.toc
\global\let\tocactive1%
\else
\input Z-T-\jobname.tex
\fi}
% Cross-references
% \openxrefout loads all the TAG-VALUE associations in
% \jobname.xrf and then opens \jobname.xrf as an
% output channel that \tag can use
\def\openxrefout{\openin0=\jobname.xrf
\ifeof0 \closein0 \else
{\catcode`\\0 \input \jobname.xrf }\fi
\csname newwrite\endcsname\xrefout
\openout\xrefout=\jobname.xrf }
% \tag{TAG}{VALUE} associates TAG with VALUE.
% Hereafter, \ref{TAG} will output VALUE.
% \tag stores its associations in \xrefout.
% \tag calls \openxrefout if \jobname.xrf hasn't
% already been opened
\def\tag#1#2{\ifx\xrefout\UNDEFINED\openxrefout\fi
{\let\folio0%
\edef\temp{%
\write\xrefout{\string\expandafter\string\gdef
\string\csname\space XREF#1\string\endcsname
{#2}\string\relax}}%
\temp}}
% \ref{TAG} outputs VALUE, assuming \tag put such
% an association into \xrefout. \ref calls
% \openxrefout if \jobname.xrf hasn't already
% been opened
\def\ref#1{\ifx\xrefout\UNDEFINED\openxrefout\fi
\expandafter\ifx\csname XREF#1\endcsname\relax
%\message or \write16 ?
\message{\the\inputlineno: Unresolved label `#1'.}?\else
\csname XREF#1\endcsname\fi}
% \label, as in LaTeX
\let\recentlabel\relax
% The sectioning commands
% define \recentlabel so a subsequent call to \label will pick up the
% right label.
\def\label#1{\tag{#1}{\recentlabel}%
\tag{PAGE#1}{\folio}}
% \pageref, as in LaTeX
\def\pageref#1{\ref{PAGE#1}}
% Numbered footnotes
\newcheapcount\footnotenumber
\ifx\plainfootnote\UNDEFINED
\let\plainfootnote\footnote
\fi
\def\numfootnote{\globaladvancecheapcount\footnotenumber 1%
\bgroup\csname footnotehook\endcsname
\plainfootnote{$^{\footnotenumber}$}\bgroup
\edef\recentlabel{\footnotenumber}%
\aftergroup\egroup
\let\dummy=}
%
\def\iffileexists#1#2#3{%
\openin0 #1
\ifeof0 \closein0
#3%
\else \closein0
#2\fi}
% \ifx\bibitem\UNDEFINED
% \newcheapcount\bibitemnumber
% \def\bibitem{\par\globaladvancecheapcount\bibitemnumber 1%
% \edef\recentlabel{\bibitemnumber}%
% [\bibitemnumber]\label}
% \fi
%
% \def\begin#1{\begingroup
% \def\end##1{\csname end#1\endcsname\endgroup}%
% \def\envname{#1}%
% \def\envnameI{thebibliography}%
% \csname #1\endcsname
% \ifx\envname\envnameI\let\next\gobblegroup
% \else\let\next\relax\fi\next}
% \def\begin#1{\begingroup
% \let\end\endbegin
% \csname #1\endcsname}
% \def\endbegin#1{\csname end#1\endcsname\endgroup}
% Index generation
%
% Your TeX source contains \index{NAME} to
% signal that NAME should be included in the index.
% Check the makeindex documentation to see the various
% ways NAME can be specified, e.g., for subitems, for
% explicitly specifying the alphabetization for a name
% involving TeX control sequences, etc.
%
% The first run of TeX will create \jobname.idx.
% makeindex on \jobname[.idx] will create the sorted
% index \jobname.ind.
%
% Use \inputindex (without arguments) to include this
% sorted index, typically somewhere to the end of your
% document. This will produce the items and subitems.
% It won't produce a section heading however -- you
% will have to typeset one yourself.
%
% Use \printindex instead of \inputindex if you want
% the section heading ``Index'' automatically generated.
\def\sanitizeidxletters{\def\do##1{\catcode`##1=11 }%
\do\\\do\$\do\&\do\#\do\^\do\_\do\%\do\~%
\do\@\do\"\do\!\do\|\do\-\do\ \do\'}
\def\index{%\unskip
\ifx\indexout\UNDEFINED
\csname newwrite\endcsname\indexout
\openout\indexout \jobname.idx\fi
\begingroup
\sanitizeidxletters
\indexI}
\def\indexI#1{\endgroup
\write\indexout{\string\indexentry{#1}{\folio}}%
\ignorespaces}
% The following index style indents subitems on a
% separate lines
\def\theindex{\begingroup
\parskip0pt \parindent0pt
\def\indexitem##1{\par\hangindent30pt \hangafter1
\hskip ##1 }%
\def\item{\indexitem{0em}}%
\def\subitem{\indexitem{2em}}%
\def\subsubitem{\indexitem{4em}}%
\let\indexspace\medskip}
\def\endtheindex{\endgroup}
% \packindex declares that subitems be bundled into one
% semicolon-separated paragraph
\def\packindex{%
\def\theindex{\begingroup
\parskip0pt \parindent0pt
\def\item{\par\hangindent20pt \hangafter1 }%
\def\subitem{\unskip; }%
\def\subsubitem{\unskip; }%
\let\indexspace\medskip}}
\def\inputindex{%
\openin0 \jobname.ind
\ifeof0 \closein0
\message{\jobname.ind missing.}%
\else\closein0
\begingroup
\def\begin##1{\csname##1\endcsname}%
\def\end##1{\csname end##1\endcsname}%
\input\jobname.ind
\endgroup\fi}
\def\printindex{\csname beginsection\endcsname Index\par
\inputindex}
%
\def\italiccorrection{\futurelet\italiccorrectionI
\italiccorrectionII}
\def\italiccorrectionII{%
\if\noexpand\italiccorrectionI,\else
\if\noexpand\italiccorrectionI.\else
\/\fi\fi}
\def\em{\it\ifmmode\else\aftergroup\italiccorrection\fi}
%\def\emph{\bgroup\it
% \ifmmode\else\aftergroup\italiccorrection\fi
% \let\dummy=}
\def\itemize{\par\begingroup
\advance\leftskip 1.5em
\smallbreak
\def\item{\smallbreak$\bullet$\enspace\ignorespaces}}
\def\enditemize{\smallbreak\smallbreak\endgroup\par}
\def\enumerate{\par\begingroup
\newcheapcount\enumeratenumber
\advance\leftskip 1.5em
\smallbreak
\def\item{\smallbreak
\advancecheapcount\enumeratenumber1%
{\bf \enumeratenumber.}\enspace\ignorespaces}}
\def\endenumerate{\smallbreak\smallbreak\endgroup\par}
\endtexonly
% end of file