Skip to content
Merged
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
6 changes: 3 additions & 3 deletions ext/LatexifyExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function _transform(q::AbstractQuantity, ::AbstractNumberFormatter)
Expr(
:latexifymerge,
NakedNumber(q.val),
has_unit_spacing(unit(q)) ? "\\;" : nothing,
has_unit_spacing(unit(q)) ? "\\," : nothing,
NakedUnits(unit(q)),
)
end
Expand Down Expand Up @@ -243,7 +243,7 @@ end
)
end
env --> :inline
return Expr(:latexifymerge, q.val, "\\;\\mathrm{", unitnames[(:mathrm, unitname)], "}")
return Expr(:latexifymerge, q.val, "\\,\\mathrm{", unitnames[(:mathrm, unitname)], "}")
end

# arrays -------------------------
Expand All @@ -253,7 +253,7 @@ end
# Array of quantities with the same unit
env --> :equation
return Expr(
:latexifymerge, ustrip.(a), has_unit_spacing(first(a)) ? "\\;" : "", unit(first(a))
:latexifymerge, ustrip.(a), has_unit_spacing(first(a)) ? "\\," : "", unit(first(a))
)
end

Expand Down
24 changes: 12 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1793,15 +1793,15 @@ end
)
unitfullatexifytest(
24.7e9u"Gm/s^2",
raw"$2.47 \cdot 10^{10}\;\mathrm{Gm}\,\mathrm{s}^{-2}$",
raw"$2.47 \cdot 10^{10}\,\mathrm{Gm}\,\mathrm{s}^{-2}$",
raw"\qty{2.47e10}{\giga\meter\per\second\tothe{2}}",
raw"\qty{2.47e10}{Gm.s^{-2}}",
)
unitfullatexifytest(
u"percent", raw"$\mathrm{\%}$", raw"\unit{\percent}", raw"\unit{\%}"
)
unitfullatexifytest(
2u"°C", raw"$2\;\mathrm{^\circ C}$", raw"\qty{2}{\celsius}", raw"\qty{2}{\celsius}"
2u"°C", raw"$2\,\mathrm{^\circ C}$", raw"\qty{2}{\celsius}", raw"\qty{2}{\celsius}"
)
unitfullatexifytest(
1u"°", raw"$1\mathrm{^{\circ}}$", raw"\qty{1}{\degree}", raw"\qty{1}{\degree}"
Expand All @@ -1816,7 +1816,7 @@ end
2 \\
3 \\
\end{array}
\right]\;\mathrm{m}
\right]\,\mathrm{m}
\end{equation}
""",
raw"""
Expand All @@ -1827,7 +1827,7 @@ end
\num{2} \\
\num{3} \\
\end{array}
\right]\;\unit{\meter}
\right]\,\unit{\meter}
\end{equation}
""",
raw"""
Expand All @@ -1838,7 +1838,7 @@ end
\num{2} \\
\num{3} \\
\end{array}
\right]\;\unit{m}
\right]\,\unit{m}
\end{equation}
""",
)
Expand All @@ -1851,15 +1851,15 @@ end
2 \\
3 \\
\end{array}
\right]\;\mathrm{m}
\right]\,\mathrm{m}
\end{equation}
""",
raw"\qtylist{1;2;3}{\meter}",
raw"\qtylist{1;2;3}{m}",
)

@test latexify(24.7e9u"Gm/s^2"; fmt="%.1e") ==
L"$2.5e+10\;\mathrm{Gm}\,\mathrm{s}^{-2}$"
L"$2.5e+10\,\mathrm{Gm}\,\mathrm{s}^{-2}$"
@test latexify(5.9722e24u"kg"; fmt=SiunitxNumberFormatter(version=2)) ==
raw"\SI{5.9722e24}{\kilo\gram}"
@test latexify(u"eV"; fmt=SiunitxNumberFormatter(version=2)) == raw"\si{\electronvolt}"
Expand All @@ -1868,16 +1868,16 @@ end
@testset "permode" begin
p = 5u"m^3*s^2/H/kg^4"
@test latexify(p) == LaTeXString(
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
)
@test latexify(p; permode=:power) == LaTeXString(
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,\mathrm{kg}^{-4}\,\mathrm{H}^{-1}$"
)
@test latexify(p; permode=:slash) == LaTeXString(
raw"$5\;\mathrm{m}^{3}\,\mathrm{s}^{2}\,/\,\mathrm{kg}^{4}\,\mathrm{H}$"
raw"$5\,\mathrm{m}^{3}\,\mathrm{s}^{2}\,/\,\mathrm{kg}^{4}\,\mathrm{H}$"
)
@test latexify(p; permode=:frac) == LaTeXString(
raw"$5\;\frac{\mathrm{m}^{3}\,\mathrm{s}^{2}}{\mathrm{kg}^{4}\,\mathrm{H}}$"
raw"$5\,\frac{\mathrm{m}^{3}\,\mathrm{s}^{2}}{\mathrm{kg}^{4}\,\mathrm{H}}$"
)
@test latexify(p; permode=:frac, fmt=SiunitxNumberFormatter()) ==
latexify(p; fmt=SiunitxNumberFormatter())
Expand All @@ -1899,7 +1899,7 @@ end

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

Expand Down
Loading