Hide keyboard shortcuts

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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

""" 

@file 

@brief Simplified function versions. 

""" 

import os 

 

 

_preamble = ''' 

\\usepackage{etex} 

\\usepackage{fixltx2e} % LaTeX patches, \\textsubscript 

\\usepackage{cmap} % fix search and cut-and-paste in Acrobat 

\\usepackage[raccourcis]{fast-diagram} 

\\usepackage{titlesec} 

\\usepackage{amsmath} 

\\usepackage{amssymb} 

\\usepackage{amsfonts} 

\\usepackage{graphics} 

\\usepackage{epic} 

\\usepackage{eepic} 

%\\usepackage{pict2e} 

%%% Redefined titleformat 

\\setlength{\\parindent}{0cm} 

\\setlength{\\parskip}{1ex plus 0.5ex minus 0.2ex} 

\\newcommand{\\hsp}{\\hspace{20pt}} 

\\newcommand{\\acc}[1]{\\left\\{#1\\right\\}} 

\\newcommand{\\cro}[1]{\\left[#1\\right]} 

\\newcommand{\\pa}[1]{\\left(#1\\right)} 

\\newcommand{\\R}{\\mathbb{R}} 

\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}} 

%\\titleformat{\\chapter}[hang]{\\Huge\\bfseries\\sffamily}{\\thechapter\\hsp}{0pt}{\\Huge\\bfseries\\sffamily} 

''' 

 

_custom_preamble = """\n 

\\usepackage[all]{xy} 

\\newcommand{\\vecteur}[2]{\\pa{#1,\\dots,#2}} 

\\newcommand{\\N}[0]{\\mathbb{N}} 

\\newcommand{\\indicatrice}[1]{\\mathbf{1\\!\\!1}_{\\acc{#1}}} 

\\newcommand{\\infegal}[0]{\\leqslant} 

\\newcommand{\\supegal}[0]{\\geqslant} 

\\newcommand{\\ensemble}[2]{\\acc{#1,\\dots,#2}} 

\\newcommand{\\fleche}[1]{\\overrightarrow{ #1 }} 

\\newcommand{\\intervalle}[2]{\\left\\{#1,\\cdots,#2\\right\\}} 

\\newcommand{\\independant}[0] 

{\\;\\makebox[3ex]{\\makebox[0ex]{\\rule[-0.2ex]{3ex}{.1ex}}\\!\\!\\!\\!\\makebox[.5ex][l] 

{\\rule[-.2ex]{.1ex}{2ex}}\\makebox[.5ex][l]{\\rule[-.2ex]{.1ex}{2ex}}} \\,\\,} 

\\newcommand{\\esp}{\\mathbb{E}} 

\\newcommand{\\espf}[2]{\\mathbb{E}_{#1}\\pa{#2}} 

\\newcommand{\\var}{\\mathbb{V}} 

\\newcommand{\\pr}[1]{\\mathbb{P}\\pa{#1}} 

\\newcommand{\\loi}[0]{{\\cal L}} 

\\newcommand{\\vecteurno}[2]{#1,\\dots,#2} 

\\newcommand{\\norm}[1]{\\left\\Vert#1\\right\\Vert} 

\\newcommand{\\norme}[1]{\\left\\Vert#1\\right\\Vert} 

\\newcommand{\\dans}[0]{\\rightarrow} 

\\newcommand{\\partialfrac}[2]{\\frac{\\partial #1}{\\partial #2}} 

\\newcommand{\\partialdfrac}[2]{\\dfrac{\\partial #1}{\\partial #2}} 

\\newcommand{\\trace}[1]{tr\\pa{#1}} 

\\newcommand{\\sac}[0]{|} 

\\newcommand{\\abs}[1]{\\left|#1\\right|} 

\\newcommand{\\loinormale}[2]{{\\cal N} \\pa{#1,#2}} 

\\newcommand{\\loibinomialea}[1]{{\\cal B} \\pa{#1}} 

\\newcommand{\\loibinomiale}[2]{{\\cal B} \\pa{#1,#2}} 

\\newcommand{\\loimultinomiale}[1]{{\\cal M} \\pa{#1}} 

\\newcommand{\\variance}[1]{\\mathbb{V}\\pa{#1}} 

\\newcommand{\\scal}[2]{\\left<#1,#2\\right>} 

""" 

 

 

def sphinx_rst(input="", writer="html", keep_warnings=False, 

directives=None, language="en", 

layout='sphinx', output="output"): 

""" 

Converts a string from *RST* 

to *HTML* to *RST* format. 

 

@param input text of filename 

@param writer ``'html'`` for :epkg:`HTML` format, 

``'rst'`` for :epkg:`RST` format, 

``'md'`` for :epkg:`MD` format, 

``'elatex'`` for :epkg:`latex` format, 

``'doctree'`` to get the doctree, *writer* can also be a tuple 

for custom formats and must be like ``('buider_name', builder_class)``. 

@param keep_warnings keep_warnings in the final HTML 

@param directives new directives to add, comma separated values 

@param language language 

@param layout ``'docutils'``, ``'sphinx'``, ``'sphinx_body'``, see below. 

@param output document name, the function adds the extension 

@return output 

""" 

from ..helpgen import rst2html 

from ..helpgen.default_conf import get_epkg_dictionary 

from ..filehelper import read_content_ufs 

if output: 

ext = os.path.splitext(output)[-1] 

if not ext: 

output += "." + writer 

if len(input) <= 5000 and \ 

(input.startswith('http') or 

os.path.exists(input)): 

content = read_content_ufs(input) 

else: 

content = input 

if directives: 

raise NotImplementedError("Cannot specify directives yet.") 

 

preamble = _preamble + _custom_preamble 

epkg_dictionary = get_epkg_dictionary() 

 

ht = rst2html(content, writer=writer, keep_warnings=keep_warnings, 

language=language, layout=layout, 

document_name=output, imgmath_latex_preamble=preamble, 

epkg_dictionary=epkg_dictionary) 

ht = ht.replace('src="_images/', 'src="') 

ht = ht.replace('/scripts\\bokeh', '../bokeh_plot\\bokeh') 

ht = ht.replace('/scripts/bokeh', '../bokeh_plot/bokeh') 

if output: 

with open(output, "w", encoding="utf-8") as f: 

f.write(ht) 

return ht