Ask Your Question

Kabi's profile - activity

2019-01-21 07:21:44 -0500 received badge  Famous Question (source)
2017-12-03 09:38:50 -0500 received badge  Notable Question (source)
2016-11-09 08:32:13 -0500 received badge  Famous Question (source)
2016-06-01 07:02:14 -0500 received badge  Notable Question (source)
2016-05-24 12:24:03 -0500 received badge  Famous Question (source)
2016-04-30 18:07:54 -0500 received badge  Famous Question (source)
2014-06-28 20:13:15 -0500 marked best answer Print to pdf, Bad quality in evaluated latex

Hi

In the sage notebook there is a problem when wanting to print to pdf or printer. I have "typeset" enabled. An example: 1st cell:

%latex
Something is wrong

2nd cell:

2/3

The first cell produces blurry output and the second cell produces much better output. I have read that when using the latex interpreter then sage prints to pdf/dvi (depending on using latex/pdflatex) converts to png and crops the png. And the output of the first cell is obviously an image of poor quality.

What I would like to be able to do, is to write latex code such as sections and formatting, and then print or email the resulting notebook in a normal readable quality.

Any help appreciated.

2014-06-12 01:29:25 -0500 received badge  Notable Question (source)
2014-01-04 02:00:25 -0500 received badge  Notable Question (source)
2013-09-20 06:41:19 -0500 received badge  Popular Question (source)
2013-03-06 08:14:41 -0500 received badge  Popular Question (source)
2013-02-14 22:10:35 -0500 received badge  Popular Question (source)
2012-12-30 09:33:03 -0500 commented answer Problem using \sage{} in latex cells in the notebook

Ah of course. Thanks!

2012-12-28 22:50:21 -0500 asked a question Problem using \sage{} in latex cells in the notebook

Hi

I am using SAGE 5.5-1. When using the \sage{} command in the notebook the result is sometimes a bit weird. An example could be the following cell:

%latex
\sage{1/2}

Edit: here is the output

image description

Is there a different way to use results from SAGE in latex or text cells?

2012-12-28 07:44:32 -0500 received badge  Notable Question (source)
2012-12-16 02:34:26 -0500 received badge  Good Question (source)
2012-09-25 00:24:03 -0500 commented answer Is it possible to use tikz in notebook

I have a full installation of TeX. The question is if I can have tikz rendered in the notebook from code entered in the notebook. Or do I have to create the tikz picture outside the notebook and then import as image?

2012-09-24 23:53:40 -0500 asked a question Is it possible to use tikz in notebook

Hi

I am wondering if it is possible to render tikz from code inside the notebook.

If not: Is there some other way of drawing graphs with the same degree of control as you get with tikz?

I am using matplotlib for some plots in the notebook and the built-in Graph function for some graph theory. The problem is that sometimes I want to show a graph with specific proportions and with specific placement of nodes, lines and points, to make some argument clearly shown.

An example:

f= {'House 1': ['Water', 'Electricity', 'Phone Line'], 
'House 2': ['Water', 'Electricity', 'Phone Line'],
'House 3': ['Water', 'Electricity']}
g = Graph(f)
g.plot(pos=g.layout_planar())

Gives:

image description

Where I want something like:

image description

I hope it makes sense what I am asking....

2012-09-16 12:09:45 -0500 received badge  Popular Question (source)
2012-07-15 09:49:16 -0500 received badge  Notable Question (source)
2012-03-12 00:39:41 -0500 received badge  Popular Question (source)
2012-01-27 05:56:15 -0500 answered a question How to if python script runs in notebook?
2011-12-14 22:18:03 -0500 received badge  Teacher (source)
2011-12-14 22:18:03 -0500 received badge  Self-Learner (source)
2011-10-20 05:52:08 -0500 received badge  Popular Question (source)
2011-09-12 22:12:33 -0500 answered a question default startup options for sage notebook

I have done something similar to what you suggest to solve this. I have defined the following in init.sage, which is run every time a worksheet opens:

def clear():
    reset()
    attach('~/.sage/init.sage')

I can then use clear() instead of reset(), and all other functions and options put in init.sage will be available all the time. But thanks for pointing me in the right direction.

2011-09-08 13:56:10 -0500 asked a question default startup options for sage notebook

I am trying to set some default options for the sage notebook. An example is:

latex = Latex(density=90, pdflatex=True)

This is for getting smaller output images in the notebook from %latex cells.

Right now I set this option manually, but my problem is that reset() also resets this option. Is there some way to set default options/settings to avoid having settings like this repeated numerous times in each worksheet?

2011-09-06 12:07:46 -0500 commented answer Disable syntax highlighting in sws2tex

I have problems with the TinyMCE editor when wanting to use the "align" environment. In the editor you need to enclose latex math in $$ or \\[\\], but in the converted latex code you will get, \\[ \begin{align} ..., which will fail when compiling the document. So I use the TinyMCE for normal text and simple math stuff and then the %latex cell for more complicated math expressions.

2011-09-05 23:04:56 -0500 answered a question Disable syntax highlighting in sws2tex

Thanks!

I have now changed several things in the sws2tex.py file including disabling syntax highlighting.

It is practical in the notebook to be able to use %hide and then %latex in the second line or only %latex, and then only have the pure latex code included in the tex file without adding the input cell with latex code in a verbatim environment. I achieve this with sws2tex by changing the following in the, class InputCell(Cell):

def _detect_language(self):
    first_line = self.text.splitlines()[0]
    try:
        second_line = self.text.splitlines()[1]    
    except: 
        second_line = ""
    if first_line == '%latex':
        self.language = 'latex'
    elif second_line == '%latex':
        self.language = 'latex'
    ...

and

def latex(self):
    if options.hide:
        first_line = self.text.splitlines()[0]
        if first_line == '%hide':
            return ""
    if self.language == 'latex':
        return ""
    ...

Another thing for people having problems with special letters like æ, ø or å in danish: One solution is to add the following as the first line in html2latex.py:

# -*- coding: utf-8 -*-

and the following to convert the letters from the html to utf-8:

entities = {
    ...
    "aelig": 'æ',
    "oslash": 'ø',
    "aring": 'å',
    "AElig": 'Æ',
    "Oslash": 'Ø',
    "Aring": 'Å'

With these changes the sage notebook becomes a near complete math/report environment for me. sws2tex makes it possible to produce very good paper print of your work done in the notebook, which (in my opinion) is not the case with the existing print function with jsMath directly from the notebook.

So thanks for sws2tex and keep up the good work! :-)

2011-09-05 22:30:24 -0500 marked best answer Disable syntax highlighting in sws2tex

Kabi, this is all possible, but for now you have to do it all yourself by modifying sws2tex.py. I have done this myself at times.

As you noted, removing the "attachfile" is very simple. I usually also do

shutil.copyfile(temp_dir + os.sep + output_filename + ".tex", output_filename + ".tex")

so I have the original TeX source to look at (or modify).

The easiest way to remove the syntax highlighting is to comment out all the stuff about colorizing, like so (I also do this):

#try:
#    from pygments import highlight
#    from pygments.lexers import PythonLexer, TexLexer, HtmlLexer
#    from pygments.formatters import LatexFormatter
<snip>
#except ImportError:
#    print "Warning: Unable to load module pygments"
#    print "Warning: Syntax highlighting will be disabled"
#
#    def colorize(s, **kwds):
#        return "\\begin{Verbatim}[commandchars=@\\[\\]]\n" + s + "\n\\end{Verbatim}\n"

def colorize(s, **kwds):
    return "\\begin{Verbatim}\n" + s + "\n\\end{Verbatim}\n"

Or you can do your own colorizing. It's also possible to remove this from the place where the stuff happens in the methods for cells.


It's great to hear you use this, by the way; sws2tex is not part of Sage yet, but the hope is that it would eventually be ready for inclusion, and comments like this for options are great to hear.

2011-09-05 02:42:15 -0500 received badge  Nice Question (source)
2011-09-03 03:07:46 -0500 asked a question Disable syntax highlighting in sws2tex

Hi

I am using sws2tex to convert sage notebooks to latex. I am wondering if it is possible to disable syntax highlighting?

The reason I want this is that sometimes I use the Maple and Matlab interfaces directly in the notebook, and the syntax highlighting looks wrong here. I know I can remove it manually after creating the tex file, but I would like to be able to disable it instead.

Another small question: Is it possible to disable the "attachfile"? Of course this is not so important since it requires removing 1 or 2 lines, but it could be nice though...

2011-04-10 11:05:04 -0500 commented answer Scaling of png from Matlab

I have tried saving the image from the notebook, from the sage interactive console, and directly from matlab. All using the same code. The images from sage are 576x432 and the one directly from matlab is 1200x901.

2011-04-05 07:58:15 -0500 commented question Scaling of png from Matlab

I have tried doing this from the command line, and the problem persists. So maybe the problem is caused by the python/sage interface to Matlab.