Ask Your Question

Kabi's profile - activity

2023-12-25 03:33:46 +0200 received badge  Taxonomist
2022-08-03 19:43:18 +0200 received badge  Famous Question (source)
2019-01-21 14:21:44 +0200 received badge  Famous Question (source)
2017-12-03 16:38:50 +0200 received badge  Notable Question (source)
2016-11-09 15:32:13 +0200 received badge  Famous Question (source)
2016-06-01 14:02:14 +0200 received badge  Notable Question (source)
2016-05-24 19:24:03 +0200 received badge  Famous Question (source)
2016-05-01 01:07:54 +0200 received badge  Famous Question (source)
2014-06-29 03:13:15 +0200 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 08:29:25 +0200 received badge  Notable Question (source)
2014-01-04 09:00:25 +0200 received badge  Notable Question (source)
2013-09-20 13:41:19 +0200 received badge  Popular Question (source)
2013-03-06 15:14:41 +0200 received badge  Popular Question (source)
2013-02-15 05:10:35 +0200 received badge  Popular Question (source)
2012-12-30 16:33:03 +0200 commented answer Problem using \sage{} in latex cells in the notebook

Ah of course. Thanks!

2012-12-29 05:50:21 +0200 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 14:44:32 +0200 received badge  Notable Question (source)
2012-12-16 09:34:26 +0200 received badge  Good Question (source)
2012-09-25 07:24:03 +0200 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-25 06:53:40 +0200 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 19:09:45 +0200 received badge  Popular Question (source)
2012-07-15 16:49:16 +0200 received badge  Notable Question (source)
2012-03-12 06:39:41 +0200 received badge  Popular Question (source)
2012-01-27 12:56:15 +0200 answered a question How to if python script runs in notebook?
2011-12-15 05:18:03 +0200 received badge  Teacher (source)
2011-12-15 05:18:03 +0200 received badge  Self-Learner (source)
2011-10-20 12:52:08 +0200 received badge  Popular Question (source)
2011-09-13 05:12:33 +0200 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 20:56:10 +0200 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 19:07:46 +0200 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-06 06:04:56 +0200 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-06 05:30:24 +0200 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 09:42:15 +0200 received badge  Nice Question (source)
2011-09-03 10:07:46 +0200 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...