# Call for a typography Unitful package

**URL:** <https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331>\
**Category:** Community\
**Tags:** proposal\
**Created:** [August 11, 2017, 1:20pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331 "2017-08-11T13:20:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 11, 2017, 1:20pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/1 "2017-08-11T13:20:55Z")

</div>

How about it? Anyone good with typography lengths? Could be nice to be able to convert and deal with em, px, pt… etc. Just checking to see if there is anyone enthusiastic about typography. Writing one of those supplemental units package for Unitful.jl is relatively easy.  
Anyone?

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [August 11, 2017, 4:11pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/2 "2017-08-11T16:11:09Z")

</div>

> [@yakir12](#):
>
> Writing one of those supplemental units package for Unitful.jl is relatively easy.

i don’t disagree, however for something more than just scaling px and pt and inches and cm, i’d recommend to read the recent [Font-size: An Unexpectedly Complex CSS Property - In Pursuit of Laziness](https://manishearth.github.io/blog/2017/08/10/font-size-an-unexpectedly-complex-css-property/) which gives some insight into ‘em’ domain.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [August 11, 2017, 4:17pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/3 "2017-08-11T16:17:13Z")

</div>

How do you display your typography?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 11, 2017, 5:25pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/4 "2017-08-11T17:25:21Z")

</div>

Well, that escalated quickly… Yea, I see, so this might be impossible unless there was some kind of `pt` context to calculate the `em` in. Difficult.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [August 11, 2017, 5:27pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/5 "2017-08-11T17:27:21Z")

</div>

Good question. I mean, there are many many outputs, none of which are natively juliaian… I personally either output straight into a `tex` (and then, yea, I could let latex figure it all out), or `markdown` and then `pandoc` it out to whatever.

---

<div class="post-metadata">

**Author:** ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)\
**Post date:** [August 11, 2017, 5:39pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/6 "2017-08-11T17:39:02Z")

</div>

Well actually with FreeType, Cairo and some additional code you could go to all standard outputs (ps/pdf/svg/png). I thinking now for some time to do something on top of FreeType to access all font metrics (for something more special than pango only) but looking at the time i spend on this …  
So picking up from above, yes we could have some TypographicDimensions.jl but this will be way bigger than fixed scaling only.

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 5, 2018, 12:12pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/7 "2018-02-05T12:12:56Z")

</div>

I was about to post about this exact same thing (i.e., the problem of mixing stuff like pt and cm with em and ex, for example). I could really use this as well, and my thinking was that this could/should be handled symbolically, as an irreducable sum of two (or more) separate things. So that 1cm + 1em was just that – and you could, for example, convert that directly to (say) TeX, which could then handle the em based on the context.

However, it seems this goes beyond the current capabilites of Unitful.jl (reasonably enough). Is it a kind of (general) mechanism that could be part of such a package, or ought it involve something else entirely (such as a full-blown symbolic computation package), or something in-between, such as a custom type representing such a sum?

Or … I guess one could define em and ex (and the like) as FixedUnits (preventing conversion, but also preventing addition with other lengths), and then just use vectors or something. Or one could define a length type with one general length field, one em field, one ex field, etc., and then define addition on them. (Seems to cry out for a simpler, more general solution, though…)

(The font metrics etc. are not really of that much interest to me at present – though it may be useful. I remember actually implementing something similar based on real font metrics in Python a couple of decades ago, but that’s more work than it’s worth for my current use, where I’ll just be shipping stuff to TeX, anyway.)

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 5, 2018, 5:16pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/8 "2018-02-05T17:16:31Z")

</div>

I put together a quick sketch of how this might work, here:

[https://gist.github.com/mlhetland/562220c73d2b5c454c678c5df52a6540](https://gist.github.com/mlhetland/562220c73d2b5c454c678c5df52a6540)

Beyond the obvious stuff (mirroring many of the kinds of methods defined for, say, Complex), one could also have functions for specifying a conversion from em, ex and px to the absolute scale, and then resolve the sums, yielding a single, absolute length. (Or maybe go in the other direction, ending up in one of the relative dimensions, which could then later be used with other fonts/sizes.)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 5, 2018, 7:09pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/9 "2018-02-05T19:09:24Z")

</div>

Unless someone knowledgeable objects, I don’t see why this should not be a package…? I kind of like the idea that connecting the `EM`, `EX`, and `PX` lengths to the rest can be handled _optionally_ by some other external add-on package (using `Require` or some similar mechanism).

By publishing this now, you can let someone else pick it up when they need to and other to use this if it suffices. Cool work!

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 6, 2018, 10:46am UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/10 "2018-02-06T10:46:48Z")

</div>

Sure thing 🙂 I’ve polished it a bit, but am trying to improve the typing a bit (to reduce the jit-lag for computing all kinds of type parameter combinations, etc.). And I’ve run into a snag – which I wonder if may be a bug in Unitful, perhaps. It seems you can’t promote more than three unitful quantities?

For example, the following works just fine:

```julia
julia> promote(1cm, 1.0kg, 1s)
(1.0 cm, 1.0 kg, 1.0 s)

```

The following, however, does not:

```julia
julia> promote(1cm, 1.0kg, 1s, 1N)
ERROR: MethodError: Cannot `convert` an object of type Tuple{Unitful.Quantity{…}} …

```

Thoughts? Maybe it’s just a matter of defining a conversion method for tuples of quantities, to make the built-in promotion machinery work? (Haven’t studied the issue in detail.)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 6, 2018, 10:49am UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/11 "2018-02-06T10:49:35Z")

</div>

(oops! meant should **not** , got confused with the double negation: I mean this should be a package 🙂 )

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 6, 2018, 10:50am UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/12 "2018-02-06T10:50:17Z")

</div>

No idea, you could post an issue on `Unitful`.

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 6, 2018, 10:53am UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/13 "2018-02-06T10:53:24Z")

</div>

Done: [https://github.com/ajkeller34/Unitful.jl/issues/119](https://github.com/ajkeller34/Unitful.jl/issues/119)

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 8, 2018, 1:56pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/14 "2018-02-08T13:56:31Z")

</div>

Okay, I polished the code a bit, and worked around a couple of things I had some trouble with in `Unitful`, and have something that seems to work okay:

[https://github.com/mlhetland/UnitfulTypo.jl](https://github.com/mlhetland/UnitfulTypo.jl)

The initial compile times are kind of high; I guess there might be ways to improve that. (And maybe there is some better architecture, where one could add new length-like dimensions to the mix without having to modify `MixedLength`.)

Anyway, I think it should be sort of usable – at least for my purposes 🙂

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 8, 2018, 2:00pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/15 "2018-02-08T14:00:13Z")

</div>

Cool!

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 8, 2018, 2:10pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/16 "2018-02-08T14:10:17Z")

</div>

Very cool package. The name seems a bit unfortunate since it sounds (to me) like there’s a typo somewhere and I wouldn’t guess that it has anything to do with typography. Given that the explanation is:

> Typographic units for `Unitful.jl`.

perhaps a good name would be `TypographicUnits`?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 8, 2018, 2:12pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/17 "2018-02-08T14:12:08Z")

</div>

I think it needs to have `Unitful*` in it, in accordance to all the other `Unitful` packages. So maybe `UnitfulTypographics` (with the plural)?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 8, 2018, 2:13pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/18 "2018-02-08T14:13:13Z")

</div>

Seems like a highly breakable rule 😬

---

<div class="post-metadata">

**Author:** ![mlhetland](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlhetland/32/283_2.png) [@mlhetland](https://discourse.julialang.org/u/mlhetland)\
**Post date:** [February 8, 2018, 2:13pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/19 "2018-02-08T14:13:47Z")

</div>

I don’t have any strong naming preferences, really. Just modeled it on UnitfulAstro.jl (and the typo thing subsequently struck me as funny ;-), but I’d be happy to change it.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [February 8, 2018, 2:16pm UTC](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331/20 "2018-02-08T14:16:31Z")

</div>

Yea, I like the pun, and I guess it’s useful to know which units packages belong to which. But hey, what ever works 🙂

[Next page](https://discourse.julialang.org/t/call-for-a-typography-unitful-package/5331.md?page=2)
