Generate a PDF version of the User Manual

This commit is contained in:
Kovid Goyal 2012-08-07 13:55:58 +05:30
parent 6190f7acfc
commit 89472f78ec
6 changed files with 51 additions and 6 deletions

View File

@ -60,7 +60,7 @@ htmlhelp:
latex:
mkdir -p .build/latex .build/doctrees
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) .build/latex
$(SPHINXBUILD) -b mylatex $(ALLSPHINXOPTS) .build/latex
@echo
@echo "Build finished; the LaTeX files are in .build/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \

View File

@ -14,10 +14,10 @@
import sys, os
# If your extensions are in another directory, add it here.
sys.path.append(os.path.abspath('../src'))
sys.path.append(os.path.abspath('.'))
__appname__ = os.environ.get('__appname__', 'calibre')
__version__ = os.environ.get('__version__', '0.0.0')
import init_calibre
init_calibre
from calibre.constants import __appname__, __version__
import custom
custom
# General configuration
@ -154,7 +154,8 @@ latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
#latex_documents = []
latex_documents = [('index', 'calibre.tex', 'calibre User Manual',
'Kovid Goyal', 'manual', False)]
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
@ -164,3 +165,11 @@ latex_font_size = '10pt'
# If false, no module index is generated.
#latex_use_modindex = True
latex_logo = 'resources/logo.png'
latex_show_pagerefs = True
latex_show_urls = 'footnote'
latex_elements = {
'papersize':'letterpaper',
'fontenc':r'\usepackage[T2A,T1]{fontenc}'
}

View File

@ -14,6 +14,7 @@ from sphinx.util.console import bold
sys.path.append(os.path.abspath('../../../'))
from calibre.linux import entry_points
from epub import EPUBHelpBuilder
from latex import LaTeXHelpBuilder
def substitute(app, doctree):
pass
@ -251,6 +252,7 @@ def template_docs(app):
def setup(app):
app.add_config_value('kovid_epub_cover', None, False)
app.add_builder(EPUBHelpBuilder)
app.add_builder(LaTeXHelpBuilder)
app.connect('doctree-read', substitute)
app.connect('builder-inited', generate_docs)
app.connect('build-finished', finished)

View File

@ -17,7 +17,7 @@ To get started with more advanced usage, you should read about the :ref:`Graphic
.. only:: online
**An ebook version of this user manual is available in** `EPUB format <calibre.epub>`_ and `AZW3 (Kindle Fire) format <calibre.azw3>`_.
**An ebook version of this user manual is available in** `EPUB format <calibre.epub>`_, `AZW3 (Kindle Fire) format <calibre.azw3>`_ and `PDF format <calibre.pdf>`_.
Sections
------------

25
manual/latex.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
from sphinx.builders.latex import LaTeXBuilder
class LaTeXHelpBuilder(LaTeXBuilder):
name = 'mylatex'
def finish(self):
LaTeXBuilder.finish(self)
self.info('Fixing Cyrillic characters...')
tex = os.path.join(self.outdir, 'calibre.tex')
with open(tex, 'r+b') as f:
raw = f.read().replace(b'Михаил Горбачёв',
br'{\fontencoding{T2A}\selectfont Михаил Горбачёв}')
f.seek(0)
f.write(raw)

View File

@ -80,8 +80,17 @@ class Manual(Command):
'-d', '.build/doctrees', '.', '.build/html'])
subprocess.check_call(['sphinx-build', '-b', 'myepub', '-d',
'.build/doctrees', '.', '.build/epub'])
subprocess.check_call(['sphinx-build', '-b', 'mylatex', '-d',
'.build/doctrees', '.', '.build/latex'])
pwd = os.getcwdu()
os.chdir('.build/latex')
subprocess.check_call(['make', 'all-pdf'], stdout=open(os.devnull,
'wb'))
os.chdir(pwd)
epub_dest = self.j('.build', 'html', 'calibre.epub')
pdf_dest = self.j('.build', 'html', 'calibre.pdf')
shutil.copyfile(self.j('.build', 'epub', 'calibre.epub'), epub_dest)
shutil.copyfile(self.j('.build', 'latex', 'calibre.pdf'), pdf_dest)
subprocess.check_call(['ebook-convert', epub_dest,
epub_dest.rpartition('.')[0] + '.azw3',
'--page-breaks-before=/', '--disable-font-rescaling',