支持在readthedocs和本地生成中文PDF

This commit is contained in:
Dongdong Tian 2015-11-09 10:23:02 +08:00
parent 9222aa6d7a
commit 35288dbcd8
2 changed files with 59 additions and 25 deletions

View File

@ -34,6 +34,7 @@ help:
@echo " epub to make an epub" @echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " xelatexpdf to make LaTeX files and run them through xelatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files" @echo " text to make text files"
@echo " man to make manual pages" @echo " man to make manual pages"
@ -116,6 +117,13 @@ latexpdf:
$(MAKE) -C $(BUILDDIR)/latex all-pdf $(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
xelatexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through xelatex..."
sed -i s/pdflatex/xelatex/ $(BUILDDIR)/latex/Makefile
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "xelatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja: latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..." @echo "Running LaTeX files through platex and dvipdfmx..."

View File

@ -44,7 +44,7 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'跟我一起写Makefile' project = u'跟我一起写Makefile'
copyright = u'2014, 作者陈皓排版SeisMan' copyright = u'2014-2015, 作者陈皓排版SeisMan'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@ -95,10 +95,16 @@ pygments_style = 'sphinx'
# -- Options for HTML output ---------------------------------------------- # -- Options for HTML output ----------------------------------------------
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
html_theme = 'sphinx_rtd_theme' if on_rtd:
html_theme = 'default'
else:
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the
@ -107,7 +113,6 @@ html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom themes here, relative to this directory. # Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = [] #html_theme_path = []
html_theme_path = ["_themes",]
# The name for this set of Sphinx documents. If None, it defaults to # The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation". # "<project> v<release> documentation".
@ -182,35 +187,56 @@ htmlhelp_basename = 'Makefiledoc'
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
latex_elements = { if on_rtd:
# The paper size ('letterpaper' or 'a4paper'). latex_elements = {
'papersize': 'a4paper', # The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
'pointsize': '11pt', 'pointsize': '11pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
'preamble': r''' 'preamble': r'''
\usepackage{xeCJK} \hypersetup{unicode=true}
\setCJKmainfont{SimSun} \usepackage{CJKutf8}
\setCJKsansfont{KaiTi} \DeclareUnicodeCharacter{00A0}{\nobreakspace}
\setCJKmonofont{SimHei} \DeclareUnicodeCharacter{2203}{\ensuremath{\exists}}
\XeTeXlinebreaklocale "zh" \DeclareUnicodeCharacter{2200}{\ensuremath{\forall}}
\XeTeXlinebreakskip = 0pt plus 1pt \DeclareUnicodeCharacter{2286}{\ensuremath{\subseteq}}
\parindent 2em \DeclareUnicodeCharacter{2713}{x}
\setcounter{tocdepth}{3} \DeclareUnicodeCharacter{27FA}{\ensuremath{\Longleftrightarrow}}
\renewcommand\familydefault{\ttdefault} \DeclareUnicodeCharacter{221A}{\ensuremath{\sqrt{}}}
\renewcommand\CJKfamilydefault{\CJKrmdefault} \DeclareUnicodeCharacter{221B}{\ensuremath{\sqrt[3]{}}}
''', \DeclareUnicodeCharacter{2295}{\ensuremath{\oplus}}
'releasename' : 'By SeisMan@GitHub', \DeclareUnicodeCharacter{2297}{\ensuremath{\otimes}}
'release' : '', \begin{CJK}{UTF8}{gbsn}
} \AtEndDocument{\end{CJK}}
''',
}
else:
latex_elements = {
'papersize' : 'a4paper',
'utf8extra' : '',
'inputenc' : '',
'cmappkg' : '',
'fontenc' : '',
'releasename' : 'By SeisMan@GitHub',
'release' : '',
'babel' : r'''\usepackage[english]{babel}''',
'preamble' : r'''
\usepackage{ctex}
\parindent 2em
\setcounter{tocdepth}{3}
\renewcommand\familydefault{\ttdefault}
\renewcommand\CJKfamilydefault{\CJKrmdefault}
''',
}
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
('index', 'Makefile.tex', ('index', 'Makefile.tex',
u'跟我一起写Makefile (PDF重制版)', u'跟我一起写Makefile (PDF重制版)',
u'作者: 陈皓', 'manual', True), u'作者: 陈皓', 'manual', True),
] ]