Skip to content

Commit

Permalink
further work on clean-typst format
Browse files Browse the repository at this point in the history
  • Loading branch information
gl-eb committed Nov 5, 2024
1 parent 68e01aa commit 10d6cca
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 39 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# Clean Manuscript

This template was designed for long-form text documents.
The three formats (html, typst, docx) were not designed to be as close to eachother visually as possible.
Their design was informed by partical decisions and according to the capabilities of the respective file types.
The Typst template is based on my own [minimal doc template](https://github.com/gl-eb/minimal-doc) and uses code written by Christopher T. Kenny for his own [ctk-article template](https://github.com/christopherkenny/ctk-article/).
While I use it in an academic context, it should be versatile enough for anyone to use.
I tried to follow established typographic principles (e.g. in terms of line length and height) to enhance readability.
Personal taste also played a big role, so feel free to fork this repository and tweak the template.
Nevertheless, it is fairly opinionated and does not provide easy customization through YAML options.
Feel free to fork this repository and tweak the template (while complying with the [MIT license](LICENSE)).

## Installing
## Installation

The following command will install the extension and create an example qmd file that you can use as a starting place for your document.

```bash
quarto use template gl-eb/quarto-clean-manuscript
```

This will install the extension and create an example qmd file that you can use as a starting place for your document.
Should you want to install the extension in an already existing Quarto project, use the following command:

```bash
quarto add gl-eb/quarto-clean-manuscript
```

## Using
## Usage

```yaml
---
Expand All @@ -27,7 +37,15 @@ format:
---
```

You can learn more about controlling the appearance of HTML output here: <https://quarto.org/docs/output-formats/html-basics.html>
None of the formats were designed to be easily customizable.
Should you want to do so anyways, refer to the following files:

- The style of the `clean-html` format is determined by custom stylesheets and fonts
- The `clean-docx` format is contained within a reference document [reference.docx](_extensions/clean/resources/reference.docx)
- The `clean-typst` format is controlled from the [typst-show.typ](_extensions/clean/resources/typst-show.typ), [typst-template.typ](_extensions/clean/resources/typst-template.typ), and [biblio.typ](_extensions/clean/resources/biblio.typ) files

You can also try using Quarto's YAML options, but your mileage may vary since some design choices are hard coded.
Refer to the [HTML](https://quarto.org/docs/output-formats/html-basics.html), [Typst](https://quarto.org/docs/output-formats/typst.html), and [MS Word / docx](https://quarto.org/docs/output-formats/ms-word.html) guides.

## Resources

Expand Down
3 changes: 3 additions & 0 deletions _extensions/clean/_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ contributes:
template-partials:
- resources/typst-show.typ
- resources/typst-template.typ
- resources/biblio.typ
paper: a4
margin:
x: 30mm
top: 25mm
bottom: 30mm
fontsize: "11pt"
lineheight: 1.7
number-sections: true
bibliography-title: References
docx:
reference-doc: resources/reference.docx
number-sections: true
14 changes: 14 additions & 0 deletions _extensions/clean/resources/biblio.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$if(citations)$
$if(csl)$
#set bibliography(style: "$csl$")
$elseif(bibliographystyle)$
#set bibliography(style: "$bibliographystyle$")
$endif$

$if(bibliography)$
#bibliography(
$for(bibliography)$"$bibliography$"$sep$,$endfor$,
title: "$bibliography-title$"
)
$endif$
$endif$
31 changes: 27 additions & 4 deletions _extensions/clean/resources/typst-show.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// the source code for a typst template) and a 'typst-show.typ' which calls the
// template's function (forwarding Pandoc metadata values as required)

#show: doc => minimal(
#show: doc => clean(
$if(title)$
title: [$title$],
$endif$
Expand All @@ -13,9 +13,23 @@ $if(by-author)$
authors: (
$for(by-author)$
$if(it.name.literal)$
( name: [$it.name.literal$],
affiliation: [$for(it.affiliations)$$it.name$$sep$, $endfor$],
email: [$it.email$] ),
(
name: [$it.name.literal$],
last: [$it.name.family$],
$if(it.affiliations/first)$
$for(it.affiliations/first)$
department: $if(it.department)$[$it.department$]$else$none$endif$,
university: $if(it.name)$[$it.name$]$else$none$endif$,
location: [$if(it.city)$$it.city$$if(it.country)$, $endif$$endif$$if(it.country)$$it.country$$endif$],
$endfor$
$endif$
$if(it.email)$
email: [$it.email$],
$endif$
$if(it.orcid)$
orcid: "$it.orcid$"
$endif$
),
$endif$
$endfor$
),
Expand Down Expand Up @@ -44,6 +58,15 @@ $endif$
$if(fontsize)$
fontsize: $fontsize$,
$endif$
$if(monofont)$
monofont: ("$monofont$",),
$endif$
$if(lineheight)$
lineheight: $lineheight$,
$endif$
$if(linkcolor)$
linkcolor: "$linkcolor$",
$endif$
$if(section-numbering)$
sectionnumbering: "$section-numbering$",
$endif$
Expand Down
173 changes: 153 additions & 20 deletions _extensions/clean/resources/typst-template.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
#let minimal(
// All of the code in this file is MIT licensed, but some parts are by different authors.
// If the authors is not Gleb Ebert, copyright notices are included at the beginning and end of a code snippet

// MIT License

// Copyright (c) 2024 Gleb Ebert

// 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.

// start: Copyright (c) 2024 Christopher T. Kenny
#let to-string(content) = {
if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")
} else if content.has("body") {
to-string(content.body)
} else if content == [ ] {
" "
}
}
// end: Copyright (c) 2024 Christopher T. Kenny

#let orcid_svg = str(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"
viewBox=\"0 0 256 256\" style=\"enable-background:new 0 0 256 256;\" xml:space=\"preserve\">
<style type=\"text/css\">
.st0{fill:#A6CE39;}
.st1{fill:#FFFFFF;}
</style>
<path class=\"st0\" d=\"M256,128c0,70.7-57.3,128-128,128C57.3,256,0,198.7,0,128C0,57.3,57.3,0,128,0C198.7,0,256,57.3,256,128z\"/>
<g>
<path class=\"st1\" d=\"M86.3,186.2H70.9V79.1h15.4v48.4V186.2z\"/>
<path class=\"st1\" d=\"M108.9,79.1h41.6c39.6,0,57,28.3,57,53.6c0,27.5-21.5,53.6-56.8,53.6h-41.8V79.1z M124.3,172.4h24.5
c34.9,0,42.9-26.5,42.9-39.7c0-21.5-13.7-39.7-43.7-39.7h-23.7V172.4z\"/>
<path class=\"st1\" d=\"M88.7,56.8c0,5.5-4.5,10.1-10.1,10.1c-5.6,0-10.1-4.6-10.1-10.1c0-5.6,4.5-10.1,10.1-10.1
C84.2,46.7,88.7,51.3,88.7,56.8z\"/>
</g>
</svg>"
)

#let clean(
title: none,
subtitle: none,
authors: none,
Expand All @@ -11,16 +70,20 @@
region: "UK",
font: (),
fontsize: 11pt,
sectionnumbering: none,
monofont: (),
lineheight: 1.7,
linkcolor: rgb(31, 78, 182),
sectionnumbering: "1.1.1",
toc: false,
doc,
) = {
set page(
paper: paper,
margin: margin,
numbering: "1",
numbering: "1"
)
set par(
leading: lineheight * 1em - 1em,
justify: true
)
set text(
Expand All @@ -36,35 +99,105 @@
stroke: none
)
show link: set text(fill: rgb(31, 78, 182))
show raw: set text(font: monofont)
show figure: set block(breakable: true)

if title != none {
align(center)[
#text(weight: "bold", size: 1.5em)[#title]
// start: Copyright (c) 2024 Christopher T. Kenny
// from: https://github.com/christopherkenny/ctk-article/.
show figure.caption: it => [
#v(-0.75em)
#align(left)[
#block(inset: 1em)[
#text(
size: fontsize - 1pt,
// fill: rgb(65, 65, 65)
)[
#text(
weight: "bold",
)[
#it.supplement
#context it.counter.display(it.numbering)#it.separator
]
#it.body
]
]
]
]

let list_authors = if authors == none {
none
} else if authors.len() == 2 {
authors.map(author => author.name).join(" and ")
} else if authors.len() < 5 {
authors.map(author => author.name).join(", ", last: ", and ")
} else {
authors.first().name + " et al."
}
// end: Copyright (c) 2024 Christopher T. Kenny

set document(
title: title,
author: to-string(list_authors),
date: auto
)

if subtitle != none {
align(center)[
#text(weight: "bold", size: 1.25em)[#subtitle]
if title != none {
align(center)[
#block(inset: 1em)[
#text(weight: "bold", size: 1.8em)[#title]
#if subtitle != none {
v(0em)
text(subtitle, weight: "semibold", size: 1.25em)
}
#if date != none {
v(0em)
date
}
]
}
]

if authors != none {
let list_authors = ()
for author in authors {
list_authors.push(author.name)
for i in range(authors.len()) {
let author = authors.at(i)
if i == 0 [
#text(weight: "semibold", author.name)
] else [
#text(weight: "semibold", linebreak() + author.name)
]
if "orcid" in author [
#link("https://orcid.org/" + author.orcid)[
#box(
height: 8pt,
baseline: 0.75pt,
outset: (y: 1pt),
image.decode(orcid_svg)
)
]
]
if "email" in author {
if type(author.email) == str [
#link("mailto:" + author.email)
] else [
#author.email
]
}
let author_affiliation = ()
if "department" in author and author.department != none [
#author_affiliation.push(author.department)
]
if "university" in author and author.university != none [
#author_affiliation.push(author.university)
]
if "location" in author and author.location != [] [
#author_affiliation.push(author.location)
]
author_affiliation.join(", ")
}
list_authors = list_authors.join(", ", last: " and ")
align(center)[#list_authors]
}

if date != none {
align(center)[#date]
}

if abstract != none {
block(inset: 2em)[
#text(weight: "semibold")[Abstract] #h(1em) #abstract
#text(weight: "medium")[Abstract] #h(1em) #abstract
]
}

Expand Down
Loading

0 comments on commit 10d6cca

Please sign in to comment.