pub struct HeadingElem {
pub body: Content,
/* private fields */
}
Expand description
A section heading.
With headings, you can structure your document into sections. Each heading has a level, which starts at one and is unbounded upwards. This level indicates the logical role of the following content (section, subsection, etc.) A top-level heading indicates a top-level section of the document (not the document’s title).
Typst can automatically number your headings for you. To enable numbering, specify how you want your headings to be numbered with a numbering pattern or function.
Independently of the numbering, Typst can also automatically generate an
[outline] of all headings for you. To exclude one or more headings from this
outline, you can set the outlined
parameter to {false}
.
§Example
#set heading(numbering: "1.a)")
= Introduction
In recent years, ...
== Preliminaries
To start, ...
§Syntax
Headings have dedicated syntax: They can be created by starting a line with
one or multiple equals signs, followed by a space. The number of equals
signs determines the heading’s logical nesting depth. The {offset}
field
can be set to configure the starting depth.
Fields§
§body: Content
Implementations§
Source§impl HeadingElem
impl HeadingElem
Sourcepub fn with_level(self, level: Smart<NonZeroUsize>) -> Self
pub fn with_level(self, level: Smart<NonZeroUsize>) -> Self
Builder-style setter for the level
field.
Sourcepub fn with_depth(self, depth: NonZeroUsize) -> Self
pub fn with_depth(self, depth: NonZeroUsize) -> Self
Builder-style setter for the depth
field.
Sourcepub fn with_offset(self, offset: usize) -> Self
pub fn with_offset(self, offset: usize) -> Self
Builder-style setter for the offset
field.
Sourcepub fn with_numbering(self, numbering: Option<Numbering>) -> Self
pub fn with_numbering(self, numbering: Option<Numbering>) -> Self
Builder-style setter for the numbering
field.
Sourcepub fn with_supplement(self, supplement: Smart<Option<Supplement>>) -> Self
pub fn with_supplement(self, supplement: Smart<Option<Supplement>>) -> Self
Builder-style setter for the supplement
field.
Sourcepub fn with_outlined(self, outlined: bool) -> Self
pub fn with_outlined(self, outlined: bool) -> Self
Builder-style setter for the outlined
field.
Sourcepub fn with_bookmarked(self, bookmarked: Smart<bool>) -> Self
pub fn with_bookmarked(self, bookmarked: Smart<bool>) -> Self
Builder-style setter for the bookmarked
field.
Sourcepub fn with_hanging_indent(self, hanging_indent: Smart<Length>) -> Self
pub fn with_hanging_indent(self, hanging_indent: Smart<Length>) -> Self
Builder-style setter for the hanging-indent
field.
Sourcepub fn push_level(&mut self, level: Smart<NonZeroUsize>)
pub fn push_level(&mut self, level: Smart<NonZeroUsize>)
Setter for the level
field.
Sourcepub fn push_depth(&mut self, depth: NonZeroUsize)
pub fn push_depth(&mut self, depth: NonZeroUsize)
Setter for the depth
field.
Sourcepub fn push_offset(&mut self, offset: usize)
pub fn push_offset(&mut self, offset: usize)
Setter for the offset
field.
Sourcepub fn push_numbering(&mut self, numbering: Option<Numbering>)
pub fn push_numbering(&mut self, numbering: Option<Numbering>)
Setter for the numbering
field.
Sourcepub fn push_supplement(&mut self, supplement: Smart<Option<Supplement>>)
pub fn push_supplement(&mut self, supplement: Smart<Option<Supplement>>)
Setter for the supplement
field.
Sourcepub fn push_outlined(&mut self, outlined: bool)
pub fn push_outlined(&mut self, outlined: bool)
Setter for the outlined
field.
Sourcepub fn push_bookmarked(&mut self, bookmarked: Smart<bool>)
pub fn push_bookmarked(&mut self, bookmarked: Smart<bool>)
Setter for the bookmarked
field.
Sourcepub fn push_hanging_indent(&mut self, hanging_indent: Smart<Length>)
pub fn push_hanging_indent(&mut self, hanging_indent: Smart<Length>)
Setter for the hanging-indent
field.
Sourcepub fn level(&self, styles: StyleChain<'_>) -> Smart<NonZeroUsize>
pub fn level(&self, styles: StyleChain<'_>) -> Smart<NonZeroUsize>
The absolute nesting depth of the heading, starting from one. If set
to {auto}
, it is computed from {offset + depth}
.
This is primarily useful for usage in show rules
(either with where
selectors or by accessing the
level directly on a shown heading).
#show heading.where(level: 2): set text(red)
= Level 1
== Level 2
#set heading(offset: 1)
= Also level 2
== Level 3
Sourcepub fn depth(&self, styles: StyleChain<'_>) -> NonZeroUsize
pub fn depth(&self, styles: StyleChain<'_>) -> NonZeroUsize
The relative nesting depth of the heading, starting from one. This is
combined with {offset}
to compute the actual {level}
.
This is set by the heading syntax, such that [== Heading]
creates a
heading with logical depth of 2, but actual level {offset + 2}
. If you
construct a heading manually, you should typically prefer this over
setting the absolute level.
Sourcepub fn offset(&self, styles: StyleChain<'_>) -> usize
pub fn offset(&self, styles: StyleChain<'_>) -> usize
The starting offset of each heading’s {level}
, used to turn its
relative {depth}
into its absolute {level}
.
= Level 1
#set heading(offset: 1, numbering: "1.1")
= Level 2
#heading(offset: 2, depth: 2)[
I'm level 4
]
Sourcepub fn numbering<'a>(&'a self, styles: StyleChain<'a>) -> &'a Option<Numbering>
pub fn numbering<'a>(&'a self, styles: StyleChain<'a>) -> &'a Option<Numbering>
How to number the heading. Accepts a numbering pattern or function.
#set heading(numbering: "1.a.")
= A section
== A subsection
=== A sub-subsection
Sourcepub fn supplement(&self, styles: StyleChain<'_>) -> Smart<Option<Supplement>>
pub fn supplement(&self, styles: StyleChain<'_>) -> Smart<Option<Supplement>>
A supplement for the heading.
For references to headings, this is added before the referenced number.
If a function is specified, it is passed the referenced heading and should return content.
#set heading(numbering: "1.", supplement: [Chapter])
= Introduction <intro>
In @intro, we see how to turn
Sections into Chapters. And
in @intro[Part], it is done
manually.
Sourcepub fn outlined(&self, styles: StyleChain<'_>) -> bool
pub fn outlined(&self, styles: StyleChain<'_>) -> bool
Whether the heading should appear in the [outline].
Note that this property, if set to {true}
, ensures the heading is also
shown as a bookmark in the exported PDF’s outline (when exporting to
PDF). To change that behavior, use the bookmarked
property.
#outline()
#heading[Normal]
This is a normal heading.
#heading(outlined: false)[Hidden]
This heading does not appear
in the outline.
Sourcepub fn bookmarked(&self, styles: StyleChain<'_>) -> Smart<bool>
pub fn bookmarked(&self, styles: StyleChain<'_>) -> Smart<bool>
Whether the heading should appear as a bookmark in the exported PDF’s outline. Doesn’t affect other export formats, such as PNG.
The default value of {auto}
indicates that the heading will only
appear in the exported PDF’s outline if its outlined
property is set
to {true}
, that is, if it would also be listed in Typst’s [outline].
Setting this property to either {true}
(bookmark) or {false}
(don’t
bookmark) bypasses that behavior.
#heading[Normal heading]
This heading will be shown in
the PDF's bookmark outline.
#heading(bookmarked: false)[Not bookmarked]
This heading won't be
bookmarked in the resulting
PDF.
Sourcepub fn hanging_indent(&self, styles: StyleChain<'_>) -> Smart<Length>
pub fn hanging_indent(&self, styles: StyleChain<'_>) -> Smart<Length>
The indent all but the first line of a heading should have.
The default value of {auto}
indicates that the subsequent heading
lines will be indented based on the width of the numbering.
#set heading(numbering: "1.")
#heading[A very, very, very, very, very, very long heading]
Sourcepub fn level_in(styles: StyleChain<'_>) -> Smart<NonZeroUsize>
pub fn level_in(styles: StyleChain<'_>) -> Smart<NonZeroUsize>
Access the level
field in the given style chain.
Sourcepub fn depth_in(styles: StyleChain<'_>) -> NonZeroUsize
pub fn depth_in(styles: StyleChain<'_>) -> NonZeroUsize
Access the depth
field in the given style chain.
Sourcepub fn offset_in(styles: StyleChain<'_>) -> usize
pub fn offset_in(styles: StyleChain<'_>) -> usize
Access the offset
field in the given style chain.
Sourcepub fn numbering_in(styles: StyleChain<'_>) -> &Option<Numbering>
pub fn numbering_in(styles: StyleChain<'_>) -> &Option<Numbering>
Access the numbering
field in the given style chain.
Sourcepub fn supplement_in(styles: StyleChain<'_>) -> Smart<Option<Supplement>>
pub fn supplement_in(styles: StyleChain<'_>) -> Smart<Option<Supplement>>
Access the supplement
field in the given style chain.
Sourcepub fn outlined_in(styles: StyleChain<'_>) -> bool
pub fn outlined_in(styles: StyleChain<'_>) -> bool
Access the outlined
field in the given style chain.
Sourcepub fn bookmarked_in(styles: StyleChain<'_>) -> Smart<bool>
pub fn bookmarked_in(styles: StyleChain<'_>) -> Smart<bool>
Access the bookmarked
field in the given style chain.
Sourcepub fn hanging_indent_in(styles: StyleChain<'_>) -> Smart<Length>
pub fn hanging_indent_in(styles: StyleChain<'_>) -> Smart<Length>
Access the hanging-indent
field in the given style chain.
Sourcepub fn set_level(level: Smart<NonZeroUsize>) -> Property
pub fn set_level(level: Smart<NonZeroUsize>) -> Property
Create a style property for the level
field.
Sourcepub fn set_depth(depth: NonZeroUsize) -> Property
pub fn set_depth(depth: NonZeroUsize) -> Property
Create a style property for the depth
field.
Sourcepub fn set_offset(offset: usize) -> Property
pub fn set_offset(offset: usize) -> Property
Create a style property for the offset
field.
Sourcepub fn set_numbering(numbering: Option<Numbering>) -> Property
pub fn set_numbering(numbering: Option<Numbering>) -> Property
Create a style property for the numbering
field.
Sourcepub fn set_supplement(supplement: Smart<Option<Supplement>>) -> Property
pub fn set_supplement(supplement: Smart<Option<Supplement>>) -> Property
Create a style property for the supplement
field.
Sourcepub fn set_outlined(outlined: bool) -> Property
pub fn set_outlined(outlined: bool) -> Property
Create a style property for the outlined
field.
Sourcepub fn set_bookmarked(bookmarked: Smart<bool>) -> Property
pub fn set_bookmarked(bookmarked: Smart<bool>) -> Property
Create a style property for the bookmarked
field.
Sourcepub fn set_hanging_indent(hanging_indent: Smart<Length>) -> Property
pub fn set_hanging_indent(hanging_indent: Smart<Length>) -> Property
Create a style property for the hanging-indent
field.
Source§impl HeadingElem
impl HeadingElem
pub fn resolve_level(&self, styles: StyleChain<'_>) -> NonZeroUsize
Trait Implementations§
Source§impl Capable for HeadingElem
impl Capable for HeadingElem
Source§impl Clone for HeadingElem
impl Clone for HeadingElem
Source§fn clone(&self) -> HeadingElem
fn clone(&self) -> HeadingElem
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Construct for HeadingElem
impl Construct for HeadingElem
Source§impl Debug for HeadingElem
impl Debug for HeadingElem
Source§impl Fields for HeadingElem
impl Fields for HeadingElem
Source§fn field(&self, id: u8) -> Result<Value, FieldAccessError>
fn field(&self, id: u8) -> Result<Value, FieldAccessError>
Source§fn field_with_styles(
&self,
id: u8,
styles: StyleChain<'_>,
) -> Result<Value, FieldAccessError>
fn field_with_styles( &self, id: u8, styles: StyleChain<'_>, ) -> Result<Value, FieldAccessError>
Source§fn field_from_styles(
id: u8,
styles: StyleChain<'_>,
) -> Result<Value, FieldAccessError>
fn field_from_styles( id: u8, styles: StyleChain<'_>, ) -> Result<Value, FieldAccessError>
Source§fn materialize(&mut self, styles: StyleChain<'_>)
fn materialize(&mut self, styles: StyleChain<'_>)
Source§impl Hash for HeadingElem
impl Hash for HeadingElem
Source§impl IntoValue for HeadingElem
impl IntoValue for HeadingElem
Source§fn into_value(self) -> Value
fn into_value(self) -> Value
Source§impl NativeElement for HeadingElem
impl NativeElement for HeadingElem
Source§impl PartialEq for HeadingElem
impl PartialEq for HeadingElem
Source§impl Repr for HeadingElem
impl Repr for HeadingElem
Auto Trait Implementations§
impl Freeze for HeadingElem
impl !RefUnwindSafe for HeadingElem
impl Send for HeadingElem
impl Sync for HeadingElem
impl Unpin for HeadingElem
impl !UnwindSafe for HeadingElem
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult for Twhere
T: IntoValue,
impl<T> IntoResult for Twhere
T: IntoValue,
Source§fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more