Skip to content

Commit

Permalink
Use asciidoctor-pdf
Browse files Browse the repository at this point in the history
Using asciidoctor-pdf it would be easier to generate differnt formats of
documents with single source. For example, pdf file generation can use
its' own custom settings, and still benefits the same foundation of
asciidoc.

This change mainly includes improvement of pdf file generation.
- Header/Footer
- TOC
- Appendix
- Admonition icon is now available in pdf

NOTE: This is still WIP, so keeping old commands in Makefile
  • Loading branch information
hirotnk authored and happi committed Apr 22, 2020
1 parent 0782ede commit 544d97f
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ xml/beam-book-from-ab.xml: chapters/opcodes_doc.asciidoc
beam-book.pdf: xml/beam-book-from-ab.xml
dblatex $(DBLATEX_OPTS) xml/beam-book-from-ab.xml -o $@

### Experimental pdf command
beam-book2.pdf: chapters/opcodes_doc.asciidoc
asciidoctor-pdf -r ./custom-pdf-converter.rb --doctype book -a media=prepress -a pdf-style=pdf-theme.yml book.asciidoc -o $@

index.html:
asciidoctor -r asciidoctor-diagram --backend=html5 --doctype=book -o site/index.html book.asciidoc

Expand Down
34 changes: 34 additions & 0 deletions custom-pdf-converter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class CustomPDFConverter < (Asciidoctor::Converter.for 'pdf')
register_for 'pdf'

# Customize the layout of part titles
def layout_part_title node, title, opts = {}
puts 'Processing node.id:' + node.id
puts 'Processing title:' + title
num_part, title = title.split ':', 2
move_down 150
typeset_text num_part + "\n" + title, (calc_line_metrics 1.5), inline_format: true, align: :center
end

# Customize the layout of:
# - Preface
# - Appendix
# - Chapter
def layout_chapter_title node, title, opts = {}
puts 'Processing node.id:' + node.id
puts 'Processing title:' + title
if title == "Preface" or title.include? "Appendix"
move_down 1
typeset_text title, (calc_line_metrics 1.5), inline_format: true, align: :right, size: 21
stroke_horizontal_rule '000000', line_width: 0.5, line_style: :solid
else
num_chapter, title = title.split '.', 2
typeset_text num_chapter, (calc_line_metrics 1.5), inline_format: true, align: :right, size: 15
move_down 1
stroke_horizontal_rule '000000', line_width: 0.5, line_style: :solid
typeset_text title, (calc_line_metrics 1.5), inline_format: true, align: :right, size: 21
end
move_down 50
end
end

266 changes: 266 additions & 0 deletions pdf-theme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
#
# This file was copied from default-theme.yml of ascii-doctor-pdf, and customized for the BEAM book.
# - header and footer was customized
font:
catalog:
# Noto Serif supports Latin, Latin-1 Supplement, Latin Extended-A, Greek, Cyrillic, Vietnamese & an assortment of symbols
Noto Serif:
normal: GEM_FONTS_DIR/notoserif-regular-subset.ttf
bold: GEM_FONTS_DIR/notoserif-bold-subset.ttf
italic: GEM_FONTS_DIR/notoserif-italic-subset.ttf
bold_italic: GEM_FONTS_DIR/notoserif-bold_italic-subset.ttf
# M+ 1mn supports ASCII and the circled numbers used for conums
M+ 1mn:
normal: GEM_FONTS_DIR/mplus1mn-regular-subset.ttf
bold: GEM_FONTS_DIR/mplus1mn-bold-subset.ttf
italic: GEM_FONTS_DIR/mplus1mn-italic-subset.ttf
bold_italic: GEM_FONTS_DIR/mplus1mn-bold_italic-subset.ttf
page:
background_color: FFFFFF
layout: portrait
initial_zoom: FitH
margin: [0.82in, 0.67in, 0.75in, 0.67in]
# margin_inner and margin_outer keys are used for recto/verso print margins when media=prepress
margin_inner: 0.55in
margin_outer: 0.39in
size: A4
base:
align: justify
# color as hex string (leading # is optional)
font_color: 000000
font_family: Times-Roman
font_size: 10
line_height_length: 11.25
line_height: $base_line_height_length / $base_font_size
font_size_large: round($base_font_size * 1.25)
font_size_small: round($base_font_size * 0.85)
font_size_min: $base_font_size * 0.75
font_style: normal
border_color: EEEEEE
border_radius: 4
border_width: 0.5
header:
border-color: #dddddd
height: 0.65in
line-height: 1.0
vertical-align: bottom
recto:
right:
content: '{document-title} {part-title}'
verso:
left:
content: $header-recto-right-content
running-content:
start-at: 4
footer:
border-color: #dddddd
height: 0.65in
line-height: 1.0
vertical-align: top
padding: [3, 0, 0, 0]
recto:
right:
content: '{part-title} {section-or-chapter-title} {page-number} / {page-count}'
verso:
left:
content: '{page-number} / {page-count} {chapter-title}'
role:
line-through:
text_decoration: line-through
underline:
text_decoration: underline
big:
font_size: $base_font_size_large
small:
font_size: $base_font_size_small
subtitle:
font_color: 999999
font_size: 0.8em
font_style: normal_italic
vertical_rhythm: $base_line_height_length
horizontal_rhythm: $base_line_height_length
vertical_spacing: $vertical_rhythm
link:
font_color: 428BCA
# literal is currently used for inline monospaced in prose and table cells
literal:
font_color: B12146
font_family: M+ 1mn
button:
content: "[\u2009%s\u2009]"
font_style: bold
key:
background_color: F5F5F5
border_color: CCCCCC
border_offset: 2
border_radius: 2
border_width: 0.5
font_family: $literal_font_family
separator: "\u202f+\u202f"
mark:
background_color: FFFF00
border_offset: 1
menu:
caret_content: " <font size=\"1.15em\"><color rgb=\"b12146\">\u203a</color></font> "
heading:
align: left
font_color: $base_font_color
font_style: bold
# h1 is used for part titles (book doctype) or the doctitle (article doctype)
h1_font_size: floor($base_font_size * 2.6)
# h2 is used for chapter titles (book doctype only)
h2_font_size: floor($base_font_size * 2.15)
h3_font_size: round($base_font_size * 1.7)
h4_font_size: $base_font_size_large
h5_font_size: $base_font_size
h6_font_size: $base_font_size_small
line_height: 1
margin_top: $vertical_rhythm * 0.4
margin_bottom: $vertical_rhythm * 0.9
min_height_after: $base_line_height_length * 1.5
title_page:
align: right
logo:
top: 10%
title:
top: 55%
font_size: $heading_h1_font_size
font_color: 999999
line_height: 0.9
subtitle:
font_size: $heading_h3_font_size
font_style: bold_italic
line_height: 1
authors:
margin_top: $base_font_size * 1.25
font_size: $base_font_size_large
font_color: 181818
revision:
margin_top: $base_font_size * 1.25
block:
margin_top: 0
margin_bottom: $vertical_rhythm
caption:
align: left
font_size: $base_font_size * 0.95
font_style: italic
margin_inside: $vertical_rhythm / 3
margin_outside: 0
lead:
font_size: $base_font_size_large
line_height: 1.4
abstract:
font_color: 5C6266
font_size: $lead_font_size
line_height: $lead_line_height
font_style: italic
first_line_font_style: bold
title:
align: center
font_color: $heading_font_color
font_size: $heading_h4_font_size
font_style: $heading_font_style
admonition:
column_rule_color: $base_border_color
column_rule_width: $base_border_width
padding: [0, $horizontal_rhythm, 0, $horizontal_rhythm]
#icon:
# tip:
# name: far-lightbulb
# stroke_color: 111111
# size: 24
label:
text_transform: uppercase
font_style: bold
blockquote:
font_size: $base_font_size_large
border_color: $base_border_color
border_width: 0
border_left_width: 5
padding: [0, $horizontal_rhythm, $block_margin_bottom * -0.75, $horizontal_rhythm + $blockquote_border_left_width / 2]
cite_font_size: $base_font_size_small
cite_font_color: 999999
verse:
font_size: $blockquote_font_size
border_color: $blockquote_border_color
border_width: $blockquote_border_width
border_left_width: $blockquote_border_left_width
padding: $blockquote_padding
cite_font_size: $blockquote_cite_font_size
cite_font_color: $blockquote_cite_font_color
# code is used for source blocks (perhaps change to source or listing?)
code:
font_color: $base_font_color
#font_family: $literal_font_family
font_family: Courier
font_size: ceil($base_font_size)
padding: $code_font_size
line_height: 1.25
# line_gap is an experimental property to control how a background color is applied to an inline block element
line_gap: 3.8
background_color: F5F5F5
conum:
font_family: $literal_font_family
font_color: $literal_font_color
font_size: $base_font_size
line_height: 4 / 3
glyphs: circled
example:
border_color: $base_border_color
border_radius: $base_border_radius
border_width: 0.75
background_color: $page_background_color
padding: [$vertical_rhythm, $horizontal_rhythm, 0, $horizontal_rhythm]
image:
align: left
prose:
margin_top: $block_margin_top
margin_bottom: $block_margin_bottom
sidebar:
background_color: EEEEEE
border_color: E1E1E1
border_radius: $base_border_radius
border_width: $base_border_width
padding: [$vertical_rhythm, $vertical_rhythm * 1.25, 0, $vertical_rhythm * 1.25]
title:
align: center
font_color: $heading_font_color
font_size: $heading_h4_font_size
font_style: $heading_font_style
thematic_break:
border_color: $base_border_color
border_style: solid
border_width: $base_border_width
margin_top: $vertical_rhythm * 0.5
margin_bottom: $vertical_rhythm * 1.5
description_list:
term_font_style: bold
term_spacing: $vertical_rhythm / 4
description_indent: $horizontal_rhythm * 1.25
outline_list:
indent: $horizontal_rhythm * 1.5
# NOTE outline_list_item_spacing applies to list items that do not have complex content
item_spacing: $vertical_rhythm / 2
table:
background_color: $page_background_color
border_color: DDDDDD
border_width: $base_border_width
cell_padding: 3
head:
font_style: bold
border_bottom_width: $base_border_width * 2.5
body:
stripe_background_color: F9F9F9
foot:
background_color: F0F0F0
sectnums:
levels: 5
toc:
indent: $horizontal_rhythm
line_height: 1.4
dot_leader:
content: ". "
font_color: A9A9A9
footnotes:
font_size: round($base_font_size * 0.75)
item_spacing: $outline_list_item_spacing / 2

0 comments on commit 544d97f

Please sign in to comment.