##// 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 48 png = latex_to_png(s)
49 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 58 _loaded = False
52 59
53 60 def load_ipython_extension(ip):
@@ -71,5 +78,13 b' def load_ipython_extension(ip):'
71 78 png_formatter.for_type_by_name(
72 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 89 _loaded = True
75 90
@@ -6,70 +6,37 b''
6 6 * Modified by Rob G (aka Fudgey/Mottie)
7 7 * - Converted into a plugin
8 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($){
12 // if "full" is true, auto adjust textarea cols
13 $.fn.autoGrow = function(full){
13 (function($) {
14 $.fn.autogrow = function() {
14 15
15 // resize textarea
16 var grow = function(d){
17 var linesCount = 0,
18 // modified split rule from
19 // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
20 lines = d.txt.value.split(/\r|\r\n|\n/);
21 for (var i = lines.length-1; i>=0; --i){
22 linesCount += Math.round((lines[i].length / d.colsDefault) + 1);
23 }
24 if (linesCount >= d.rowsDefault) {
25 d.txt.rows = linesCount + 1; // added one more here because of IE
26 } else {
27 d.txt.rows = d.rowsDefault;
28 }
29 };
16 var grow = function(d) {
17 var linesCount = 0;
18 // modified split rule from
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/);
21 linesCount = lines.length;
22 if (linesCount >= d.rowsDefault) {
23 d.txt.rows = linesCount;
24 } else {
25 d.txt.rows = d.rowsDefault;
26 }
27 };
30 28
31 // Calculate # of columns from width of textarea
32 // this is a very rough approximation; set textarea CSS width to 100% to maintain full size
33 var setColsWidth = function(d){
34 var pWidth = d.$txt.parent().innerWidth();
35 // if char width not set, add window resize events
36 if (d.charWidth === 0){
37 $(window).resize(function(){
38 setColsWidth(d);
39 grow(d);
29 return this.each(function() {
30 var d = {
31 colsDefault : 0,
32 rowsDefault : 1,
33 txt : this,
34 $txt : $(this)
35 };
36 d.txt.onkeyup = function() {
37 grow(d);
38 };
39 grow(d);
40 40 });
41 // assume charwidth is roughly 1/2 font-size (on average)
42 d.charWidth = parseInt(d.$txt.css('font-size'),10)/2;
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
41 };
42 })(jQuery);
@@ -635,7 +635,7 b' CodeCell.prototype.create_element = function () {'
635 635 var cell = $('<div></div>').addClass('cell code_cell');
636 636 var input = $('<div></div>').addClass('input');
637 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 639 input.append($('<div/>').addClass('input_area').append(input_textarea));
640 640 var output = $('<div></div>').addClass('output');
641 641 output.append($('<div/>').addClass('prompt output_prompt'));
@@ -652,8 +652,11 b' CodeCell.prototype.append_stream = function (data) {'
652 652 if (data_list.length > 0) {
653 653 for (var i=0; i<data_list.length; i++) {
654 654 console.log(i, data_list[i]);
655 var toinsert = fixConsole(data_list[i]);
656 this.element.find("div.output_area").append($("<p>").append(toinsert));
655 var toinsert = $("<div/>").
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 767 addClass('text_cell_input').
765 768 attr('rows',1).
766 769 attr('cols',80).
767 autoGrow()
770 autogrow()
768 771 ).append(
769 772 $('<div></div>').addClass('text_cell_render')
770 773 )
@@ -12,7 +12,8 b''
12 12 <!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
13 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 18 </head>
18 19
@@ -268,6 +268,7 b' def find_scripts(entry_points=False):'
268 268 if entry_points:
269 269 console_scripts = [
270 270 'ipython = IPython.frontend.terminal.ipapp:launch_new_instance',
271 'ipython-notebook = IPython.frontend.html.notebook.notebook:main',
271 272 'pycolor = IPython.utils.PyColorize:main',
272 273 'ipcontroller = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
273 274 'ipengine = IPython.parallel.apps.ipengineapp:launch_new_instance',
@@ -289,6 +290,7 b' def find_scripts(entry_points=False):'
289 290 pjoin(parallel_scripts, 'ipcluster'),
290 291 pjoin(parallel_scripts, 'iplogger'),
291 292 pjoin(main_scripts, 'ipython'),
293 pjoin(main_scripts, 'ipython-notebook'),
292 294 pjoin(main_scripts, 'pycolor'),
293 295 pjoin(main_scripts, 'irunner'),
294 296 pjoin(main_scripts, 'iptest')
General Comments 0
You need to be logged in to leave comments. Login now