Enter the package manager by typing a close bracket: ] and then
pkg> add LatexPrint
Key functions
This module provides functions for converting Julia objects into
string representations for use in LaTeX mathematics mode. The primary
function is laprintln which behaves precisely like println except
Julia objects are first converted to a form suitable for
LaTeX. Because laprintln is a lot to type, we also provide the
abbreviation lap.
julia> using LatexPrint
julia> x = 2//6
1//3
julia> lap(x)
\frac{1}{3}
We also provide the function laprint which does not append a new
line (just like print).
These functions rely on latex_form which converts a Julia object
into an String representation in its LaTeX form:
julia> latex_form(x)
"\\frac{1}{3}"
The double backslash in the output of latex_form is converted to a
single backslash when run through a print function.
Supported Types
Numbers
Integers and floating point numbers
FloatingPoint and Integer numbers are printed unchanged.
The LaTeX version of an String is wrapped in the command
\text (which requires the amsmath package in LaTeX). The rationale
is that we always want to able to paste the output of lap directly
into mathematics mode in LaTeX.
julia> lap("Hello, world!")
\text{Hello, world!}
Arrays
Vectors (one-dimensional arrays) and matrices (two-dimensional arrays)
are converted into LaTeX array environments bounded by square
brackets with centering alignment. (These default options can be
changed; see "Customizing existing types" later in this document.)
Julia Set and IntSet objects are rendered as a comma separated
list between curly braces. The elements are sorted into ascending
order (if possible). An empty set is returned as \emptyset (unless
another form is specified using set_empty).
julia> A = Set({3.5, 2, -5})
Set{Any}({2,-5,3.5})
julia> lap(A)
\left\{-5,2,3.5\right\}
julia> B = IntSet(4,5,1)
IntSet([1, 4, 5])
julia> lap(B)
\left\{1,4,5\right\}
julia> C = Set()
Set{Any}({})
julia> lap(C)
\emptyset
The tabular function
If A is a matrix (two-dimensional array), then laprintln(A) (or
lap(A)) prints the LaTeX code for that matrix (complete with
bounding delimeters) for inclusion in LaTeX's mathematics mode.
As an alternative, we also provide the function tabular that prints
the array for inclusion in LaTeX's text mode in the tabular
environment.
Notice that each entry is encased in dollar signs.
By default, each column is center aligned. This can be modified in
two ways. See the set_align function described below or by calling
tabular with the named alignment argument, like this:
In addition, the end-of-line command \\ can be changed to
\\ \hline (so LaTeX inserts a horizontal line between rows)
by means of the named hlines argument:
Note that the last row of the array does not include an \hline.
Customization
Customizing existing types
The LatexPrint module comes with default LaTeX representations for
infinity, not-a-number, and so forth. Some of these can be modified by
the following functions.
set_inf is used to set the representation of infinity. The default
creates the output \infty but here's how it can be changed.
Users might like to try \varnothing as a nice alternative to
\empytset. In that case, the Julia command would be
set_emptyset("\\varnothing").
set_align is used to specify the alignment character for
arrays. By default elements of columns are aligned to their
center. Use one of l, r, or c as the alignment character.
There are other Julia types (such as UnitRange) for which
we have not implemented a conversion to LaTeX. In this
case lap (and our other functions) simply convert the type
to an String.
julia> lap(1:10)
1:10
If we want to create a LaTeX representation, then we
need to define a suitable version of latex_form like this:
请发表评论