Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Simplified function versions.
4"""
5import os
8_preamble = '''
9\\usepackage{etex}
10\\usepackage{fixltx2e} % LaTeX patches, \\textsubscript
11\\usepackage{cmap} % fix search and cut-and-paste in Acrobat
12\\usepackage[raccourcis]{fast-diagram}
13\\usepackage{titlesec}
14\\usepackage{amsmath}
15\\usepackage{amssymb}
16\\usepackage{amsfonts}
17\\usepackage{graphics}
18\\usepackage{epic}
19\\usepackage{eepic}
20%\\usepackage{pict2e}
21%%% Redefined titleformat
22\\setlength{\\parindent}{0cm}
23\\setlength{\\parskip}{1ex plus 0.5ex minus 0.2ex}
24\\newcommand{\\hsp}{\\hspace{20pt}}
25\\newcommand{\\acc}[1]{\\left\\{#1\\right\\}}
26\\newcommand{\\cro}[1]{\\left[#1\\right]}
27\\newcommand{\\pa}[1]{\\left(#1\\right)}
28\\newcommand{\\R}{\\mathbb{R}}
29\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}
30%\\titleformat{\\chapter}[hang]{\\Huge\\bfseries\\sffamily}{\\thechapter\\hsp}{0pt}{\\Huge\\bfseries\\sffamily}
31'''
33_custom_preamble = """\n
34\\usepackage[all]{xy}
35\\newcommand{\\vecteur}[2]{\\pa{#1,\\dots,#2}}
36\\newcommand{\\N}[0]{\\mathbb{N}}
37\\newcommand{\\indicatrice}[1]{\\mathbf{1\\!\\!1}_{\\acc{#1}}}
38\\newcommand{\\infegal}[0]{\\leqslant}
39\\newcommand{\\supegal}[0]{\\geqslant}
40\\newcommand{\\ensemble}[2]{\\acc{#1,\\dots,#2}}
41\\newcommand{\\fleche}[1]{\\overrightarrow{ #1 }}
42\\newcommand{\\intervalle}[2]{\\left\\{#1,\\cdots,#2\\right\\}}
43\\newcommand{\\independant}[0]
44{\\;\\makebox[3ex]{\\makebox[0ex]{\\rule[-0.2ex]{3ex}{.1ex}}\\!\\!\\!\\!\\makebox[.5ex][l]
45{\\rule[-.2ex]{.1ex}{2ex}}\\makebox[.5ex][l]{\\rule[-.2ex]{.1ex}{2ex}}} \\,\\,}
46\\newcommand{\\esp}{\\mathbb{E}}
47\\newcommand{\\espf}[2]{\\mathbb{E}_{#1}\\pa{#2}}
48\\newcommand{\\var}{\\mathbb{V}}
49\\newcommand{\\pr}[1]{\\mathbb{P}\\pa{#1}}
50\\newcommand{\\loi}[0]{{\\cal L}}
51\\newcommand{\\vecteurno}[2]{#1,\\dots,#2}
52\\newcommand{\\norm}[1]{\\left\\Vert#1\\right\\Vert}
53\\newcommand{\\norme}[1]{\\left\\Vert#1\\right\\Vert}
54\\newcommand{\\dans}[0]{\\rightarrow}
55\\newcommand{\\partialfrac}[2]{\\frac{\\partial #1}{\\partial #2}}
56\\newcommand{\\partialdfrac}[2]{\\dfrac{\\partial #1}{\\partial #2}}
57\\newcommand{\\trace}[1]{tr\\pa{#1}}
58\\newcommand{\\sac}[0]{|}
59\\newcommand{\\abs}[1]{\\left|#1\\right|}
60\\newcommand{\\loinormale}[2]{{\\cal N} \\pa{#1,#2}}
61\\newcommand{\\loibinomialea}[1]{{\\cal B} \\pa{#1}}
62\\newcommand{\\loibinomiale}[2]{{\\cal B} \\pa{#1,#2}}
63\\newcommand{\\loimultinomiale}[1]{{\\cal M} \\pa{#1}}
64\\newcommand{\\variance}[1]{\\mathbb{V}\\pa{#1}}
65\\newcommand{\\scal}[2]{\\left<#1,#2\\right>}
66"""
69def sphinx_rst(input="", writer="html", keep_warnings=False,
70 directives=None, language="en",
71 layout='sphinx', output="output"):
72 """
73 Converts a string from *RST*
74 to *HTML* or *RST* format.
76 :param input: text of filename
77 :param writer: ``'html'`` for :epkg:`HTML` format,
78 ``'rst'`` for :epkg:`RST` format,
79 ``'md'`` for :epkg:`MD` format,
80 ``'elatex'`` for :epkg:`latex` format,
81 ``'doctree'`` to get the doctree, *writer* can also be a tuple
82 for custom formats and must be like ``('buider_name', builder_class)``.
83 :param keep_warnings: keep_warnings in the final HTML
84 :param directives: new directives to add, comma separated values
85 :param language: language
86 :param layout: ``'docutils'``, ``'sphinx'``, ``'sphinx_body'``, see below.
87 :param output: document name, the function adds the extension
88 :return: output
90 .. cmdref::
91 :title: Convert RST document into HTML
92 :cmd: -m pyquickhelper sphinx_rst --help
94 Converts RST documents into HTML or even RST.
95 """
96 from ..helpgen import rst2html
97 from ..helpgen.default_conf import get_epkg_dictionary
98 from ..filehelper import read_content_ufs
99 if output:
100 ext = os.path.splitext(output)[-1]
101 if not ext:
102 output += "." + writer
103 if len(input) <= 5000 and \
104 (input.startswith('http') or
105 os.path.exists(input)):
106 content = read_content_ufs(input)
107 else:
108 content = input # pragma: no cover
109 if directives:
110 raise NotImplementedError(
111 "Cannot specify directives yet.") # pragma: no cover
113 preamble = _preamble + _custom_preamble
114 epkg_dictionary = get_epkg_dictionary()
116 ht = rst2html(content, writer=writer, keep_warnings=keep_warnings,
117 language=language, layout=layout,
118 document_name=output, imgmath_latex_preamble=preamble,
119 epkg_dictionary=epkg_dictionary)
120 ht = ht.replace('src="_images/', 'src="')
121 ht = ht.replace('/scripts\\bokeh', '../bokeh_plot\\bokeh')
122 ht = ht.replace('/scripts/bokeh', '../bokeh_plot/bokeh')
123 if output:
124 with open(output, "w", encoding="utf-8") as f:
125 f.write(ht)
126 return ht