I want to have a long main title in my template, how I can ensure that the words aren’t hyphenated, instead they are moved to the new line?
Headings are not hyphenated by default. If for some reason they are hyphenated in your template you can deactivate it with a show rule.
= urbane Stoicos irridente, statua est in quo a nobis philosophia defensa et collaudata
#show heading: set text(hyphenate: true)
= urbane Stoicos irridente, statua est in quo a nobis philosophia defensa et collaudata
#show heading: set text(hyphenate: false)
= urbane Stoicos irridente, statua est in quo a nobis philosophia defensa et collaudata
Result
thanks, I should phrase my question differently - how I can ensure that my custom titleblock isn’t hyphenated (or is less prone to hyphenation when the line below has enough free space)?
The block in the template is defined as below
/* Content front matter */
let titleblock(
body,
width: 100%,
size: 1.5em,
weight: "bold",
above: 1em,
below: 0em
) = [
#align(center)[
#block(width: width, above: above, below: below)[
#text(weight: weight, size: size)[#body]
]
]
]
if title != none {
titleblock(title)
}
I am struggling with long titles, for example:
title: Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...
gives me hyphenation in the middle of the `dolor``
Hello! which version of typst are you using? You can find that out by typing typst --version
, or check in the webapp in the project settings.
I am unable to reproduce your issue.
Hi @quachpas this was on 0.11
, on 0.12
dolor is not hyphenated, but when I replace it with dolordolor
it is, I think there is some other customization within the code that might cause this behaviour (I took typst code from existing template and modified it for Minimum Reproducible Example)
// Paragraph and text settings that affect title area
#set par(justify: true, leading: 0.6em, spacing: 1em, first-line-indent: 0cm)
#set text(font: ("Times New Roman", "Arial"), size: 11pt, lang: "en", region: "US")
// Title block function
#let titleblock(body, width: 100%, size: 1.5em, weight: "bold", above: 1em, below: 0em) = [
#align(center)[
#block(width: width, above: above, below: below)[
#text(weight: weight, size: size)[#body]
]
]
]
// Main document function
#let preprint(
title: none,
running-head: none,
authors: (),
affiliations: none,
abstract: none,
keywords: none,
wordcount: none,
authornote: none,
citation: none,
date: none,
branding: none,
leading: 0.6em,
spacing: 1em,
first-line-indent: 0cm,
linkcolor: black,
margin: (x: 3.2cm, y: 3cm),
paper: "a4",
lang: "en",
region: "US",
font: ("Times New Roman", "Arial"),
fontsize: 11pt,
) = {
// Set link colors for DOIs etc.
show link: set text(fill: linkcolor)
show cite: set text(fill: linkcolor)
// Format author strings
let author_strings = ()
if authors != none {
for a in authors {
let author_string = [
#box[#a.name]#if authors.len() > 1 [#super[#a.affiliation]]#if a.keys().contains("email") { [\*] }
#if a.keys().contains("orcid") {
box(height: 1em, link(a.orcid, figure(image("orcid.svg", height: 0.9em))))
}
]
if a.keys().contains("corresponding") {
authornote = [\*Send correspondence to: #a.name, #a.email.\ #authornote]
}
author_strings.push(author_string)
}
}
// Page settings for title page
set page(paper: paper, margin: margin, numbering: "1", header-ascent: 50%, header: locate(loc => {
if [#loc.page()] == [1] {
set align(right)
set text(size: 0.85em)
box(inset: 0.2em, [
#date
#if citation != none {
linebreak()
link("https://doi.org/" + citation.doi, "https://doi.org/" + citation.doi)
}
])
} else {
grid(columns: (1fr, 1fr), align(left)[#running-head], align(right)[#counter(page).display()])
}
}), footer-descent: 24pt, footer: locate(loc => {
if [#loc.page()] == [1] {
[#text(size: 0.85em)[#authornote]]
} else {
[]
}
}))
// Paragraph settings
set par(justify: true, leading: leading, first-line-indent: first-line-indent)
if sys.version >= version(0, 12, 0) {
set par(spacing: spacing)
} else {
show par: set block(spacing: spacing)
}
// Text settings
set text(lang: lang, region: region, font: font, size: fontsize)
// Apply title
if title != none {
titleblock(title)
}
// Apply authors
if authors != none {
titleblock(weight: "regular", size: 1.25em, [#author_strings.join(", ", last: " & ")])
}
// Apply affiliations
if affiliations != none {
titleblock(weight: "regular", size: 1.1em, below: 2em, for a in affiliations [
#if authors.len() > 1 [#super[#a.id]]#a.name#if a.keys().contains("department") [, #a.department] \
])
}
// Add vertical space after front matter
v(2em)
}
// Example usage
#show: doc => preprint(
title: [Neque porro quisquam est qui dolorem ipsum quia dolordolor sit amet, consectetur, adipisci velit],
running-head: [Running head],
authors: (
(name: [Author Author], affiliation: [1], corresponding: true, email: [authoremail]),
(name: [Author Author], affiliation: [1]),
(name: [Author Author], affiliation: [1]),
(name: [Author Author], affiliation: [1]),
(name: [Author Author], affiliation: [1]),
),
affiliations: ((id: "1", name: "Test University"),),
authornote: [This is an example author note.],
date: [2024-11-06],
linkcolor: blue,
font: ("Libertinus Serif",),
fontsize: 10.5pt,
)
It also gives me spaces after author names and before commas when there is no orcid included, how can I fix it?
Add hyphenate: false
!
#text(weight: weight, size: size, hyphenate: false)[#body]
Also, don’t hesitate to add “typ” to your blocks, so it highlights the code, i.e. ```typ
.
thanks! I was trying to add something like it before, but maybe I used wrong syntax