From 798b7dfc5396b827f0aba51a67972ff9e61036d6 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Tue, 17 Sep 2019 12:07:33 +0100
Subject: [PATCH] Build pdf doc

The is one of community goals that each project should produce a
single PDF file. The pdf should be in the output of openstack-tox-docs
job.

TeX packages are required to build PDF locally, following is
recommended:

* inkscape
* texlive-latex-base
* texlive-latex-extra
* texlive-fonts-recommended

More about the goal:
https://governance.openstack.org/tc/goals/train/pdf-doc-generation.html
https://etherpad.openstack.org/p/train-pdf-support-goal
https://etherpad.openstack.org/p/pdf-goal-train-common-problems

Change-Id: Ib8a238f5ad4329527147be72331b87f57877f68e
---
 doc/requirements.txt | 1 +
 doc/source/conf.py   | 8 ++++++--
 tox.ini              | 8 ++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/doc/requirements.txt b/doc/requirements.txt
index f556feaeb..e2f8f6b67 100644
--- a/doc/requirements.txt
+++ b/doc/requirements.txt
@@ -6,3 +6,4 @@ openstackdocstheme>=1.19.0 # Apache-2.0
 reno!=2.3.1,>=1.8.0 # Apache-2.0
 sphinx!=1.6.6,!=1.6.7,>=1.6.2,<2.0.0;python_version=='2.7'  # BSD
 sphinx!=1.6.6,!=1.6.7,!=2.1.0,>=1.6.2;python_version>='3.4'  # BSD
+sphinxcontrib-svg2pdfconverter>=0.1.0 # BSD
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 682126a74..fba4509a5 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -40,8 +40,9 @@ extensions = [
     'sphinx.ext.autodoc',
     #'sphinx.ext.intersphinx',
     # Uncomment this to enable the OpenStack documentation style, adding
-    # oslosphinx to test-requirements.txt.  
+    # oslosphinx to test-requirements.txt.
     #'oslosphinx',
+    'sphinxcontrib.rsvgconverter',
 ]
 
 # autodoc generation is a bit aggressive and a nuisance when doing heavy
@@ -97,11 +98,14 @@ html_last_updated_fmt = '%Y-%m-%d %H:%M'
 # [howto/manual]).
 latex_documents = [
     ('index',
-     '%s.tex' % project,
+     'doc-%s.tex' % project,
      u'%s Documentation' % project,
      u'OpenStack Foundation', 'manual'),
 ]
 
+# Disable usage of xindy https://bugzilla.redhat.com/show_bug.cgi?id=1643664
+latex_use_xindy = False
+
 # openstackdocstheme options
 # TODO(mgoddard): Change to openstack/kayobe.
 repository_name = 'openstack/kayobe'
diff --git a/tox.ini b/tox.ini
index 036e78884..b73f01575 100644
--- a/tox.ini
+++ b/tox.ini
@@ -118,6 +118,14 @@ deps =
     -r{toxinidir}/doc/requirements.txt
 commands = sphinx-build -W -b html doc/source doc/build/html
 
+[testenv:pdf-docs]
+basepython = python3
+whitelist_externals = make
+deps = {[testenv:docs]deps}
+commands =
+  sphinx-build -W -b latex doc/source doc/build/pdf
+  make -C doc/build/pdf
+
 [testenv:debug]
 basepython = python3
 commands = oslo_debug_helper {posargs}