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
1 change: 1 addition & 0 deletions packages/preview/smartaref/0.1.0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf
10 changes: 10 additions & 0 deletions packages/preview/smartaref/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 changes: 33 additions & 0 deletions packages/preview/smartaref/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Clever references for Typst

Smart handling of consecutive references (i.e. `cleveref` for Typst).

## Figures, tables, listings, sections, equations and footnotes example

See [example/example.typ](example/example.typ).

![Figures, tables, listings, sections, equations and footnotes example](example/example.png)

## Subfigures example

See [example/example-subfig.typ](example/example-subfig.typ).

![Subfigures example](example/example-subfig.png)

## Heading-dependent numbering of subfigures

See [example/example-subfig-headings.typ](example/example-subfig-headings.typ).

![Heading-dependent numbering of subfigures](example/example-subfig-headings.png)

## Compact consecutive references

See [example/example-compact.typ](example/example-compact.typ).

![Compact consecutive references example](example/example-compact.png)

## Subpar example

See [example/example-subpar.typ](example/example-subpar.typ).

![Subfigures example](example/example-subpar.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
192 changes: 192 additions & 0 deletions packages/preview/smartaref/0.1.0/example/example-compact.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#set page(width: 15cm, height: auto)

#import "@preview/smartaref:0.1.0"

#let cref = smartaref.cref.with(compact: true)
#let Cref = smartaref.Cref.with(compact: true)

// Highlight links.
#show link: set text(fill: blue)
#show ref: set text(fill: blue)

// Set heading numbering style.
#set heading(numbering: "1.1")

// === [ figure example ] ======================================================

#let example-fig = rect(fill: aqua)

= Figures example

// NOTE: skip fig-qux ("Figure 4") reference to showcase compat.
`ref`: See @fig-foo, @fig-bar, @fig-baz and @fig-foob.

#emph[`compact: false`] \
`cref`: See #cref(compact: false)[@fig-foo @fig-bar @fig-baz @fig-foob].

#emph[`compact: true`] \
`cref`: See #cref[@fig-foo @fig-bar @fig-baz @fig-foob].

#grid(
columns: 5,
gutter: 1.5em,
[#figure(
example-fig,
caption: [foo],
) <fig-foo>],
[#figure(
example-fig,
caption: [bar],
) <fig-bar>],
[#figure(
example-fig,
caption: [baz],
) <fig-baz>],
[#figure(
example-fig,
caption: [qux],
) <fig-qux>],
[#figure(
example-fig,
caption: [foob],
) <fig-foob>],
)

// === [ tables example ] ======================================================

// Position caption of tables on top.
#show figure.where(kind: table): set figure.caption(position: top)

#let example-table = table(
columns: 2,
stroke: 0.3pt,
table.header[*asdf*][*qwerty*],
[a], [b],
[c], [d],
)

= Tables example

`ref`: See @tbl-foo, @tbl-bar and @tbl-baz.

#emph[`compact: false`] \
`cref`: See #cref(compact: false)[@tbl-foo @tbl-bar @tbl-baz].

#emph[`compact: true`] \
`cref`: See #cref[@tbl-foo @tbl-bar @tbl-baz].

#grid(
columns: 3,
gutter: 1.5em,
[#figure(
caption: [foo],
example-table,
) <tbl-foo>],
[#figure(
caption: [bar],
example-table,
) <tbl-bar>],
[#figure(
caption: [baz],
example-table,
) <tbl-baz>],
)

// === [ listings example ] ====================================================

// Position caption of listings on top.
#show figure.where(kind: raw): set figure.caption(position: top)

#let example-raw = ```typst
#set document(title: "meta")
```

= Listings example

`ref`: See @lst-foo, @lst-bar and @lst-baz.

#emph[`compact: false`] \
`cref`: See #cref(compact: false)[@lst-foo @lst-bar @lst-baz].

#emph[`compact: true`] \
`cref`: See #cref[@lst-foo @lst-bar @lst-baz].

#grid(
columns: 2,
gutter: 1.5em,
[#figure(
caption: [foo],
example-raw,
) <lst-foo>],
[#figure(
caption: [bar],
example-raw,
) <lst-bar>],
[#figure(
caption: [baz],
example-raw,
) <lst-baz>],
)

// === [ sections example ] ====================================================

= Sections example
<sec-sections-example>

`ref`: See @sec-sections-example, @sec-subsection-one, @sec-subsection-two and @sec-subsection-three.

#emph[`compact: false`] \
`cref`: See #cref(compact: false)[@sec-sections-example @sec-subsection-one @sec-subsection-two @sec-subsection-three].

#emph[`compact: true`] \
`cref`: See #cref[@sec-sections-example @sec-subsection-one @sec-subsection-two @sec-subsection-three].

== Subsection one
<sec-subsection-one>

#lorem(10)

== Subsection two
<sec-subsection-two>

#lorem(15)

== Subsection three
<sec-subsection-three>

#lorem(20)

// === [ equations example ] ===================================================

// Set equation numbering style.
#set math.equation(numbering: "(1)")

= Equations example

`ref`: See @eq-pythagoras, @eq-eulers-identity and @eq-de-moivres-formula.

#emph[`compact: false`] \
`cref`: See #cref(compact: false)[@eq-pythagoras @eq-eulers-identity @eq-de-moivres-formula].

#emph[`compact: true`] \
`cref`: See #cref[@eq-pythagoras @eq-eulers-identity @eq-de-moivres-formula].

$ abs(z) = sqrt(x^2 + y^2) $ <eq-pythagoras>

$ e^(i pi) = -1 $ <eq-eulers-identity>

$ (cos x + i sin x)^n = cos(n x) + i sin(n x) $ <eq-de-moivres-formula>

// === [ footnotes example ] ===================================================

= Footnotes example

`ref`: See @foot-foo, @foot-bar, @foot-baz and @foot-qux.

#emph[`compact: false`] \
`cref`: See #cref(compact: false, supplement: "footnotes")[@foot-foo @foot-bar @foot-baz @foot-qux].

#emph[`compact: true`] \
`cref`: See #cref(supplement: "footnotes")[@foot-foo @foot-bar @foot-baz @foot-qux].

A few#footnote[foo]<foot-foo> footnotes#footnote[bar]<foot-bar> are present#footnote[baz]<foot-baz> in this sentence.#footnote[qux]<foot-qux>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions packages/preview/smartaref/0.1.0/example/example-subfig-headings.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#set page(width: 12cm, height: auto)

#import "@preview/hallon:0.1.0" as hallon: subfigure
#import "@preview/smartaref:0.1.0": cref, Cref

// Apply subfigure styles (using one heading level as figure numbering prefix,
// e.g. "1.1a").
#show: hallon.style-figures.with(heading-levels: 1)

// Set heading numbering style.
#set heading(numbering: "1.1")

// Highlight links.
#show link: set text(fill: blue)
#show ref: set text(fill: blue)

// === [ heading dependent figure numbering ] ==================================

#let example-fig = rect(fill: aqua)

= Heading one

`ref`: See @fig1, @subfig1-foo and @subfig1-bar.

`cref`: See #cref[@fig1 @subfig1-foo @subfig1-bar].

#figure(
grid(
columns: 2,
gutter: 1.5em,
subfigure(
example-fig,
caption: [foo],
label: <subfig1-foo>,
),
// manual placement of subfigure (figure with "subfigure" kind)
[#figure(
example-fig,
caption: [bar],
kind: "subfigure",
) <subfig1-bar>],
),
gap: 1em,
caption: lorem(5),
) <fig1>

`ref`: See @fig2, @subfig2-foo and @subfig2-bar.

`cref`: See #cref(supplement: "figs.")[@fig2 @subfig2-foo @subfig2-bar].

#figure(
grid(
columns: 2,
gutter: 1.5em,
subfigure(
example-fig,
caption: [foo],
label: <subfig2-foo>,
),
subfigure(
example-fig,
caption: [bar],
label: <subfig2-bar>,
),
),
gap: 1em,
caption: lorem(5),
) <fig2>

= Heading two

`ref`: @fig3, @subfig3-foo and @subfig3-bar are ...

`Cref`: #Cref[@fig3 @subfig3-foo @subfig3-bar] are ...

#figure(
grid(
columns: 2,
gutter: 1.5em,
subfigure(
example-fig,
caption: [foo],
label: <subfig3-foo>,
),
subfigure(
example-fig,
caption: [bar],
label: <subfig3-bar>,
),
),
gap: 1em,
caption: lorem(5),
) <fig3>

`ref`: @fig4, @subfig4-foo and @subfig4-bar are ...

`Cref`: #Cref(supplement: "Figs.")[@fig4 @subfig4-foo @subfig4-bar] are ...

#figure(
grid(
columns: 2,
gutter: 1.5em,
subfigure(
example-fig,
caption: [foo],
label: <subfig4-foo>,
),
subfigure(
example-fig,
caption: [bar],
label: <subfig4-bar>,
),
),
gap: 1em,
caption: lorem(5),
) <fig4>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading