LaTeX::Driver(3pm)

๐Ÿ“ฆ
version 1.3.1 ยท 3 versions
, in ubuntu resolute, ubuntu stonking

๐Ÿ’– 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 of dvi (TeX Device Independent format), ps (PostScript) or pdf (Adobe Portable Document Format). and these special values are also accepted: pdf(ps) (makes PDF via PostScript, using dvips and ps2pdf), pdf(dvi) (makes PDF via dvi, using dvipdfm). 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:

  • dvi
  • ps
  • postscript
  • pdf
  • pdf(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 value 1, 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 to 10. ๐Ÿ”
  • 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 are none (do no cleanup), logfiles (remove log files) and tempfiles (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 a makeindex index style file that should be passed to makeindex. ๐Ÿ“š
  • indexoptions โ€” additional options that should be passed to makeindex. useful ones are: -c to compress intermediate blanks in index keys, -l to specify letter ordering rather than word ordering, and -r to 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 (latex or pdflatex).
  • 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 .dvi file.
  • 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 $DEBUG to 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 the source parameter!! 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 โ€” source is 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 an output parameter 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 (latex or pdflatex) exited with the errors listed. You might have errors in your source file, bestie, check it ๐Ÿซถ.
  • bibtex FILE failed (EXITCODE) โ€” the bibtex program 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) โ€” the makeindex program exited with errors. Not fully parsed yet.
  • dvips FILE failed (EXITCODE) โ€” the dvips program exited with errors. Not fully parsed yet.
  • ps2pdf FILE failed (EXITCODE) โ€” the ps2pdf program 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)

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