asciidoctor-pdf 1.6.2 → 2.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.adoc +224 -30
- data/NOTICE.adoc +16 -4
- data/README.adoc +207 -67
- data/asciidoctor-pdf.gemspec +3 -7
- data/data/fonts/ABOUT-mplus1mn-subset +1 -1
- data/data/fonts/ABOUT-mplus1p-subset +2 -2
- data/data/fonts/ABOUT-notosans-subset +26 -0
- data/data/fonts/ABOUT-notoserif-subset +1 -1
- data/data/fonts/{LICENSE-notoserif → LICENSE-noto} +0 -0
- data/data/fonts/mplus1mn-bold-subset.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-regular-subset.ttf +0 -0
- data/data/fonts/mplus1p-regular-fallback.ttf +0 -0
- data/data/fonts/notoemoji-subset.ttf +0 -0
- data/data/fonts/notosans-bold-subset.ttf +0 -0
- data/data/fonts/notosans-bold_italic-subset.ttf +0 -0
- data/data/fonts/notosans-italic-subset.ttf +0 -0
- data/data/fonts/notosans-regular-subset.ttf +0 -0
- data/data/fonts/notoserif-bold-subset.ttf +0 -0
- data/data/fonts/notoserif-bold_italic-subset.ttf +0 -0
- data/data/fonts/notoserif-italic-subset.ttf +0 -0
- data/data/fonts/notoserif-regular-subset.ttf +0 -0
- data/data/themes/base-theme.yml +18 -22
- data/data/themes/default-for-print-theme.yml +24 -0
- data/data/themes/default-for-print-with-fallback-font-theme.yml +3 -0
- data/data/themes/default-theme.yml +49 -54
- data/data/themes/default-with-fallback-font-theme.yml +2 -2
- data/data/themes/sans-with-fallback-font-theme.yml +10 -0
- data/docs/theming-guide.adoc +967 -344
- data/lib/asciidoctor/pdf/converter.rb +1691 -1478
- data/lib/asciidoctor/pdf/ext/asciidoctor/document.rb +18 -1
- data/lib/asciidoctor/pdf/ext/asciidoctor/image.rb +9 -15
- data/lib/asciidoctor/pdf/ext/asciidoctor/list.rb +6 -13
- data/lib/asciidoctor/pdf/ext/asciidoctor/section.rb +3 -16
- data/lib/asciidoctor/pdf/ext/asciidoctor.rb +1 -5
- data/lib/asciidoctor/pdf/ext/core/file.rb +1 -1
- data/lib/asciidoctor/pdf/ext/core/quantifiable_stdout.rb +1 -4
- data/lib/asciidoctor/pdf/ext/core/string.rb +2 -2
- data/lib/asciidoctor/pdf/ext/core.rb +1 -4
- data/lib/asciidoctor/pdf/ext/pdf-core/page.rb +8 -33
- data/lib/asciidoctor/pdf/ext/pdf-core.rb +0 -18
- data/lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb +5 -7
- data/lib/asciidoctor/pdf/ext/prawn/extensions.rb +433 -329
- data/lib/asciidoctor/pdf/ext/prawn/font/afm.rb +0 -4
- data/lib/asciidoctor/pdf/ext/prawn/font_metric_cache.rb +1 -1
- data/lib/asciidoctor/pdf/ext/prawn/formatted_text/arranger.rb +33 -3
- data/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +20 -14
- data/lib/asciidoctor/pdf/ext/prawn/formatted_text/fragment.rb +9 -3
- data/lib/asciidoctor/pdf/ext/prawn/images.rb +14 -16
- data/lib/asciidoctor/pdf/ext/prawn-svg/loaders/data.rb +6 -0
- data/lib/asciidoctor/pdf/ext/prawn-svg/loaders/web.rb +22 -0
- data/lib/asciidoctor/pdf/ext/prawn-svg/url_loader.rb +13 -0
- data/lib/asciidoctor/pdf/ext/prawn-svg.rb +5 -2
- data/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb +76 -20
- data/lib/asciidoctor/pdf/ext/prawn-table/cell/text.rb +39 -1
- data/lib/asciidoctor/pdf/ext/prawn-table/cell.rb +21 -15
- data/lib/asciidoctor/pdf/ext/prawn-table.rb +1 -1
- data/lib/asciidoctor/pdf/ext/pygments.rb +2 -2
- data/lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb +17 -20
- data/lib/asciidoctor/pdf/ext/rouge/themes/asciidoctor_pdf_default.rb +1 -0
- data/lib/asciidoctor/pdf/ext/rouge.rb +0 -1
- data/lib/asciidoctor/pdf/formatted_text/formatter.rb +2 -2
- data/lib/asciidoctor/pdf/formatted_text/inline_destination_marker.rb +8 -10
- data/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb +69 -78
- data/lib/asciidoctor/pdf/formatted_text/inline_image_renderer.rb +7 -10
- data/lib/asciidoctor/pdf/formatted_text/inline_text_aligner.rb +2 -4
- data/lib/asciidoctor/pdf/formatted_text/parser.rb +53 -47
- data/lib/asciidoctor/pdf/formatted_text/parser.treetop +5 -7
- data/lib/asciidoctor/pdf/formatted_text/source_wrap.rb +14 -14
- data/lib/asciidoctor/pdf/formatted_text/text_background_and_border_renderer.rb +4 -7
- data/lib/asciidoctor/pdf/formatted_text/transform.rb +116 -109
- data/lib/asciidoctor/pdf/formatted_text.rb +0 -1
- data/lib/asciidoctor/pdf/index_catalog.rb +7 -11
- data/lib/asciidoctor/pdf/optimizer.rb +3 -5
- data/lib/asciidoctor/pdf/pdfmark.rb +16 -8
- data/lib/asciidoctor/pdf/roman_numeral.rb +4 -22
- data/lib/asciidoctor/pdf/sanitizer.rb +18 -13
- data/lib/asciidoctor/pdf/section_info_by_page.rb +24 -0
- data/lib/asciidoctor/pdf/theme_loader.rb +89 -79
- data/lib/asciidoctor/pdf/version.rb +1 -2
- data/lib/asciidoctor/pdf.rb +5 -2
- metadata +34 -64
- data/data/fonts/mplus1mn-bold-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-regular-ascii-conums.ttf +0 -0
- data/lib/asciidoctor/pdf/ext/asciidoctor/abstract_block.rb +0 -7
- data/lib/asciidoctor/pdf/ext/asciidoctor/abstract_node.rb +0 -7
- data/lib/asciidoctor/pdf/ext/asciidoctor/list_item.rb +0 -18
- data/lib/asciidoctor/pdf/ext/asciidoctor/logging_shim.rb +0 -33
- data/lib/asciidoctor/pdf/ext/core/array.rb +0 -11
- data/lib/asciidoctor/pdf/ext/core/hash.rb +0 -7
- data/lib/asciidoctor/pdf/ext/core/regexp.rb +0 -5
- data/lib/asciidoctor/pdf/ext/pdf-core/pdf_object.rb +0 -8
- data/lib/asciidoctor-pdf/converter.rb +0 -3
- data/lib/asciidoctor-pdf/version.rb +0 -3
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Asciidoctor PDF: A native PDF converter for AsciiDoc
|
2
2
|
Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
|
3
|
-
|
3
|
+
v2.0.0.alpha.1, 2022-04-20
|
4
4
|
// Settings:
|
5
5
|
:experimental:
|
6
6
|
:idprefix:
|
@@ -23,15 +23,14 @@ endif::[]
|
|
23
23
|
:project-name: Asciidoctor PDF
|
24
24
|
:project-handle: asciidoctor-pdf
|
25
25
|
// Variables:
|
26
|
-
:release-line:
|
27
|
-
:release-version:
|
26
|
+
:release-line: 2.0.x
|
27
|
+
:release-version: 2.0.0.alpha.1
|
28
28
|
// URIs:
|
29
29
|
:url-asciidoctor: http://asciidoctor.org
|
30
30
|
:url-gem: http://rubygems.org/gems/asciidoctor-pdf
|
31
31
|
:url-project: https://github.com/asciidoctor/asciidoctor-pdf
|
32
32
|
:url-project-repo: {url-project}
|
33
33
|
:url-project-issues: {url-project-repo}/issues
|
34
|
-
:url-project-list: http://discuss.asciidoctor.org
|
35
34
|
:url-prawn: http://prawnpdf.org
|
36
35
|
:url-prawn-gmagick: https://github.com/packetmonkey/prawn-gmagick
|
37
36
|
:url-prawn-svg: https://github.com/mogest/prawn-svg
|
@@ -41,7 +40,7 @@ endif::[]
|
|
41
40
|
|
42
41
|
ifdef::status[]
|
43
42
|
image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg[project chat,link=https://asciidoctor.zulipchat.com/]
|
44
|
-
image:{url-project-repo}/workflows/CI/badge.svg
|
43
|
+
image:{url-project-repo}/workflows/CI/badge.svg[Build Status (GitHub Actions),link={url-project-repo}/actions?query=workflow%3ACI+branch%3Amain]
|
45
44
|
image:https://img.shields.io/gem/v/asciidoctor-pdf.svg[Latest Release, link={url-gem}]
|
46
45
|
endif::[]
|
47
46
|
|
@@ -50,11 +49,11 @@ It bypasses the requirement to generate an intermediary format such as DocBook,
|
|
50
49
|
Instead, you can use this extension to convert your documents directly from AsciiDoc to PDF.
|
51
50
|
Its aim is to take the pain out of creating PDF documents from AsciiDoc.
|
52
51
|
|
53
|
-
NOTE: You're viewing the documentation for the {release-line} release line.
|
52
|
+
NOTE: You're viewing the documentation for the (unreleased) {release-line} release line.
|
54
53
|
If you're looking for the documentation for another release line, please refer to one of the following branches: +
|
55
|
-
{url-project-repo}/tree/main#readme[2.0.x]
|
56
|
-
⁃
|
57
54
|
{url-project-repo}/tree/v1.5.x#readme[1.5.x]
|
55
|
+
-
|
56
|
+
{url-project-repo}/tree/v1.6.x#readme[1.6.x]
|
58
57
|
|
59
58
|
toc::[]
|
60
59
|
|
@@ -91,7 +90,9 @@ But don't miss the <<Highlights>> to get a preview of what's possible.
|
|
91
90
|
* Page numbering
|
92
91
|
* Double-sided (aka prepress) printing mode (i.e., margins alternate on recto and verso pages)
|
93
92
|
* Customizable running content (header and footer)
|
94
|
-
* “Keep together” blocks (i.e., page breaks avoided in certain block content)
|
93
|
+
* “Keep together” blocks (i.e., page breaks avoided in certain block content):
|
94
|
+
** Explicitly delimited blocks other than open blocks
|
95
|
+
** Open blocks with the "unbreakable" option `[%unbreakable]`
|
95
96
|
* Orphaned section titles avoided
|
96
97
|
* Autofit verbatim blocks (as permitted by base_font_size_min setting)
|
97
98
|
* Table border settings honored
|
@@ -103,27 +104,31 @@ But don't miss the <<Highlights>> to get a preview of what's possible.
|
|
103
104
|
|
104
105
|
== Known Limitations
|
105
106
|
|
106
|
-
* Footnotes are always
|
107
|
-
*
|
108
|
-
*
|
109
|
-
* Columns cannot be assigned a 0% width (or a width less than the width of a single character); in the same vein, a column cannot be set to autowidth if width of all other columns meets or exceeds 100%; the result is that the converter with throw a Prawn::Errors::CannotFit error
|
110
|
-
* An inline image in a table cell will not force the column wider if the width of the image exceeds the width of the column; either reduce the image width using `pdfwidth
|
111
|
-
* Must use development version of prawn
|
112
|
-
*
|
113
|
-
*
|
114
|
-
*
|
115
|
-
*
|
116
|
-
*
|
117
|
-
*
|
118
|
-
|
107
|
+
* Footnotes are always displayed as endnotes (at the end of chapter for books; at the end of document for all other doctypes).
|
108
|
+
*Footnotes cannot be displayed at the bottom of the page because the PDF generator does not support content reflows* (see {url-project-issues}/85#issuecomment-577412975[#85] for reasoning).
|
109
|
+
* Table cells that exceed the height of a single page will be truncated (see https://github.com/prawnpdf/prawn-table/issues/41[prawn-table#41]).
|
110
|
+
* Columns cannot be assigned a 0% width (or a width less than the width of a single character); in the same vein, a column cannot be set to autowidth if width of all other columns meets or exceeds 100%; the result is that the converter with throw a Prawn::Errors::CannotFit error.
|
111
|
+
* An inline image in a table cell will not force the column wider if the width of the image exceeds the width of the column; either reduce the image width using `pdfwidth`, increase the width of the column using `cols`, or convert the cell to an AsciiDoc table cell and, preferably, use a block image (see {url-project-issues}/830).
|
112
|
+
* Must use development version of prawn for error to include font name when requested font style is missing.
|
113
|
+
* AsciiDoc table cell leaves padding below last block (due to lack of margin collapsing).
|
114
|
+
* Prawn does not support double-wide box drawing glyphs correctly, so box drawings aren't aligned properly in verbatim blocks (see https://github.com/prawnpdf/prawn/issues/1002[prawn#1002]).
|
115
|
+
* Orphan / widow support is limited; a page break can occur between a section title and its section content, a table caption and the caption, etc.; use a manual page break to avoid.
|
116
|
+
* If a no-break hyphen is surrounded by formatted text on both sides (or is formatted individually), it will not prevent a line break.
|
117
|
+
* Images cannot float.
|
118
|
+
* You cannot use inline HTML (like a link or emphasized text) in a source block that also uses syntax highlighting.
|
119
|
+
These two technologies just don't combine in the PDF generation process due to how the syntax highlighters work.
|
120
|
+
* Verse blocks do not use a fixed-width font by default, but you can control this setting using the theme.
|
121
|
+
* An inline image with a percentage width value in an autowidth table cell is resized relative to its intrinsic width.
|
122
|
+
The space reserved for the image matches its intrinsic width.
|
123
|
+
This matches the behavior of HTML.
|
119
124
|
|
120
125
|
== Prerequisites
|
121
126
|
|
122
|
-
All that's needed is Ruby
|
127
|
+
All that's needed is Ruby 2.5 or better (or JRuby 9.2 or better) and a few Ruby gems (including at least Asciidoctor 2.0.0), which we explain how to install in the next section.
|
123
128
|
|
124
129
|
To check if you have Ruby available, use the `ruby` command to query the version installed:
|
125
130
|
|
126
|
-
$ ruby
|
131
|
+
$ ruby -e 'puts RUBY_VERSION'
|
127
132
|
|
128
133
|
Make sure this command reports a Ruby version that's at least 2.5.
|
129
134
|
If so, you may proceed.
|
@@ -167,6 +172,13 @@ Then, install the gem from RubyGems.org using the following command:
|
|
167
172
|
|
168
173
|
$ gem install asciidoctor-pdf
|
169
174
|
|
175
|
+
If you're using Ruby 3.1 or better, you must also install the matrix gem until Prawn 2.5.0 or better is released.
|
176
|
+
|
177
|
+
$ gem install matrix
|
178
|
+
|
179
|
+
The matrix gem used to be bundled in the Ruby distribution, but was split out starting in Ruby 3.1.
|
180
|
+
This requirement will be lifted once Prawn declares it as a runtime dependency.
|
181
|
+
|
170
182
|
==== Installation Troubleshooting
|
171
183
|
|
172
184
|
If you get a permission error while installing the gem, such as the one below, it's likely you're attempting to install the gem directly into your system.
|
@@ -219,16 +231,16 @@ You then activate syntax highlighting for a given document by adding the `source
|
|
219
231
|
:source-highlighter: rouge
|
220
232
|
----
|
221
233
|
|
222
|
-
|
234
|
+
[#use-dev-versions]
|
235
|
+
==== Upgrade prawn
|
223
236
|
|
224
|
-
{project-name} uses Prawn to handle the PDF generation
|
225
|
-
At times, there may be development features
|
237
|
+
{project-name} uses Prawn to handle the PDF generation.
|
238
|
+
At times, there may be development features or fixes you need in Prawn or one of its extensions that's still unreleased.
|
226
239
|
No problem.
|
227
|
-
You can
|
240
|
+
You can gain access to these features by installing the unreleased gems directly from GitHub.
|
228
241
|
|
229
242
|
To get started, first create a [.path]_Gemfile_ in the root of your project.
|
230
|
-
In that file, declare the gem source, the {project-handle} gem, and the prawn gem
|
231
|
-
In this example, we'll install both the prawn and prawn-table gems from GitHub.
|
243
|
+
In that file, declare the gem source, the {project-handle} gem, and the prawn gem (plus any other development gems you want to use).
|
232
244
|
|
233
245
|
.Gemfile
|
234
246
|
[source,ruby]
|
@@ -236,8 +248,7 @@ In this example, we'll install both the prawn and prawn-table gems from GitHub.
|
|
236
248
|
source 'https://rubygems.org'
|
237
249
|
|
238
250
|
gem 'asciidoctor-pdf'
|
239
|
-
gem 'prawn', github: 'prawnpdf/prawn'
|
240
|
-
gem 'prawn-table', github: 'prawnpdf/prawn-table'
|
251
|
+
gem 'prawn', github: 'prawnpdf/prawn', branch: 'HEAD'
|
241
252
|
----
|
242
253
|
|
243
254
|
You can then install the gems into your project using the `bundle` command:
|
@@ -347,11 +358,18 @@ You can get such a theme by installing the `asciidoctor-pdf-cjk-kai_gen_gothic`
|
|
347
358
|
The https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic[asciidoctor-pdf-cjk-kai_gen_gothic] project provides themes optimized for CJK languages based on the kai_gen_gothic font.
|
348
359
|
See the https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic[asciidoctor-pdf-cjk-kai_gen_gothic] project README for detailed setup instructions.
|
349
360
|
|
361
|
+
WARNING: The theme provided by the `asciidoctor-pdf-cjk-kai_gen_gothic` gem is no longer compatiable with the stable release of Asciidoctor PDF.
|
362
|
+
However, you can still use it to create a <<Create a Custom CJK Theme,custom CJK theme>>.
|
363
|
+
|
350
364
|
Once you have that gem installed (and the fonts), you need to tell Asciidoctor PDF to use one of the themes.
|
351
365
|
If you're converting a document that is primarily written in Japanese, you'd run Asciidoctor PDF as follows:
|
352
366
|
|
353
367
|
asciidoctor-pdf -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-theme=KaiGenGothicJP document.adoc
|
354
368
|
|
369
|
+
If that command fails, you may have better luck creating your own CJK theme.
|
370
|
+
|
371
|
+
=== Create a Custom CJK Theme
|
372
|
+
|
355
373
|
You also have to option of creating your own theme gem that uses fonts of your choice.
|
356
374
|
For example, if you want to use the `asciidoctor-pdf-cjk-kai_gen_gothic` gem to fetch fonts, but then use them in your own theme, here's how you'd do it.
|
357
375
|
|
@@ -363,27 +381,23 @@ For example, if you want to use the `asciidoctor-pdf-cjk-kai_gen_gothic` gem to
|
|
363
381
|
|
364
382
|
$ asciidoctor-pdf-cjk-kai_gen_gothic-install
|
365
383
|
|
366
|
-
. Create a theme that extends the default theme:
|
384
|
+
. Create a theme file named [.path]_cjk-theme.yml_ that extends the default theme to override the fonts:
|
367
385
|
+
|
368
386
|
[source,yml]
|
369
387
|
----
|
370
388
|
extends: default
|
371
389
|
font:
|
372
390
|
catalog:
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
normal: GEM_FONTS_DIR/mplus1mn-regular-subset.ttf
|
380
|
-
bold: GEM_FONTS_DIR/mplus1mn-bold-subset.ttf
|
381
|
-
italic: GEM_FONTS_DIR/mplus1mn-italic-subset.ttf
|
382
|
-
bold_italic: GEM_FONTS_DIR/mplus1mn-bold_italic-subset.ttf
|
391
|
+
merge: true
|
392
|
+
KaiGen Gothic CN:
|
393
|
+
normal: KaiGenGothicCN-Regular.ttf
|
394
|
+
bold: KaiGenGothicCN-Bold.ttf
|
395
|
+
italic: KaiGenGothicCN-Regular-Italic.ttf
|
396
|
+
bold_italic: KaiGenGothicCN-Bold-Italic.ttf
|
383
397
|
fallbacks:
|
384
|
-
- KaiGen Gothic
|
398
|
+
- KaiGen Gothic CN
|
385
399
|
base:
|
386
|
-
font-family: KaiGen Gothic
|
400
|
+
font-family: KaiGen Gothic CN
|
387
401
|
heading:
|
388
402
|
font-family: $base-font-family
|
389
403
|
abstract:
|
@@ -396,9 +410,10 @@ sidebar:
|
|
396
410
|
|
397
411
|
. Load your theme when running Asciidoctor PDF:
|
398
412
|
|
399
|
-
$ asciidoctor-pdf -a scripts=cjk -a pdf-theme=./
|
413
|
+
$ asciidoctor-pdf -a scripts=cjk -a pdf-theme=./cjk-theme.yml -a pdf-fontsdir=GEM_FONTS_DIR,`ruby -r asciidoctor-pdf-cjk-kai_gen_gothic -e "print File.expand_path '../fonts', (Gem.datadir 'asciidoctor-pdf-cjk-kai_gen_gothic')"` document.adoc
|
400
414
|
|
401
415
|
The `-a pdf-fontsdir` option is important to tell Asciidoctor PDF where to find your custom fonts.
|
416
|
+
(Note that the inclusion of GEM_FONTS_DIR in the value is only required when using Asciidoctor PDF 1.5).
|
402
417
|
|
403
418
|
Rather than using the installer from the `asciidoctor-pdf-cjk-kai_gen_gothic` gem, you can download fonts whatever way you choose.
|
404
419
|
When using your own fonts, be sure to consult the <<docs/theming-guide.adoc#preparing-a-custom-font,Preparing a Custom Font>> section of the theming guide to find recommended modifications.
|
@@ -759,11 +774,51 @@ It should be a direct descendant of the document or a section.
|
|
759
774
|
That's because what it imports are entire pages.
|
760
775
|
If it's used inside a delimited block or table cell, the behavior is unspecified.
|
761
776
|
|
762
|
-
==
|
777
|
+
== Interdocument Xrefs
|
778
|
+
|
779
|
+
An xref to another AsciiDoc document (i.e., an interdocument xref) will either become a link to the PDF file generated from that source document or an internal link to an anchor within the current document.
|
780
|
+
Which one it becomes depends on whether the target has been included into the current document.
|
781
|
+
These section describes these two scenarios.
|
782
|
+
|
783
|
+
=== Referencing Another Document
|
784
|
+
|
785
|
+
If the target PDF is generated from an AsciiDoc file, you can make a reference to that PDF using the xref macro.
|
786
|
+
|
787
|
+
Let's assume the current document is [.path]_a.adoc_ and the PDF you want to reference is generated from [.path]_b.adoc_.
|
788
|
+
Here's how you can make a reference from the PDF generated from [.path]_a.adoc_ to the PDF generated from [.path]_b.adoc_.
|
789
|
+
|
790
|
+
[source,asciidoc]
|
791
|
+
----
|
792
|
+
A link to xref:b.adoc[b].
|
793
|
+
----
|
794
|
+
|
795
|
+
This xref macro is translated to a link that refers to [.path]_b.pdf_.
|
796
|
+
|
797
|
+
If there's an anchor you want to target in [.path]_b.pdf_, for example _chapter-b_, you can describe it using a URL fragment just like you would with any URL.
|
798
|
+
|
799
|
+
[source,asciidoc]
|
800
|
+
----
|
801
|
+
A link to xref:b.adoc#chapter-b[b].
|
802
|
+
----
|
803
|
+
|
804
|
+
WARNING: Linking to a named anchor isn't supported by all PDF viewers.
|
805
|
+
Some viewers (like Firefox) only support relative links when the PDF is accessed through a web server.
|
806
|
+
To verify it's working, test the PDF in Firefox and served through a local web server.
|
807
|
+
|
808
|
+
PDF supports a variety of PDF link open parameters you can control using the URL fragment.
|
809
|
+
For example, you can configure the PDF to open on a specific page using the special fragment `page=<N>`, where `<N>` is the 1-based page number.
|
810
|
+
|
811
|
+
[source,asciidoc]
|
812
|
+
----
|
813
|
+
A link to page 2 of xref:b.adoc#page=2[b].
|
814
|
+
----
|
815
|
+
|
816
|
+
You can find a list of all the special fragment parameters in the https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf#G4.1500549[PDF Open Parameters^] reference.
|
817
|
+
|
818
|
+
=== Converting Interdocument Xrefs to Internal Xrefs
|
763
819
|
|
764
|
-
|
765
|
-
|
766
|
-
These interdocument cross references (i.e., xrefs) will only successfully make that transition if you structure your document in accordance with the rules.
|
820
|
+
If you're using this converter to generate a single PDF file from multiple source documents (combined using the include directive), references between those included documents must become internal references.
|
821
|
+
Interdocument cross references (i.e., xrefs) will only successfully make that transition if you structure your document in accordance with the rules.
|
767
822
|
|
768
823
|
Those rules are as follows:
|
769
824
|
|
@@ -848,43 +903,48 @@ In other words, it encodes the complete information about the reference so the c
|
|
848
903
|
|
849
904
|
Unlike the built-in HTML converter, Asciidoctor PDF does not provide native support for STEM blocks and inline macros (i.e., asciimath and latexmath).
|
850
905
|
That's because Asciidoctor core doesn't process the STEM content itself.
|
851
|
-
It
|
852
|
-
|
853
|
-
The HTML converter
|
906
|
+
It simply passes it through to the converter.
|
907
|
+
When converting to HTML, Asciidoctor relies on the JavaScript-based MathJax library to parse and render the STEM expressions in the browser when the page is loaded.
|
908
|
+
The HTML converter wraps the expressions in special markup so MathJax can find and process them.
|
854
909
|
|
855
|
-
In order to insert a rendered
|
910
|
+
In order to insert a rendered expression into the PDF, the toolchain must parse the expressions and convert them to a format the PDF writer (Prawn) can understand.
|
856
911
|
That typically means converting to an image.
|
857
912
|
|
858
|
-
|
913
|
+
One solution that provides this capability is an extension named Asciidoctor Mathematical, which we'll cover in the next section.
|
859
914
|
|
915
|
+
////
|
860
916
|
Another solution, which is still under development, uses Mathoid to convert STEM equations to images.
|
861
917
|
Mathoid is a library that invokes MathJax using a headless browser, so it supports both asciimath and latexmath equations.
|
862
918
|
That prototype can be found in the https://github.com/asciidoctor/asciidoctor-extensions-lab#extension-catalog[Asciidoctor extensions lab].
|
919
|
+
////
|
863
920
|
|
864
921
|
=== Asciidoctor Mathematical
|
865
922
|
|
866
|
-
{url-asciidoctor-mathematical}[Asciidoctor Mathematical] is an extension for Asciidoctor that provides alternate processing of STEM blocks and inline macros
|
867
|
-
After the document has been parsed, the extension locates
|
923
|
+
{url-asciidoctor-mathematical}[Asciidoctor Mathematical] is an extension for Asciidoctor that provides alternate processing of STEM blocks and inline macros.
|
924
|
+
After the document has been parsed, the extension locates each asciimath, latexmath, and stem block and inline macro, converts the expression to an image, and replaces the expression with an image.
|
925
|
+
It uses Mathematical to render the LaTeX notation as an image.
|
926
|
+
If the expression is AsciiMath, it first uses AsciiMath gem to convert to LaTeX.
|
868
927
|
Conversion then proceeds as normal.
|
869
928
|
|
870
929
|
Asciidoctor Mathematical is a Ruby gem that uses native extensions.
|
871
|
-
It has a few system prerequisites which limit installation to Linux and
|
930
|
+
It has a few system prerequisites which limit installation to Linux and macOS.
|
872
931
|
Please refer to the {url-asciidoctor-mathematical}#installation[installation section] in the Asciidoctor Mathematical README to learn how to install it.
|
873
932
|
|
874
|
-
Once Asciidoctor Mathematical is installed, you
|
933
|
+
Once Asciidoctor Mathematical is installed, you can enable it when invoking Asciidoctor PDF using the `-r` flag:
|
875
934
|
|
876
935
|
$ asciidoctor-pdf -r asciidoctor-mathematical sample.adoc
|
877
936
|
|
878
|
-
If you're invoking Asciidoctor via the API,
|
937
|
+
If you're invoking Asciidoctor via the API, you need to require the gem before invoking Asciidoctor:
|
879
938
|
|
880
939
|
[source,ruby]
|
881
940
|
----
|
882
941
|
require 'asciidoctor-mathematical'
|
942
|
+
require 'asciidoctor-pdf'
|
883
943
|
|
884
|
-
Asciidoctor.convert_file 'sample.adoc', safe: :safe
|
944
|
+
Asciidoctor.convert_file 'sample.adoc', backend: 'pdf', safe: :safe
|
885
945
|
----
|
886
946
|
|
887
|
-
To get the best quality
|
947
|
+
To get the best quality output and maximize speed of conversion, we recommend configuring Asciidoctor Mathematical to convert equations to SVG.
|
888
948
|
You control this setting using the `mathematical-format` AsciiDoc attribute:
|
889
949
|
|
890
950
|
$ asciidoctor-pdf -r asciidoctor-mathematical -a mathematical-format=svg sample.adoc
|
@@ -1015,13 +1075,17 @@ When the title page is enabled, the table of contents (aka TOC) also gets is own
|
|
1015
1075
|
|
1016
1076
|
The table of contents (TOC) is not included by default.
|
1017
1077
|
The TOC is only included if the `toc` attribute is set on the document.
|
1078
|
+
The value of this attribute determines the placement.
|
1079
|
+
If a value is not specified, the placement defaults to `auto`, which is directly after the document title.
|
1018
1080
|
|
1019
|
-
The placement of the table of contents is fixed, and thus the value of the `toc` attribute is effectively ignored in this backend.
|
1020
1081
|
For documents that have the book doctype, the TOC is inserted using discrete pages between the title page and the first page of content.
|
1021
|
-
For all other doctypes (unless the `title-page` attribute is set), the TOC is inserted in the flow of text
|
1082
|
+
For all other doctypes (unless the `title-page` attribute is set), the TOC is inserted in the flow of text.
|
1083
|
+
If a placement is not specifie, that location is between the document title and the first block of content.
|
1022
1084
|
|
1023
1085
|
While the table of contents is not included by default, the PDF outline is always included.
|
1024
1086
|
The `toclevels` attribute controls the depth of both the TOC and the PDF outline (regardless of whether the TOC is enabled).
|
1087
|
+
The depth of the outline can be controlled independently using the `outlinelevels` attribute.
|
1088
|
+
Both attributes can also be set on individual sections to override the depth for a given section and its children.
|
1025
1089
|
|
1026
1090
|
NOTE: If a document that has the book doctype includes a preface, an entry for the preface is only included in the TOC if the `preface-title` is assigned a value (e.g., `preface-title=Preface`).
|
1027
1091
|
This value is used as the heading of the preface and as the text of the entry in the TOC.
|
@@ -1030,7 +1094,7 @@ This value is used as the heading of the preface and as the text of the entry in
|
|
1030
1094
|
|
1031
1095
|
Asciidoctor PDF supports generating an index catalog that itemizes all index terms defined in the document, allowing the reader to navigate the document by keyword.
|
1032
1096
|
|
1033
|
-
To get Asciidoctor PDF to generate an index, add a level-1 section
|
1097
|
+
To get Asciidoctor PDF to generate an index, add a level-1 section annotated with the `index` style near the end of your document.
|
1034
1098
|
The converter will automatically populate the catalog with the list of index terms in the document, organized by first letter.
|
1035
1099
|
|
1036
1100
|
[source,asciidoc]
|
@@ -1039,17 +1103,68 @@ The converter will automatically populate the catalog with the list of index ter
|
|
1039
1103
|
= Index
|
1040
1104
|
----
|
1041
1105
|
|
1042
|
-
You can use any text you want for the title of
|
1106
|
+
You can use any text you want for the title of this section.
|
1043
1107
|
The only restriction is that no index terms may be defined below this section.
|
1044
1108
|
|
1045
1109
|
NOTE: Although the catalog is generated automatically, you have to mark the index terms manually.
|
1046
1110
|
However, you could use an extension, such as a TreeProcessor, to automatically mark index terms.
|
1047
1111
|
|
1112
|
+
=== How Index Terms are Grouped and Sorted
|
1113
|
+
|
1114
|
+
By default, the converter groups index terms by the first letter of the primary term (e.g., A), which we call the category.
|
1115
|
+
These categories are displayed in alphabetically order in the index.
|
1116
|
+
Within the category, the converter sorts the terms alphabetically.
|
1117
|
+
|
1118
|
+
The exception to this rule is if the primary term does not start with a letter.
|
1119
|
+
In this case, the converter group the term (along with its secondary and tertiary terms) in a special category named @.
|
1120
|
+
The @ category is displayed before all other categories in the index.
|
1121
|
+
|
1122
|
+
If you want to modify this behavior, you must extend the index catalog and apply your own grouping and sorting rules.
|
1123
|
+
|
1124
|
+
For example, let's say that all your functions begin with the prefix `fn`, but you want to group and sort them by the function name that follows.
|
1125
|
+
Here's rudimentary code you can use to do that:
|
1126
|
+
|
1127
|
+
.index-customizer.rb
|
1128
|
+
[source,ruby]
|
1129
|
+
----
|
1130
|
+
require 'asciidoctor-pdf'
|
1131
|
+
|
1132
|
+
module Asciidoctor::PDF
|
1133
|
+
IndexCatalog.prepend (::Module.new do
|
1134
|
+
def store_primary_term name, dest = nil
|
1135
|
+
store_dest dest if dest
|
1136
|
+
category = (name.delete_prefix 'fn').upcase.chr
|
1137
|
+
(init_category category).store_term name, dest
|
1138
|
+
end
|
1139
|
+
end)
|
1140
|
+
|
1141
|
+
IndexTermGroup.prepend (::Module.new do
|
1142
|
+
def <=> other
|
1143
|
+
this = @name.delete_prefix 'fn'
|
1144
|
+
that = other.name.delete_prefix 'fn'
|
1145
|
+
(val = this.casecmp that) == 0 ? this <=> that : val
|
1146
|
+
end
|
1147
|
+
end)
|
1148
|
+
end
|
1149
|
+
----
|
1150
|
+
|
1151
|
+
You load this code when calling Asciidoctor PDF as follows:
|
1152
|
+
|
1153
|
+
$ asciidoctor-pdf -r ./index-customizer.rb doc.adoc
|
1154
|
+
|
1155
|
+
Now the index terms will be grouped and sorted according to your custom rules.
|
1156
|
+
|
1048
1157
|
== Optimizing the Generated PDF
|
1049
1158
|
|
1050
1159
|
By default, Asciidoctor PDF does not optimize the PDF it generates or compress its streams.
|
1051
1160
|
This section covers several approaches you can take to optimize your PDF.
|
1052
1161
|
|
1162
|
+
IMPORTANT: If you're creating a PDF for Amazon's Kindle Direct Publishing (KDP), GitLab repository preview, or other online publishers, you'll likely need to optimize the file before uploading.
|
1163
|
+
In their words, you must tidy up the reference tree and https://kdp.amazon.com/en_US/help/topic/G201953020#check[flatten all transparencies^] (mostly likely referring to images).
|
1164
|
+
If you don't do this step, the platform may reject your upload or fail to display it properly.
|
1165
|
+
(For KDP, `-a optimize` works best.
|
1166
|
+
For GitLab repository preview, either `-a optimize` or `hexapdf optimize` will do the trick.)
|
1167
|
+
|
1053
1168
|
=== Enable Stream Compression
|
1054
1169
|
|
1055
1170
|
The simplest way to reduce the size of the PDF file is to enable stream compression (using the FlateDecode method).
|
@@ -1114,7 +1229,7 @@ If you have difficulty getting the `rghost` gem installed, or you aren't getting
|
|
1114
1229
|
|
1115
1230
|
=== hexapdf
|
1116
1231
|
|
1117
|
-
Another option to optimize the PDF is https://hexapdf.gettalong.org/[hexapdf
|
1232
|
+
Another option to optimize the PDF is https://hexapdf.gettalong.org/[hexapdf] (gem: hexapdf, command: hexapdf).
|
1118
1233
|
Before introducing it, though, it's important to point out that its license is AGPL.
|
1119
1234
|
If that's okay with you, read on to learn how to use it.
|
1120
1235
|
|
@@ -1177,6 +1292,31 @@ You can also disable page compressioin (e.g., `--no-compress-pages` from the CLI
|
|
1177
1292
|
|
1178
1293
|
hexapdf also allows you to add password protection to your PDF, if that's something you're interested in doing.
|
1179
1294
|
|
1295
|
+
=== Rasterizing the PDF
|
1296
|
+
|
1297
|
+
Instead of optimizing the objects in the vector PDF, you may want to rasterize the PDF instead.
|
1298
|
+
Rasterizing the PDF prevents any of the text or other objects from being selected, similar to a scanned document.
|
1299
|
+
|
1300
|
+
Asciidoctor PDF doesn't provide built-in support for rasterizing the generated PDF.
|
1301
|
+
However, you can use Ghostscript to flatten all the text in the PDF, thus preventing it from being selected.
|
1302
|
+
|
1303
|
+
$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dNoOutputFonts -r300 -o output.pdf input.pdf
|
1304
|
+
|
1305
|
+
You can adjust the value of the `-r` option (the density) to get a higher or lower quality result.
|
1306
|
+
|
1307
|
+
Alternately, you can use the `convert` command from ImageMagick to convert each page in the PDF to an image.
|
1308
|
+
|
1309
|
+
$ convert -density 300 -quality 100 input.pdf output.pdf
|
1310
|
+
|
1311
|
+
Yet another option is to combine Ghostscript and ImageMagick to produce a PDF with pages converted to images.
|
1312
|
+
|
1313
|
+
$ gs -dBATCH -dNOPAUSE -sDEVICE=png16m -o /tmp/tmp-%02d.png -r300 input.pdf
|
1314
|
+
convert /tmp/tmp-*.png output.pdf
|
1315
|
+
rm -f /tmp/tmp-*.png
|
1316
|
+
|
1317
|
+
Using Ghostscript to handle the rasterization produces a much smaller output file.
|
1318
|
+
The drawback of using Ghostscript in this way is that it has to use intermediate files.
|
1319
|
+
|
1180
1320
|
ifndef::env-site[]
|
1181
1321
|
== Contributing
|
1182
1322
|
|
data/asciidoctor-pdf.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.homepage = 'https://asciidoctor.org/docs/asciidoctor-pdf'
|
15
15
|
s.license = 'MIT'
|
16
16
|
# NOTE required ruby version is informational only; it's not enforced since it can't be overridden and can cause builds to break
|
17
|
-
#s.required_ruby_version = '>= 2.
|
17
|
+
#s.required_ruby_version = '>= 2.7.0'
|
18
18
|
s.metadata = {
|
19
19
|
'bug_tracker_uri' => 'https://github.com/asciidoctor/asciidoctor-pdf/issues',
|
20
20
|
'changelog_uri' => 'https://github.com/asciidoctor/asciidoctor-pdf/blob/main/CHANGELOG.adoc',
|
@@ -35,20 +35,16 @@ Gem::Specification.new do |s|
|
|
35
35
|
|
36
36
|
s.add_runtime_dependency 'asciidoctor', '~> 2.0'
|
37
37
|
s.add_runtime_dependency 'prawn', '~> 2.4.0'
|
38
|
-
|
38
|
+
s.add_runtime_dependency 'matrix', '~> 0.4' # required until prawn >= 2.5.0 is released
|
39
39
|
s.add_runtime_dependency 'prawn-table', '~> 0.2.0'
|
40
40
|
s.add_runtime_dependency 'prawn-templates', '~> 0.1.0'
|
41
41
|
s.add_runtime_dependency 'prawn-svg', '~> 0.32.0'
|
42
42
|
s.add_runtime_dependency 'prawn-icon', '~> 3.0.0'
|
43
|
-
s.add_runtime_dependency 'safe_yaml', '~> 1.0.0'
|
44
43
|
s.add_runtime_dependency 'concurrent-ruby', '~> 1.1'
|
45
44
|
s.add_runtime_dependency 'treetop', '~> 1.6.0'
|
46
45
|
|
47
46
|
s.add_development_dependency 'rake', '~> 13.0.0'
|
48
|
-
s.add_development_dependency 'rspec', '~> 3.
|
47
|
+
s.add_development_dependency 'rspec', '~> 3.11.0'
|
49
48
|
s.add_development_dependency 'pdf-inspector', '~> 1.3.0'
|
50
|
-
# Asciidoctor PDF supports Rouge >= 2 (verified in CI build using 2.0.0)
|
51
|
-
s.add_development_dependency 'rouge', '~> 3.0'
|
52
|
-
s.add_development_dependency 'coderay', '~> 1.1.0'
|
53
49
|
s.add_development_dependency 'chunky_png', '~> 1.4.0'
|
54
50
|
end
|
@@ -15,7 +15,7 @@ The following changes were made using fontforge to produce mplus1mn-*-ascii.ttf
|
|
15
15
|
** Latin Extended-A (U+0100–U+017f)
|
16
16
|
** Greek Alphabet (U+0391–U+03c9)
|
17
17
|
** Cyrillic (U+0400–U+04ff)
|
18
|
-
** Assorted Symbols (U+20ac)
|
18
|
+
** Assorted Symbols (U+20ac, U+2713–U+2714)
|
19
19
|
** Enclosed Numbers (U+2460–U+2473, U+2776–U+277f, U+24eb–U+24f4) (mplus1mn-regular only)
|
20
20
|
** Box Drawing Symbols (U+2500–U+257f)
|
21
21
|
** .notdef glyph
|
@@ -13,10 +13,10 @@ The following changes were made using fontforge to produce mplus1p-regular-fallb
|
|
13
13
|
** Cyrillic (U+0400–U+04ff)
|
14
14
|
** Vietnamese (U+01a0–U01b0, U+1ea0–U1ef9)
|
15
15
|
** CJK (U+4e00–U+9fff, U+3000–U+303f) (mostly Japanese, limited selection based on what M+ supports)
|
16
|
-
** Mathematical Operators (U+2200–U+22ff)
|
16
|
+
** Mathematical Operators (U+2200–U+22ff, U+2116)
|
17
17
|
** General Punctuation (U+2000–U203a)
|
18
18
|
** Geometric Shapes (U+25a0–U25ff)
|
19
|
-
** Assorted Symbols (U+20ac, U+2122, U+21d0–U+21d5, U+2190–U+2195, U+2610–U+2611, U+2713)
|
19
|
+
** Assorted Symbols (U+20ac, U+2122, U+21d0–U+21d5, U+2190–U+2195, U+2610–U+2611, U+2713–U+2714)
|
20
20
|
** .notdef glyph
|
21
21
|
* Added BOM (U+feff), hair space (U+200a), zero-width space (U+200b) and line feed (U+000a) characters (from blank)
|
22
22
|
* Manually added non-breaking hyphen (U+2011) from hyphen (U+002d)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Noto Sans fonts are generated from the google-noto-sans-fonts-20161022 Fedora RPM package (commit 86b2e553c3e3e4d6614dadd1fa0a7a6dafd74552).
|
2
|
+
|
3
|
+
The following changes were made using fontforge to produce the notosans-*-subset.ttf fonts:
|
4
|
+
|
5
|
+
* Mapped single arrows <- (U+2190) and -> (U+2192) to double arrows <= (U+21d0) and => (U+21d2)
|
6
|
+
* Manually added non-breaking hyphen (U+2011) from hyphen (U+002d)
|
7
|
+
* Moved arrows (U+21d0, U+21d2, U+2190, U+2192) up in line to align with middle of X
|
8
|
+
* Subsetted to include:
|
9
|
+
** Non-visible Characters (U+feff, U+00a0)
|
10
|
+
** Basic Latin (U+0020–U+007e)
|
11
|
+
** Latin-1 Supplement (U+00a0–U+00fd)
|
12
|
+
** Latin Extended-A (U+0100–U+017f)
|
13
|
+
** Greek (U+0370–U+03ff)
|
14
|
+
** Cyrillic (U+0400–U+04ff)
|
15
|
+
** Vietnamese (U+01a0–U01b0, U+1ea0–U1ef9)
|
16
|
+
** Mathematical Operators (U+2200–U+22ff, U+2116)
|
17
|
+
** General Punctuation (U+2000–U203a)
|
18
|
+
** Geometric Shapes (U+25a0–U25ff)
|
19
|
+
** Assorted Symbols (U+20ac, U+2122, U+21d0, U+21d2, U+2190, U+2192)
|
20
|
+
** .notdef glyph
|
21
|
+
* Imported ballot boxes from Font Awesome (U+2610, U+2611) (Noto Serif Regular only)
|
22
|
+
* Added line feed character (U+000a)
|
23
|
+
* Generated old-style kern table (neither Apple or OpenType) (required to make kerning work in Prawn) (flags: 0x90)
|
24
|
+
* Removed Truetype instructions (information not used by Prawn)
|
25
|
+
* Generated with PS Glyph Names option enabled (didn't use 0x04 flag)
|
26
|
+
* Generate flags used, in total: 0x90 + 0x08
|
@@ -13,7 +13,7 @@ The following changes were made using fontforge to produce the notoserif-*-subse
|
|
13
13
|
** Greek (U+0370–U+03ff)
|
14
14
|
** Cyrillic (U+0400–U+04ff)
|
15
15
|
** Vietnamese (U+01a0–U01b0, U+1ea0–U1ef9)
|
16
|
-
** Mathematical Operators (U+2200–U+22ff)
|
16
|
+
** Mathematical Operators (U+2200–U+22ff, U+2116)
|
17
17
|
** General Punctuation (U+2000–U203a)
|
18
18
|
** Geometric Shapes (U+25a0–U25ff)
|
19
19
|
** Assorted Symbols (U+20ac, U+2122, U+21d0, U+21d2, U+2190, U+2192)
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|