Showybox is a Typst package for creating colorful and customizable boxes.
Usage
To use this library through the Typst package manager (for Typst 0.6.0 or greater), write #import "@preview/showybox:0.2.0": showybox
at the beginning of your Typst file.
Once imported, you can create an empty showybox by using the function showybox()
and giving a default body content inside the parenthesis or outside them using squared brackets []
.
By default, a box with no title, black borders, white background, and 5pt
border radius will be created.
#import "@preview/showybox:0.2.0": showybox
#showybox(
[Hello world!]
)
Looks quite simple, but the “magic” starts when adding a title and color. The following code creates two “unique” boxes with defined colors and custom borders:
// First showybox
#showybox(
frame: (
upper-color: red.darken(40%),
lower-color: red.lighten(90%),
border-color: black,
width: 2pt
),
title: "Hello world! - An example",
[
Hello world!
]
)
// Second showybox
#showybox(
frame: (
dash: "dotted",
border-color: red.darken(40%)
),
body-style: (
align: center
),
sep: (
dash: "dashed"
),
[This is an important message!],
[Be careful outside. There are dangerous bananas!]
)
Reference
The showybox()
function can receive the following parameters:
frame
: A dictionary containing the frame’s propertiestitle-style
: A dictionary containing the title’s stylesbody-styles
: A dictionary containing the body’s stylestitle
: A string used as the title of the showyboxbody
: The content of the showyboxsep
: A dictionary containing the separator’s propertiesbreakable
: A boolean indicating whether a no-title showybox can break
Frame properties
upper-color
: Color used as background color where the title goes (default isblack
)lower-color
: Color used as background color where the body goes (default iswhite
)border-color
: Color used for the showybox’s border (default isblack
)radius
: Showybox’s radius (default is5pt
)width
: Border width of the showybox (default is2pt
)dash
: Showybox’s border style (default issolid
)
Title styles
color
: Text color (default iswhite
)weight
: Text weight (default isbold
)align
: Text align (default isleft
)
Body styles
color
: Text color (default isblack
)align
: Text align (default isleft
)
Separator properties
width
: Separator’s widthdash
: Separator’s style (as aline
dash style)
Known issues
- A
break
property for showyboxes with a title would be great - There’s a slightly thin line in showyboxes that have no borders or dashed borders, instead of white spaces or nothing.
Gallery
Encapsulation
May have some bugs
Enabling breaking
Custom radius
Changelog
Version 0.1.0
- Initial release
Version 0.1.1
- Changed package name from colorbox to showybox
- Fixed a spacing bug in encapsulated showyboxes
- Details: When a showybox was encapsulated inside another, the spacing after that showybox was
0pt
, probably due to some “fixes” improved to manage default spacing betweenrect
elements. The issue was solved by avoiding#set
statements and adding a#v(-1.1em)
to correct extra spacing between the titlerect
and the bodyrect
.
- Details: When a showybox was encapsulated inside another, the spacing after that showybox was
Version 0.2.0
- Improved code documentation
- Enabled an auto-break functionality for non-titled showyboxes
- Created a separator functionality to separate content inside a showybox with a horizontal line