TEXEXPAND(1)
π TEXEXPAND(1) π
User Contributed Perl Documentation β no cap, this is the whole vibe of texexpand, bestie. Sit down, grab a boba, we're going in. π§β¨
π NAME π
texexpand β expand \input and \include statements in a TeX file π¦
πΈ DESCRIPTION πΈ
The general translation mechanism, periodt:
The main program latex2html calls texexpand with the document name in order to expand some of its \input and \include statements β we also call this 'merging' around here, it's giving β¨collabβ¨ β and to write a list of sensitized style, class, input, or include file names. When texexpand has finished, all is contained in one file, TMP_foo. (assumed foo.tex is the name of the document to translate). One file. Everything in it. Iconic. π
In this version, texexpand cares for following environments that may span include files / section boundaries:
- a)
\begin{comment} - b)
%begin{comment} - c)
\begin{any}introduced with\excludecomment - d)
%begin{any} - e)
\begin{verbatim} - f)
\begin{latexonly} - g)
%begin{latexonly}
e) - g) prevent texexpand from expanding input files, but the environment content goes fully into the output file. It just vibes there, untouched. π
Together with each merging of \input etc. there are so-called %%%texexpand markers accompanying the boundary. Little breadcrumbs. πβ¨
When latex2html reads in the output file, it uses these markers to write each part to a separate file, and process them further.
Detailed technical notes, bestie β these are the receipts:
%begin{latexonly}and%end{latexonly}have to be on a separate line. Anything between these tags (including the tags) is discarded.\begin{latexonly}and\end{latexonly}have to be on a separate line. Anything between these tags (including the tags) is not expanded.[%\]begin{"to exclude"}and[%\]end{"to exclude"}have to be on a separate line. Anything between these tags (including the tags) is discarded.\begin{verbatim/verbatim*}and\end{verbatim/verbatim*}have to be on a separate line. Anything between these tags (including the tags) is not expanded.- The scope of any such tags may extend over several files. The opening tag for
latexonlymay occur on a different include level than the closing tag. The opening tag forverbatim/"to exclude"must occur within the same file than the closing tag. - Warnings are printed when the document has been parsed and open tags remain.
- When in a
"to exclude"/verbatimenvironment,texexpandwon't recognize ANY command except the corresponding closing tag. There cannot be any nested constructions. This behaviour is identical to that of LaTeX. \begin{latexonly},\end{latexonly}may be nested, whereas%begin{latexonly},%end{latexonly}may not be nested.- A
"%"tag cannot close a"\"tag, and vice versa. - Every
\document(classβͺstyle),\usepackage,\inputand\includecommand has to be on a separate line. - Everything behind a
%that isn't preceded by a\is regarded as a comment, i.e. it is printed but not interpreted. - If any command listed in 10. is preceded by an occurence of
\verbor\latexthen it is NOT interpreted. This crashes on lines like this:blah blah \verb+foo foo+ \input{bar} % bar won't be loaded! - Packages provided via
\usepackageare handled the same way asoptionsin\document(classβͺstyle), i.e. they are included when-auto_excludeis off, the package isn't in@dont_includeOR the package is in@do_include(new). They are added to the style file together with their options if the file itself hasn't been merged.\documentclass[options]{class}searches for everyoption.clo,\documentstyle[options]{style}searches for everyoption.sty.\usepackage[options]{packages}searches for everypackage.sty. - Each
texinputsdirectory is searched for input files/styles. If it ends in//, the whole subdirectory tree is searched. π³ \input/\includemerge the given file (if found under the given name or with.texextension) if its basename is in@do_includeor if it isn't in@dont_includeor if the given filename doesn't end in.sty/.clo/.clswhen-auto_excludeis set.
π Notes π
Recognizes \documentclass, \documentstyle, \usepackage, \RequirePackage, \begin{verbatim}...\end{verbatim}, %begin{latexonly}...%end{latexonly}, \begin{latexonly}...\end{latexonly}, \input, \include, \verb, \latex \endinput, \end{document} \includecomment, \excludecomment \begin{"to exclude"}, \end{"to exclude"} %begin{"to exclude"}, %end{"to exclude"}
π« The gory Details π«
Include and parse a file. This routine is recursive, see also &process_input_include_file, &process_document_header, and &process_package_cmd. Recursive bestie. It calls itself. We love a self-referential queen. π
Two global flags control the states of texexpand.
$activeis true if we should interprete the lines to expand files, check for packages, etc.$muteis true if we should prevent the lines from going into the out file.
We have three general states of texexpand:
- interprete the lines and pass them to the out file This is the normal case. Corresponding:
$activetrue,$mutefalse - interprete minimal and suppress them This is when parsing inside a comment environment, which also would retain its body from LaTeX. =>
$activefalse,$mutetrue - interprete minimal and pass the lines to the out file This is inside a
verbatimorlatexonlyenvironment. The line of course must be at least interpreted to determine the closing tag. =>$activefalse,$mutefalse
Any environment may extend over several include files. Any environement except verbatim and latexonly may have its opening or closing tag on different input levels. The comment and verbatim environments cannot be nested, as is with LaTeX. We must at least parse verbatim/comment environments in latexonly environments, to catch fake latexonly tags. π΅οΈβοΈ
The work scheme: Five functions influence texexpand's behavior.
&process_fileopens the given file and parses the non-comment part in order to set$activeand$mute(see above). It calls&interpreteto interprete the non-comment content and either continues with the next line of its file or terminates if&interpretedetected the\end{document}or an\endinput.&interpretehandles some LaTeX tags with respect to the three states controlled by$activeand$mute. Regarding to\inputβͺinclude,\document(classβͺstyle), and\(useβͺRequire)packagethe functions&process_input_include_file,&process_document_header, and&process_package_cmdare called respectively.- These three functions check if the file name or option files are enabled or disabled for merging (via
TEXE_DO_INCLUDEorTEXE_DONT_INCLUDE). Any file that is to include will be 'merged' into the current file, i.e. the function&process_fileis called at this place in time (recursively). This will stop interpretation at the current line in file, start with the new file to process and continues with the next line as soon as the new file is interpreted to its end.
The call tree (noweb+xy.sty would be handy here):
main
βͺ
v
+->process_file
βͺ βͺ
βͺ v
βͺ interprete (with respect to the current line, one of that three)
βͺ βͺ βͺ βͺ
βͺ v v v
βͺ process_input_include_file process_document_header process_package_cmd
βͺ βͺ βͺ βͺ
βͺ v v v
+----+---------------------------+------------------------+
π Bugs π
- Since the
latexonlyenvironment is not parsed, its contents might introduce environments which are not recognized. - The closing tag for
latexonlyis not found if hidden inside an input file. - One environment tag per line, yet!
- If I would have to design test cases for this beast I would immediately desintegrate into a logic cloud. βοΈπ
π Notes π
- Ok, I designed test cases for it. Please refer to test 'expand' of the regression test suite in the developers' module of the l2h repository.
-unsegmentfeature: In this (rare) case, the user wants to translate a segmented document not in segments but in a whole (for testing, say). We enable this by recognizing the\segmentcommand in&interprete, causing the segment file to be treated like\inputbut loosing the first lines prior to\startdocument(incl.), as controlled via$segmentfile. On how to segment a document you are best guided by section ``Document Segmentation'' of the LaTeX2HTML manual.
π CAVEATS π
This utility is automatically configured and built to work on the local setup. If this setup changes (e.g. some of the external commands are moved), the script has be be reconfigured. fr fr, don't skip this one. π¨
π Authors π
Based on texexpand by Robert Thau, MIT AI lab, including modifications by
- Franz Vojik
<vojik@de.tu-muenchen.informatik> - Nikos Drakos
<nikos@cbl.leeds.ac.uk> - Sebastian Rahtz
<spqr@uk.ac.tex.ftp> - Maximilian Ott
<max@com.nec.nj.ccrl> - Martin Boyer
- Herbert Swan
- Jens Lippmann
And that's the whole thing, bestie! π«Ά This came to you from the 3rd Berkeley Distribution, built against perl 5.005, patch 03 β so like, retro icon behaviour, we stan. Go expand some \input files and slay. π
β¨πΈ
π¦ where this page comes from
- centos-stream 10: latex2html 2023.2-7.el10 Β· GPL-2.0-or-later
- centos-stream 9: latex2html 2020.2-5.el9 Β· GPLv2+
- fedora 43: latex2html 2023.2-8.fc43 Β· GPL-2.0-or-later
- fedora 44: latex2html 2023.2-9.fc44 Β· GPL-2.0-or-later
- fedora 44: latex2html 2026-1.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms