Permalink
Browse files

Initial latex printing for sympy and fixes to autogrow.

  • Loading branch information...
1 parent 2607443 commit 68db752a0cd7b9060eab96e8e69b1282ae5777de @ellisonbg ellisonbg committed with ellisonbg May 3, 2011
@@ -48,6 +48,13 @@ def print_png(o):
png = latex_to_png(s)
return png
+
+def print_latex(o):
+ """A function to generate the latex representation of sympy expressions."""
+ s = latex(o, mode='equation', itex=True)
+ return s
+
+
_loaded = False
def load_ipython_extension(ip):
@@ -71,5 +78,13 @@ def load_ipython_extension(ip):
png_formatter.for_type_by_name(
'sympy.core.basic', 'Basic', print_png
)
+
+ latex_formatter = ip.display_formatter.formatters['text/latex']
+ latex_formatter.for_type_by_name(
+ 'sympy.core.basic', 'Basic', print_latex
+ )
+ latex_formatter.for_type_by_name(
+ 'sympy.matrices.matrices', 'Matrix', print_latex
+ )
_loaded = True
@@ -6,70 +6,37 @@
* Modified by Rob G (aka Fudgey/Mottie)
* - Converted into a plugin
* - Added ability to calculate approximate # cols when textarea is set to 100%
+ *
+ * Simplified by Brian Granger on 5/2/2011
*/
-(function($){
- // if "full" is true, auto adjust textarea cols
- $.fn.autoGrow = function(full){
+(function($) {
+ $.fn.autogrow = function() {
- // resize textarea
- var grow = function(d){
- var linesCount = 0,
- // modified split rule from
- // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
- lines = d.txt.value.split(/\r|\r\n|\n/);
- for (var i = lines.length-1; i>=0; --i){
- linesCount += Math.round((lines[i].length / d.colsDefault) + 1);
- }
- if (linesCount >= d.rowsDefault) {
- d.txt.rows = linesCount + 1; // added one more here because of IE
- } else {
- d.txt.rows = d.rowsDefault;
- }
- };
+ var grow = function(d) {
+ var linesCount = 0;
+ // modified split rule from
+ // http://stackoverflow.com/questions/2035910/how-to-get-the-number-of-lines-in-a-textarea/2036424#2036424
+ var lines = d.txt.value.split(/\r|\r\n|\n/);
+ linesCount = lines.length;
+ if (linesCount >= d.rowsDefault) {
+ d.txt.rows = linesCount;
+ } else {
+ d.txt.rows = d.rowsDefault;
+ }
+ };
- // Calculate # of columns from width of textarea
- // this is a very rough approximation; set textarea CSS width to 100% to maintain full size
- var setColsWidth = function(d){
- var pWidth = d.$txt.parent().innerWidth();
- // if char width not set, add window resize events
- if (d.charWidth === 0){
- $(window).resize(function(){
- setColsWidth(d);
- grow(d);
+ return this.each(function() {
+ var d = {
+ colsDefault : 0,
+ rowsDefault : 1,
+ txt : this,
+ $txt : $(this)
+ };
+ d.txt.onkeyup = function() {
+ grow(d);
+ };
+ grow(d);
});
- // assume charwidth is roughly 1/2 font-size (on average)
- d.charWidth = parseInt(d.$txt.css('font-size'),10)/2;
- }
- var cols = Math.round(pWidth / d.charWidth); // calculate number of columns
- d.colsDefault = cols;
- d.$txt.attr('cols', cols );
- };
-
- // set default textarea size
- var setDefaultValues = function(d){
- // call cols-adjusting script if $("textarea").autoGrow(true);
- if (full && d.charWidth === 0) { setColsWidth(d); }
- d.colsDefault = d.txt.cols;
- d.rowsDefault = d.txt.rows;
- };
-
- return this.each(function(){
- // defaults
- var d = {
- colsDefault : 0,
- rowsDefault : 0,
- charWidth : 0,
- txt : this,
- $txt : $(this)
- };
- // bind keyup
- d.txt.onkeyup = function(){
- grow(d);
- };
- setDefaultValues(d);
- grow(d);
- });
-
- };
-})(jQuery);
+};
+})(jQuery);
@@ -635,7 +635,7 @@ CodeCell.prototype.create_element = function () {
var cell = $('<div></div>').addClass('cell code_cell');
var input = $('<div></div>').addClass('input');
input.append($('<div/>').addClass('prompt input_prompt'));
- var input_textarea = $('<textarea/>').addClass('input_textarea').attr('rows',1).attr('wrap','hard').autoGrow();
+ var input_textarea = $('<textarea/>').addClass('input_textarea').attr('rows',1).attr('wrap','hard').autogrow();
input.append($('<div/>').addClass('input_area').append(input_textarea));
var output = $('<div></div>').addClass('output');
output.append($('<div/>').addClass('prompt output_prompt'));
@@ -652,8 +652,11 @@ CodeCell.prototype.append_stream = function (data) {
if (data_list.length > 0) {
for (var i=0; i<data_list.length; i++) {
console.log(i, data_list[i]);
- var toinsert = fixConsole(data_list[i]);
- this.element.find("div.output_area").append($("<p>").append(toinsert));
+ var toinsert = $("<div/>").
+ append(
+ $("<pre/>").append(fixConsole(data_list[i]))
+ );
+ this.element.find("div.output_area").append(toinsert);
};
}
};
@@ -764,7 +767,7 @@ TextCell.prototype.create_element = function () {
addClass('text_cell_input').
attr('rows',1).
attr('cols',80).
- autoGrow()
+ autogrow()
).append(
$('<div></div>').addClass('text_cell_render')
)
@@ -12,7 +12,8 @@
<!-- <link rel="stylesheet" href="static/jquery/css/themes/rocket/jquery-wijmo.css" type="text/css" /> -->
<!-- <link rel="stylesheet" href="static/jquery/css/themes/smoothness/jquery-ui-1.8.11.custom.css" type="text/css" /> -->
- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script>
+ <!-- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script> -->
+ <script type="text/javascript" src="static/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML" charset="utf-8"></script>
</head>
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from IPython.frontend.html.notebook import notebook
+
+notebook.main()
View
@@ -268,6 +268,7 @@ def find_scripts(entry_points=False):
if entry_points:
console_scripts = [
'ipython = IPython.frontend.terminal.ipapp:launch_new_instance',
+ 'ipython-notebook = IPython.frontend.html.notebook.notebook:main',
'pycolor = IPython.utils.PyColorize:main',
'ipcontroller = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
'ipengine = IPython.parallel.apps.ipengineapp:launch_new_instance',
@@ -289,6 +290,7 @@ def find_scripts(entry_points=False):
pjoin(parallel_scripts, 'ipcluster'),
pjoin(parallel_scripts, 'iplogger'),
pjoin(main_scripts, 'ipython'),
+ pjoin(main_scripts, 'ipython-notebook'),
pjoin(main_scripts, 'pycolor'),
pjoin(main_scripts, 'irunner'),
pjoin(main_scripts, 'iptest')

0 comments on commit 68db752

Please sign in to comment.