|
| 1 | +// This function gets your whole document as its `body` and formats |
| 2 | +// it as an article in the style of the IEEE. |
| 3 | +#let ieee( |
| 4 | + // The paper's title. |
| 5 | + title: [Paper Title], |
| 6 | + |
| 7 | + // An array of authors. For each author you can specify a name, |
| 8 | + // department, organization, location, and email. Everything but |
| 9 | + // but the name is optional. |
| 10 | + authors: (), |
| 11 | + |
| 12 | + // The paper's abstract. Can be omitted if you don't have one. |
| 13 | + abstract: none, |
| 14 | + |
| 15 | + // A list of index terms to display after the abstract. |
| 16 | + index-terms: (), |
| 17 | + |
| 18 | + // The article's paper size. Also affects the margins. |
| 19 | + paper-size: "us-letter", |
| 20 | + |
| 21 | + // The result of a call to the `bibliography` function or `none`. |
| 22 | + bibliography: none, |
| 23 | + |
| 24 | + // How figures are referred to from within the text. |
| 25 | + // Use "Figure" instead of "Fig." for computer-related publications. |
| 26 | + figure-supplement: [Fig.], |
| 27 | + |
| 28 | + // The paper's content. |
| 29 | + body |
| 30 | +) = { |
| 31 | + // Set document metadata. |
| 32 | + set document(title: title, author: authors.map(author => author.name)) |
| 33 | + |
| 34 | + // Set the body font. |
| 35 | + // As of 2024-08, the IEEE LaTeX template uses wider interword spacing |
| 36 | + // - See e.g. the definition \def\@IEEEinterspaceratioM{0.35} in IEEEtran.cls |
| 37 | + set text(font: "TeX Gyre Termes", size: 10pt, spacing: .35em) |
| 38 | + |
| 39 | + // Enums numbering |
| 40 | + set enum(numbering: "1)a)i)") |
| 41 | + |
| 42 | + // Tables & figures |
| 43 | + show figure: set block(spacing: 15.5pt) |
| 44 | + show figure: set place(clearance: 15.5pt) |
| 45 | + show figure.where(kind: table): set figure.caption(position: top, separator: [\ ]) |
| 46 | + show figure.where(kind: table): set text(size: 8pt) |
| 47 | + show figure.where(kind: table): set figure(numbering: "I") |
| 48 | + show figure.where(kind: image): set figure(supplement: figure-supplement, numbering: "1") |
| 49 | + show figure.caption: set text(size: 8pt) |
| 50 | + show figure.caption: set align(start) |
| 51 | + show figure.caption.where(kind: table): set align(center) |
| 52 | + |
| 53 | + // Adapt supplement in caption independently from supplement used for |
| 54 | + // references. |
| 55 | + set figure.caption(separator: [. ]) |
| 56 | + show figure: fig => { |
| 57 | + let prefix = ( |
| 58 | + if fig.kind == table [TABLE] |
| 59 | + else if fig.kind == image [Fig.] |
| 60 | + else [#fig.supplement] |
| 61 | + ) |
| 62 | + let numbers = numbering(fig.numbering, ..fig.counter.at(fig.location())) |
| 63 | + // Wrap figure captions in block to prevent the creation of paragraphs. In |
| 64 | + // particular, this means `par.first-line-indent` does not apply. |
| 65 | + // See https://github.com/typst/templates/pull/73#discussion_r2112947947. |
| 66 | + show figure.caption: it => block[#prefix~#numbers#it.separator#it.body] |
| 67 | + show figure.caption.where(kind: table): smallcaps |
| 68 | + fig |
| 69 | + } |
| 70 | + |
| 71 | + // Code blocks |
| 72 | + show raw: set text( |
| 73 | + font: "TeX Gyre Cursor", |
| 74 | + ligatures: false, |
| 75 | + size: 1em / 0.8, |
| 76 | + spacing: 100%, |
| 77 | + ) |
| 78 | + |
| 79 | + // Configure the page and multi-column properties. |
| 80 | + set columns(gutter: 12pt) |
| 81 | + set page( |
| 82 | + columns: 2, |
| 83 | + paper: paper-size, |
| 84 | + // The margins depend on the paper size. |
| 85 | + margin: if paper-size == "a4" { |
| 86 | + (x: 41.5pt, top: 80.51pt, bottom: 89.51pt) |
| 87 | + } else { |
| 88 | + ( |
| 89 | + x: (50pt / 216mm) * 100%, |
| 90 | + top: (55pt / 279mm) * 100%, |
| 91 | + bottom: (64pt / 279mm) * 100%, |
| 92 | + ) |
| 93 | + } |
| 94 | + ) |
| 95 | + |
| 96 | + // Configure equation numbering and spacing. |
| 97 | + set math.equation(numbering: "(1)") |
| 98 | + show math.equation: set block(spacing: 0.65em) |
| 99 | + |
| 100 | + // Configure appearance of equation references |
| 101 | + show ref: it => { |
| 102 | + if it.element != none and it.element.func() == math.equation { |
| 103 | + // Override equation references. |
| 104 | + link(it.element.location(), numbering( |
| 105 | + it.element.numbering, |
| 106 | + ..counter(math.equation).at(it.element.location()) |
| 107 | + )) |
| 108 | + } else { |
| 109 | + // Other references as usual. |
| 110 | + it |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + // Configure lists. |
| 115 | + set enum(indent: 10pt, body-indent: 9pt) |
| 116 | + set list(indent: 10pt, body-indent: 9pt) |
| 117 | + |
| 118 | + // Configure headings. |
| 119 | + set heading(numbering: "I.A.a)") |
| 120 | + show heading: it => { |
| 121 | + // Find out the final number of the heading counter. |
| 122 | + let levels = counter(heading).get() |
| 123 | + let deepest = if levels != () { |
| 124 | + levels.last() |
| 125 | + } else { |
| 126 | + 1 |
| 127 | + } |
| 128 | + |
| 129 | + set text(10pt, weight: 400) |
| 130 | + if it.level == 1 { |
| 131 | + // First-level headings are centered smallcaps. |
| 132 | + // We don't want to number the acknowledgment section. |
| 133 | + let is-ack = it.body in ([Acknowledgment], [Acknowledgement], [Acknowledgments], [Acknowledgements]) |
| 134 | + set align(center) |
| 135 | + set text(if is-ack { 10pt } else { 11pt }) |
| 136 | + show: block.with(above: 15pt, below: 13.75pt, sticky: true) |
| 137 | + show: smallcaps |
| 138 | + if it.numbering != none and not is-ack { |
| 139 | + numbering("I.", deepest) |
| 140 | + h(7pt, weak: true) |
| 141 | + } |
| 142 | + it.body |
| 143 | + } else if it.level == 2 { |
| 144 | + // Second-level headings are run-ins. |
| 145 | + set text(style: "italic") |
| 146 | + show: block.with(spacing: 10pt, sticky: true) |
| 147 | + if it.numbering != none { |
| 148 | + numbering("A.", deepest) |
| 149 | + h(7pt, weak: true) |
| 150 | + } |
| 151 | + it.body |
| 152 | + } else [ |
| 153 | + // Third level headings are run-ins too, but different. |
| 154 | + #if it.level == 3 { |
| 155 | + numbering("a)", deepest) |
| 156 | + [ ] |
| 157 | + } |
| 158 | + _#(it.body):_ |
| 159 | + ] |
| 160 | + } |
| 161 | + |
| 162 | + // Style bibliography. |
| 163 | + show std.bibliography: set text(8pt) |
| 164 | + show std.bibliography: set block(spacing: 0.5em) |
| 165 | + set std.bibliography(title: text(10pt)[References], style: "ieee") |
| 166 | + |
| 167 | + // Display the paper's title and authors at the top of the page, |
| 168 | + // spanning all columns (hence floating at the scope of the |
| 169 | + // columns' parent, which is the page). |
| 170 | + place( |
| 171 | + top, |
| 172 | + float: true, |
| 173 | + scope: "parent", |
| 174 | + clearance: 30pt, |
| 175 | + { |
| 176 | + { |
| 177 | + set align(center) |
| 178 | + set par(leading: 0.5em) |
| 179 | + set text(size: 24pt) |
| 180 | + block(below: 8.35mm, title) |
| 181 | + } |
| 182 | + |
| 183 | + // Display the authors list. |
| 184 | + set par(leading: 0.6em) |
| 185 | + for i in range(calc.ceil(authors.len() / 3)) { |
| 186 | + let end = calc.min((i + 1) * 3, authors.len()) |
| 187 | + let is-last = authors.len() == end |
| 188 | + let slice = authors.slice(i * 3, end) |
| 189 | + grid( |
| 190 | + columns: slice.len() * (1fr,), |
| 191 | + gutter: 12pt, |
| 192 | + ..slice.map(author => align(center, { |
| 193 | + text(size: 11pt, author.name) |
| 194 | + if "department" in author [ |
| 195 | + \ #emph(author.department) |
| 196 | + ] |
| 197 | + if "organization" in author [ |
| 198 | + \ #emph(author.organization) |
| 199 | + ] |
| 200 | + if "location" in author [ |
| 201 | + \ #author.location |
| 202 | + ] |
| 203 | + if "email" in author { |
| 204 | + if type(author.email) == str [ |
| 205 | + \ #link("mailto:" + author.email) |
| 206 | + ] else [ |
| 207 | + \ #author.email |
| 208 | + ] |
| 209 | + } |
| 210 | + })) |
| 211 | + ) |
| 212 | + |
| 213 | + if not is-last { |
| 214 | + v(16pt, weak: true) |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | + ) |
| 219 | + |
| 220 | + set par(justify: true, first-line-indent: (amount: 1em, all: true), spacing: 0.5em, leading: 0.5em) |
| 221 | + |
| 222 | + // Display abstract and index terms. |
| 223 | + if abstract != none { |
| 224 | + set par(spacing: 0.45em, leading: 0.45em) |
| 225 | + set text(9pt, weight: 700, spacing: 150%) |
| 226 | + |
| 227 | + [_Abstract_---#h(weak: true, 0pt)#abstract] |
| 228 | + |
| 229 | + if index-terms != () { |
| 230 | + parbreak() |
| 231 | + [_Index Terms_---#h(weak: true, 0pt)#index-terms.join[, ]] |
| 232 | + } |
| 233 | + v(2pt) |
| 234 | + } |
| 235 | + |
| 236 | + // Display the paper's contents. |
| 237 | + body |
| 238 | + |
| 239 | + // Display bibliography. |
| 240 | + bibliography |
| 241 | +} |
0 commit comments