##// END OF EJS Templates
Initial latex printing for sympy and fixes to autogrow.
Brian Granger -
Show More
@@ -0,0 +1,6 b''
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from IPython.frontend.html.notebook import notebook
5
6 notebook.main() No newline at end of file
@@ -48,6 +48,13 b' def print_png(o):'
48 png = latex_to_png(s)
48 png = latex_to_png(s)
49 return png
49 return png
50
50
51
52 def print_latex(o):
53 """A function to generate the latex representation of sympy expressions."""
54 s = latex(o, mode='equation', itex=True)
55 return s
56
57
51 _loaded = False
58 _loaded = False
52
59
53 def load_ipython_extension(ip):
60 def load_ipython_extension(ip):
@@ -71,5 +78,13 b' def load_ipython_extension(ip):'
71 png_formatter.for_type_by_name(
78 png_formatter.for_type_by_name(
72 'sympy.core.basic', 'Basic', print_png
79 'sympy.core.basic', 'Basic', print_png
73 )
80 )
81
82 latex_formatter = ip.display_formatter.formatters['text/latex']
83 latex_formatter.for_type_by_name(
84 'sympy.core.basic', 'Basic', print_latex
85 )
86 latex_formatter.for_type_by_name(
87 'sympy.matrices.matrices', 'Matrix', print_latex
88 )
74 _loaded = True
89 _loaded = True
75
90
@@ -6,70 +6,37 b''
6 * Modified by Rob G (aka Fudgey/Mottie)
6 * Modified by Rob G (aka Fudgey/Mottie)
7 * - Converted into a plugin
7 * - Converted into a plugin
8 * - Added ability to calculate approximate # cols when textarea is set to 100%
8 * - Added ability to calculate approximate # cols when textarea is set to 100%
9 *
10 * Simplified by Brian Granger on 5/2/2011
9 */
11 */
10
12
11 (function($){
13 (function($) {
12 // if "full" is true, auto adjust textarea cols
14 $.fn.autogrow = function() {
13 $.fn.autoGrow = function(full){
14
15
15 // resize textarea
16 var grow = function(d) {
16 var grow = function(d){
17 var linesCount = 0;
17 var linesCount = 0,
18 // modified split rule from
18 // modified split rule from
19 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
19 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
20 var lines = d.txt.value.split(/\r|\r\n|\n/);
20 lines = d.txt.value.split(/\r|\r\n|\n/);
21 linesCount = lines.length;
21 for (var i = lines.length-1; i>=0; --i){
22 if (linesCount >= d.rowsDefault) {
22 linesCount += Math.round((lines[i].length / d.colsDefault) + 1);
23 d.txt.rows = linesCount;
23 }
24 } else {
24 if (linesCount >= d.rowsDefault) {
25 d.txt.rows = d.rowsDefault;
25 d.txt.rows = linesCount + 1; // added one more here because of IE
26 }
26 } else {
27 };
27 d.txt.rows = d.rowsDefault;
28 }
29 };
30
28
31 // Calculate # of columns from width of textarea
29 return this.each(function() {
32 // this is a very rough approximation; set textarea CSS width to 100% to maintain full size
30 var d = {
33 var setColsWidth = function(d){
31 colsDefault : 0,
34 var pWidth = d.$txt.parent().innerWidth();
32 rowsDefault : 1,
35 // if char width not set, add window resize events
33 txt : this,
36 if (d.charWidth === 0){
34 $txt : $(this)
37 $(window).resize(function(){
35 };
38 setColsWidth(d);
36 d.txt.onkeyup = function() {
39 grow(d);
37 grow(d);
38 };
39 grow(d);
40 });
40 });
41 // assume charwidth is roughly 1/2 font-size (on average)
41 };
42 d.charWidth = parseInt(d.$txt.css('font-size'),10)/2;
42 })(jQuery);
43 }
44 var cols = Math.round(pWidth / d.charWidth); // calculate number of columns
45 d.colsDefault = cols;
46 d.$txt.attr('cols', cols );
47 };
48
49 // set default textarea size
50 var setDefaultValues = function(d){
51 // call cols-adjusting script if $("textarea").autoGrow(true);
52 if (full && d.charWidth === 0) { setColsWidth(d); }
53 d.colsDefault = d.txt.cols;
54 d.rowsDefault = d.txt.rows;
55 };
56
57 return this.each(function(){
58 // defaults
59 var d = {
60 colsDefault : 0,
61 rowsDefault : 0,
62 charWidth : 0,
63 txt : this,
64 $txt : $(this)
65 };
66 // bind keyup
67 d.txt.onkeyup = function(){
68 grow(d);
69 };
70 setDefaultValues(d);
71 grow(d);
72 });
73
74 };
75 })(jQuery); No newline at end of file
@@ -635,7 +635,7 b' CodeCell.prototype.create_element = function () {'
635 var cell = $('<div></div>').addClass('cell code_cell');
635 var cell = $('<div></div>').addClass('cell code_cell');
636 var input = $('<div></div>').addClass('input');
636 var input = $('<div></div>').addClass('input');
637 input.append($('<div/>').addClass('prompt input_prompt'));
637 input.append($('<div/>').addClass('prompt input_prompt'));
638 var input_textarea = $('<textarea/>').addClass('input_textarea').attr('rows',1).attr('wrap','hard').autoGrow();
638 var input_textarea = $('<textarea/>').addClass('input_textarea').attr('rows',1).attr('wrap','hard').autogrow();
639 input.append($('<div/>').addClass('input_area').append(input_textarea));
639 input.append($('<div/>').addClass('input_area').append(input_textarea));
640 var output = $('<div></div>').addClass('output');
640 var output = $('<div></div>').addClass('output');
641 output.append($('<div/>').addClass('prompt output_prompt'));
641 output.append($('<div/>').addClass('prompt output_prompt'));
@@ -652,8 +652,11 b' CodeCell.prototype.append_stream = function (data) {'
652 if (data_list.length > 0) {
652 if (data_list.length > 0) {
653 for (var i=0; i<data_list.length; i++) {
653 for (var i=0; i<data_list.length; i++) {
654 console.log(i, data_list[i]);
654 console.log(i, data_list[i]);
655 var toinsert = fixConsole(data_list[i]);
655 var toinsert = $("<div/>").
656 this.element.find("div.output_area").append($("<p>").append(toinsert));
656 append(
657 $("<pre/>").append(fixConsole(data_list[i]))
658 );
659 this.element.find("div.output_area").append(toinsert);
657 };
660 };
658 }
661 }
659 };
662 };
@@ -764,7 +767,7 b' TextCell.prototype.create_element = function () {'
764 addClass('text_cell_input').
767 addClass('text_cell_input').
765 attr('rows',1).
768 attr('rows',1).
766 attr('cols',80).
769 attr('cols',80).
767 autoGrow()
770 autogrow()
768 ).append(
771 ).append(
769 $('<div></div>').addClass('text_cell_render')
772 $('<div></div>').addClass('text_cell_render')
770 )
773 )
@@ -12,7 +12,8 b''
12 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
12 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
13 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.11.custom.css" type="text/css" /> -->
13 <!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.11.custom.css" type="text/css" /> -->
14
14
15 <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script>
15 <!-- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script> -->
16 <script type="text/javascript" src="static/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script>
16
17
17 </head>
18 </head>
18
19
@@ -268,6 +268,7 b' def find_scripts(entry_points=False):'
268 if entry_points:
268 if entry_points:
269 console_scripts = [
269 console_scripts = [
270 'ipython = IPython.frontend.terminal.ipapp:launch_new_instance',
270 'ipython = IPython.frontend.terminal.ipapp:launch_new_instance',
271 'ipython-notebook = IPython.frontend.html.notebook.notebook:main',
271 'pycolor = IPython.utils.PyColorize:main',
272 'pycolor = IPython.utils.PyColorize:main',
272 'ipcontroller = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
273 'ipcontroller = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
273 'ipengine = IPython.parallel.apps.ipengineapp:launch_new_instance',
274 'ipengine = IPython.parallel.apps.ipengineapp:launch_new_instance',
@@ -289,6 +290,7 b' def find_scripts(entry_points=False):'
289 pjoin(parallel_scripts, 'ipcluster'),
290 pjoin(parallel_scripts, 'ipcluster'),
290 pjoin(parallel_scripts, 'iplogger'),
291 pjoin(parallel_scripts, 'iplogger'),
291 pjoin(main_scripts, 'ipython'),
292 pjoin(main_scripts, 'ipython'),
293 pjoin(main_scripts, 'ipython-notebook'),
292 pjoin(main_scripts, 'pycolor'),
294 pjoin(main_scripts, 'pycolor'),
293 pjoin(main_scripts, 'irunner'),
295 pjoin(main_scripts, 'irunner'),
294 pjoin(main_scripts, 'iptest')
296 pjoin(main_scripts, 'iptest')
General Comments 0
You need to be logged in to leave comments. Login now