TeXTools 1.24

documentation notebook

Eric Rowland
https://ericrowland.github.io/packages.html

Introduction

TeXTools automates some common tasks involved in writing papers in LATEX.
This introduction gets you started with the main features of the package; the next section provides a complete list of package symbols along with their usage messages and further examples.

To use TeXTools, first you will need to load the package by evaluating the following cell. (If you need help, see loading a package.)

<<TeXTools`

Exporting figures

The value of $TeXSourceDirectory is the current working directory for TeXTools functions.  It specifies the location of the .tex source file.
Let’s create a temporary directory for the purpose of demonstrating how to use the functions in TeXTools and set $TeXSourceDirectory to our new directory.

$TeXSourceDirectory=CreateDirectory[];

If your graphics files are in a different directory than your source file, you may set $TeXFiguresDirectory to your figures directory.  By default, $TeXFiguresDirectory is a subdirectory of $TeXSourceDirectory:

$TeXFiguresDirectory

However, since this directory doesn't exist yet, we'll want to create it too.  (Of course, you can do all of this so far in your operating system, outside of Mathematica.)

CreateDirectory[$TeXFiguresDirectory]

When working on a paper in LATEX, it is useful to have graphics files in both .ps and .pdf formats, so that the paper looks correct as both .dvi and .pdf documents.  ExportFigure exports an image to both formats.  This exports a circle:

ExportFigure["circle",Graphics[Circle[]]]

Checking your spelling

Let's create a .tex file in our temporary directory.

Export[FileNameJoin[{$TeXSourceDirectory,"paper.tex"}],Cell["This is a survey paper on opallic hypergeoids.","Text"]]

Now let's check the spelling.
The output is a list of rules, where each rule contains certain misspelled words along with corresponding line numbers.

MisspelledWords[%]

There are several dictionaries in the package source file that you can add words to.

You can also search for duplicate words in your paper:

DuplicateWords[%%]

Working with TEX files

TeXCompile compiles a .tex file.  Let's first make a .dvi file.

TeXCompile["paper","dvi"]

We can also make a .pdf file.

TeXCompile["paper","pdf"]

One way to set up your work environment when writing a LATEX paper is to have open the source file, a command window for compiling the source, and the dvi file for viewing the results.  TeXOpen opens all three.
(Note that the opening of the command window here is Windows-specific.  If you know what the corresponding code should be for other operating systems, let me know and I'll add it to the package.)

TeXOpen["paper"]

This deletes our temporary directory and its contents:

DeleteDirectory[$TeXSourceDirectory,DeleteContents->True]

Package symbols

CommandArguments

?CommandArguments

Find all the graphics files used in a paper:

Union[CommandArguments["\\includegraphics"|"\\vcentergraphics"]]

Delete unused graphics files:

With[{graphics=First/@CommandArguments["includegraphics"]},((DeleteFile[FileNameJoin[{$TeXFiguresDirectory,#1}]];FileNameJoin[{$TeXFiguresDirectory,#1}])&)/@Select[FileNameTake/@FileNames[___,$TeXFiguresDirectory],!MemberQ[graphics,StringDrop[#1,-4]]&]]

DuplicateWords

?DuplicateWords

ExportFigure

?ExportFigure

$TeXFiguresDirectory=FileNameJoin[{$TemporaryDirectory,"temp"}];
CreateDirectory[$TeXFiguresDirectory];
ExportFigure["rule30",ArrayPlot[CellularAutomaton[30,{{1},0},100]]]

MisspelledWords

?MisspelledWords

SymbolReplace

?SymbolReplace

Replace all instances of the variable f with a:

SymbolReplace["paper",FileNameJoin[{$HomeDirectory,"copy.tex"}],"f"->"a"]

TeXCompile

?TeXCompile

Possible file types include dvi, pdf, and ps.

TeXOpen

?TeXOpen

TeXOpen[]

TeXPublish

?TeXPublish

TeXTableForm

?TeXTableForm

This is a minor improvement over the functionality for tables built into TeXForm.
In addition to having two options, it handles ragged arrays.

There is a trick to actually copying the output from this function:  It is best to select the entire output cell by its bracket on the right or by triple-clicking on the output; if Mathematica does not believe that you intend to copy the entire cell (even if every character is selected), several stray quotes and backslashes will appear when it is pasted.

TeXTableForm[{{47,1104,1105},{817,744,1105},{943,576,1105},{1073,264,1105}}]

Options:

Options[TeXTableForm]

TeXTableForm[{{47,1104,1105},{817,744,1105},{943,576,1105},{1073,264,1105}},Alignment->Center,TableHeadings->{None,{x,y,(Sqrt[(x^2)+(y^2)])}}]

TeXTableForm[{{47,1104,1105},{817,744,1105},{943,576,1105},{1073,264,1105}},TableHeadings->{Range[4],{x,y,(Sqrt[(x^2)+(y^2)])}}]

TeXTableForm[{{47,1104,1105},{817,744,1105},{943,576,1105},{1073,264,1105}},Alignment->{{Right,Right,Left}}]

$TeXFiguresDirectory

?$TeXFiguresDirectory

ExportFigure exports graphics files to the directory given by $TeXFiguresDirectory if no full path is given.

By default, $TeXFiguresDirectory is set to the following.

FileNameJoin[{$TeXSourceDirectory,"figures"}]

$TeXPublicationDirectory

?$TeXPublicationDirectory

$TeXSourceDirectory

?$TeXSourceDirectory

The functions in TeXTools check for files in the directory given by $TeXSourceDirectory if no full path is given.

By default, $TeXSourceDirectory is set to the directory containing the notebook into which TeXTools was loaded, if it exists; if not, it is set to the value of $InitialDirectory.