Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
Expand Down
10 changes: 4 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
name = "UnitfulLatexify"
uuid = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"
authors = ["David Gustavsson <david.e.gustavsson@gmail.com> and contributors"]
version = "1.7.0"
version = "2.0.0"

[deps]
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
LaTeXStrings = "1.2.0"
Latexify = "0.16.8"
Unitful = "<1.23.1"
julia = "1"
Latexify = "0.16.9"
Unitful = "1.25"
julia = "1.10"
10 changes: 1 addition & 9 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"
UnitfulRecipes = "42071c24-d89e-48dd-8a24-8a12d9b8861f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
8 changes: 2 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using Documenter
using UnitfulLatexify
using LaTeXStrings

Base.show(io::IO, mime::MIME"text/html", l::LaTeXString) = show(io, mime, l.s)

makedocs(;
sitename="UnitfulLatexify.jl",
format=Documenter.HTML(;
prettyurls=get(ENV, "CI", nothing) == "true", mathengine=MathJax3()
),
modules=[UnitfulLatexify],
doctest=false,
pages=["index.md"],
checkdocs=:exports,
)

deploydocs(; devbranch="main", repo="github.com/gustaphe/UnitfulLatexify.jl.git")
deploydocs(; devbranch="main", repo="github.com/gustaphe/UnitfulLatexify.jl.git",
versions=["dev" => "2.0", "1.7", "1.4"])
Binary file removed docs/src/assets/allunits.png
Binary file not shown.
Binary file removed docs/src/assets/examples.png
Binary file not shown.
154 changes: 15 additions & 139 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,144 +6,20 @@ pretty latexification of Unitful quantities, numbers and units.

## Deprecation

As of Unitful.jl 1.25, UnitfulLatexify is superceded by an extension to Unitful.
As of Unitful.jl 1.25, UnitfulLatexify is superseded by an extension to Unitful.
Loading both Unitful and Latexify will automatically load this functionality.

## Archival Examples

The default usage is pretty intuitive:

```@example main
using Unitful, Latexify, UnitfulLatexify

a = 9.82u"m/s^2"
t = 4u"s"
x = a*t^2

latexify(x)
```

or more usefully:

```@example main
latexify(:(x = a*t^2 = $x))
```

This of course also works for `Units` objects by themselves:

```@example main
latexify(u"kg*m")
```

Some more usage examples:

![](assets/examples.png)


## Arrays

Because Latexify is recursive, an array of unitful quantities is shown as
expected:


```@example main
latexify([12u"m", 1u"m^2", 4u"m^3"])
```

A special case is an array where all elements have the same unit, and here
UnitfulLatexify does some extra work:
```@example main
latexify([1, 2, 3]u"cm")
```


## siunitx.sty

If you are exporting your numbers to an actual LaTeX document, you will of
course want to use the commands from `siunitx.sty` rather than the `\mathrm`
style used by default. To this end you can use Latexify's `fmt=SiunitxNumberFormatter` for `\qty{8}{\second\meter\per\kilo\gram}` style and `fmt=SiunitxNumberFormatter(simple=true)` for
`\qty{8}{s.m/kg}`. Like other Latexify keywords, this can be set to be a default
by using `set_default(fmt=SiunitxNumberFormatter())`, or given with each latexification
command:

```@example main
latexify(612.2u"nm"; fmt=SiunitxNumberFormatter()) # This will not render right without the `siunitx` package
print(ans) # hide
```

### Ranges and lists

Another thing that `siunitx` does uniquely is lists and ranges of quantities.
If you want the default behaviour of tuples and ranges to be printed as arrays,
use `collect(x)` or `[x...]` to explicitly turn them into arrays first.

```@example main
string.([
latexify((1:5)u"m"),
latexify((1:5)u"m"; fmt=SiunitxNumberFormatter()),
latexify(collect((1:5)u"m"); fmt=SiunitxNumberFormatter()),
latexify((1u"m", 2u"m", 3u"m"); fmt=SiunitxNumberFormatter()),
])
```


## Plots labels

UnitfulLatexify also interfaces with `Plots` by way of implementing a two-argument `(label, unit)` recipe:

```@example main
latexify("v", u"km/s")
```

This enables this dreamlike example:

```@example plot
using Unitful, Plots, Latexify, UnitfulLatexify
gr()
default(fontfamily="Computer Modern")

m = randn(10)u"kg"
v = randn(10)u"m/s"
plot(m, v; xguide="\\mathrm{mass}", yguide="v_x", unitformat=latexify)
```

This format, ``v_x\;/\;\mathrm{m}\,\mathrm{s}^{-1}``, is subject to personal
preference. UnitfulLatexify offers a couple of other formats, and you can
simply provide any two-argument function that turns a label and a unit into a
string:

```@example plot
args = (m, v)
kwargs = (xguide="\\mathrm{mass}", yguide="v_x", legend=false)
plot(
plot(args...; kwargs..., unitformat=latexslashunitlabel),
plot(args...; kwargs..., unitformat=latexroundunitlabel),
plot(args...; kwargs..., unitformat=latexsquareunitlabel),
plot(args...; kwargs..., unitformat=latexfracunitlabel),
plot(args...; kwargs..., unitformat=(l, u)->string("\$", l, " \\rightarrow ", latexraw(u), "\$")),
)
```

## Per-modes

In mathrm-mode, one might prefer ``\mathrm{J}\,/\,\mathrm{kg}`` or
``\frac{\mathrm{J}}{\mathrm{kg}}`` over ``\mathrm{J}\,\mathrm{kg}^{-1}``. This
can be achieved by supplying `permode=:slash` or `permode=:frac` respectively.

These will have no effect with `SiunitxNumberFormatter`, because the latex package handles
this for you, and you can set it in your document.

## New siunitx syntax

Starting from `v1.6`, the new syntax from `siunitx v3` (`\qty, \unit` rather
than `\SI, \si`) is used. If you cannot upgrade `siunitx`, there's the option
to use `fmt=SiunitxNumberFormatter(version=2)`.

## A more complete list of defined units

Below is a poorly scraped list of units defined in `Unitful` and what comes out
if you run it through `latexify`. Feel free to create an issue if there's a
unit missing or being incorrectly rendered (and suggest a better ``\LaTeX``
representation if you know one).

![](assets/allunits.png)
This package is now empty, to prevent errors caused by loading it at the same time as the Unitful extension.

In updating code which previously used `UnitfulLatexify` explicitly, be aware of the following breaking changes:
- The `unitformat` keyword argument to `latexify` is replaced by the `fmt` keyword argument,
which can be set to `FancyNumberFormatter()`, `SiunitxNumberFormatter()`.,
or `StyledNumberFormatter()`.
- The `siunitxlegacy` keyword argument is replaced by the `version` keyword
argument of `SiunitxNumberFormatter()`, where `2` means legacy and `3` means current.",
- The functions `latexslashunitlabel`, `latexroundunitlabel`,
`latexsquareunitlabel`, and `latexfracunitlabel` no longer exist,
and should be replaced as either:
- Direct substitute: `(l,u) -> latexify(l, u; labelformat=:slash)`
with `:slash`, `:round`, `:square`, or `:frac`
- First call `Latexify.set_default(labelformat=:slash)`, then use `latexify`
52 changes: 3 additions & 49 deletions src/UnitfulLatexify.jl
Original file line number Diff line number Diff line change
@@ -1,47 +1,12 @@
module UnitfulLatexify

using Unitful:
Unitful,
Unit,
Units,
AbstractQuantity,
AffineUnits,
AffineQuantity,
power,
abbr,
name,
tens,
sortexp,
unit,
@unit,
register,
NoDims,
ustrip,
@u_str,
genericunit,
has_unit_spacing
using Latexify:
Latexify,
@latexrecipe,
latexify,
_latexarray,
latexraw,
FancyNumberFormatter,
PlainNumberFormatter,
StyledNumberFormatter,
SiunitxNumberFormatter,
AbstractNumberFormatter
using LaTeXStrings: LaTeXString

import Latexify: latexify

import Base.*

export latexslashunitlabel, latexroundunitlabel, latexsquareunitlabel, latexfracunitlabel
import Unitful, Latexify

function __init__()
@warn """
UnitfulLatexify is deprecated, and replaced with an extension on Unitful.

The package is now empty, to prevent errors caused by loading it at the same time as the Unitful extension.

```
using Unitful, Latexify
Expand All @@ -61,17 +26,6 @@ function __init__()
with `:slash`, `:round`, `:square`, or `:frac`
- First call `Latexify.set_default(labelformat=:slash)`, then use `latexify`
"""
return register(UnitfulLatexify)
end

include("prefixes.jl")
include("unitnames.jl")

include("auxiliary.jl")
include("default.jl")
include("one.jl")
include("arrays.jl")
include("affine.jl")
include("label.jl")

end
45 changes: 0 additions & 45 deletions src/affine.jl

This file was deleted.

52 changes: 0 additions & 52 deletions src/arrays.jl

This file was deleted.

Loading
Loading