LaTeX::Driver(3pm)
๐ LaTeX::Driver โ the LaTeX::Driver manual, but make it a group chat ๐
perl v5.8.0-ish era, User Contributed Perl Documentation โจ
๐ NAME ๐
LaTeX::Driver โ bestie, it's a Latex driver. That's the whole name. Short, iconic, does what it says ๐
โจ VERSION โจ
1.3.1 ๐ฆ
๐ธ SYNOPSIS ๐ธ
okay so this is literally the whole vibe in five lines:
use LaTeX::Driver;
$drv = LaTeX::Driver->new( source => \$doc_text,
output => $filename,
format => 'pdf',
%other_params );
$ok = $drv->run;
$stats = $drv->stats;
see? new, run, stats. that's the whole main character arc right there ๐ฅ
๐ DESCRIPTION ๐
so LaTeX::Driver wraps up all the messy behind-the-scenes drama of calling the Latex programs to format a LaTeX document. like, formatting with LaTeX is genuinely complicated โ there can be so many programs to run and you have to sit there watching their output to figure out if you need to run even more. it's giving "group project where nobody knows who's doing what" ๐ญ
this module runs the commands it needs in the directory you specify โ either you say it explicitly with the dirname option, or it's implied by the directory part of basename, or it just uses the current directory. and as a result of all that processing, up to a dozen or more intermediate files get created ๐ซถ those get removed when the object is destroyed, as long as you gave the cleanup argument to new.
๐ SOURCE ๐
source code lives at <https://github.com/fordmason/LaTeX-Driver>
feel free to fork and add your stuff! no gatekeeping here, bestie ๐
๐ SUBROUTINES/METHODS ๐
โญ new(%params) โญ
this is the constructor method. it builds you a driver object, and then you use the run method on that object to format the document you specified. the main arguments are source and output โ source is required to say what the input document is, and output is only mandatory if source is a scalar reference.
the full list of arguments, no skips, no cuts, we don't do that here ๐:
sourceโ this parameter is mandatory. it can either be the name of the document to format, or a reference to a scalar that holds the document source itself. ๐outputโ says where the formatted document goes. can be a file name, or a scalar reference. if it's a scalar reference, the contents of the formatted document file get copied into the scalar variable being referenced. โจformatโ the format of output you want. one ofdvi(TeX Device Independent format),ps(PostScript) orpdf(Adobe Portable Document Format). and these special values are also accepted:pdf(ps)(makes PDF via PostScript, usingdvipsandps2pdf),pdf(dvi)(makes PDF via dvi, usingdvipdfm). if you don't specify it, the format gets figured out from the name of the output document if you gave one โ otherwise it defaults to PDF.
the following list of formats is supported:
dvipspostscriptpdfpdf(pdflatex)pdf(xelatex)pdf(lualatex)pdf(dvi)pdf(ps)ps(pdf)ps(pdflatex)ps(xelatex)ps(lualatex)
thirteen formats, she contains multitudes ๐
tmpdirโ says whether the formatting should happen in a temporary directory, in which case the source document gets copied in there before formatting. this option either takes the value1, meaning a temporary directory gets automatically generated, or it's taken as the name of a subdirectory of the system temporary directory. oh and โ a temporary directory is always created if the source document is given as a scalar reference. ๐pathsโ a mapping of program names to full pathnames, as a hash reference. these paths override the paths that were determined at installation time. ๐ ๏ธmaxrunsโ the maximum number of runs of the formatter program. defaults to10. ๐extrarunsโ how many additional runs of the formatter program happen after the document has stabilized. โจtimeoutโ a timeout in seconds, within which any commands that get spawned should finish. โฐcleanupโ whether temporary files and directories should be automatically removed when the object destructor is called. accepted values arenone(do no cleanup),logfiles(remove log files) andtempfiles(remove log and temporary files). by default the destructor removes the entire contents of any automatically generated temporary directory, but leaves all other files intact. ๐งนindexstyleโ the name of amakeindexindex style file that should be passed tomakeindex. ๐indexoptionsโ additional options that should be passed tomakeindex. useful ones are:-cto compress intermediate blanks in index keys,-lto specify letter ordering rather than word ordering, and-rto disable implicit range formation. refer to makeindex(1) for full details. ๐texinputsโ one or more directories to be searched for LaTeX files. ๐DEBUGโ enables debug statements if set to a non-zero value. ๐DEBUGPREFIXโ sets the debug prefix, which gets prepended to debug output when there are debug statements. by default there's no prefix. ๐
the constructor does sanity checking on the options and will die if it detects the following conditions ๐ญ:
- no source is specified
- an invalid format is specified
๐จ bestie, seriously: no source = death. invalid format = death. the constructor does NOT play.
the constructor method returns a driver object. ๐ซถ
๐ฅ run() ๐ฅ
format the document. that's it. that's the whole job. go off, king ๐
๐ฆ "stderr" ๐ฆ
holds the error output from subcommands โ but only if the -capture_stderr option was passed to new(). ๐
๐ stats() ๐
returns a reference to a hash containing stats about all the processing that was performed. it contains:
pagesโ number of pages in the formatted document ๐bytesโ number of bytes in the formatted document ๐พrunsโ hash of the number of times each of the programs was run ๐
note: the return value will probably become an object in a future version of the module. so don't get too attached to the hash, bestie, it might glow up ๐
๐ program_path($program_name, $opt_value) ๐
get or set the path to the named program. you can use it as a class method to set the default path, or as an object method to set the path for that specific instance of the driver object. both, she's versatile โจ
there are a number of other methods that are used internally by the driver. calling these methods directly may lead to unpredictable results. โ ๏ธ
fr fr, hands off these unless you know exactly what you're doing. unpredictable results is not a vibe.
run_latexโ runs the formatter (latexorpdflatex).need_to_run_latexโ determines whether the formatter needs to be run.reset_latex_requiredโ resets the flags that indicate whether latex needs to be re-run (invoked prior to each iteration of running any necessary commands).run_bibtexโ runs bibtex to generate the bibliography.need_to_run_bibtexโ determines whether bibtex needs to be run.run_makeindexโ runs makeindex to generate the index.need_to_run_makeindexโ determines whether makeindex needs to be run.run_dvipsโ runs dvips to generate postscript output from an intermediate.dvifile.run_ps2pdfโ runs ps2pdf to generate PDF output from an intermediate PostScript file.run_pdf2psโ runs pdf2ps to generate PostScript output from an intermediate PDF file.run_commandโ run a command in a controlled environment, allowing for operating system differences.copy_to_outputโ copy the output to its final destination.throwโ throw an exception.debugโ print a debug message โ the caller should test$DEBUGto determine whether to invoke this function.
okay that's part one bestie, breathe, hydrate, part two is coming ๐ง๐ธ
๐ DIAGNOSTICS ๐
ok bestie so this is the part where things can go ๐ but it's fine, it's fine, we just need to know what the errors mean. These first ones get caught by the constructor method:
not available on XXXโ the module isn't supported on MacOS, OS/2 or VMS (and honestly probably a whole host of other operating systems too, but those three are the only ones that get explicitly tested for ๐).no source specifiedโ you gotta hand over thesourceparameter!! It should be either the name of a LaTeX source file, or a reference to a scalar variable that's holding your LaTeX source document. Pick one, bestie.source is an invalid referenceโsourceis a reference, sure, but it's not a reference to a scalar variable. Wrong vibe, rejected.source file XXX.tex does not existโ the source file you named justโฆ isn't there. Nowhere. Not found. ๐ญoutput directory DIR does not existโ you gave anoutputparameter as a scalar value (which got read as the output filename), but the directory part of that path doesn't exist. Rude of the path, honestly.invalid output format XXXโ an output format got specified, either explicitly or sneakily implied by the extension of your output file, and that format is just not supported. โcannot create temporary directoryโ the module couldn't make the temp directory. It needs one when the source isn't given as a filename, and the output isn't meant to stay in the same directory as the source, or when a temporary directory name was explicitly specified.cannot create temporary latex fileโ the module figured out it needs a temp file holding the source document andโฆ just couldn't make it happen. ๐cannot copy XXX.ext to temporary directoryโ it was trying to copy the specified source file into the temporary directory and couldn't. Maybe you specified the temp dir name explicitly but that directory doesn't exist or isn't writeable ๐.
And these next ones get caught when the driver's run() method is called:
file XXX.tex does not existโ the source file doesn't exist; it might've gotten removed between the moment the constructor ran and the moment the driver actually ran. Chaos.PROGRAM exited with errors: ERRORSโ the named program (latexorpdflatex) exited with the errors listed. You might have errors in your source file, bestie, check it ๐ซถ.bibtex FILE failed (EXITCODE)โ thebibtexprogram exited with errors. These are not fully parsed yet.failed to open BASEPATH.citโ the driver generates its own temporary file listing the citations for a document so it can figure out whether the citations changed. This error means it couldn't create that file.makeindex FILE failed (EXITCODE)โ themakeindexprogram exited with errors. Not fully parsed yet.dvips FILE failed (EXITCODE)โ thedvipsprogram exited with errors. Not fully parsed yet.ps2pdf FILE failed (EXITCODE)โ theps2pdfprogram exited with errors. Not fully parsed yet.PROGNAME cannot be found, please specify its locationโ the pathname for the specified program wasn't found in the module's configuration. The program may not have been found, and the pathname may not have been explicitly specified back when the module was installed.failed to copy FILE to OUTPUTโ the driver failed to copy the formatted file to the output location you specified.
๐ CONFIGURATION AND ENVIRONMENT ๐
When the using application configures Log::Any, this module will use it to log debug and trace level messages to the LaTeX::Driver category. Please note that the $DEBUG variable does not need to be set to enable this type of logging. And when this type of logging is enabled, the value of $DEBUG is just straight up ignored. periodt.
๐ DEPENDENCIES ๐
LaTeX::Driver depends on latex and friends being installed. The whole squad. ๐ซ
๐ซ INCOMPATIBILITIES ๐ซ
None known. slay.
๐ BUGS AND LIMITATIONS ๐
If you have any comments about this software I would be very grateful to hear them; please file your comments as issues at <https://github.com/Template-Toolkit-Latex/LaTeX-Driver/issues>. ๐
Among the things I am aware of are:
- I haven't worked out how I am going to deal with tex-related environment variables. ๐
๐ฎ FUTURE DIRECTIONS ๐ฎ
- Look at how path variables could be specified to the filter (
TEXINPUTS,TEXINPUTS_latex,TEXINPUTS_pdflatex,BIBINPUTS, etc), and how these should interact with the system paths. - Investigate pre- and post-processors and other auxiliary programs.
๐ BACKGROUND ๐
ok so this module has its origins in the original latex filter that was part of Template Toolkit prior to version 2.16. That code was fairly simplistic ngl; it created a temporary directory, copied the source text to a file in that directory, and ran either latex or pdflatex on the file once; if postscript output was requested then it would run dvips after running latex. The way that it did not cope with documents that contained forward references, a table of contents, lists of figures or tables, bibliographies, or indexesโฆ ๐ฌ iconic behavior, honestly.
The current module does not create a temporary directory for formatting the document; it is given the name and location of an existing LaTeX document and runs the latex programs in the directory specified (the Template Toolkit plugin will be modified to set up a temporary directory, copy the source text in, then run this module, extract the output and remove the temporary directory). โจ
๐ง INTERNALS ๐ง
This section is aimed at a technical audience. It documents the internal methods and subroutines as a reference for the module's developers, maintainers and anyone interesting in understanding how it works. You don't need to know anything about them to use the module and can safely skip this section. like genuinely, skip it if you want, no hard feelings ๐
๐๏ธ Formatting with LaTeX or PDFLaTeX
LaTeX documents can be formatted with latex or pdflatex; the former generates a .dvi file (device independent โ TeX's native output format), which can be converted to PostScript or PDF; the latter program generates PDF directly. Two paths, two vibes, both valid ๐
finds inputs in TEXINPUTS, TEXINPUTS_latex, TEXINPUTS_pdflatex, etc
๐๏ธ Generating indexes
The standard program for generating indexes is makeindex, is a general purpose hierarchical index generator. makeindex accepts one or more input files (.idx), sorts the entries, and produces an output (.ind) file which can be formatted.
The style of the generated index is specified by a style file (.ist), which is found in the path specified by the INDEXSTYLE environment variable.
An alternative to makeindex is xindy, but that program is not widespread yet. ๐
๐ Generating bibliographies with BiBTeX
BiBTeX generates a bibliography for a LaTeX document. It reads the top-level auxiliary file (.aux) output during the running of latex and creates a bibliography file (.bbl) that will be incorporated into the document on subsequent runs of latex. It looks up the entries specified by \cite and \nocite commands in the bibliographic database files (.bib) specified by the \bibliography commands. The entries are formatted according to instructions in a bibliography style file (.bst), specified by the \bibliographystyle command.
Bibliography style files are searched for in the path specified by the BSTINPUTS environment variable; for bibliography files it uses the BIBINPUTS environment variable. System defaults are used if these environment variables are not set. no cap.
๐ป Running Dvips
The dvips program takes a DVI file produced by TeX and converts it to PostScript.
๐ Running ps2pdf
The ps2pdf program invokes Ghostscript to converts a PostScript file to PDF.
๐ช Running on Windows
Commands are executed with cmd.exe. The syntax is:
cmd /c "cd $dir && $program $args"
This changes to the specified directory and executes the program there, without affecting the working directory of the the Perl process.
Need more information on how to set environment variables for the invoked programs.
๐งฉ Miscellaneous Information
This is a placeholder for information not yet incorporated into the rest of the document.
May want to mention the kpathsea library, the kpsewhich program, the web2c TeX distribution, TeX live, tetex, TeX on Windows, etc.
๐ AUTHOR ๐
Erik Huelsmann <erik@efficito.com> (current maintainer)
๐ LICENSE AND COPYRIGHT ๐
Copyright (C) 2020 Erik Huelsmann. Copyright (C) 2014 Chris Travers. Copyright (C) 2009-2013 Ford & Mason Ltd. Copyright (C) 2006-2007 Andrew Ford. Portions Copyright (C) 1996-2006 Andy Wardley.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
๐ซถ SEE ALSO ๐ซถ
Template::Plugin::Latex, latex(1), makeindex(1), bibtex(1), dvips(1), The dvips manual
There are a number of books and other documents that cover LaTeX:
- The LaTeX Companion
- Web2c manual
and that's a wrap bestie!! ๐ธ this lil page is from perl v5.40.1 and it's dated 2026-01-25 โ that's the LaTeX::Driver(3pm) footer btw, we're just saying it cute. now go format something gorgeous ๐โจ๐
๐ฆ where this page comes from
- ubuntu resolute: liblatex-driver-perl 1.3.1-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblatex-driver-perl 1.3.1-1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms