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 from inspect import formatargspec, getargspec, getdoc
29 from re import match, search
30 import sys
31 from string import lowercase, lstrip, punctuation, replace, rstrip, split, upper, whitespace
32
33
34 sys.path.append(sys.path[0])
35 sys.path[0] = '../..'
36
37
38 from prompt.interpreter import Interpreter
39
40
42 - def __init__(self, file='docstring.tex'):
43 """Fetch all the docstrings of the user functions and format them LaTeX style."""
44
45
46 self.script_file = None
47 self.intro_string = ''
48 self.dummy_mode = 1
49
50
51 self.interpreter = Interpreter(self)
52 self.interpreter.run()
53
54
55 self.get_blacklist()
56
57
58 self.file = open(file, 'w')
59
60
61 names = self.local.keys()
62
63
64 names.sort()
65
66
67
68 for name in names:
69
70 if name in self.blacklist:
71 continue
72
73
74 object = self.local[name]
75
76
77 if hasattr(object, '__relax_help__'):
78
79 self.doc_user_class(name, object)
80
81
82 if not hasattr(object, '__doc__') or not object.__doc__:
83 continue
84
85
86 self.parse_docstring(name, object)
87
88
89 self.file.close()
90
91
93 """Document the user class."""
94
95
96 names = dir(parent_object)
97
98
99 names.sort()
100
101
102 for name in names:
103
104 if search('^_', name):
105 continue
106
107
108 object = getattr(parent_object, name)
109
110
111 if not hasattr(object, '__doc__') or not object.__doc__:
112 continue
113
114
115 self.parse_docstring(parent_name + '.' + name, object)
116
117
119 """Maintained list of objects in the interpreter namespace which should not be documented."""
120
121
122 self.blacklist = []
123
124
125 self.blacklist.append('Numeric')
126 self.blacklist.append('Scientific')
127 self.blacklist.append('pi')
128 self.blacklist.append('script')
129
130
132 """Function of inserting index marks into the text."""
133
134
135 if bold:
136 end_string = '|textbf}'
137 else:
138 end_string = '}'
139
140
141 for i in xrange(len(self.entries)):
142
143 if index+2 < len(self.words) and self.entries[i][2] == 3 and search(self.entries[i][0], self.words[index] + ' ' + self.words[index+1] + ' ' + self.words[index+2]):
144 self.words[index] = self.words[index] + '\\index{' + self.entries[i][1] + end_string
145
146
147 elif index+1 < len(self.words) and self.entries[i][2] == 2 and search(self.entries[i][0], self.words[index] + ' ' + self.words[index+1]):
148 self.words[index] = self.words[index] + '\\index{' + self.entries[i][1] + end_string
149
150
151 elif self.entries[i][2] == 1 and search(self.entries[i][0], self.words[index]):
152 self.words[index] = self.words[index] + '\\index{' + self.entries[i][1] + end_string
153
154
156 """Function for returning a data structure containing all words which should be indexed."""
157
158
159 self.entries = []
160
161
162
163
164 self.entries.append(['angle', 'angles'])
165 self.entries.append(['anisotropic', 'diffusion!anisotropic'])
166 self.entries.append(['asymmetric', 'diffusion!ellipsoid (asymmetric)'])
167 self.entries.append(['axially symmetric', 'diffusion!spheroid (axially symmetric)'])
168
169 self.entries.append(['BFGS', 'minimisation techniques!BFGS'])
170 self.entries.append(['bond length', 'bond length'])
171 self.entries.append(['bound', 'parameter!bounds'])
172 self.entries.append(['Brownian', 'diffusion!Brownian'])
173 self.entries.append(['bzip2', 'compression!bzip2'])
174
175 self.entries.append(['cauchy', 'minimisation techniques!Cauchy point'])
176 self.entries.append(['CG-Steihaug', 'minimisation techniques!CG-Steihaug'])
177 self.entries.append(['chemical exchange', 'chemical exchange'])
178 self.entries.append(['chi-squared', 'chi-squared'])
179 self.entries.append(['compression', 'compression'])
180 self.entries.append(['conjugate gradient', 'minimisation techniques!conjugate gradient'])
181 self.entries.append(['constraint', 'constraint'])
182 self.entries.append(['copy', 'copy'])
183 self.entries.append(['correlation time', 'correlation time'])
184
185 self.entries.append(['dasha', 'computer programs!Dasha'])
186 self.entries.append(['Dasha', 'computer programs!Dasha'])
187 self.entries.append(['delete', 'delete'])
188 self.entries.append(['diffusion tensor', 'diffusion!tensor'])
189 self.entries.append(['display', 'display'])
190 self.entries.append(['dogleg', 'minimisation techniques!dogleg'])
191
192 self.entries.append(['eigenvalue', 'eigenvalues'])
193 self.entries.append(['elimination', 'model elimination'])
194 self.entries.append(['ellipsoid', 'diffusion!ellipsoid (asymmetric)'])
195 self.entries.append(['Euler angle', 'Euler angles'])
196 self.entries.append(['exact trust region', 'minimisation techniques!exact trust region'])
197
198 self.entries.append(['Fletcher-Reeves', 'minimisation techniques!Fletcher-Reeves'])
199 self.entries.append(['floating point', 'floating point number'])
200
201 self.entries.append(['grace', 'computer programs!Grace'])
202 self.entries.append(['Grace', 'computer programs!Grace'])
203 self.entries.append(['gzip', 'compression!gzip'])
204
205 self.entries.append(['Hestenes-Stiefel', 'minimisation techniques!Hestenes-Stiefel'])
206
207 self.entries.append(['isotropic', 'diffusion!sphere (isotropic)'])
208
209 self.entries.append(['Levenberg-Marquardt', 'minimisation techniques!Levenberg-Marquardt'])
210 self.entries.append(['limit', 'parameter!limit'])
211
212 self.entries.append(['map', 'map'])
213 self.entries.append(['method of [Mm]ultipliers', 'minimisation techniques!Method of Multipliers'])
214 self.entries.append(['minimise', 'minimisation'])
215 self.entries.append(['minimisation', 'minimisation'])
216 self.entries.append(['model elimination', 'model elimination'])
217 self.entries.append(['modelfree4', 'computer programs!Modelfree4'])
218 self.entries.append(['Modelfree4', 'computer programs!Modelfree4'])
219 self.entries.append(['modelling', 'modelling'])
220 self.entries.append(['molecule', 'molecule'])
221 self.entries.append(['molmol', 'computer programs!Molmol'])
222 self.entries.append(['Molmol', 'computer programs!Molmol'])
223
224 self.entries.append(['opendx', 'computer programs!OpenDX'])
225 self.entries.append(['OpenDX', 'computer programs!OpenDX'])
226 self.entries.append(['optimise', 'optimise'])
227 self.entries.append(['order parameter', 'order parameter'])
228
229 self.entries.append(['newton', 'minimisation techniques!Newton'])
230 self.entries.append(['newton-CG', 'minimisation techniques!Newton conjugate gradient'])
231 self.entries.append(['NMR', 'NMR'])
232
233 self.entries.append(['PDB', 'PDB'])
234 self.entries.append(['Polak-Ribi.*re', 'minimisation techniques!Polak-Ribiere@Polak-Ribi\`ere'])
235 self.entries.append(['Polak-Ribi.*re +', 'minimisation techniques!Polak-Ribiere@Polak-Ribi\`ere +'])
236 self.entries.append(['plot', 'plot'])
237 self.entries.append(['python', 'Python'])
238
239 self.entries.append(['read', 'read'])
240 self.entries.append(['regular expression', 'regular expression'])
241 self.entries.append(['relaxation', 'relaxation'])
242 self.entries.append(['rotation', 'rotation'])
243
244 self.entries.append(['sequence', 'sequence'])
245 self.entries.append(['script', 'scripting!script file'])
246 self.entries.append(['scripting', 'scripting'])
247 self.entries.append(['simplex', 'minimisation techniques!simplex'])
248 self.entries.append(['sphere', 'diffusion!sphere (isotropic)'])
249 self.entries.append(['spheroid', 'diffusion!spheroid (axially symmetric)'])
250 self.entries.append(['sparky', 'computer programs!Sparky'])
251 self.entries.append(['Sparky', 'computer programs!Sparky'])
252 self.entries.append(['steepest descent', 'minimisation techniques!steepest descent'])
253
254 self.entries.append(['tar', 'tar'])
255
256 self.entries.append(['uncompressed', 'compression!uncompressed'])
257
258 self.entries.append(['write', 'write'])
259
260 self.entries.append(['xeasy', 'computer programs!XEasy'])
261 self.entries.append(['Xeasy', 'computer programs!XEasy'])
262 self.entries.append(['XEasy', 'computer programs!XEasy'])
263
264
265 for i in xrange(len(self.entries)):
266
267 self.entries[i].append(len(split(self.entries[i][0], ' ')))
268
269
270 if search(self.entries[i][0][0], lowercase):
271 self.entries[i][0] = '[' + upper(self.entries[i][0][0]) + self.entries[i][0][0] + ']' + self.entries[i][0][1:]
272
273
274 self.entries[i][0] = '^' + self.entries[i][0]
275
276
277 self.entries[i].reverse()
278
279
280 self.entries.sort(reverse=1)
281 for i in xrange(len(self.entries)):
282 self.entries[i].reverse()
283
284
286 """Change the keyword label to bold sans serif font."""
287
288
289 string = ''
290
291
292 while 1:
293
294 if self.i+1 > len(self.docstring_lines) or (self.docstring_lines[self.i] == '' and self.docstring_lines[self.i+1] == ''):
295 self.i = self.i + 1
296 break
297
298
299 if self.docstring_lines[self.i] == '':
300 string = string + ' \n '
301
302
303 else:
304 string = string + self.docstring_lines[self.i] + ' '
305
306
307 self.i = self.i + 1
308
309
310 self.section.append(string)
311 self.section_type.append('keywords')
312
313
457
458
460 """Function for changing the quotes for LaTeX processing."""
461
462
463 new_string = ''
464 in_quote = 0
465
466
467 for i in xrange(len(string)):
468
469 if search('\'', string[i]):
470
471 if not in_quote and (i == 0 or not search('[a-z]', string[i-1])):
472 new_string = new_string + '`'
473 in_quote = 1
474 continue
475
476
477 else:
478 in_quote = 0
479
480
481 new_string = new_string + string[i]
482
483 return new_string
484
485
487 """Function for handling LaTeX special characters."""
488
489
490 string = replace(string, '\\', 'This is a backslash to be replaced at the end of this functioN')
491
492
493 for char in "#$%&_{}":
494 string = replace(string, char, '\\'+char)
495
496
497 for char in "^~":
498 string = replace(string, char, '\\'+char+'{}')
499
500
501 string = replace(string, 'This is a backslash to be replaced at the end of this functioN', '$\\backslash$')
502
503
504 return string
505
506
508 """Function for creating LaTeX lists."""
509
510
511 string = lstrip(self.docstring_lines[self.i])
512
513
514 j = self.i
515 while 1:
516
517 j = j + 1
518
519
520 if len(self.docstring_lines) <= j:
521 list_spacing = 0
522 break
523
524
525 if len(self.docstring_lines[j]) == 0:
526
527 if len(self.docstring_lines) <= j+1:
528 list_spacing = 0
529
530
531 elif search('^ ', self.docstring_lines[j+1]):
532 list_spacing = 1
533
534
535 else:
536 list_spacing = 0
537
538
539 break
540
541
542 if not list_spacing:
543
544 string = string + ' \n '
545
546
547 while 1:
548
549 self.i = self.i + 1
550
551
552 if self.i >= len(self.docstring_lines) or len(self.docstring_lines[self.i]) == 0:
553 break
554
555
556 string = string + lstrip(self.docstring_lines[self.i]) + ' \n '
557
558
559 else:
560
561 while 1:
562
563 self.i = self.i + 1
564
565
566 if self.i >= len(self.docstring_lines):
567 break
568
569
570 if len(self.docstring_lines[self.i]) == 0:
571
572 string = string + ' \n '
573
574
575 continue
576
577
578 if self.i >= len(self.docstring_lines) or not search('^ ', (self.docstring_lines[self.i])):
579 break
580
581
582 string = string + ' ' + lstrip(self.docstring_lines[self.i])
583
584
585 self.i = self.i - 1
586
587
588 self.section.append(string)
589 self.section_type.append('list')
590
591
593 """Function for extracting the paragraphs from the docstring."""
594
595
596 string = self.docstring_lines[self.i]
597
598
599 while 1:
600
601 self.i = self.i + 1
602
603
604 if self.i >= len(self.docstring_lines):
605 break
606
607
608 if len(self.docstring_lines[self.i]) == 0:
609 break
610
611
612 if search('^___', self.docstring_lines[self.i]):
613 break
614
615
616 if search('^ ', self.docstring_lines[self.i]):
617 break
618
619
620 string = string + ' ' + self.docstring_lines[self.i]
621
622
623 self.i = self.i - 1
624
625
626 self.section.append(string)
627 self.section_type.append('paragraph')
628
629
631 """Function for creating the LaTeX file."""
632
633
634
635
636
637 sys.stdout.write("Function: " + `function` + "\n")
638
639
640 docstring = getdoc(object)
641
642
643 self.docstring_lines = split(docstring, "\n")
644
645
646 self.section = []
647 self.section_type = []
648
649
650
651
652
653 self.section.append(function)
654 self.section_type.append('subsection')
655
656
657
658
659
660
661 self.section.append('Synopsis')
662 self.section_type.append('subsubsection')
663
664
665 self.section.append(self.docstring_lines[0])
666 self.section_type.append('paragraph')
667
668
669
670
671
672
673 self.section.append('Defaults')
674 self.section_type.append('subsubsection')
675
676
677 args, varargs, varkw, defaults = getargspec(object)
678
679
680 arguments = formatargspec(args, varargs, varkw, defaults)
681
682
683 self.section.append(arguments)
684 self.section_type.append('arguments')
685
686
687
688
689
690
691 self.i = 1
692 while 1:
693
694 self.i = self.i + 1
695
696
697 if self.i >= len(self.docstring_lines):
698 break
699
700
701 self.docstring_lines[self.i] = rstrip(self.docstring_lines[self.i])
702
703
704 if self.docstring_lines[self.i] == '':
705 continue
706
707
708 if self.i+1 < len(self.docstring_lines) and search('^~~~', self.docstring_lines[self.i+1]):
709
710 self.section_title = self.docstring_lines[self.i]
711 self.section.append(self.docstring_lines[self.i])
712 self.section_type.append('subsubsection')
713
714
715 self.i = self.i + 2
716 continue
717
718
719 if search('^Keyword ', self.section_title):
720 self.keywords()
721
722
723 elif search('---', self.docstring_lines[self.i]):
724 self.verbatim()
725
726
727 elif search('^relax>', self.docstring_lines[self.i]) or search('^\$ ', self.docstring_lines[self.i]):
728 self.relax_examples()
729
730
731 elif search('^___', self.docstring_lines[self.i]):
732 self.tables()
733
734
735 elif search('^ ', self.docstring_lines[self.i]):
736 self.lists()
737
738
739 else:
740 self.paragraph()
741
742
743
744
745
746
747
748 self.index_entries()
749
750
751 for i in xrange(len(self.section)):
752
753 st = self.section_type[i]
754
755
756 if st == 'arguments' or st == 'example':
757 self.section[i] = self.latex_quotes(self.section[i])
758
759
760 if not st == 'verbatim':
761 self.section[i] = self.latex_special_chars(self.section[i])
762
763
764 if not st == 'arguments' and not st == 'verbatim' and not st == 'example' and not st == 'subsection':
765 self.section[i] = self.latex_formatting(self.section[i])
766
767
768 if not st == 'arguments' and not st == 'verbatim' and not st == 'example':
769
770 self.words = split(self.section[i], ' ')
771
772
773 self.in_quote = 0
774
775
776 for j in xrange(len(self.words)):
777
778 if st == 'subsection' or st == 'subsubsection':
779 self.indexing(j, bold=1)
780 else:
781 self.indexing(j, bold=0)
782
783
784 self.quotes(j)
785
786
787 if j == 0:
788 self.section[i] = self.words[j]
789 else:
790 self.section[i] = self.section[i] + ' ' + self.words[j]
791
792
793
794
795
796
797 self.file.write(" \n\n \\newpage")
798
799
800 for i in xrange(len(self.section)):
801
802 st = self.section_type[i]
803
804
805 if st == 'subsection':
806 self.file.write(" \n\n \\subsection{" + self.section[i] + "}")
807
808
809 elif st == 'subsubsection':
810 self.file.write(" \n \\subsubsection{" + self.section[i] + "}")
811
812
813 elif st == 'arguments':
814 self.file.write("\\textsf{\\textbf{" + self.latex_special_chars(function) + "}" + self.section[i] + "}")
815
816
817 elif st == 'keywords':
818
819 lines = split(self.section[i], '\n')
820
821
822 for line in lines:
823
824 line_elements = split(line, ':')
825
826
827 if len(line_elements) > 2:
828 sys.write("Keyword failure in: " + `line` + " \n ")
829 sys.exit()
830
831
832 self.file.write("\\keyword{" + line_elements[0] + ":}" + line_elements[1] + " \n\n ")
833
834
835
836 elif st == 'verbatim':
837 self.file.write("{\\footnotesize \\begin{verbatim} \n " + self.section[i] + "\\end{verbatim}}")
838
839
840 elif st == 'example':
841 self.file.write("\\example{" + self.section[i] + "}")
842
843
844 elif st == 'table':
845
846 lines = split(self.section[i], '\n')
847
848
849 self.file.write("\\begin{center} \n ")
850 self.file.write("\\begin{tabular}{" + (int(lines[0]))*"l" + "} \n ")
851 self.file.write("\\toprule \n ")
852
853
854 elements = split(lines[1], 'SEPARATOR')
855 self.file.write(elements[0])
856 for j in range(1, len(elements)):
857 self.file.write('&' + elements[j])
858 self.file.write(" \\\\ \n ")
859
860
861 self.file.write("\\midrule \n ")
862
863
864 for line in lines[2:-1]:
865
866 elements = split(line, 'SEPARATOR')
867
868
869 self.file.write(elements[0])
870 for j in range(1, len(elements)):
871 self.file.write('&' + elements[j])
872 self.file.write(" \\\\\n ")
873
874
875 self.file.write("\\bottomrule \n ")
876 self.file.write("\\end{tabular} \n ")
877 self.file.write("\\end{center} \n ")
878
879
880 elif st == 'list':
881
882 lines = split(self.section[i], '\n')
883
884
885 if len(lines[-1]) == 0:
886 lines = lines[:-1]
887
888
889 elements = split(lines[0], ':')
890
891
892 if len(elements) > 2:
893 sys.stderr.write("Error: Badly formatted list element.\n")
894 sys.stderr.write("The element is: " + `lines[i]` + "\n")
895 sys.exit()
896
897
898 if len(elements) == 1:
899 list_type = 0
900
901
902 else:
903 list_type = 1
904
905
906 if list_type == 1:
907 self.file.write("\\begin{description} \n ")
908 else:
909 self.file.write("\\begin{itemize} \n ")
910
911
912 for j in xrange(len(lines)):
913
914 if list_type == 0:
915 self.file.write("\\item[] " + lstrip(lines[j]) + ' \n ')
916
917
918 else:
919
920 elements = split(lines[j], ':')
921
922
923 if len(elements) != 2:
924 continue
925
926
927 self.file.write("\\item[" + lstrip(elements[0]) + " --]" + elements[1] + ' \n ')
928
929
930 if list_type == 1:
931 self.file.write("\\end{description} \n ")
932 else:
933 self.file.write("\\end{itemize} \n ")
934
935
936 else:
937 self.file.write(self.section[i] + ' \n ')
938
939
940 self.file.write(" \n\n ")
941
942
944 """Function for placing quotes within the quote environment."""
945
946
947 elements = split(self.words[index], "'")
948
949
950 if len(elements) == 3:
951 self.words[index] = elements[0] + '\quotecmd{' + elements[1] + '}' + elements[2]
952
953
954 elif len(elements) > 3:
955 sys.stderr.write('Unknown quote: ' + `self.words[index]`)
956 sys.exit()
957
958
959 if len(elements) == 2:
960
961 if not self.in_quote and not search('[a-z]$', elements[0]):
962 self.words[index] = elements[0] + '\quotecmd{' + elements[1]
963 self.in_quote = 1
964
965
966 elif self.in_quote:
967 self.words[index] = elements[0] + '}' + elements[1]
968 self.in_quote = 0
969
970
972 """Use typewriter font for relax examples."""
973
974
975 string = self.docstring_lines[self.i]
976
977
978 while 1:
979
980 self.i = self.i + 1
981
982
983 if self.i >= len(self.docstring_lines) or self.docstring_lines[self.i] == '' or search('^relax>', self.docstring_lines[self.i]) or search('^\$ ', self.docstring_lines[self.i]):
984 self.i = self.i - 1
985 break
986
987
988 string = string + ' ' + lstrip(self.docstring_lines[self.i])
989
990
991 self.section.append(string)
992 self.section_type.append('example')
993
994
996 """Only replace in safe places within the text."""
997
998
999
1000
1001 string = replace(string, '0'+text, '0'+latex)
1002 string = replace(string, '1'+text, '1'+latex)
1003 string = replace(string, '2'+text, '2'+latex)
1004 string = replace(string, '3'+text, '3'+latex)
1005 string = replace(string, '4'+text, '4'+latex)
1006 string = replace(string, '5'+text, '5'+latex)
1007 string = replace(string, '6'+text, '6'+latex)
1008 string = replace(string, '7'+text, '7'+latex)
1009 string = replace(string, '8'+text, '8'+latex)
1010 string = replace(string, '9'+text, '9'+latex)
1011
1012
1013 string = replace(string, ' '+text+',', ' '+latex+',')
1014 string = replace(string, ' '+text+'.', ' '+latex+'.')
1015 string = replace(string, ' '+text+' ', ' '+latex+' ')
1016 string = replace(string, ' '+text+';', ' '+latex+';')
1017 string = replace(string, ' '+text+':', ' '+latex+':')
1018
1019
1020 string = replace(string, '['+text+']', '['+latex+']')
1021 string = replace(string, '['+text+' ', '['+latex+' ')
1022 string = replace(string, '['+text+',', '['+latex+',')
1023 string = replace(string, '['+text+';', '['+latex+';')
1024 string = replace(string, ' '+text+']', ' '+latex+']')
1025
1026
1027 string = replace(string, '('+text+')', '('+latex+')')
1028 string = replace(string, '('+text+' ', '('+latex+' ')
1029 string = replace(string, '('+text+',', '('+latex+',')
1030 string = replace(string, '('+text+';', '('+latex+';')
1031 string = replace(string, ' '+text+')', ' '+latex+')')
1032
1033
1034 string = replace(string, '{'+text+' ', '{'+latex+' ')
1035 string = replace(string, '{'+text+',', '{'+latex+',')
1036 string = replace(string, '{'+text+';', '{'+latex+';')
1037 string = replace(string, ' '+text+'\\', ' '+latex+'\\')
1038
1039
1040 string = replace(string, '`'+text+'\'', '`'+latex+'\'')
1041 string = replace(string, '`'+text+' ', '`'+latex+' ')
1042 string = replace(string, '`'+text+',', '`'+latex+',')
1043 string = replace(string, '`'+text+'.', '`'+latex+'.')
1044 string = replace(string, '`'+text+';', '`'+latex+';')
1045 string = replace(string, ' '+text+'\'', ' '+latex+'\'')
1046
1047
1048 substring = replace(string[-len(text)-1:], ' '+text, ' '+latex)
1049 string = string[0:-len(text)-1] + substring
1050
1051 substring = replace(string[-len(text)-1:], '.'+text, '.'+latex)
1052 string = string[0:-len(text)-1] + substring
1053
1054 string = replace(string, ' '+text+'\n', ' '+latex+'\n')
1055 string = replace(string, '.'+text+'\n', '.'+latex+'\n')
1056
1057
1058 string = replace(string, ' '+text+'\^', ' '+latex+'\^')
1059 string = replace(string, '('+text+'\^', '('+latex+'\^')
1060 string = replace(string, '\n'+text+'\^', '\n'+latex+'\^')
1061
1062
1063 if search('^'+text+'['+punctuation+']', string) or search('^'+text+'['+whitespace+']', string) or search('\n'+text+'['+punctuation+']', string) or search('\n'+text+'['+whitespace+']', string):
1064 string = replace(string, text+' ', latex+' ')
1065 string = replace(string, text+',', latex+',')
1066 string = replace(string, text+'.', latex+'.')
1067 string = replace(string, text+';', latex+';')
1068 string = replace(string, text+']', latex+']')
1069 string = replace(string, text+')', latex+')')
1070 string = replace(string, text+'^', latex+'^')
1071 string = replace(string, text+'\\', latex+'\\')
1072 string = replace(string, text+'\'', latex+'\'')
1073 string = replace(string, text+'\n', latex+'\n')
1074
1075
1076
1077 return string
1078
1079
1081 """Function for creating LaTeX tables."""
1082
1083
1084 self.i = self.i + 1
1085
1086
1087 num_col = len(split(self.docstring_lines[self.i], '|'))
1088 string = `num_col-2` + ' \n '
1089
1090
1091 if num_col == 1:
1092 sys.write('Not a table!')
1093 sys.exit()
1094
1095
1096 self.i = self.i + 1
1097
1098
1099 headings = split(self.docstring_lines[self.i], '|')
1100 headings = headings[1:-1]
1101 for j in xrange(len(headings)):
1102 headings[j] = lstrip(rstrip(headings[j]))
1103
1104
1105 string = string + headings[0]
1106 for j in range(1, len(headings)):
1107 string = string + " SEPARATOR " + headings[j]
1108 string = string + ' \n '
1109
1110
1111 self.i = self.i + 3
1112
1113
1114 while 1:
1115
1116 if self.i >= len(self.docstring_lines) or search('^\\|_', self.docstring_lines[self.i]):
1117 self.i = self.i + 1
1118 break
1119
1120
1121 columns = split(self.docstring_lines[self.i], '|')
1122
1123
1124 if len(columns) > 1:
1125 string = string + lstrip(rstrip(columns[1]))
1126 for j in range(2, len(columns)-1):
1127 string = string + " SEPARATOR " + lstrip(rstrip(columns[j]))
1128 string = string + ' \n '
1129 else:
1130 string = string + columns[0] + ' \n '
1131
1132
1133 self.i = self.i + 1
1134
1135
1136 self.section.append(string)
1137 self.section_type.append('table')
1138
1139
1141 """Function for extracting the verbatim docstring section."""
1142
1143
1144 string = ''
1145
1146
1147 while 1:
1148
1149 self.i = self.i + 1
1150
1151
1152 if self.i >= len(self.docstring_lines) or search('---', self.docstring_lines[self.i]):
1153 self.i = self.i + 1
1154 break
1155
1156
1157 string = string + self.docstring_lines[self.i] + ' \n '
1158
1159
1160 self.section.append(string)
1161 self.section_type.append('verbatim')
1162