Skip to content

Commit 448bd54

Browse files
committed
Merge branch 'master' into mark_public_units
2 parents 6cde5e4 + 2eba283 commit 448bd54

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Unitful.jl changelog
22

3+
## v1.25.0 (2025-09-16)
4+
5+
* ![Feature:](https://img.shields.io/badge/-feature-green) Quantities and units can now be converted to a LaTeX representation using [`Latexify.jl`](https://github.com/korsbo/Latexify.jl). This is provided via a package extension and replaces the [UnitfulLatexify.jl](https://github.com/gustaphe/UnitfulLatexify.jl) package ([#795](https://github.com/JuliaPhysics/Unitful.jl/pull/795)).
6+
* This package now requires Julia ≥ 1.6.
7+
38
## v1.24.0 (2025-07-31)
49

510
* ![Feature:](https://img.shields.io/badge/-feature-green) The alias `deg` for `°` is added ([#764](https://github.com/JuliaPhysics/Unitful.jl/pull/764)).

ext/LatexifyExt.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function _transform(q::AbstractQuantity, ::AbstractNumberFormatter)
193193
Expr(
194194
:latexifymerge,
195195
NakedNumber(q.val),
196-
has_unit_spacing(unit(q)) ? "\\;" : nothing,
196+
has_unit_spacing(unit(q)) ? "\\," : nothing,
197197
NakedUnits(unit(q)),
198198
)
199199
end
@@ -243,7 +243,7 @@ end
243243
)
244244
end
245245
env --> :inline
246-
return Expr(:latexifymerge, q.val, "\\;\\mathrm{", unitnames[(:mathrm, unitname)], "}")
246+
return Expr(:latexifymerge, q.val, "\\,\\mathrm{", unitnames[(:mathrm, unitname)], "}")
247247
end
248248

249249
# arrays -------------------------
@@ -253,7 +253,7 @@ end
253253
# Array of quantities with the same unit
254254
env --> :equation
255255
return Expr(
256-
:latexifymerge, ustrip.(a), has_unit_spacing(first(a)) ? "\\;" : "", unit(first(a))
256+
:latexifymerge, ustrip.(a), has_unit_spacing(first(a)) ? "\\," : "", unit(first(a))
257257
)
258258
end
259259

src/utils.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ true
145145
@inline unit(x::Type{Missing}) = missing
146146
@inline unit(x::Missing) = missing
147147

148+
# Prevent infinite recursion, in case unit(Any) is called.
149+
@inline unit(x::Type{Any}) = throw(ArgumentError(
150+
"unit(Any) was called, which has no meaningful result. This may be due to calling unit(eltype(…)), since eltype has a generic fallback method that returns Any."
151+
))
152+
148153
"""
149154
absoluteunit(::Units)
150155
absoluteunit(::Quantity)

test/runtests.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,15 +1816,15 @@ end
18161816
)
18171817
unitfullatexifytest(
18181818
24.7e9u"Gm/s^2",
1819-
raw"$2.47 \cdot 10^{10}\;\mathrm{Gm}\,\mathrm{s}^{-2}$",
1819+
raw"$2.47 \cdot 10^{10}\,\mathrm{Gm}\,\mathrm{s}^{-2}$",
18201820
raw"\qty{2.47e10}{\giga\meter\per\second\tothe{2}}",
18211821
raw"\qty{2.47e10}{Gm.s^{-2}}",
18221822
)
18231823
unitfullatexifytest(
18241824
u"percent", raw"$\mathrm{\%}$", raw"\unit{\percent}", raw"\unit{\%}"
18251825
)
18261826
unitfullatexifytest(
1827-
2u"°C", raw"$2\;\mathrm{^\circ C}$", raw"\qty{2}{\celsius}", raw"\qty{2}{\celsius}"
1827+
2u"°C", raw"$2\,\mathrm{^\circ C}$", raw"\qty{2}{\celsius}", raw"\qty{2}{\celsius}"
18281828
)
18291829
unitfullatexifytest(
18301830
1u"°", raw"$1\mathrm{^{\circ}}$", raw"\qty{1}{\degree}", raw"\qty{1}{\degree}"
@@ -1839,7 +1839,7 @@ end
18391839
2 \\
18401840
3 \\
18411841
\end{array}
1842-
\right]\;\mathrm{m}
1842+
\right]\,\mathrm{m}
18431843
\end{equation}
18441844
""",
18451845
raw"""
@@ -1850,7 +1850,7 @@ end
18501850
\num{2} \\
18511851
\num{3} \\
18521852
\end{array}
1853-
\right]\;\unit{\meter}
1853+
\right]\,\unit{\meter}
18541854
\end{equation}
18551855
""",
18561856
raw"""
@@ -1861,7 +1861,7 @@ end
18611861
\num{2} \\
18621862
\num{3} \\
18631863
\end{array}
1864-
\right]\;\unit{m}
1864+
\right]\,\unit{m}
18651865
\end{equation}
18661866
""",
18671867
)
@@ -1874,15 +1874,15 @@ end
18741874
2 \\
18751875
3 \\
18761876
\end{array}
1877-
\right]\;\mathrm{m}
1877+
\right]\,\mathrm{m}
18781878
\end{equation}
18791879
""",
18801880
raw"\qtylist{1;2;3}{\meter}",
18811881
raw"\qtylist{1;2;3}{m}",
18821882
)
18831883

18841884
@test latexify(24.7e9u"Gm/s^2"; fmt="%.1e") ==
1885-
L"$2.5e+10\;\mathrm{Gm}\,\mathrm{s}^{-2}$"
1885+
L"$2.5e+10\,\mathrm{Gm}\,\mathrm{s}^{-2}$"
18861886
@test latexify(5.9722e24u"kg"; fmt=SiunitxNumberFormatter(version=2)) ==
18871887
raw"\SI{5.9722e24}{\kilo\gram}"
18881888
@test latexify(u"eV"; fmt=SiunitxNumberFormatter(version=2)) == raw"\si{\electronvolt}"
@@ -1891,16 +1891,16 @@ end
18911891
@testset "permode" begin
18921892
p = 5u"m^3*s^2/H/kg^4"
18931893
@test latexify(p) == LaTeXString(
1894-
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
1894+
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
18951895
)
18961896
@test latexify(p; permode=:power) == LaTeXString(
1897-
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
1897+
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
18981898
)
18991899
@test latexify(p; permode=:slash) == LaTeXString(
1900-
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,/\,\mathrm{kg}^{4}\,\mathrm{H}$"
1900+
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,/\,\mathrm{kg}^{4}\,\mathrm{H}$"
19011901
)
19021902
@test latexify(p; permode=:frac) == LaTeXString(
1903-
raw"$5\;\frac{\mathrm{m}^{3}\,\mathrm{s}^{2}}{\mathrm{kg}^{4}\,\mathrm{H}}$"
1903+
raw"$5\,\frac{\mathrm{m}^{3}\,\mathrm{s}^{2}}{\mathrm{kg}^{4}\,\mathrm{H}}$"
19041904
)
19051905
@test latexify(p; permode=:frac, fmt=SiunitxNumberFormatter()) ==
19061906
latexify(p; fmt=SiunitxNumberFormatter())
@@ -1922,7 +1922,7 @@ end
19221922

19231923
@testset "Parentheses" begin
19241924
@test @latexify($(3u"mm")^2 - 4 * $(2u"mm^2")) ==
1925-
raw"$\left( 3\;\mathrm{mm} \right)^{2} - 4 \cdot 2\;\mathrm{mm}^{2}$"
1925+
raw"$\left( 3\,\mathrm{mm} \right)^{2} - 4 \cdot 2\,\mathrm{mm}^{2}$"
19261926
end
19271927
end
19281928

0 commit comments

Comments
 (0)