Examples of using latex in cocalc
## -*- encoding: utf-8 -*-1## This file (sagetex.sagetex.sage) was *autogenerated* from sagetex.tex with sagetex.sty version 2015/08/26 v3.0-92d9f7a.2import sagetex3_st_ = sagetex.SageTeXProcessor('sagetex', version='2015/08/26 v3.0-92d9f7a', version_check=True)4try:5_st_.current_tex_line = 356_st_.inline(0, latex(2+2))7except:8_st_.goboom(35)9try:10_st_.current_tex_line = 3611_st_.inline(1, latex(mod(2018, 100)))12except:13_st_.goboom(36)14try:15_st_.current_tex_line = 3816_st_.inline(2, latex(Integer(mod(2018, 100))^21))17except:18_st_.goboom(38)19try:20_st_.current_tex_line = 3921_st_.inline(3, latex(2018%42))22except:23_st_.goboom(39)24_st_.current_tex_line = 4225_st_.blockbegin()26try:271+128var('a,b,c')29eqn = [a+b*c==1, b-a*c==0, a+b==5]30s = solve(eqn, a,b,c)31except:32_st_.goboom(47)33_st_.blockend()34try:35_st_.current_tex_line = 4936_st_.inline(4, latex(eqn))37except:38_st_.goboom(49)39try:40_st_.current_tex_line = 5141_st_.inline(5, latex(s[0]))42except:43_st_.goboom(51)44try:45_st_.current_tex_line = 5446_st_.inline(6, latex(s[1]))47except:48_st_.goboom(54)49_st_.current_tex_line = 5850_st_.blockbegin()51try:52E = EllipticCurve("37a")53except:54_st_.goboom(60)55_st_.blockend()56try:57_st_.current_tex_line = 6358_st_.inline(7, latex(E))59except:60_st_.goboom(63)61try:62_st_.current_tex_line = 6463_st_.inline(8, latex(E.discriminant()))64except:65_st_.goboom(64)66_st_.current_tex_line = 6867_st_.blockbegin()68try:69try:70E = load('E2')71except IOError:72E = EllipticCurve([1,2,3,4,5])73E.anlist(100000)74E.save('E2')75except:76_st_.goboom(75)77_st_.blockend()78try:79_st_.current_tex_line = 7780_st_.inline(9, latex(E))81except:82_st_.goboom(77)83try:84_st_.current_tex_line = 7885_st_.inline(10, latex(E.anlist(100000)[9999]))86except:87_st_.goboom(78)88_st_.current_tex_line = 8189_st_.blockbegin()90try:91e = 292e = 3*e + 193except:94_st_.goboom(84)95_st_.blockend()96try:97_st_.current_tex_line = 8598_st_.inline(11, latex(e))99except:100_st_.goboom(85)101_st_.current_tex_line = 87102_st_.blockbegin()103try:104var('x')105f(x) = log(sin(x)/x)106except:107_st_.goboom(90)108_st_.blockend()109try:110_st_.current_tex_line = 91111_st_.inline(12, latex( f.taylor(x, 0, 10) ))112except:113_st_.goboom(91)114try:115_st_.current_tex_line = 97116_st_.plot(0, format='notprovided', _p_=E.plot(-3,3))117except:118_st_.goboom(97)119_st_.current_tex_line = 99120_st_.blockbegin()121try:122# the var line is unecessary unless you've defined x to be something123# other than a symbolic variable124var('x')125f(x) = -x^3+3*x^2+7*x-4126except:127_st_.goboom(104)128_st_.blockend()129_st_.current_tex_line = 107130_st_.blockbegin()131try:132p = plot(f, x, -5, 5)133except:134_st_.goboom(109)135_st_.blockend()136try:137_st_.current_tex_line = 113138_st_.plot(1, format='notprovided', _p_=p)139except:140_st_.goboom(113)141try:142_st_.current_tex_line = 118143_st_.plot(2, format='notprovided', _p_=p, axes=False)144except:145_st_.goboom(118)146_st_.current_tex_line = 122147_st_.blockbegin()148try:149f = maxima('sin(x)^2*exp(x)')150g = f.integrate('x')151except:152_st_.goboom(125)153_st_.blockend()154_st_.current_tex_line = 127155_st_.blockbegin()156try:157# g is a Maxima thingy, it needs to get converted into a Sage object158plot1 = plot(g.sage(),x,-1,2*pi)159except:160_st_.goboom(130)161_st_.blockend()162try:163_st_.current_tex_line = 136164_st_.plot(3, format='png', _p_=plot1)165except:166_st_.goboom(136)167try:168_st_.current_tex_line = 146169_st_.plot(4, format='notprovided', _p_=plot1 + plot(f.sage(),x,-1,2*pi,rgbcolor=hue(0.4)), figsize=[1,2])170except:171_st_.goboom(146)172_st_.current_tex_line = 151173_st_.blockbegin()174try:175p = plot(x, 0, 1) + circle((0,0), 1)176p.set_aspect_ratio(1)177except:178_st_.goboom(154)179_st_.blockend()180try:181_st_.current_tex_line = 158182_st_.plot(5, format='notprovided', _p_=p)183except:184_st_.goboom(158)185_st_.current_tex_line = 161186_st_.blockbegin()187try:188s = 7189s2 = 2^s190P.<x> = GF(2)[]191M = matrix(parent(x),s2)192for i in range(s2):193p = (1+x)^i194pc = p.coefficients(sparse=False)195a = pc.count(1)196for j in range(a):197idx = pc.index(1)198M[i,idx+j] = pc.pop(idx)199200matrixprogram = matrix_plot(M,cmap='Greys')201except:202_st_.goboom(175)203_st_.blockend()204try:205_st_.current_tex_line = 178206_st_.plot(6, format='notprovided', _p_=matrixprogram)207except:208_st_.goboom(178)209try:210_st_.current_tex_line = 181211_st_.inline(13, latex(var('x')))212except:213_st_.goboom(181)214try:215_st_.current_tex_line = 253216_st_.inline(14, latex(var('x')))217except:218_st_.goboom(253)219_st_.current_tex_line = 337220_st_.blockbegin()221try:222x, y = var('x y')223except:224_st_.goboom(339)225_st_.blockend()226try:227_st_.current_tex_line = 345228_st_.plot(7, format='notprovided', _p_=plot3d(sin(pi*(x^2+y^2))/2,(x,-1,1),(y,-1,1)))229except:230_st_.goboom(345)231_st_.current_tex_line = 349232_st_.blockbegin()233try:234G = graphs.CubeGraph(5)235except:236_st_.goboom(351)237_st_.blockend()238try:239_st_.current_tex_line = 355240_st_.plot(8, format='png', _p_=G.plot3d())241except:242_st_.goboom(355)243print 'SageTeX paused on sagetex.tex line 365'244"""245try:246_st_.current_tex_line = 367247_st_.inline(15, latex(factor(2^325 + 1)))248except:249_st_.goboom(367)250_st_.current_tex_line = 370251_st_.blockbegin()252try:253import time254time.sleep(15)255except:256_st_.goboom(373)257_st_.blockend()258try:259_st_.current_tex_line = 375260_st_.plot(9, format='notprovided', _p_=plot(2*sin(x^2) + x^2, (x, 0, 5)))261except:262_st_.goboom(375)263"""264print 'SageTeX unpaused on sagetex.tex line 377'265_st_.current_tex_line = 389266_st_.blockbegin()267try:268def pascals_triangle(n):269# start of the table270s = [r"\begin{tabular}{cc|" + "r" * (n+1) + "}"]271s.append(r" & & $k$: & \\")272# second row, with k values:273s.append(r" & ")274for k in [0..n]:275s.append("& {0} ".format(k))276s.append(r"\\")277# the n = 0 row:278s.append(r"\hline" + "\n" + r"$n$: & 0 & 1 & \\")279# now the rest of the rows280for r in [1..n]:281s.append(" & {0} ".format(r))282for k in [0..r]:283s.append("& {0} ".format(binomial(r, k)))284s.append(r"\\")285# add the last line and return286s.append(r"\end{tabular}")287return ''.join(s)288289# how big should the table be?290n = 8291except:292_st_.goboom(413)293_st_.blockend()294try:295_st_.current_tex_line = 420296_st_.inline(16, pascals_triangle(n))297except:298_st_.goboom(420)299try:300_st_.current_tex_line = 426301_st_.doctest(17, r"""302sage: 2+23034304sage: print 'middle'305middle306sage: factor(x^2 + 2*x + 1)307(x + 1)^2308""", globals(), locals(), False)309except:310_st_.goboom(433)311try:312_st_.current_tex_line = 448313_st_.doctest(18, r"""314sage: print 'middle'315middle316""", globals(), locals(), True)317except:318_st_.goboom(451)319try:320_st_.current_tex_line = 455321_st_.doctest(19, r"""322sage: is_prime(57)323toothpaste324""", globals(), locals(), True)325except:326_st_.goboom(458)327try:328_st_.current_tex_line = 463329_st_.doctest(20, r"""330sage: gcd([5656565656,331....: 4747474747,332....: 123456789])3331334sage: mystr = '''my335....: string336....: has337....: several338....: lines.'''339sage: len(mystr)34028341sage: def f(a):342....: '''This function is really quite nice,343....: although perhaps not very useful.'''344....: print "f called with a = ", a345....: y = integrate(SR(cyclotomic_polynomial(10)) + a, x)346....: return y + 1347sage: f(x)348f called with a = x3491/5*x^5 - 1/4*x^4 + 1/3*x^3 + x + 1350""", globals(), locals(), False)351except:352_st_.goboom(484)353try:354_st_.current_tex_line = 512355_st_.doctest(21, r"""356sage: 1; 2; a=4; 3; a3571358235933604361""", globals(), locals(), False)362except:363_st_.goboom(518)364try:365_st_.current_tex_line = 519366_st_.inline(22, latex(a))367except:368_st_.goboom(519)369try:370_st_.current_tex_line = 521371_st_.doctest(23, r"""372sage: f(a)373f called with a = 43741/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + 5*x + 1375""", globals(), locals(), False)376except:377_st_.goboom(525)378try:379_st_.current_tex_line = 622380_st_.commandline(0, r"""381sage: 1+1382sage: is_prime(57)383sage: if is_prime(57):384....: print 'prime'385....: else:386....: print 'composite'387""", globals(), locals(), True)388except:389_st_.goboom(629)390try:391_st_.current_tex_line = 639392_st_.commandline(1, r"""393sage: x = 2010; len(x.divisors())394sage: print 'Hola, mundo!'395""", globals(), locals(), True)396except:397_st_.goboom(642)398try:399_st_.current_tex_line = 651400_st_.commandline(2, r"""401sage: l = matrix([[1,0,0],[3/5,1,0],[-2/5,-2,1]])402sage: d = diagonal_matrix([15, -1, 4]) #@\label{diagonal}403sage: u = matrix([[1,0,1/3],[0,1,2],[0,0,1]]) #@\label{anotherlabel} \# foo404sage: l*d*u # this is a comment405""", globals(), locals(), True)406except:407_st_.goboom(656)408try:409_st_.current_tex_line = 667410_st_.commandline(3, r"""411sage: l*d*u412sage: x = var('x')413sage: (1-cos(x)^2).trig_simplify()414""", globals(), locals(), False)415except:416_st_.goboom(671)417try:418_st_.current_tex_line = 683419_st_.commandline(4, r"""420sage: pi.n(100)421""", globals(), locals(), True)422except:423_st_.goboom(685)424try:425_st_.current_tex_line = 693426_st_.commandline(5, r"""427sage: plot(sin(x), (x, 0, 2*pi))428""", globals(), locals(), True)429except:430_st_.goboom(695)431try:432_st_.current_tex_line = 709433_st_.commandline(6, r"""434sage: factor(x^2 + 2*x + 1)435(x + 999)^2436""", globals(), locals(), True)437except:438_st_.goboom(712)439_st_.endofdoc()440441442