/docs/theming-guide.adoc

https://github.com/DavidGamba/asciidoctor-pdf · AsciiDoc · 1547 lines · 1153 code · 394 blank · 0 comment · 0 complexity · 8b7478276225424c3fcccd63d90da548 MD5 · raw file

  1. = Asciidoctor PDF Theming Guide
  2. Dan Allen <https://github.com/mojavelinux>
  3. :toc: macro
  4. :icons: font
  5. :idprefix:
  6. :idseparator: -
  7. :window: _blank
  8. ////
  9. Topics remaining to document:
  10. * line height and line height length (and what that all means)
  11. * title page layout / title page images (logo & background)
  12. * document that unicode escape sequences can be used inside double-quoted strings
  13. ////
  14. The theming system in Asciidoctor PDF is used to control the layout and styling of the PDF file that Asciidoctor PDF generates from AsciiDoc.
  15. The theme is driven by a YAML-based configuration file.
  16. This document explains how the theming system works, how to define a custom theme and how to enable the theme when running Asciidoctor PDF.
  17. toc::[]
  18. == Language overview
  19. The theme language in Asciidoctor PDF is based on the http://en.wikipedia.org/wiki/YAML[YAML] data format and incorporates many concepts from CSS and SASS.
  20. Therefore, if you have a background in web design, the theme language should be immediately familiar to you.
  21. Like CSS, themes have both selectors and properties.
  22. Selectors are the component you want to style.
  23. The properties are the style elements of that component that can be styled.
  24. All selector names are implicit (e.g., `heading`), so you customize the theme primarily by manipulating pre-defined property values (e.g., `font_size`).
  25. [NOTE]
  26. ====
  27. The theme language in Asciidoctor PDF supports a limited subset of the properties from CSS.
  28. Some of these properties have different names from those found in CSS.
  29. Instead of separate properties for font weight and font style, the theme language combines these as the `font_style` property (allowing values "normal", "bold", "italic" and "bold_italic").
  30. The `text_align` property from CSS is the `align` property in the theme language.
  31. The `color` property from CSS is the `font_color` property in the theme language.
  32. ====
  33. A theme (or style) is described in a YAML-based data format and stored in a dedicated theme file.
  34. YAML is a human-friendly data format that resembles CSS and helps to describe the theme.
  35. The theme language adds some extra features to YAML, such as variables, basic math, measurements and color values.
  36. These enhancements will be explained in detail in later sections.
  37. The theme file must be named _<name>-theme.yml_, where `<name>` is the name of the theme.
  38. Here's an example of a basic theme file:
  39. .basic-theme.yml
  40. [source,yaml]
  41. ----
  42. page:
  43. layout: portrait
  44. margin: [0.75in, 1in, 0.75in, 1in]
  45. size: Letter
  46. base:
  47. font_color: #333333
  48. font_family: Times-Roman
  49. font_size: 12
  50. line_height_length: 17
  51. line_height: $base_line_height_length / $base_font_size
  52. vertical_rhythm: $base_line_height_length
  53. heading:
  54. font_color: #262626
  55. font_size: 17
  56. font_style: bold
  57. line_height: 1.2
  58. margin_bottom: $vertical_rhythm
  59. link:
  60. font_color: #002FA7
  61. outline_list:
  62. indent: $base_font_size * 1.5
  63. ----
  64. When creating a new theme, you only have to define the keys you want to override from the base theme (PENDING, see https://github.com/asciidoctor/asciidoctor-pdf/issues/132[#132]).
  65. The converter uses the information from the theme map to help construct the PDF.
  66. All the available keys are documented in <<keys>>.
  67. Keys may be nested to an arbitrary depth to eliminate redundant prefixes (an approach inspired by SASS).
  68. Once the theme is loaded, all keys are flattened into a single map of qualified keys.
  69. Nesting is simply a shorthand way of organizing the keys.
  70. In the end, a theme is just a map of key/value pairs.
  71. Nested keys are adjoined to their parent key with an underscore (`_`).
  72. This means the selector part (e.g., `link`) is combined with the property name (e.g., `font_color`) into a single, qualified key (e.g., `link_font_color`).
  73. For example, let's assume we want to set the base (i.e., global) font size and color.
  74. These keys may be written longhand:
  75. [source,yaml]
  76. ----
  77. base_font_color: #333333
  78. base_font_family: Times-Roman
  79. base_font_size: 12
  80. ----
  81. Or, to avoid having to type the prefix `base_` multiple times, the keys may be written hierarchically:
  82. [source,yaml]
  83. ----
  84. base:
  85. font_color: #333333
  86. font_family: Times-Roman
  87. font_size: 12
  88. ----
  89. Or even:
  90. [source,yaml]
  91. ----
  92. base:
  93. font:
  94. color: #333333
  95. family: Times-Roman
  96. size: 12
  97. ----
  98. Each level of nesting must be indented by twice the amount of indentation of the parent level.
  99. Also note the placement of the colon after each key name.
  100. == Values
  101. The value of a key may be one of the following types:
  102. * String
  103. - Font family name (e.g., Roboto)
  104. - Font style (normal, bold, italic, bold_italic)
  105. - Alignment (left, center, right, justify)
  106. - Color as hex string (e.g., #ffffff)
  107. - Image path
  108. * Number (integer or float) with optional units (default unit is points)
  109. * Array
  110. - Color as RGB array (e.g., [51, 51, 51])
  111. - Color CMYK array (e.g., [50, 100, 0, 0])
  112. - Margin (e.g., [1in, 1in, 1in, 1in])
  113. - Padding (e.g., [1in, 1in, 1in, 1in])
  114. * Variable reference (e.g., $base_font_color)
  115. * Math expression
  116. Note that keys almost always require a value of a specific type, as documented in <<keys>>.
  117. === Inheritance
  118. Like CSS, inheritance is a key feature in the Asciidoctor PDF theme language.
  119. For many of the properties, if a key is not specified, the key inherits the value applied to the parent content in the content hierarchy.
  120. This behavior saves you from having to specify properties unless you want to override the inherited value.
  121. The following keys are inherited:
  122. * font_family
  123. * font_color
  124. * font_size
  125. * font_style
  126. * line_height (currently some exceptions)
  127. * text_transform (only for headings)
  128. * margin_bottom (falls back to $vertical_rhythm)
  129. .Heading Inheritance
  130. ****
  131. Headings are special in that they inherit starting from a specific heading level (e.g., `heading_font_size_h2`) to the heading category (e.g., `heading_font_size`) and then directly to the base value (e.g., `base_font_size`), skipping any enclosing context.
  132. ****
  133. === Variables
  134. To save you from having to type the same value in your theme over and over, or to allow you to base one value on another, the theme language supports variables.
  135. Variables consist of the key name preceded by a dollar (`$`) (e.g., `$base_font_size`).
  136. Any qualified key that has already been defined can be referenced in the value of another key.
  137. (In order words, as soon as the key is assigned, it's available to be used as a variable).
  138. For example, once the following line is processed,
  139. [source,yaml]
  140. ----
  141. base:
  142. font_color: #333333
  143. ----
  144. the variable `$base_font_color` will be available for use in subsequent lines and will resolve to `#333333`.
  145. Let's say you want to make the font color of the sidebar title the same as the heading font color.
  146. Just assign the value `$heading_font_color` to the `$sidebar_title_font_color`.
  147. [source,yaml]
  148. ----
  149. heading:
  150. font_color: #191919
  151. sidebar:
  152. title:
  153. font_color: $heading_font_color
  154. ----
  155. You can also use variables in math expressions to use one value to build another.
  156. This is commonly done to set font sizes proportionally.
  157. It also makes it easy to test different values very quickly.
  158. [source,yaml]
  159. ----
  160. base:
  161. font_size: 12
  162. font_size_large: $base_font_size * 1.25
  163. font_size_small: $base_font_size * 0.85
  164. ----
  165. We'll cover more about math expressions later.
  166. ==== Custom variables
  167. You can define arbitrary key names to make custom variables.
  168. This is one way to group reusable values at the top of your theme file.
  169. If you are going to do this, it's recommended that you organize the keys under a custom namespace, such as `brand`.
  170. For instance, here's how you can define your (very patriotic) brand colors:
  171. [source,yaml]
  172. ----
  173. brand:
  174. red: #E0162B
  175. white: #FFFFFF
  176. blue: #0052A5
  177. ----
  178. You can now use these custom variables later in the theme file:
  179. [source,yaml]
  180. ----
  181. base:
  182. font_color: $brand_blue
  183. ----
  184. === Math expressions & functions
  185. The theme language supports basic math operations to support calculated values.
  186. The following table lists the supported operations and the corresponding operator for each.
  187. [%header%autowidth]
  188. |===
  189. |Operation |Operator
  190. |multiply
  191. |*
  192. |divide
  193. |/
  194. |add
  195. |+
  196. |subtract
  197. |-
  198. |===
  199. NOTE: Like programming languages, multiple and divide take precedence over add and subtract.
  200. The operator must always be surrounded by a space on either side.
  201. Here's an example of a math expression with fixed values.
  202. [source,yaml]
  203. ----
  204. conum:
  205. line_height: 4 / 3
  206. ----
  207. Variables may be used in place of numbers anywhere in the expression:
  208. [source,yaml]
  209. ----
  210. base:
  211. font_size: 12
  212. font_size_large: $base_font_size * 1.25
  213. ----
  214. Values used in a math expression are automatically coerced to a float value before the operation.
  215. If the result of the expression is an integer, the value is coerced to an integer afterwards.
  216. IMPORTANT: Numeric values less than 1 must have a 0 before the decimal point (e.g., 0.85).
  217. The theme language also supports several functions for rounding the result of a math expression.
  218. The following functions may be used if they surround the whole value or expression for a key.
  219. round(...):: Rounds the number to the nearest half integer.
  220. floor(...):: Rounds the number up to the next integer.
  221. ceil(...):: Rounds the number down the previous integer.
  222. You might use these functions in font size calculations so that you get more exact values.
  223. [source,yaml]
  224. ----
  225. base:
  226. font_size: 12.5
  227. font_size_large: ceil($base_font_size * 1.25)
  228. ----
  229. === Measurement units
  230. Several of the keys require a value in points (pt), the unit of measure for the PDF canvas.
  231. A point is defined as 1/72 of an inch.
  232. However, us humans like to think in real world units like inches (in), centimeters (cm) or millimeters (mm).
  233. You can let the theme do this conversion for you automatically by adding a unit notation next to any number.
  234. The following units are supported:
  235. [%header%autowidth]
  236. |===
  237. |Unit |Suffix
  238. |Inches
  239. |in
  240. |Centimeter
  241. |cm
  242. |Millimeter
  243. |mm
  244. |Points
  245. |pt
  246. |===
  247. Here's an example of how you can use inches to define the page margins:
  248. [source,yaml]
  249. ----
  250. page:
  251. margin: [0.75in, 1in, 0.75in, 1in]
  252. ----
  253. The order of elements in a measurement array is the same as it is in CSS:
  254. . top
  255. . right
  256. . bottom
  257. . left
  258. === Colors
  259. The theme language supports color values in three formats:
  260. Hex:: A string of 3 or 6 characters with an optional leading `#`.
  261. +
  262. The special value `transparent` indicates that a color should not be used.
  263. RGB:: An array of numeric values ranging from 0 to 255.
  264. CMYK:: An array of numeric values ranging from 0 to 1 or from 0% to 100%.
  265. ==== Hex
  266. The hex color value is likely most familiar to web developers.
  267. The value must be either 3 or 6 characters (case insensitive) with an optional leading hash (`#`).
  268. The following are all equivalent values for the color red:
  269. [%autowidth,cols=4]
  270. |===
  271. |f00
  272. |#f00
  273. |ff0000
  274. |#ff0000
  275. |F00
  276. |#F00
  277. |FF0000
  278. |#FF0000
  279. |===
  280. Here's how a hex color value appears in the theme file:
  281. [source,yaml]
  282. ----
  283. base:
  284. font_color: #ff0000
  285. ----
  286. It's also possible to specify no color by assigning the special value `transparent` as shown here:
  287. [source,yaml]
  288. ----
  289. base:
  290. background_color: transparent
  291. ----
  292. ==== RGB
  293. An RGB array value must be three numbers ranging from 0 to 255.
  294. The values must be separated by commas and be surrounded by square brackets.
  295. NOTE: An RGB array is automatically converted to a hex string internally, so there's no difference between ff0000 and [255, 0, 0].
  296. Here's how to specify the color red in RGB:
  297. * [255, 0, 0]
  298. Here's how a RGB color value appears in the theme file:
  299. [source,yaml]
  300. ----
  301. base:
  302. font_color: [255, 0, 0]
  303. ----
  304. ==== CMYK
  305. A CMYK array value must be four numbers ranging from 0 and 1 or from 0% to 100%.
  306. The values must be separated by commas and be surrounded by square brackets.
  307. Unlike the RGB array, the CMYK array _is not_ converted to a hex string internally.
  308. PDF has native support for CMYK colors, so you can preserve the original color values in the final PDF.
  309. Here's how to specify the color red in CMYK:
  310. * [0, 0.99, 1, 0]
  311. * [0, 99%, 100%, 0]
  312. Here's how a CMYK color value appears in the theme file:
  313. [source,yaml]
  314. ----
  315. base:
  316. font_color: [0, 0.99, 1, 0]
  317. ----
  318. === Images
  319. An image is specified either as a bare image path or as an inline image macro as found in the AsciiDoc syntax.
  320. Images are currently resolved relative to the value of the `pdf-stylesdir` attribute.
  321. The following image types (and corresponding file extensions) are supported:
  322. * PNG (.png)
  323. * JPEG (.jpg)
  324. * SVG (.svg)
  325. CAUTION: The GIF format (.gif) is not supported.
  326. Here's how an image is specified in the theme file as a bare image path:
  327. [source,yaml]
  328. ----
  329. title_page:
  330. background_image: title-cover.png
  331. ----
  332. Here's how the image is specified using the inline image macro:
  333. [source,yaml]
  334. ----
  335. title_page:
  336. background_image: image:title-cover.png[]
  337. ----
  338. Like in the AsciiDoc syntax, the inline image macro allows you to supply set the width of the image and the alignment:
  339. [source,yaml]
  340. ----
  341. title_page:
  342. logo_image: image:logo.png[width=250,align=center]
  343. ----
  344. == Fonts
  345. You can select from <<built-in-fonts,built-in PDF fonts>>, <<bundled-fonts,fonts bundled with Asciidoctor PDF>> or <<custom-fonts,custom fonts>> loaded from TrueType font (TTF) files.
  346. If you want to use custom fonts, you must first declare them in your theme file.
  347. === Built-in fonts
  348. The names of the built-in fonts (for general-purpose text) are as follows:
  349. [%header%autowidth]
  350. |===
  351. |Font Name |Font Family
  352. |Helvetica
  353. |sans-serif
  354. |Times-Roman
  355. |serif
  356. |Courier
  357. |monospace
  358. |===
  359. Using a built-in font requires no additional files.
  360. You can use the key anywhere a `font_family` property is accepted in the theme file.
  361. For example:
  362. [source,yaml]
  363. ----
  364. base:
  365. font_family: Times-Roman
  366. ----
  367. However, when you use a built-in font, the characters that you use in your document are limited to the WINANSI (http://en.wikipedia.org/wiki/Windows-1252[Windows-1252]) code set.
  368. WINANSI includes most of the characters needed for writing in Western languages (English, French, Spanish, etc).
  369. For anything outside of that, PDF is BYOF (Bring Your Own Font).
  370. Even though the built-in fonts require the content to be encoded in WINANSI, _you still type your AsciiDoc document in UTF-8_.
  371. Asciidoctor PDF encodes the content into WINANSI when building the PDF.
  372. Any characters in your AsciiDoc document that cannot be encoded will be replaced with an underscore (`_`).
  373. === Bundled fonts
  374. Asciidoctor PDF bundles several fonts that are used in the default theme.
  375. You can also use these fonts in your custom theme.
  376. These fonts provide more characters than the built-in PDF fonts, but still only a subset of UTF-8.
  377. The family name of the fonts bundled with Asciidoctor PDF are as follows:
  378. http://www.google.com/get/noto/#/family/noto-serif[NotoSerif]::
  379. A serif font that can be styled as normal, italic, bold or bold_italic.
  380. http://mplus-fonts.osdn.jp/mplus-outline-fonts/design/index-en.html#mplus_1mn[Mplus1mn]::
  381. A monospaced font that maps different thicknesses to the styles normal, italic, bold and bold_italic.
  382. Also provides the circuled numbers used in callouts.
  383. http://mplus-fonts.osdn.jp/mplus-outline-fonts/design/index-en.html#mplus_1p[Mplus1pMultilingual]::
  384. A sans-serif font that provides a very complete set of Unicode glyphs.
  385. Cannot be styled as italic, bold or bold_italic.
  386. Useful as a fallback font.
  387. CAUTION: At the time of this writing, you cannot use the bundled fonts if you define your own custom fonts.
  388. This limitation may be lifted in the future.
  389. === Custom fonts
  390. The limited character set of WINANSI, or the bland look of the built-in fonts, may motivate you to load your own font.
  391. Custom fonts can enhance the look of your PDF theme substantially.
  392. To start, you need to find a collection of TTF file of the font you want to use.
  393. A collection typically consists of all four styles of a font:
  394. * normal
  395. * italic
  396. * bold
  397. * bold_italic
  398. You'll need all four styles to support AsciiDoc content properly.
  399. _Asciidoctor PDF cannot italicize a font that is not italic like a browser can._
  400. Once you've obtained the TTF files, put them into a directory in your project where you want to store the fonts.
  401. It's recommended that you name them consistently so it's easier to type the names in the theme file.
  402. Let's assume the name of the font is https://github.com/google/roboto/tree/master/out/RobotoTTF[Roboto].
  403. Name the files as follows:
  404. * roboto-normal.ttf (_originally Roboto-Regular.ttf_)
  405. * roboto-italic.ttf (_originally Roboto-Italic.ttf_)
  406. * roboto-bold.ttf (_originally Roboto-Bold.ttf_)
  407. * roboto-bold_italic.ttf (_originally Roboto-BoldItalic.ttf_)
  408. Next, declare the font under the `font_catalog` key at the top of your theme file, giving it a unique key (e.g., `Roboto`).
  409. [source,yaml]
  410. ----
  411. font:
  412. catalog:
  413. Roboto:
  414. normal: roboto-normal.ttf
  415. italic: roboto-italic.ttf
  416. bold: roboto-bold.ttf
  417. bold_italic: roboto-bold_italic.ttf
  418. ----
  419. You can use the key you gave to the font in the font catalog anywhere a `font_family` property is accepted in the theme file.
  420. For instance, to use the Roboto font for all headings, you'd use:
  421. [source,yaml]
  422. ----
  423. heading:
  424. font_family: Roboto
  425. ----
  426. When you execute Asciidoctor PDF, you need to specify the directory where the fonts reside using the `pdf-fontsdir` attribute:
  427. $ asciidoctor-pdf -a pdf-style=basic-theme.yml -a pdf-fontsdir=path/to/fonts document.adoc
  428. WARNING: Currently, all fonts referenced by the theme need to be present in the directory specified by the `pdf-fontsdir` attribute.
  429. You can add any number of fonts to the catalog.
  430. Each font must be assigned a unique key, as shown here:
  431. [source,yaml]
  432. ----
  433. font:
  434. catalog:
  435. Roboto:
  436. normal: roboto-normal.ttf
  437. italic: roboto-italic.ttf
  438. bold: roboto-bold.ttf
  439. bold_italic: roboto-bold_italic.ttf
  440. RobotoLight:
  441. normal: roboto-light-normal.ttf
  442. italic: roboto-light-italic.ttf
  443. bold: roboto-light-bold.ttf
  444. bold_italic: roboto-light-bold_italic.ttf
  445. ----
  446. === Fallback fonts
  447. If one of your fonts is missing a character that is used in a document, such as special symbols, you can tell Asciidoctor PDF to retrieve the character from a fallback font.
  448. You only need to specify one fallback font...typically one that has a full set of symbols.
  449. Like with other custom fonts, you first need to declare the fallback font.
  450. Let's choose https://android.googlesource.com/platform/frameworks/base/+/master/data/fonts/[Droid Sans Fallback].
  451. You can map all the styles to a single font file (since bold and italic don't usually make sense for symbols).
  452. [source,yaml]
  453. ----
  454. font:
  455. catalog:
  456. Roboto:
  457. normal: roboto-normal.ttf
  458. italic: roboto-italic.ttf
  459. bold: roboto-bold.ttf
  460. bold_italic: roboto-bold_italic.ttf
  461. DroidSansFallback:
  462. normal: droid-sans-fallback.ttf
  463. italic: droid-sans-fallback.ttf
  464. bold: droid-sans-fallback.ttf
  465. bold_italic: droid-sans-fallback.ttf
  466. ----
  467. Next, assign the key to the `fallbacks` key under the `font_catalog` key.
  468. Be sure to surround the key name in square brackets as shown below.
  469. [source,yaml]
  470. ----
  471. font:
  472. catalog:
  473. Roboto:
  474. normal: roboto-normal.ttf
  475. italic: roboto-italic.ttf
  476. bold: roboto-bold.ttf
  477. bold_italic: roboto-bold_italic.ttf
  478. DroidSansFallback:
  479. normal: droid-sans-fallback.ttf
  480. italic: droid-sans-fallback.ttf
  481. bold: droid-sans-fallback.ttf
  482. bold_italic: droid-sans-fallback.ttf
  483. fallbacks: [DroidSansFallback]
  484. ----
  485. TIP: If you are using more than one fallback font, separate each key name by a comma.
  486. That's it!
  487. Now you're covered.
  488. You don't need to reference the fallback font anywhere else in your theme file to use it.
  489. CAUTION: Using a fallback font does slow down PDF generation slightly.
  490. It's best to select fonts that have all the characters you need.
  491. == Keys
  492. TBW
  493. === Page
  494. [cols="3,3,5m"]
  495. |===
  496. |Key |Value Type |Example
  497. |page_background_color
  498. |<<colors,color>>
  499. |background_color: ffffff
  500. |page_layout
  501. |portrait, landscape
  502. |layout: portrait
  503. |page_margin
  504. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  505. |margin: [0.5in, 0.67in, 0.67in, 0.67in]
  506. |page_size
  507. |named size, <<measurement-units,measurement array [width, height]>>
  508. |size: Letter
  509. |===
  510. === Base
  511. [cols="3,3,5m"]
  512. |===
  513. |Key |Value Type |Example
  514. |base_font_color
  515. |<<colors,color>>
  516. |font_color: #333333
  517. |base_font_family
  518. |<<fonts,font family name>>
  519. |font_family: NotoSerif
  520. |base_font_size
  521. |<<values,number>>
  522. |font_size: 10.5
  523. |base_line_height_length^[1]^
  524. |<<values,number>>
  525. |line_height_length: 12
  526. |base_line_height^[1]^
  527. |<<values,number>>
  528. |line_height: 1.14
  529. |base_font_size_large
  530. |<<values,number>>
  531. |font_size_large: 13
  532. |base_font_size_small
  533. |<<values,number>>
  534. |font_size_small: 9
  535. |base_font_style
  536. |normal, italic, bold, bold_italic
  537. |font_style: normal
  538. |base_align
  539. |left, center, right, justify
  540. |align: justify
  541. |base_border_radius
  542. |<<values,number>>
  543. |border_radius: 4
  544. |base_border_width
  545. |<<values,number>>
  546. |border_width: 0.5
  547. |base_border_color
  548. |<<colors,color>>
  549. |border_color: eee
  550. |===
  551. ^[1]^ You should set either `line_height` or `line_height_length` and derive the value of the other using a calculation since these are correlated values.
  552. For instance, if you set `line_height_length`, then use `line_height: $base_line_height_length / $base_font_size` to define the line height.
  553. === Vertical and horizontal rhythm
  554. [cols="3,3,5m"]
  555. |===
  556. |Key |Value Type |Example
  557. |vertical_rhythm
  558. |<<values,number>>
  559. |vertical_rhythm: 12
  560. |horizontal_rhythm
  561. |<<values,number>>
  562. |horizontal_rhythm: 12
  563. |===
  564. NOTE: Vertical and horizontal rhythm are used for vertical and horizontal spacing, respectively, when there a specific theme key is not defined for a certain purpose.
  565. These keys predated the CSS-style theme system and are planned to be phased out.
  566. === Link
  567. [cols="3,3,5m"]
  568. |===
  569. |Key |Value Type |Example
  570. |link_font_color
  571. |<<colors,color>>
  572. |font_color: 428BCA
  573. |link_font_family
  574. |<<fonts,font family name>>
  575. |font_family: Roboto
  576. |link_font_size
  577. |<<values,number>>
  578. |font_size: 9
  579. |link_font_style
  580. |normal, italic, bold, bold_italic
  581. |font_style: normal
  582. |===
  583. === Literal inline
  584. The literal key is used for inline monospaced text in prose and table cells.
  585. [cols="3,3,5m"]
  586. |===
  587. |Key |Value Type |Example
  588. |literal_font_color
  589. |<<colors,color>>
  590. |font_color: B12146
  591. |literal_font_family
  592. |<<fonts,font family name>>
  593. |font_family: Mplus1mn
  594. |literal_font_size
  595. |<<values,number>>
  596. |font_size: 12
  597. |literal_font_style
  598. |normal, italic, bold, bold_italic
  599. |font_style: bold
  600. |===
  601. === Heading
  602. [cols="3,3,5m"]
  603. |===
  604. |Key |Value Type |Example
  605. |heading_font_color
  606. |<<colors,color>>
  607. |font_color: 333333
  608. |heading_font_family
  609. |<<fonts,font family name>>
  610. |font_family: NotoSerif
  611. |heading_font_size
  612. |<<values,number>>
  613. |font_size: 9
  614. |heading_font_style
  615. |normal, italic, bold, bold_italic
  616. |font_style: bold
  617. |heading_h<n>_font_color^[1]^
  618. |<<colors,color>>
  619. |h2_font_color: [0, 99%, 100%, 0]
  620. |heading_h<n>_font_family^[1]^
  621. |<<fonts,font family name>>
  622. |h4_font_family: Roboto
  623. |heading_h<n>_font_size^[1]^
  624. |<<values,number>>
  625. |h6_font_size: round($base_font_size * 1.7)
  626. |heading_h<n>_font_style^[1]^
  627. |normal, italic, bold, bold_italic
  628. |h3_font_style: bold_italic
  629. |heading_line_height
  630. |<<values,number>>
  631. |line_height: 1.2
  632. |heading_margin_top
  633. |<<measurement-units,measurement>>
  634. |margin_top: $vertical_rhythm * 0.2
  635. |heading_margin_bottom
  636. |<<measurement-units,measurement>>
  637. |margin_bottom: 9.600
  638. |===
  639. ^[1]^ `<n>` may be a number ranging from 1 to 6, representing each of the six heading levels.
  640. === Title page
  641. [cols="3,3,5m"]
  642. |===
  643. |Key |Value Type |Example
  644. |title_page_align
  645. |left, center, right, justify
  646. |align: right
  647. |title_page_title_top
  648. |percentage
  649. |title_top: 55%
  650. |title_page_title_font_size
  651. |<<values,number>>
  652. |title_font_size: 27
  653. |title_page_title_font_color
  654. |<<colors,color>>
  655. |title_font_color: 999999
  656. |title_page_title_line_height
  657. |<<values,number>>
  658. |title_line_height: 0.9
  659. |title_page_subtitle_font_size
  660. |<<values,number>>
  661. |subtitle_font_size: 18
  662. |title_page_subtitle_font_style
  663. |normal, italic, bold, bold_italic
  664. |subtitle_font_style: bold_italic
  665. |title_page_subtitle_line_height
  666. |<<values,number>>
  667. |subtitle_line_height: 1
  668. |title_page_authors_margin_top
  669. |<<measurement-units,measurement>>
  670. |authors_margin_top: 13.125
  671. |title_page_authors_font_size
  672. |<<values,number>>
  673. |authors_font_size: $base_font_size_large
  674. |title_page_authors_font_color
  675. |<<colors,color>>
  676. |authors_font_color: 181818
  677. |title_page_revision_margin_top
  678. |<<measurement-units,measurement>>
  679. |revision_margin_top: 13.125
  680. |===
  681. === Block
  682. [cols="3,3,5m"]
  683. |===
  684. |Key |Value Type |Example
  685. |block_padding
  686. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  687. |padding: [12, 15, 12, 15]
  688. |block_margin_top
  689. |<<measurement-units,measurement>>
  690. |margin_top: 0
  691. |block_margin_bottom
  692. |<<measurement-units,measurement>>
  693. |margin_bottom: 1
  694. |===
  695. Block styles are applied to the following block types:
  696. [cols="1a,1a,1a", grid=none, frame=none]
  697. |===
  698. |
  699. * admonition
  700. * example
  701. * quote
  702. |
  703. * verse
  704. * sidebar
  705. * image
  706. |
  707. * listing
  708. * literal
  709. * table
  710. |===
  711. === Caption
  712. [cols="3,3,5m"]
  713. |===
  714. |Key |Value Type |Example
  715. |caption_font_color
  716. |<<colors,color>>
  717. |font_color: 333333
  718. |caption_font_family
  719. |<<fonts,font family name>>
  720. |font_family: Mplus1mn
  721. |caption_font_size
  722. |<<values,number>>
  723. |font_size: 11
  724. |caption_font_style
  725. |normal, italic, bold, bold_italic
  726. |font_style: italic
  727. |caption_align
  728. |left, center, right, justify
  729. |align: left
  730. |caption_margin_inside
  731. |<<measurement-units,measurement>>
  732. |margin_inside: 3
  733. |caption_margin_outside
  734. |<<measurement-units,measurement>>
  735. |margin_outside: 0
  736. |===
  737. === Code
  738. [cols="3,3,5m"]
  739. |===
  740. |Key |Value Type |Example
  741. |code_font_color
  742. |<<colors,color>>
  743. |font_color: 333333
  744. |code_font_family
  745. |<<fonts,font family name>>
  746. |font_family: Mplus1mn
  747. |code_font_size
  748. |<<values,number>>
  749. |font_size: 11
  750. |code_font_style
  751. |normal, italic, bold, bold_italic
  752. |font_style: italic
  753. |code_padding
  754. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  755. |padding: 11
  756. |code_line_height
  757. |<<values,number>>
  758. |line_height: 1.25
  759. |code_background_color
  760. |<<colors,color>>
  761. |background_color: F5F5F5
  762. |code_border_color
  763. |<<colors,color>>
  764. |border_color: CCCCCC
  765. |code_border_radius
  766. |<<values,number>>
  767. |border_radius: 4
  768. |code_border_width
  769. |<<values,number>>
  770. |border_width: 0.75
  771. |===
  772. === Blockquote
  773. [cols="3,3,5m"]
  774. |===
  775. |Key |Value Type |Example
  776. |blockquote_font_color
  777. |<<colors,color>>
  778. |font_color: 333333
  779. |blockquote_font_family
  780. |<<fonts,font family name>>
  781. |font_family: Notoserif
  782. |blockquote_font_size
  783. |<<values,number>>
  784. |font_size: 13
  785. |blockquote_font_style
  786. |normal, italic, bold, bold_italic
  787. |font_style: bold
  788. |blockquote_border_width
  789. |<<values,number>>
  790. |border_width: 5
  791. |blockquote_border_color
  792. |<<colors,color>>
  793. |border_color: EEEEEE
  794. |blockquote_cite_font_size
  795. |<<values,number>>
  796. |cite_font_size: 9
  797. |blockquote_cite_font_color
  798. |<<colors,color>>
  799. |cite_font_color: 999999
  800. |blockquote_cite_font_family
  801. |<<fonts,font family name>>
  802. |cite_font_family: Notoserif
  803. |blockquote_cite_font_style
  804. |normal, italic, bold, bold_italic
  805. |cite_font_style: bold
  806. |===
  807. === Sidebar
  808. [cols="3,3,5m"]
  809. |===
  810. |Key |Value Type |Example
  811. |sidebar_border_color
  812. |<<colors,color>>
  813. |border_color: FFFFFF
  814. |sidebar_border_radius
  815. |<<values,number>>
  816. |border_radius: 4
  817. |sidebar_border_width
  818. |<<values,number>>
  819. |border_width: 0.5
  820. |sidebar_background_color
  821. |<<colors,color>>
  822. |background_color: EEEEEE
  823. |sidebar_title_font_color
  824. |<<colors,color>>
  825. |title_font_color: 333333
  826. |sidebar_title_font_family
  827. |<<fonts,font family name>>
  828. |title_font_family: NotoSerif
  829. |sidebar_title_font_size
  830. |<<values,number>>
  831. |title_font_size: 13
  832. |sidebar_title_font_style
  833. |normal, italic, bold, bold_italic
  834. |title_font_style: bold
  835. |sidebar_title_align
  836. |left, center, right, justify
  837. |title_align: center
  838. |===
  839. === Example
  840. [cols="3,3,5m"]
  841. |===
  842. |Key |Value Type |Example
  843. |example_border_color
  844. |<<colors,color>>
  845. |border_color: EEEEEE
  846. |example_border_radius
  847. |<<values,number>>
  848. |border_radius: 4
  849. |example_border_width
  850. |<<values,number>>
  851. |border_width: 0.75
  852. |example_background_color
  853. |<<colors,color>>
  854. |background_color: transparent
  855. |===
  856. === Admonition
  857. [cols="3,3,5m"]
  858. |===
  859. |Key |Value Type |Example
  860. |admonition_border_color
  861. |<<colors,color>>
  862. |border_color: EEEEEE
  863. |admonition_border_width
  864. |<<values,number>>
  865. |border_width: 0.5
  866. |===
  867. === Image
  868. [cols="3,3,5m"]
  869. |===
  870. |Key |Value Type |Example
  871. |image_align_default
  872. |left, center, right, justify
  873. |align_default: left
  874. |===
  875. === Lead
  876. [cols="3,3,5m"]
  877. |===
  878. |Key |Value Type |Example
  879. |lead_font_size
  880. |<<values,number>>
  881. |font_size: 13
  882. |lead_line_height
  883. |<<values,number>>
  884. |line_height: 1.4
  885. |===
  886. === Abstract
  887. [cols="3,3,5m"]
  888. |===
  889. |Key |Value Type |Example
  890. |abstract_font_color
  891. |<<colors,color>>
  892. |font_color: 5C6266
  893. |abstract_font_size
  894. |<<values,number>>
  895. |font_size: 13
  896. |abstract_line_height
  897. |<<values,number>>
  898. |line_height: 1.4
  899. |abstract_font_style
  900. |normal, italic, bold, bold_italic
  901. |font_style: italic
  902. |===
  903. === Thematic break
  904. [cols="3,3,5m"]
  905. |===
  906. |Key |Value Type |Example
  907. |thematic_break_border_color
  908. |<<colors,color>>
  909. |border_colorL EEEEEE
  910. |thematic_break_margin_top
  911. |<<measurement-units,measurement>>
  912. |margin_top: 6
  913. |thematic_break_margin_bottom
  914. |<<measurement-units,measurement>>
  915. |margin_bottom: 18
  916. |===
  917. === Description list
  918. [cols="3,3,5m"]
  919. |===
  920. |Key |Value Type |Example
  921. |description_list_term_font_style
  922. |normal, italic, bold, bold_italic
  923. |term_font_style: italic
  924. |description_list_description_indent
  925. |<<values,number>>
  926. |description_indent: 15
  927. |===
  928. === Outline list
  929. [cols="3,3,5m"]
  930. |===
  931. |Key |Value Type |Example
  932. |outline_list_indent
  933. |<<measurement-units,measurement>>
  934. |list_indent: 40
  935. |outline_list_item_spacing
  936. |<<measurement-units,measurement>>
  937. |item_spacing: 4
  938. |===
  939. === Table
  940. [cols="3,3,5m"]
  941. |===
  942. |Key |Value Type |Example
  943. |table_background_color
  944. |<<colors,color>>
  945. |background_color: FFFFFF
  946. |table_even_row_background_color
  947. |<<colors,color>>
  948. |even_row_background_color: F9F9F9
  949. |table_foot_background_color
  950. |<<colors,color>>
  951. |foot_background_color: F0F0F0
  952. |table_border_color
  953. |<<colors,color>>
  954. |border_color: DDDDDD
  955. |table_border_width
  956. |<<values,number>>
  957. |border_width: 0.5
  958. |table_cell_padding
  959. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  960. |cell_padding: [3, 3, 6, 3]
  961. |===
  962. [[key-toc]]
  963. === Table of contents
  964. [cols="3,3,5m"]
  965. |===
  966. |Key |Value Type |Example
  967. |toc_dot_leader_content
  968. |double-quoted string
  969. |dot_leader_content: ". "
  970. |toc_dot_leader_color
  971. |<<colors,color>>
  972. |dot_leader_color: 999999
  973. |toc_font_color
  974. |<<colors,color>>
  975. |font_color: 333333
  976. |toc_h<n>_font_color
  977. |<<colors,color>>
  978. |h3_font_color: 999999
  979. |toc_font_family
  980. |<<fonts,font family name>>
  981. |font_family: NotoSerif
  982. |toc_font_size
  983. |<<values,number>>
  984. |font_size: 9
  985. |toc_font_style
  986. |normal, italic, bold, bold_italic
  987. |font_style: bold
  988. |toc_line_height
  989. |number
  990. |line_height: 1.5
  991. |toc_indent
  992. |<<measurement-units,measurement>>
  993. |indent: 20
  994. |toc_margin_top
  995. |<<measurement-units,measurement>>
  996. |indent: 20
  997. |===
  998. === Running header & footer
  999. [cols="3,3,5m"]
  1000. |===
  1001. |Key |Value Type |Example
  1002. |header_background_color
  1003. |<<colors,color>>
  1004. |background_color: EEEEEE
  1005. |header_border_color
  1006. |<<colors,color>>
  1007. |border_color: DDDDDD
  1008. |header_border_width
  1009. |<<measurement-units,measurement>>
  1010. |border_width: 0.25
  1011. |header_font_color
  1012. |<<colors,color>>
  1013. |font_color: 333333
  1014. |header_font_family
  1015. |<<fonts,font family name>>
  1016. |font_family: NotoSerif
  1017. |header_font_size
  1018. |<<values,number>>
  1019. |font_size: 9
  1020. |header_font_style
  1021. |normal, italic, bold, bold_italic
  1022. |font_style: italic
  1023. |header_height
  1024. |<<measurement-units,measurement>>
  1025. |height: 0.75in
  1026. |header_padding
  1027. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  1028. |padding: [0, 3, 0, 3]
  1029. |header_image_valign
  1030. |top, center, bottom, <<measurement-units,measurement>>
  1031. |image_valign: 4
  1032. |header_valign
  1033. |top, center, bottom
  1034. |valign: center
  1035. |header_<side>_content_<align>^[1]^
  1036. |quoted string
  1037. |right: '\{page-number}'
  1038. |footer_background_color
  1039. |<<colors,color>>
  1040. |background_color: EEEEEE
  1041. |footer_border_color
  1042. |<<colors,color>>
  1043. |border_color: DDDDDD
  1044. |footer_border_width
  1045. |<<measurement-units,measurement>>
  1046. |border_width: 0.25
  1047. |footer_font_color
  1048. |<<colors,color>>
  1049. |font_color: 333333
  1050. |footer_font_family
  1051. |<<fonts,font family name>>
  1052. |font_family: NotoSerif
  1053. |footer_font_size
  1054. |<<values,number>>
  1055. |font_size: 9
  1056. |footer_font_style
  1057. |normal, italic, bold, bold_italic
  1058. |font_style: italic
  1059. |footer_height
  1060. |<<measurement-units,measurement>>
  1061. |height: 0.75in
  1062. |footer_padding
  1063. |<<measurement-units,measurement>>, <<measurement-units,measurement array [4]>>
  1064. |padding: [0, 3, 0, 3]
  1065. |footer_image_valign
  1066. |top, center, bottom, <<measurement-units,measurement>>
  1067. |image_valign: 4
  1068. |footer_valign
  1069. |top, center, bottom
  1070. |valign: top
  1071. |footer_<side>_content_<align>^[1]^
  1072. |quoted string
  1073. |center: '\{page-number}'
  1074. |===
  1075. ^[1]^ `<side>` can be `recto` (odd pages) or `verso` (even pages).
  1076. `<align>` can be `left`, `center` or `right`.
  1077. IMPORTANT: You must define a height for the running header or footer, respectively, or it will not be shown.
  1078. NOTE: The background color spans the width of the page.
  1079. When a background color is specified, the border also spans the width of the page.
  1080. ==== Implicit attributes
  1081. In addition to the document-level attributes defined in the AsciiDoc document, the following attributes are available when defining the content keys in the footer:
  1082. * page-count
  1083. * page-number
  1084. * document-title
  1085. * document-subtitle
  1086. * chapter-title
  1087. * section-title
  1088. * section-or-chapter-title
  1089. Here's an example that shows how these attributes can be used in the running footer:
  1090. [source,yaml]
  1091. ----
  1092. footer:
  1093. height: 0.75in
  1094. recto_content:
  1095. right: '{section-or-chapter-title} | {page-number}'
  1096. verso_content:
  1097. left: '{page-number} | {chapter-title}'
  1098. ----
  1099. ==== Images
  1100. You can add an image to the running header or footer using the AsciiDoc inline image syntax.
  1101. Note that the image must be the whole value for a given position (left, center or right).
  1102. It cannot be combined with text.
  1103. Here's an example of how to use an image in the running header (which also applies for the footer).
  1104. [source,yaml]
  1105. ----
  1106. header:
  1107. height: 0.75in
  1108. image_valign: 2 # <1>
  1109. recto_content:
  1110. center: image:footer-logo.png[width=80]
  1111. verso_content:
  1112. center: $header_recto_content_center
  1113. ----
  1114. <1> You can use the `footer_valign` attribute to slighly nudge the image up or down.
  1115. CAUTION: The image must fit in the allotted space for the running header or footer.
  1116. Otherwise, you will run into layout issues.
  1117. Adjust the width attribute accordingly.
  1118. == Applying your theme
  1119. After creating a theme, you'll need to tell Asciidoctor PDF where to find it.
  1120. This is done using AsciiDoc attributes.
  1121. There are three AsciiDoc attributes that tell Asciidoctor PDF how to locate and apply your theme.
  1122. pdf-stylesdir:: The directory where the theme file is located.
  1123. _Specifying an absolute path is recommended._
  1124. +
  1125. If you use images in your theme, image paths are resolved relative to this directory.
  1126. pdf-style:: The name of the YAML theme file to load.
  1127. If the name ends with `.yml`, it's assumed to be the complete name of a file.
  1128. Otherwise, `-theme.yml` is appended to the name to make the file name (i.e., `<name>-theme.yml`).
  1129. pdf-fontsdir:: The directory where the fonts used by your theme, if any, are located.
  1130. _Specifying an absolute path is recommended._
  1131. Let's assume that you've put your theme files inside a directory named `resources` with the following layout:
  1132. ....
  1133. document.adoc
  1134. resources/
  1135. themes/
  1136. basic-theme.yml
  1137. fonts/
  1138. roboto-normal.ttf
  1139. roboto-italic.ttf
  1140. roboto-bold.ttf
  1141. roboto-bold_italic.ttf
  1142. ....
  1143. Here's how you'd load your theme when calling Asciidoctor PDF:
  1144. $ asciidoctor-pdf -a pdf-stylesdir=resources/themes -a pdf-style=basic -a pdf-fontsdir=resources/fonts
  1145. If all goes well, Asciidoctor PDF should run without an error or warning.
  1146. NOTE: You only need to specify the `pdf-fontsdir` if you are using custom fonts in your theme.
  1147. You can skip setting the `pdf-stylesdir` attribute and just pass the absolute path of your theme file to the `pdf-style` attribute.
  1148. $ asciidoctor-pdf -a pdf-style=resources/themes/basic-theme.yml -a pdf-fontsdir=resources/fonts
  1149. However, in this case, image paths in your theme won't be resolved properly.
  1150. Paths are resolved relative to the current directory.
  1151. However, in the future, this may change so that paths are resolved relative to the base directory (typically the document's directory).
  1152. Therefore, it's recommend that you specify absolute paths for now to future-proof your configuration.
  1153. $ asciidoctor-pdf -a pdf-stylesdir=/path/to/resources/themes -a pdf-style=basic -a pdf-fontsdir=/path/to/resources/fonts