You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expand discussion of fonts in PDF basics (#1161) (#1409)
* Expand discussion of fonts
* Minor wording edit
---------
Co-authored-by: Carlos Scheidegger <[email protected]>
(cherry picked from commit d2e9d52)
Co-authored-by: Charlotte Wickham <[email protected]>
Copy file name to clipboardExpand all lines: docs/output-formats/pdf-basics.qmd
+122-1Lines changed: 122 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -87,13 +87,134 @@ format:
87
87
- top=30mm
88
88
- left=20mm
89
89
- heightrounded
90
-
fontfamily: libertinus
90
+
mainfont: Times New Roman
91
91
colorlinks: true
92
92
---
93
93
```
94
94
95
95
See the Pandoc documentation on metadata [variables for LaTeX](https://pandoc.org/MANUAL.html#variables-for-latex) for documentation on all available options.
96
96
97
+
## Fonts
98
+
99
+
Using `xelatex`, the default engine, or the `lualatex` engine, you can specify fonts with the YAML options:
100
+
101
+
| Option | Document Element |
102
+
|----------------|--------------------------|
103
+
| `sansfont` | Headings |
104
+
| `mainfont` | Main body text |
105
+
| `monofont` | Code |
106
+
| `mathfont` | Math |
107
+
| `CJKmainfont` | The CJK main font family |
108
+
109
+
Values for these options should be the family name of system installed fonts. For example:
110
+
111
+
```{.yaml}
112
+
---
113
+
format:
114
+
pdf:
115
+
mainfont: "Times New Roman"
116
+
---
117
+
```
118
+
119
+
Fonts are set using the [`fontspec`](https://ctan.org/pkg/fontspec) package.
120
+
You can set additional font features using the corresponding `<fontoption>options` key.
121
+
For example, you could set headings to the color `#39729E`:
122
+
123
+
```{.yaml}
124
+
---
125
+
format:
126
+
pdf:
127
+
sansfont: "Open Sans"
128
+
sansfontoptions:
129
+
- Color=39729E
130
+
---
131
+
```
132
+
133
+
### `pdflatex`
134
+
135
+
If you use the `pdflatex` engine, use the `fontfamily` option to specify a font from the [The LaTeX Font Catalogue](https://tug.org/FontCatalogue/). For example:
136
+
137
+
``` yaml
138
+
---
139
+
title: pdflatex fonts
140
+
format:
141
+
pdf:
142
+
pdf-engine: pdflatex
143
+
fontfamily: anttor
144
+
---
145
+
```
146
+
147
+
## Unicode Characters
148
+
149
+
By default, Quarto uses the `xelatex` engine to produce PDFs from LaTeX. `xelatex` has native support for unicode characters, but it is possible some customization will be required in order to properly typeset specific unicode characters. In particular, it is important that you use a font that supports the characters that you using in your document. To identify fonts on your system that support specific language characters, you can use the following command:
150
+
151
+
``` {.bash filename="Terminal"}
152
+
fc-list :lang=<lang> family
153
+
```
154
+
155
+
Where `<lang>` is a [ISO 639 language code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes). For example, to see a list of fonts that support Japanese characters, use:
156
+
157
+
``` {.bash filename="Terminal"}
158
+
fc-list :lang=ja family
159
+
```
160
+
161
+
Select a font name from the list and use that as the document's main font:
162
+
163
+
``` markdown
164
+
---
165
+
title: Unicode test
166
+
format: pdf
167
+
mainfont: "Hiragino Sans GB"
168
+
---
169
+
170
+
## Test Document
171
+
172
+
青黑體簡體中文,ヒラギノ角
173
+
```
174
+
175
+
Another common example of Unicode characters are documents that include Greek symbols:
176
+
177
+
````{.markdown filename="greek.qmd"}
178
+
---
179
+
format: pdf
180
+
---
181
+
182
+
## α
183
+
184
+
```r
185
+
α <- 3
186
+
```
187
+
188
+
α is a great constant.
189
+
```
190
+
````
191
+
192
+
Follow the same process as above to discover fonts that support Greek:
193
+
194
+
``` {.bash filename="Terminal"}
195
+
fc-list :lang=el family
196
+
```
197
+
198
+
Then set the appropriate font options:
199
+
200
+
````{.markdown filename="greek.qmd"}
201
+
---
202
+
format:
203
+
pdf:
204
+
mainfont: "EB Garamond"
205
+
sansfont: "Open Sans"
206
+
monofont: "Roboto Mono"
207
+
---
208
+
````
209
+
210
+
*(These particular fonts are available from [Google Fonts](https://fonts.google.com).)*
211
+
212
+
With fonts with appropriate support, Greek symbols render correctly in headings, the main text and code cells:
213
+
214
+
{.border fig-alt="Screenshot of at PDF displaying the Greek symbol alpha in a heading, main text and code cell."}
0 commit comments