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
18 changes: 12 additions & 6 deletions src/formatting.typ
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
/// if `positive-sign` is set to true. In all other cases, the result is
/// `none`.
/// -> content | none
#let format-sign(sign, positive-sign: false) = {
if sign == "-" {
math.class("unary", sym.minus)
#let format-sign(sign, positive-sign: false, math: true) = {
sign = if sign == "-" {
sym.minus
} else if sign == "+" and positive-sign {
return math.class("unary", sym.plus)
sym.plus
}
if math {
sign = std.math.class("unary", sign)
}
sign
}


Expand Down Expand Up @@ -167,7 +171,7 @@
))

return sequence((
format-sign(it.sign, positive-sign: it.positive-sign),
format-sign(it.sign, positive-sign: it.positive-sign, math: it.math),
format-integer((int: it.int, group: it.group)),
frac,
))
Expand Down Expand Up @@ -215,6 +219,7 @@
group: false,
positive-sign: false,
decimal-separator: it.decimal-separator,
math: it.math,
)))
if is-symmetric {
if it.concise {
Expand Down Expand Up @@ -275,6 +280,7 @@
group: false,
positive-sign: it.positive-sign-exponent,
decimal-separator: it.decimal-separator,
math: it.math
))

if it.math {
Expand Down Expand Up @@ -368,7 +374,7 @@
)

let integer-part = (
format-sign(it.sign, positive-sign: it.positive-sign),
format-sign(it.sign, positive-sign: it.positive-sign, math: it.math),
format-integer(integer),
)

Expand Down
9 changes: 9 additions & 0 deletions tests/num/positive-sign-exponent/ref.typ
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ $1×10^(-1)$ \
$1×10^(-1)$ \
$1×10^(+9)$ \
$1×10^(9)$ \

#pagebreak()
#set super(typographic: false)
1#sym.space.thin×#sym.space.thin;10#super[3] \
1#sym.space.thin×#sym.space.thin;10#super[+3] \
1#sym.space.thin×#sym.space.thin;10#super[−1] \
1#sym.space.thin×#sym.space.thin;10#super[−1] \
1#sym.space.thin×#sym.space.thin;10#super[+9] \
1#sym.space.thin×#sym.space.thin;10#super[9] \
13 changes: 13 additions & 0 deletions tests/num/positive-sign-exponent/test.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
#set page(width: auto, height: auto, margin: 2pt)


#num("1e3", positive-sign-exponent: false) \
#num("1e3", positive-sign-exponent: true) \
#num("1e-1", positive-sign-exponent: false) \
#num("1e-1", positive-sign-exponent: true) \
#set-num(positive-sign-exponent: true)
#num("1e9") \
#set-num(positive-sign-exponent: false)
#num("1e9")

#pagebreak()

#set-num(math: false)

#num("1e3", positive-sign-exponent: false) \
#num("1e3", positive-sign-exponent: true) \
#num("1e-1", positive-sign-exponent: false) \
Expand Down
Loading