Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markly:0.2.0 #1638

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 21 additions & 0 deletions packages/preview/markly/0.2.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Chad Skeeters

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
172 changes: 172 additions & 0 deletions packages/preview/markly/0.2.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
This is a [Typst](https://github.com/typst/typst) package to add cut, bleed, and registration marks to documents.

It's likely that some future version of Typst will obsolete this package. Until that time, it's nice to have **a** way to achieve this functionality with the current version.


# Demo

![Markly Demo](img.png)

...can be generated with:

```typst
#import "@preview/markly:0.2.0"

#let markly-context = markly.setup(
stock-width:4in,
stock-height:3in,

content-width: 3in,
content-height:2in,
)

#show: markly.page-setup.with(markly-context)

// Here the local title template uses markly's to-bleed
#let title(body, inset-y:12pt) = {
markly.to-bleed(text(white, size:2.5em, body), markly-context)
}

#title[Bannar]

- Content
```


For a more detailed example, see [main.typ](template/main.typ) and [main.pdf](main.pdf).

# Notes

Since this is a bit difficult to do there are some limitations to using this package. Here are a few examples:

* `inside`/`outside` margins don't work on pages
* The `background` field of the `page` can't be used unless there is a wrapper function so that `marks` is called also.


# Installation

Currently, this package has **not yet** been published. To try it out, you must download it locally. There are many ways to do this.
cskeeters marked this conversation as resolved.
Show resolved Hide resolved

## Install via git and typship

```sh
git clone [email protected]:cskeeters/typst-markly.git
cd markly

# Install typship, if not already installed
cargo install typship

typship install preview
```

Answer `y`es, when warned.


## Install via git

First set `$DATA_DIR` [according to your OS](https://github.com/typst/packages/blob/main/README.md#local-packages). Yes, this sucks.

```sh
mkdir $DATA_DIR/typst/packages/preview/markly
cd $DATA_DIR/typst/packages/preview/markly

git clone [email protected]:cskeeters/typst-markly.git 0.2.0
cd 0.2.0
git checkout -b 0.2 origin/v0.2.0
```

## Install with typship to local namespace

cargo install typship

typship download https://github.com/cskeeters/typst-markly/

To use, you have to change

```typst
#import "@preview/markly:0.2.0"
```

to

```typst
#import "@local/markly:0.2.0"
```

NOTE: `typship` doesn't support downloading to the preview namespace in the `{data-dir}`, otherwise this wouldn't be necessary.


# Usage

Initialize a new project from this template:

```sh
cd
typst init @preview/markly:0.2.0
cd markly
typst compile main.typ
```

## Setup

Use `setup` to create a "context" that other markly methods need. This is just a dictionary with values it so we don't repeat values.

The *stock* width and height is your *actual* paper size.

| Parameter | Default Value
| ------------- | --------------
| stock-width | 8.5in
| stock-height | 11in

The *content* width and height will be the size of the paper after cutting along the cut marks (black).

| Parameter | Default Value
| ------------- | --------------
| content-width | 6in
| content-height | 4in

The *margin* width and height are the amounts between the edge of the cut line and the start of the content. NOTE: total width consumed by margins equals 2 * margin-width since it's used on both sides of the content. Same for height.

| Parameter | Default Value
| ------------- | --------------
| margin-width | 6in
| margin-height | 4in

Finally, the `bleed` value is the distance between the cut line and bleed line, or the over-print amount that can occur because we have extra paper past the cut line.

| Parameter | Default Value
| ------------- | --------------
| bleed | 9pt


```typst
#let markly-context = markly.setup(
// stock-width:8.5in,
// stock-height:11in,

content-width:7in,
content-height:5in,

// bleed:9pt,

// margin-width:.2in,
// margin-height:.2in
)

// Configure the page to draw marks
#show: markly.page-setup.with(markly-context)

content...

```

## Print to Bleed Templates

Use `to-bleed`, `to-bleed-left`, or `to-bleed-right` to paint a background to the bleed marks.

Use `img-to-bleed` to stretch an image horizontally and vertically to the bleed marks. The position of the "cursor" is not updated (like in the case of a background image) since it uses the `place` function.


# Design

[Cetz](https://github.com/cetz-package/cetz) is used to draw the marks on the page's background.
Binary file added packages/preview/markly/0.2.0/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions packages/preview/markly/0.2.0/img.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#import "@preview/markly:0.2.0": *

#let markly_context = markly_setup(
stock_width:4in,
stock_height:3in,

content_width: 3in,
content_height:2in,
)

#show: markly_page_setup.with(markly_context)

// Here the local title template uses markly's to_bleed
#let title(body, inset_y:12pt) = {
to_bleed(text(white, size:2.5em, body), markly_context)
}

#title[Bannar]

- Content
22 changes: 22 additions & 0 deletions packages/preview/markly/0.2.0/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is used just to generate the thumbnail so that is looks good on the
# typst universe.
PAGE := "1"
DPI := "250"

alias tt := template_thumbnail
alias pt := preview_thumbnail

[doc('Generates template thumbnail from PDF')]
template_thumbnail:
cd template; \
typst compile --pages {{PAGE}} --ppi {{DPI}} main.typ ../thumbnail.png

oxipng -o 4 --strip safe --alpha thumbnail.png

[doc('Previews the generated thumbnail')]
preview_thumbnail: template_thumbnail
ls -l thumbnail.png
open -a Acorn.app thumbnail.png

clean:
rm thumbnail.png
Loading
Loading