Skip to content

Commit 3a7ceb5

Browse files
authored
Move UnitfulLatexify into Unitful extension (#795)
1 parent c1a9b4e commit 3a7ceb5

File tree

9 files changed

+882
-3
lines changed

9 files changed

+882
-3
lines changed

.github/workflows/documentation.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- uses: actions/checkout@v5
31+
- run: sudo apt install -y ghostscript fonts-freefont-ttf
3132
- uses: julia-actions/setup-julia@v2
3233
with:
3334
version: 1

Project.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1313
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1414
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1515
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
16+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
17+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
1618
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1719

1820
[extensions]
1921
ConstructionBaseUnitfulExt = "ConstructionBase"
2022
ForwardDiffExt = "ForwardDiff"
2123
InverseFunctionsUnitfulExt = "InverseFunctions"
24+
LatexifyExt = ["Latexify", "LaTeXStrings"]
2225
PrintfExt = "Printf"
2326

2427
[compat]
@@ -27,6 +30,8 @@ ConstructionBase = "1"
2730
Dates = "<0.0.1, 1"
2831
ForwardDiff = "0.10, 1"
2932
InverseFunctions = "0.1"
33+
LaTeXStrings = "1.2.0"
34+
Latexify = "0.16.8"
3035
LinearAlgebra = "<0.0.1, 1"
3136
Printf = "<0.0.1, 1"
3237
REPL = "<0.0.1, 1"
@@ -39,11 +44,13 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3944
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
4045
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
4146
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
47+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
48+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
4249
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
4350
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
4451
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
4552
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4653
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4754

4855
[targets]
49-
test = ["Aqua", "ConstructionBase", "ForwardDiff", "InverseFunctions", "LinearAlgebra", "Test", "Random", "REPL", "Printf"]
56+
test = ["Aqua", "ConstructionBase", "ForwardDiff", "InverseFunctions", "Latexify", "LaTeXStrings", "LinearAlgebra", "Test", "Random", "REPL", "Printf"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ mathematical operations and collections that are found in Julia base.
3030
### Feature additions
3131

3232
- [UnitfulEquivalences.jl](https://github.com/sostock/UnitfulEquivalences.jl): Enables conversion between equivalent quantities of different dimensions, e.g. between energy and wavelength of a photon.
33-
- [UnitfulLatexify.jl](https://github.com/gustaphe/UnitfulLatexify.jl): Pretty print units and quantities in LaTeX format.
3433
- [UnitfulParsableString.jl](https://github.com/michikawa07/UnitfulParsableString.jl): Add a `Base.string` method that converts quantities and units to parsable strings.
3534
- [UnitfulBuckinghamPi.jl](https://github.com/rmsrosa/UnitfulBuckinghamPi.jl): Solves for the adimensional Pi groups in a list of Unitful parameters, according to the Buckingham-Pi Theorem.
3635
- [NaturallyUnitful.jl](https://github.com/MasonProtter/NaturallyUnitful.jl): Convert to and from natural units in physics.
3736
- [UnitfulChainRules.jl](https://github.com/SBuercklin/UnitfulChainRules.jl): Enables use of Unitful quantities with [ChainRules.jl](https://github.com/JuliaDiff/ChainRules.jl)-compatible autodifferentiation systems.
3837
- [DimensionfulAngles.jl](https://github.com/cmichelenstrofer/DimensionfulAngles.jl): Adds angle as a dimension. This allows dispatching on angles and derived quantities.
3938
- [Dimensionless.jl](https://github.com/martinkosch/Dimensionless.jl): Contains tools to switch between dimensional bases, conduct dimensional analysis and solve similitude problems.
4039
- [UnitfulRecipes.jl](https://github.com/jw3126/UnitfulRecipes.jl) (deprecated): Adds automatic labels and supports plot axes with units for [Plots.jl](https://github.com/JuliaPlots/Plots.jl). (UnitfulRecipes.jl is now included in Plots.jl.)
40+
- [UnitfulLatexify.jl](https://github.com/gustaphe/UnitfulLatexify.jl) (deprecated): Pretty print units and quantities in LaTeX format. (This package is now an extension to Unitful, so that loading both Unitful and [Latexify.jl](https://github.com/korsbo/Latexify.jl) loads this functionality.)
4141

4242

4343
## Related packages

docs/Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
33
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
5+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
56
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
67
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
8+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
9+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
10+
tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5"
711

812
[compat]
913
Documenter = "1"
10-
Latexify = "0.16"
14+
Latexify = "0.16.9"

docs/generate_latex_images.jl

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using LaTeXStrings, Unitful, Latexify, tectonic_jll
2+
3+
commands = [
4+
:(latexify(612.2u"nm")),
5+
:(latexify(u"kg*m/s^2")),
6+
:(latexify(612.2u"nm"; fmt=SiunitxNumberFormatter())),
7+
:(latexify(u"kg*m/s^2"; fmt=SiunitxNumberFormatter())),
8+
:(latexify(612.2u"nm"; fmt=SiunitxNumberFormatter(; simple=true))),
9+
:(latexify(u"kg*m/s^2"; fmt=SiunitxNumberFormatter(; simple=true))),
10+
:(latexify((1, 2, 4) .* u"m"; fmt=SiunitxNumberFormatter())),
11+
]
12+
tab1 = map(commands) do command
13+
LaTeXString.([
14+
"\\verb+$(string(command))+",
15+
"\\verb+$(eval(command))+",
16+
"$(eval(command)) ",
17+
])
18+
end
19+
ltab1 = latextabular(tab1, adjustment=:l, transpose=true, latex=false, booktabs=true,
20+
head=["julia", "\\LaTeX", "Result"])
21+
# Setting an explicit white background color results in transparent PDF, so go offwhite.
22+
ltab1 = LaTeXString("\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}\n\\pagecolor{offwhite}\n\\color{black}\n" * ltab1)
23+
24+
render(ltab1, MIME("image/png"); use_tectonic=true,
25+
name=(@__DIR__)*"/src/assets/latex-examples",
26+
packages=["booktabs", "color", "siunitx"],
27+
documentclass=("standalone"))
28+
29+
functions = [
30+
x -> "\\verb+$(string(x))+",
31+
x -> latexify(x),
32+
x -> latexify(x; fmt=SiunitxNumberFormatter()),
33+
x -> latexify(x; fmt=SiunitxNumberFormatter(; simple=true)),
34+
]
35+
allunits = begin
36+
uparse.([
37+
"nH*m/Hz",
38+
"m",
39+
"s",
40+
"A",
41+
"K",
42+
"cd",
43+
"g",
44+
"mol",
45+
"sr",
46+
"rad",
47+
"°",
48+
"Hz",
49+
"N",
50+
"Pa",
51+
"J",
52+
"W",
53+
"C",
54+
"V",
55+
"S",
56+
"F",
57+
"H",
58+
"T",
59+
"Wb",
60+
"lm",
61+
"lx",
62+
"Bq",
63+
"Gy",
64+
"Sv",
65+
"kat",
66+
#"percent", # Messes with comments
67+
# "permille", # Undefined in all formats
68+
# "pertenthousand", # Undefined in all formats (butchered)
69+
"°C",
70+
"°F", # No longer in siunitx
71+
"minute",
72+
"hr",
73+
"d",
74+
"wk", # Undefined in siunitx
75+
"yr", # Undefined in siunitx
76+
"rps", # Undefined in siunitx
77+
"rpm", # Undefined in siunitx
78+
"a", # Undefined in siunitx
79+
"b",
80+
"L",
81+
"M", # Undefined in siunitx
82+
"eV",
83+
"Hz2π", # Butchered by encoding
84+
"bar",
85+
"atm", # Undefined in siunitx
86+
"Torr", # Undefined in siunitx
87+
"c", # Undefined in siunitx
88+
"u", # Undefined in siunitx
89+
"ge", # Undefined in siunitx
90+
"Gal", # Undefined in siunitx
91+
"dyn", # Undefined in siunitx
92+
"erg", # Undefined in siunitx
93+
"Ba", # Undefined in siunitx
94+
"P", # Undefined in siunitx
95+
"St", # Undefined in siunitx
96+
#"Gauss", # errors in testing, maybe from Unitful.jl's dev branch?
97+
#"Oe", # errors in testing, maybe from Unitful.jl's dev branch?
98+
#"Mx", # errors in testing, maybe from Unitful.jl's dev branch?
99+
"inch", # Undefined in siunitx
100+
"mil", # Undefined in siunitx
101+
"ft", # Undefined in siunitx
102+
"yd", # Undefined in siunitx
103+
"mi", # Undefined in siunitx
104+
"angstrom", # Undefined in mathrm,siunitxsimple
105+
"ac", # Undefined in siunitx
106+
"Ra", # Undefined in siunitx
107+
"lb", # Undefined in siunitx
108+
"oz", # Undefined in siunitx
109+
"slug", # Undefined in siunitx
110+
"dr", # Undefined in siunitx
111+
"gr", # Undefined in siunitx
112+
"lbf", # Undefined in siunitx
113+
"cal", # Undefined in siunitx
114+
"btu", # Undefined in siunitx
115+
"psi", # Undefined in siunitx
116+
#"dBHz", # Cannot *yet* be latexified.
117+
#"dBm", # Cannot *yet* be latexified.
118+
#"dBV", # Cannot *yet* be latexified.
119+
#"dBu", # Cannot *yet* be latexified.
120+
#"dBμV", # Cannot *yet* be latexified.
121+
#"dBSPL", # Cannot *yet* be latexified.
122+
#"dBFS", # Cannot *yet* be latexified.
123+
#"dBΩ", # Cannot *yet* be latexified.
124+
#"dBS", # Cannot *yet* be latexified.
125+
])
126+
end
127+
128+
tab2 = map(allunits) do unit
129+
[LaTeXString(f(unit)) for f in functions]
130+
end
131+
ltab2 = latextabular(tab2, adjustment=:l, transpose=true, latex=false, booktabs=true,
132+
head=["Name", "Default number formatter", "\\verb+SiunitxNumberFormatter()+", "\\verb+SiunitxNumberFormatter(;simple=true)+"])
133+
# Set background to not-quite-white so it doesn't get treated as transparent
134+
ltab2 = LaTeXString(
135+
"""
136+
\\setmainfont{FreeSerif}
137+
\\setmonofont{FreeMono}
138+
\\definecolor{offwhite}{rgb}{0.999,0.999,0.999}
139+
\\pagecolor{offwhite}
140+
\\color{black}
141+
""" * ltab2)
142+
143+
render(ltab2, MIME("image/png"); use_tectonic=true,
144+
tectonic_flags=`-Z continue-on-errors`,
145+
name=(@__DIR__)*"/src/assets/latex-allunits",
146+
packages=["booktabs", "color", "siunitx", "fontspec"],
147+
documentclass=("standalone"))

docs/make.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Documenter, Unitful, Dates
22

3+
@info "Generating latex images for documentation"
4+
include("generate_latex_images.jl")
5+
36
DocMeta.setdocmeta!(Unitful, :DocTestSetup, :(using Unitful))
47

58
makedocs(
@@ -19,6 +22,7 @@ makedocs(
1922
"Logarithmic scales" => "logarithm.md"
2023
"Temperature scales" => "temperature.md"
2124
"Interoperability with `Dates`" => "dates.md"
25+
"Latexifying units" => "latexify.md"
2226
"Extending Unitful" => "extending.md"
2327
"Troubleshooting" => "trouble.md"
2428
"Pre-defined units and constants" => "defaultunits.md"

0 commit comments

Comments
 (0)