Package doconce :: Module sphinx
[hide private]
[frames] | no frames]

Source Code for Module doconce.sphinx

  1  # http://sphinx.pocoo.org/ext/math.html# 
  2   
  3  # can reuse most of rst module: 
  4  from rst import * 
  5   
  6  legal_pygments_languages = [ 
  7      'Cucumber', 'cucumber', 'Gherkin', 'gherkin', 
  8      'abap', 'ada', 'ada95ada2005', 
  9      'antlr-as', 'antlr-actionscript', 'antlr-cpp', 'antlr-csharp', 
 10      'antlr-c#', 'antlr-java', 'antlr-objc', 'antlr-perl', 
 11      'antlr-python', 'antlr-ruby', 'antlr-rb', 'antlr', 
 12      'apacheconf', 'aconf', 'apache', 'applescript', 'as', 
 13      'actionscript', 'as3', 'actionscript3', 'aspx-cs', 'aspx-vb', 
 14      'asy', 'asymptote', 'basemake', 'bash', 'sh', 'ksh', 'bat', 
 15      'bbcode', 'befunge', 'boo', 'brainfuck', 'bf', 'c-objdump', 
 16      'c', 'cfm', 'cfs', 'cheetah', 'spitfire', 'clojure', 'clj', 
 17      'cmake', 'coffee-script', 'coffeescript', 'common-lisp', 
 18      'cl', 'console', 'control', 
 19      'cpp', 'c++', 'cpp-objdump', 'c++-objdumb', 'cxx-objdump', 
 20      'csharp', 'c#', 
 21      'css+django', 'css+jinja', 'css+erb', 'css+ruby', 
 22      'css+genshitext', 'css+genshi', 'css+mako', 'css+myghty', 
 23      'css+php', 'css+smarty', 'css', 
 24      'cython', 'pyx', 'd-objdump', 'd', 'delphi', 'pas', 
 25      'pascal', 'objectpascal', 'diff', 'udiff', 
 26      'django', 'jinja', 'dpatch', 'dylan', 'erb', 
 27      'erl', 'erlang', 'evoque', 'felix', 'flx', 
 28      'fortran', 'gas', 'genshi', 'kid', 
 29      'xml+genshi', 'xml+kid', 'genshitext', 'glsl', 
 30      'gnuplot', 'go', 'groff', 'nroff', 'man', 'haml', 
 31      'HAML', 'haskell', 'hs', 
 32      'html+cheetah', 'html+spitfire', 'html+django', 'html+jinja', 
 33      'html+evoque', 'html+genshi', 'html+kid', 'html+mako', 
 34      'html+myghty', 'html+php', 'html+smarty', 'html', 
 35      'hx', 'haXe', 'ini', 'cfg', 'io', 'irc', 
 36      'java', 'js+cheetah', 'javascript+cheetah', 'js+spitfire', 
 37      'javascript+spitfire', 'js+django', 'javascript+django', 
 38      'js+jinja', 'javascript+jinja', 'js+erb', 'javascript+erb', 
 39      'js+ruby', 'javascript+ruby', 'js+genshitext', 'js+genshi', 
 40      'javascript+genshitext', 'javascript+genshi', 'js+mako', 
 41      'javascript+mako', 'js+myghty', 'javascript+myghty', 
 42      'js+php', 'javascript+php', 'js+smarty', 'javascript+smarty', 
 43      'js', 'javascript', 'jsp', 
 44      'lhs', 'literate-haskell', 'lighty', 'lighttpd', 'llvm', 
 45      'logtalk', 'lua', 'make', 'makefile', 'mf', 'bsdmake', 
 46      'mako', 'matlab', 'octave', 'matlabsession', 'minid', 
 47      'modelica', 'modula2', 'm2', 'moocode', 'mupad', 'mxml', 
 48      'myghty', 'mysql', 'nasm', 'newspeak', 'nginx', 'numpy', 
 49      'objdump', 'objective-c', 'objectivec', 'obj-c', 'objc', 
 50      'objective-j', 'objectivej', 'obj-j', 'objj', 'ocaml', 
 51      'ooc', 'perl', 'pl', 'php', 'php3', 'php4', 'php5', 
 52      'pot', 'po', 'pov', 'prolog', 'py3tb', 'pycon', 'pytb', 
 53      'python', 'py', 'python3', 'py3', 'ragel-c', 'ragel-cpp', 
 54      'ragel-d', 'ragel-em', 'ragel-java', 'ragel-objc', 
 55      'ragel-ruby', 'ragel-rb', 'ragel', 'raw', 'rb', 'ruby', 
 56      'rbcon', 'irb', 'rconsole', 'rout', 'rebol', 'redcode', 
 57      'rhtml', 'html+erb', 'html+ruby', 'rst', 'rest', 
 58      'restructuredtext', 'sass', 'SASS', 'scala', 'scheme', 
 59      'scm', 'smalltalk', 'squeak', 'smarty', 'sourceslist', 
 60      'sources.list', 'splus', 's', 'r', 'sql', 'sqlite3', 
 61      'squidconf', 'squid.conf', 'squid', 'tcl', 'tcsh', 
 62      'csh', 'tex', 'latex', 'text', 'trac-wiki', 'moin', 
 63      'vala', 'vapi', 'vb.net', 'vbnet', 'vim', 
 64      'xml+cheetah', 'xml+spitfire', 'xml+django', 'xml+jinja', 
 65      'xml+erb', 'xml+ruby', 'xml+evoque', 'xml+mako', 
 66      'xml+myghty', 'xml+php', 'xml+smarty', 'xml', 'xslt', 'yaml'] 
 67   
 68  # redefine what is not appropriate: 
 69   
70 -def sphinx_figure(m):
71 result = '' 72 # m is a MatchObject 73 74 caption = m.group('caption').strip() 75 76 # Stubstitute Doconce label by rst label in caption 77 # (also, remove final period in caption since caption is used as hyperlink 78 # text to figures). 79 80 m_label = re.search(r'label\{(.+?)\}', caption) 81 if m_label: 82 label = m_label.group(1) 83 result += '\n.. _%s:\n' % label 84 # remove . at the end of the caption text 85 parts = caption.split('label') 86 parts[0] = parts[0].rstrip() 87 if parts[0] and parts[0][-1] == '.': 88 parts[0] = parts[0][:-1] 89 # insert emphasize marks 90 parts[0] = '*' + parts[0].strip() + '*' 91 #caption = ' label'.join(parts) 92 caption = parts[0] 93 # contrary to rst_figure, we do not write label into caption 94 # since we just want to remove the whole label as part of 95 # the caption (otherwise done when handling ref and label) 96 else: 97 if caption and caption[-1] == '.': 98 caption = caption[:-1] 99 100 filename = m.group('filename') 101 #stem = os.path.splitext(filename)[0] 102 #result += '\n.. figure:: ' + stem + '.*\n' # utilize flexibility # does not work yet 103 result += '\n.. figure:: ' + filename + '\n' 104 opts = m.group('options') 105 if opts: 106 info = [s.split('=') for s in opts.split()] 107 rst_info = [' :%s: %s' % (option, value) for option, value in info] 108 result += '\n'.join(rst_info) 109 if caption: 110 result += '\n\n ' + caption + '\n' 111 else: 112 result += '\n\n' 113 #print 'sphinx figure: caption=\n', caption, '\nresult:\n', result 114 return result
115 116 from latex import fix_latex_command_regex as fix_latex 117
118 -def sphinx_code_orig(filestr, format):
119 # NOTE: THIS FUNCTION IS NOT USED!!!!!! 120 121 # In rst syntax, code blocks are typeset with :: (verbatim) 122 # followed by intended blocks. This function indents everything 123 # inside code (or TeX) blocks. 124 125 # grab #sphinx code-blocks: cod=python cpp=c++ etc line 126 # (do this before code is inserted in case verbatim blocks contain 127 # such specifications for illustration) 128 m = re.search(r'#\s*[Ss]phinx\s+code-blocks?:(.+?)\n', filestr) 129 if m: 130 defs_line = m.group(1) 131 # turn defs into a dictionary definition: 132 defs = {} 133 for definition in defs_line.split(): 134 key, value = definition.split('=') 135 defs[key] = value 136 else: 137 # default mappings: 138 defs = dict(cod='python', pycod='python', cycod='cython', 139 fcod='fortran', ccod='c', cppcod='c++', 140 mcod='matlab', plcod='perl', shcod='bash', 141 pro='python', pypro='python', cypro='cython', 142 fpro='fortran', cpro='c', cpppro='c++', 143 mpro='matlab', plpro='perl', shpro='bash', 144 sys='console', dat='python', ipy='python') 145 # (the "python" typesetting is neutral if the text 146 # does not parse as python) 147 148 # first indent all code/tex blocks by 1) extracting all blocks, 149 # 2) intending each block, and 3) inserting the blocks: 150 filestr, code_blocks, tex_blocks = remove_code_and_tex(filestr) 151 for i in range(len(code_blocks)): 152 code_blocks[i] = indent_lines(code_blocks[i], format) 153 for i in range(len(tex_blocks)): 154 tex_blocks[i] = indent_lines(tex_blocks[i], format) 155 # remove all \label{}s inside tex blocks: 156 tex_blocks[i] = re.sub(fix_latex(r'\label\{.+?\}', application='match'), 157 '', tex_blocks[i]) 158 # remove those without \ if there are any: 159 tex_blocks[i] = re.sub(r'label\{.+?\}', '', tex_blocks[i]) 160 161 # fix latex constructions that do not work with sphinx math 162 commands = [r'\begin{equation}', 163 r'\end{equation}', 164 r'\begin{equation*}', 165 r'\end{equation*}', 166 r'\begin{eqnarray}', 167 r'\end{eqnarray}', 168 r'\begin{eqnarray*}', 169 r'\end{eqnarray*}', 170 r'\begin{align}', 171 r'\end{align}', 172 r'\begin{align*}', 173 r'\end{align*}', 174 r'\begin{multline}', 175 r'\end{multline}', 176 r'\begin{multline*}', 177 r'\end{multline*}', 178 r'\begin{split}', 179 r'\end{split}', 180 r'\begin{gather}', 181 r'\end{gather}', 182 r'\begin{gather*}', 183 r'\end{gather*}', 184 r'\[', 185 r'\]', 186 # some common abbreviations (newcommands): 187 r'\beqan', 188 r'\eeqan', 189 r'\beqa', 190 r'\eeqa', 191 r'\balnn', 192 r'\ealnn', 193 r'\baln', 194 r'\ealn', 195 r'\beq', 196 r'\eeq', # the simplest, contained in others, must come last! 197 ] 198 for command in commands: 199 tex_blocks[i] = tex_blocks[i].replace(command, '') 200 tex_blocks[i] = re.sub('&\s*=\s*&', ' &= ', tex_blocks[i]) 201 # provide warnings for problematic environments 202 if '{alignat' in tex_blocks[i]: 203 print '\nWarning: the "alignat" environment will give errors in Sphinx:\n\n', tex_blocks[i], '\n' 204 205 206 filestr = insert_code_and_tex(filestr, code_blocks, tex_blocks, 'rst') 207 208 for key in defs: 209 language = defs[key] 210 if not language in legal_pygments_languages: 211 raise TypeError('%s is not a legal Pygments language '\ 212 '(lexer) in line with:\n %s' % \ 213 (language, defs_line)) 214 #filestr = re.sub(r'^!bc\s+%s\s*\n' % key, 215 # '\n.. code-block:: %s\n\n' % defs[key], filestr, 216 # flags=re.MULTILINE) 217 cpattern = re.compile(r'^!bc\s+%s\s*\n' % key, flags=re.MULTILINE) 218 filestr, n = cpattern.subn('\n.. code-block:: %s\n\n' % defs[key], filestr) 219 print key, n 220 if n > 0: 221 print 'sphinx: %d subst %s by %s' % (n, key, defs[key]) 222 223 # any !bc with/without argument becomes a py (python) block: 224 #filestr = re.sub(r'^!bc.+\n', '\n.. code-block:: py\n\n', filestr, 225 # flags=re.MULTILINE) 226 cpattern = re.compile(r'^!bc.+$', flags=re.MULTILINE) 227 filestr = cpattern.sub('\n.. code-block:: py\n\n', filestr) 228 229 filestr = re.sub(r'!ec *\n', '\n\n', filestr) 230 #filestr = re.sub(r'!ec\n', '\n', filestr) 231 #filestr = re.sub(r'!ec\n', '', filestr) 232 filestr = re.sub(r'!bt *\n', '\n.. math::\n\n', filestr) 233 filestr = re.sub(r'!et *\n', '\n\n', filestr) 234 235 return filestr
236
237 -def sphinx_code_newmathlabels(filestr, format):
238 # NOTE: THIS FUNCTION IS NOT USED!!!!!! 239 240 # In rst syntax, code blocks are typeset with :: (verbatim) 241 # followed by intended blocks. This function indents everything 242 # inside code (or TeX) blocks. 243 244 # grab #sphinx code-blocks: cod=python cpp=c++ etc line 245 # (do this before code is inserted in case verbatim blocks contain 246 # such specifications for illustration) 247 m = re.search(r'#\s*[Ss]phinx\s+code-blocks?:(.+?)\n', filestr) 248 if m: 249 defs_line = m.group(1) 250 # turn defs into a dictionary definition: 251 defs = {} 252 for definition in defs_line.split(): 253 key, value = definition.split('=') 254 defs[key] = value 255 else: 256 # default mappings: 257 defs = dict(cod='python', pycod='python', cppcod='c++', 258 fcod='fortran', ccod='c', 259 pro='python', pypro='python', cpppro='c++', 260 fpro='fortran', cpro='c', 261 sys='console', dat='python') 262 # (the "python" typesetting is neutral if the text 263 # does not parse as python) 264 265 # First indent all code/tex blocks by 1) extracting all blocks, 266 # 2) intending each block, and 3) inserting the blocks. 267 # In between, handle the math blocks. 268 269 filestr, code_blocks, tex_blocks = remove_code_and_tex(filestr) 270 for i in range(len(code_blocks)): 271 code_blocks[i] = indent_lines(code_blocks[i], format) 272 273 math_labels = [] 274 for i in range(len(tex_blocks)): 275 tex_blocks[i] = indent_lines(tex_blocks[i], format) 276 # extract all \label{}s inside tex blocks and typeset them 277 # with :label: tags 278 label_regex1 = fix_latex(r'\label\{(.+?)\}', application='match') 279 label_regex2 = fix_latex( r'label\{(.+?)\}', application='match') 280 math_labels.extend(re.findall(label_regex1, tex_blocks[i])) 281 tex_blocks[i] = re.sub(label_regex1, 282 r' :label: \g<1> ', tex_blocks[i]) 283 # handle also those without \ if there are any: 284 math_labels.extend(re.findall(label_regex2, tex_blocks[i])) 285 tex_blocks[i] = re.sub(label_regex2, r' :label: \g<1> ', tex_blocks[i]) 286 287 # replace all references to equations: 288 for label in math_labels: 289 filestr = filestr.replace(':ref:`%s`' % label, ':eq:`%s`' % label) 290 291 filestr = insert_code_and_tex(filestr, code_blocks, tex_blocks, 'rst') 292 293 for key in defs: 294 language = defs[key] 295 if not language in legal_pygments_languages: 296 raise TypeError('%s is not a legal Pygments language '\ 297 '(lexer) in line with:\n %s' % \ 298 (language, defs_line)) 299 #filestr = re.sub(r'^!bc\s+%s\s*\n' % key, 300 # '\n.. code-block:: %s\n\n' % defs[key], filestr, 301 # flags=re.MULTILINE) 302 cpattern = re.compile(r'^!bc\s+%s\s*\n' % key, flags=re.MULTILINE) 303 filestr = cpattern.sub('\n.. code-block:: %s\n\n' % defs[key], filestr) 304 305 # any !bc with/without argument becomes a py (python) block: 306 #filestr = re.sub(r'^!bc.+\n', '\n.. code-block:: py\n\n', filestr, 307 # flags=re.MULTILINE) 308 cpattern = re.compile(r'^!bc.+$', flags=re.MULTILINE) 309 filestr = cpattern.sub('\n.. code-block:: py\n\n', filestr) 310 311 filestr = re.sub(r'!ec *\n', '\n\n', filestr) 312 #filestr = re.sub(r'!ec\n', '\n', filestr) 313 #filestr = re.sub(r'!ec\n', '', filestr) 314 filestr = re.sub(r'!bt *\n', '\n.. math::\n :nowrap:\n\n', filestr) 315 filestr = re.sub(r'!et *\n', '\n\n', filestr) 316 317 return filestr
318
319 -def sphinx_code(filestr, format):
320 # In rst syntax, code blocks are typeset with :: (verbatim) 321 # followed by intended blocks. This function indents everything 322 # inside code (or TeX) blocks. 323 324 # grab #sphinx code-blocks: cod=python cpp=c++ etc line 325 # (do this before code is inserted in case verbatim blocks contain 326 # such specifications for illustration) 327 m = re.search(r'#\s*[Ss]phinx\s+code-blocks?:(.+?)\n', filestr) 328 if m: 329 defs_line = m.group(1) 330 # turn specifications into a dictionary: 331 envir2lang = {} 332 for definition in defs_line.split(): 333 key, value = definition.split('=') 334 envir2lang[key] = value 335 else: 336 # default mappings: 337 envir2lang = dict(cod='python', pycod='python', cycod='cython', 338 fcod='fortran', ccod='c', cppcod='c++', 339 mcod='matlab', plcod='perl', shcod='bash', 340 rst='rst', ipy='python', 341 pro='python', pypro='python', cypro='cython', 342 fpro='fortran', cpro='c', cpppro='c++', 343 mpro='matlab', plpro='perl', shpro='bash', 344 sys='console', dat='python') 345 # (the "python" typesetting is neutral if the text 346 # does not parse as python) 347 348 # Remove all !bc ipy since interactive sessions are automatically 349 # handled by sphinx without indentation (just a blank line before 350 # and after) 351 cpattern = re.compile(r'^!bc +ipy *\n(.*?)^!ec *\n', 352 re.DOTALL|re.MULTILINE) 353 filestr = cpattern.sub('\n\g<1>\n', filestr) 354 355 # First indent all code/tex blocks by 1) extracting all blocks, 356 # 2) intending each block, and 3) inserting the blocks. 357 # In between, handle the math blocks. 358 359 filestr, code_blocks, tex_blocks = remove_code_and_tex(filestr) 360 for i in range(len(code_blocks)): 361 code_blocks[i] = indent_lines(code_blocks[i], format) 362 363 # Treat math labels. Drop labels in environments with multiple 364 # equations since these do not work in Sphinx. Method: keep 365 # label if there is one and only one. Otherwise use old 366 # method of removing labels. Do not use :nowrap: since this will 367 # generate other labels that we cannot refer to. 368 # 369 math_labels = [] 370 for i in range(len(tex_blocks)): 371 tex_blocks[i] = indent_lines(tex_blocks[i], format) 372 # extract all \label{}s inside tex blocks and typeset them 373 # with :label: tags 374 label_regex1 = fix_latex(r'\label\{(.+?)\}', application='match') 375 label_regex2 = fix_latex( r'label\{(.+?)\}', application='match') 376 for label_regex in (label_regex1, label_regex2): 377 labels = re.findall(label_regex, tex_blocks[i]) 378 if len(labels) == 1: 379 math_labels.extend(labels) 380 tex_blocks[i] = ' :label: %s\n' % labels[0] + tex_blocks[i] 381 tex_blocks[i] = re.sub(label_regex, '', tex_blocks[i]) 382 383 # fix latex constructions that do not work with sphinx math 384 commands = [r'\begin{equation}', 385 r'\end{equation}', 386 r'\begin{equation*}', 387 r'\end{equation*}', 388 r'\begin{eqnarray}', 389 r'\end{eqnarray}', 390 r'\begin{eqnarray*}', 391 r'\end{eqnarray*}', 392 r'\begin{align}', 393 r'\end{align}', 394 r'\begin{align*}', 395 r'\end{align*}', 396 r'\begin{multline}', 397 r'\end{multline}', 398 r'\begin{multline*}', 399 r'\end{multline*}', 400 r'\begin{split}', 401 r'\end{split}', 402 r'\begin{gather}', 403 r'\end{gather}', 404 r'\begin{gather*}', 405 r'\end{gather*}', 406 r'\[', 407 r'\]', 408 # some common abbreviations (newcommands): 409 r'\beqan', 410 r'\eeqan', 411 r'\beqa', 412 r'\eeqa', 413 r'\balnn', 414 r'\ealnn', 415 r'\baln', 416 r'\ealn', 417 r'\beq', 418 r'\eeq', # the simplest, contained in others, must come last! 419 ] 420 for command in commands: 421 tex_blocks[i] = tex_blocks[i].replace(command, '') 422 tex_blocks[i] = re.sub('&\s*=\s*&', ' &= ', tex_blocks[i]) 423 # provide warnings for problematic environments 424 if '{alignat' in tex_blocks[i]: 425 print '\nWarning: the "alignat" environment will give errors in Sphinx:\n\n', tex_blocks[i], '\n' 426 427 # Replace all references to equations that have labels in math environments: 428 for label in math_labels: 429 filestr = filestr.replace('(:ref:`%s`)' % label, ':eq:`%s`' % label) 430 431 filestr = insert_code_and_tex(filestr, code_blocks, tex_blocks, 'rst') 432 433 # Make correct code-block:: language constructions 434 for key in envir2lang: 435 language = envir2lang[key] 436 if not language in legal_pygments_languages: 437 raise TypeError('%s is not a legal Pygments language '\ 438 '(lexer) in line with:\n %s' % \ 439 (language, defs_line)) 440 #filestr = re.sub(r'^!bc\s+%s\s*\n' % key, 441 # '\n.. code-block:: %s\n\n' % envir2lang[key], filestr, 442 # flags=re.MULTILINE) 443 cpattern = re.compile(r'^!bc\s+%s\s*\n' % key, flags=re.MULTILINE) 444 filestr = cpattern.sub('\n.. code-block:: %s\n\n' % \ 445 envir2lang[key], filestr) 446 447 # any !bc with/without argument becomes a py (python) block: 448 #filestr = re.sub(r'^!bc.+\n', '\n.. code-block:: py\n\n', filestr, 449 # flags=re.MULTILINE) 450 cpattern = re.compile(r'^!bc.+$', flags=re.MULTILINE) 451 filestr = cpattern.sub('\n.. code-block:: py\n\n', filestr) 452 453 filestr = re.sub(r'!ec *\n', '\n\n', filestr) 454 #filestr = re.sub(r'!ec\n', '\n', filestr) 455 #filestr = re.sub(r'!ec\n', '', filestr) 456 filestr = re.sub(r'!bt *\n', '\n.. math::\n', filestr) 457 filestr = re.sub(r'!et *\n', '\n\n', filestr) 458 459 return filestr
460
461 -def sphinx_ref_and_label(section_label2title, format, filestr):
462 filestr = ref_and_label_commoncode(section_label2title, format, filestr) 463 464 # replace all references to sections: 465 for label in section_label2title: 466 filestr = filestr.replace('ref{%s}' % label, ':ref:`%s`' % label) 467 468 # not of interest after sphinx got equation references: 469 #from common import ref2equations 470 #filestr = ref2equations(filestr) 471 472 # replace remaining ref{x} as :ref:`x` 473 filestr = re.sub(r'ref\{(.+?)\}', ':ref:`\g<1>`', filestr) 474 475 return filestr
476
477 -def sphinx_index_bib(filestr, index, citations, bibfile):
478 filestr = rst_bib(filestr, citations, bibfile) 479 480 for word in index: 481 word2 = word.replace('`', '') # drop verbatim in index 482 if not '!' in word: 483 filestr = filestr.replace('idx{%s}' % word, 484 '\n.. index:: ' + word2 + '\n') 485 else: 486 word3 = word2.replace('!', '; ') 487 filestr = filestr.replace('idx{%s}' % word, 488 '\n.. index::\n pair: ' + word3 + '\n') 489 return filestr
490 491
492 -def define(FILENAME_EXTENSION, 493 BLANKLINE, 494 INLINE_TAGS_SUBST, 495 CODE, 496 LIST, 497 ARGLIST, 498 TABLE, 499 EXERCISE, 500 FIGURE_EXT, 501 CROSS_REFS, 502 INDEX_BIB, 503 INTRO, 504 OUTRO):
505 if not 'rst' in BLANKLINE: 506 # rst.define is not yet ran on these dictionaries, do it: 507 import rst 508 rst.define(FILENAME_EXTENSION, 509 BLANKLINE, 510 INLINE_TAGS_SUBST, 511 CODE, 512 LIST, 513 ARGLIST, 514 TABLE, 515 FIGURE_EXT, 516 INTRO, 517 OUTRO) 518 519 FILENAME_EXTENSION['sphinx'] = FILENAME_EXTENSION['rst'] 520 BLANKLINE['sphinx'] = BLANKLINE['rst'] 521 CODE['sphinx'] = CODE['rst'] 522 LIST['sphinx'] = LIST['rst'] 523 FIGURE_EXT['sphinx'] = ('.png', '.gif', '.jpg', '.jpeg') 524 CROSS_REFS['sphinx'] = sphinx_ref_and_label 525 INDEX_BIB['sphinx'] = sphinx_index_bib 526 TABLE['sphinx'] = TABLE['rst'] 527 EXERCISE['sphinx'] = EXERCISE['rst'] 528 INTRO['sphinx'] = INTRO['rst'] 529 530 # make true copy of INLINE_TAGS_SUBST: 531 INLINE_TAGS_SUBST['sphinx'] = {} 532 for tag in INLINE_TAGS_SUBST['rst']: 533 INLINE_TAGS_SUBST['sphinx'][tag] = INLINE_TAGS_SUBST['rst'][tag] 534 535 # modify some tags: 536 INLINE_TAGS_SUBST['sphinx']['math'] = r'\g<begin>:math:`\g<subst>`\g<end>' 537 INLINE_TAGS_SUBST['sphinx']['math2'] = r'\g<begin>:math:`\g<latexmath>`\g<end>' 538 INLINE_TAGS_SUBST['sphinx']['figure'] = sphinx_figure 539 CODE['sphinx'] = sphinx_code # function for typesetting code 540 541 ARGLIST['sphinx'] = { 542 'parameter': ':param', 543 'keyword': ':keyword', 544 'return': ':return', 545 'instance variable': ':ivar', 546 'class variable': ':cvar', 547 'module variable': ':var', 548 }
549