# \[ANN\] UnitfulLatexify.jl

**URL:** <https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090>\
**Category:** Package Announcements\
**Created:** [January 27, 2021, 11:30pm UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090 "2021-01-27T23:30:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 27, 2021, 11:30pm UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/1 "2021-01-27T23:30:23Z")

</div>

Announcing [UnitfulLatexify.jl](https://github.com/gustaphe/UnitfulLatexify.jl) – A glue package between Unitful and Latexify (surprise!).

Creates LaTeXStrings from Unitful quantities and units, either on the form `35\;\mathrm{cm}` or `\SI{35}{\centi\meter}`.

I think it’s pretty cool.

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [January 27, 2021, 11:43pm UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/2 "2021-01-27T23:43:49Z")

</div>

I like it! Is there a way to get

```julia
latexify(1.12345e6*u, unitformat=:mathrm)
L"$1.12345 \times 10^6\;\mathrm{kg}\mathrm{m}\mathrm{s}^{-2}$"

```

instead of

```julia
latexify(1.12345e6*u,unitformat=:mathrm)
L"$1.12345e6\;\mathrm{kg}\mathrm{m}\mathrm{s}^{-2}$"

```

?

That would be great 🙂

---

<div class="post-metadata">

**Author:** ![NicholasWMRitchie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicholaswmritchie/32/22449_2.png) [@NicholasWMRitchie](https://discourse.julialang.org/u/NicholasWMRitchie)\
**Post date:** [January 27, 2021, 11:58pm UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/3 "2021-01-27T23:58:09Z")

</div>

> [@fgerick](#):
>
> `$1.12345 \times 10^6\;\mathrm{kg}\mathrm{m}\mathrm{s}^{-2}`

I haven’t had the opportunity to use UnitfulLatexify (yet!) but it appears to use the optionally use the siunitx package which will do as you desire.  
siunitx is great for ensuring numbers with units are formatted correctly including scientific notation and spacing rather than commas as the thousands-place separators. That is the “\SI{35}{\centi\meter}” example.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 6:13am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/4 "2021-01-28T06:13:42Z")

</div>

Yes. Apart from the siunitx route, you can use all the formatting options from Latexify.jl, so `latexify(1.2e16u"m",fmt="%.2e")` should do something like what you want.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [January 28, 2021, 6:49am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/5 "2021-01-28T06:49:30Z")

</div>

Great idea for a package and welcome to discourse!

And it even also works with siunitx – great! I definitely keep that in mind for my latex exports!

_edit_: I just saw, that `Unitful` has `NoUnits`, would that maybe be a good replacement for `u"one"`?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 7:31am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/6 "2021-01-28T07:31:16Z")

</div>

In principle yes. I actually didn’t find that one when looking through Unitful. It has the big disadvantage that from what I see the only way to get a `Quantity` with `NoUnits` that doesn’t immediately simplify to a number is to run something like `Quantity{Int64,NoDims,Unitful.FreeUnits{(),NoDims,nothing}}(28)`, and then it’s not “safe” to perform any arithmetic with. `typeof(24u"NoUnits") == Int64`. But maybe there’s a way around this, I shall investigate. Thanks for the tip!

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [January 28, 2021, 7:37am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/7 "2021-01-28T07:37:32Z")

</div>

Thanks for the insight – I was just wondering, since `u"one"`looked as `Unitful` had no `NoUnits` type, that’s why I was looking for that. Also, there are surely numbers that really just have no unit.

---

<div class="post-metadata">

**Author:** ![fgerick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fgerick/32/13228_2.png) [@fgerick](https://discourse.julialang.org/u/fgerick)\
**Post date:** [January 28, 2021, 8:31am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/8 "2021-01-28T08:31:49Z")

</div>

Hmmm your example does a normal printf format, so checking the docs of Latexify.jl I found

```julia
latexify(1.2e16; fmt=FancyNumberFormatter(3))
L"$1.2 \cdot 10^{16}$"

```

nice! But when combined with the unit this does not work:

```julia
latexify(1.2e16u"m"; fmt=FancyNumberFormatter(3))
L"$1.2e16\;\mathrm{m}$"

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 28, 2021, 9:20am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/9 "2021-01-28T09:20:27Z")

</div>

Everyone should always be using siunitx(!), it’s one of the absolute core packages that I/we use in everything we do. Strongly recommended.

Not sure how you generate the units, but it’s perhaps nice to be aware that siunitx understands ‘simple’ units, so you can just write `\SI{35}{cm/kg^2}` instead of `\SI{35}{\centi\meter\per\kilo\gram\squared}`.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 9:34am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/10 "2021-01-28T09:34:20Z")

</div>

My bad. Here I go advertising features from my internal wish list.

I’m working on a fix for this, and making good head way. I must have just dreamed about this working the way I thought.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 9:39am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/11 "2021-01-28T09:39:21Z")

</div>

No it doesn’t? Siunitx will allow you to enter literal text into the argument of `\si`, but it will not do proper siunitx stuff to it. Try `\si{cm s / m^2} \si{\centi\meter\second\per\meter\squared}` and you’ll see the difference.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 28, 2021, 10:33am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/12 "2021-01-28T10:33:17Z")

</div>

Yes, it will:

```julia
\documentclass{standalone}
\usepackage{siunitx}

\begin{document}
\begin{tabular}{l}
    \si{\centi\meter\second\per\meter\squared} \\
    \si{cm.s.m^{-2}} \\
    \si{cm.s/m^2}
\end{tabular}
\end{document}

```

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/0/6/06bb7d0c1119f084d72725484c1d4b0eb94d8bf0.png)

The macro versions are for programming purposes, and are not needed during ordinary editing.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 10:47am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/13 "2021-01-28T10:47:32Z")

</div>

Huh, good to know. I’ve never seen that. I wonder if it was introduced after I learned siunitx or if I just missed it.

I’ll probably keep using the macros, it feels more TeX philosophic, and I absolutely detest the product period.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 28, 2021, 10:49am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/14 "2021-01-28T10:49:45Z")

</div>

v1.1.2 has fixed this. The default `fmt` for `unitformat=:mathrm` is `FancyNumberFormatter()`.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 28, 2021, 10:55am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/15 "2021-01-28T10:55:14Z")

</div>

> [@gustaphe](#):
>
> and I absolutely detest the product period.

Oh, I really quite like that. Perhaps this is configurable, not sure.

One of my favourite things is that you can easily write the micro sign like this

```julia
\SI{35}{\us} # or \um or \uJ, or whatever.

```

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [February 3, 2021, 6:46am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/16 "2021-02-03T06:46:19Z")

</div>

1.2 has `unitformat=:siunitxsimple` which uses the abbreviation version.

---

<div class="post-metadata">

**Author:** ![MatFi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matfi/32/10002_2.png) [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Post date:** [February 17, 2021, 9:02am UTC](https://discourse.julialang.org/t/ann-unitfullatexify-jl/54090/17 "2021-02-17T09:02:52Z")

</div>

This package made my day… thanks so much… 🤗
