1 #LyX 2.0 created this file. For more info see http://www.lyx.org/
9 \use_default_options true
13 \maintain_unincluded_children false
15 InsetLayout sagecommand
31 \language_package default
36 \font_typewriter default
37 \font_default_family default
38 \use_non_tex_fonts false
45 \default_output_format default
47 \bibtex_command default
48 \index_command default
49 \paperfontsize default
61 \paperorientation portrait
70 \paragraph_separation indent
71 \paragraph_indentation default
72 \quotes_language english
75 \paperpagestyle default
76 \tracking_changes false
86 Example Integration of LyX with Sage
92 Original by: Murat Yildizoglu
93 \begin_inset Newline newline
96 Modified by: Thomas Coffee
105 \begin_layout Section
109 \begin_layout Standard
111 \begin_inset CommandInset href
113 name "http://sagemath.org"
114 target "http://sagemath.org"
118 ) is an open source computer algebra system that integrates a wide variety
119 of open source mathematics software, with the mission of
120 \begin_inset Quotes sld
123 creating a viable free open source alternative to Magma, Maple, Mathematica,
125 \begin_inset Quotes srd
128 Sage uses Python as the glue for integrating nearly 100 open source packages
129 for mathematics, programming, and visualization.
130 Sage speaks LaTeX and can be used for literate programming that mixes normal
131 text with Sage instructions, directly including results in PS/PDF files.
136 package allows the input of Sage instructions in a LaTeX file (in a manner
137 similar to Sweave and R-Project).
140 \begin_layout Standard
141 The file sage.module provides the following Sage
145 \begin_layout Plain Layout
155 \begin_layout Itemize
164 environments for blocks of code made visible or invisible in the final
165 document, respectively
168 \begin_layout Itemize
181 \begin_layout Plain Layout
186 defined in the sage.module file; you can define similar environments with
187 different options to conveniently generate multiple plots of different
193 environments that can be used for plotting code inside a Figure float
196 \begin_layout Itemize
209 \begin_layout Plain Layout
210 accessible via the menu item Insert >> Custom Insets
215 that can be used inline, where results of the latter appear in math mode
218 \begin_layout Itemize
223 environment, whose results appear in display math mode
227 \begin_layout Plain Layout
228 you can define similar environments in sage.module to support other math
237 \begin_layout Standard
242 \begin_layout Plain Layout
261 , along with other custom commands defined in sage.module, can also be used
263 This can be useful in math mode when results from Sage should be combined
264 seamlessly with other equation components.
265 Note that LyX's special handling of math mode formatting can cause problems
266 for some Sage input: for this reason, it may be necessary to assign a result
267 to a named variable using a
271 environment and include the variable by name in ERT where the result should
275 \begin_layout Standard
280 \begin_layout Plain Layout
291 is compiled with (pdf)latex, it automatically generates a Sage file
295 that can be run through Sage using the command
300 This compiles the results of the Sage instructions and a supplementary
301 run through (pdf)latex includes these results (computations, plots, etc.)
302 in the final document.
303 The files included with this example provide a basic capability to combine
304 this functionality with LyX, which you can extend to meet your specific
308 \begin_layout Standard
309 Using this module, to compile a document with embedded Sage code one must
311 \begin_inset Quotes eld
314 PDF (pdflatex+sagetex)
315 \begin_inset Quotes erd
318 , located by default under
319 \begin_inset Quotes eld
323 \begin_inset Quotes erd
326 To update only the LaTeX without updating any results from Sage, one can
327 use the default output format
328 \begin_inset Quotes eld
332 \begin_inset Quotes erd
336 This default can be changed in the included
343 \begin_layout Standard
344 If you are working under GNU/Linux, the included shell script
348 can be customized to place the necessary components where they belong.
349 This assumes you have already installed and tested LyX and Sage independently,
350 and includes the necessary commands to include Sage
354 \begin_layout Plain Layout
361 TeX in a common LaTeX installation.
365 \begin_layout Plain Layout
367 \begin_inset CommandInset href
369 name "http://www.sagemath.org/doc/installation/sagetex.html"
370 target "http://www.sagemath.org/doc/installation/sagetex.html"
379 After establishing the configuration, you will need to run Tools >> Reconfigure
381 This configuration has been successfully tested using the following setup:
384 \begin_layout Itemize
388 \begin_layout Itemize
389 LyX 2.0.0 with TeXLive 2009-13 (but should work with LyX 1.6+)
392 \begin_layout Itemize
393 Sage 4.8 [2012-01-20]
396 \begin_layout Standard
397 Note that in earlier versions of Sage, Sage
401 \begin_layout Plain Layout
408 TeX may produce files with extension
417 You may need to modify the
428 \begin_layout Section
432 \begin_layout Standard
433 Sage can output LaTeX:
434 \begin_inset Flex sageinline
437 \begin_layout Plain Layout
439 matrix([[1, 2], [3,4]])^2
447 \begin_layout Standard
450 Sage can do plots: Figure
451 \begin_inset CommandInset ref
453 reference "fig:Test-de-figure"
460 \begin_layout Standard
463 \begin_inset Float figure
468 \begin_layout sageplotcenter
470 plot(sin(x), 0, pi), axes=True
473 \begin_layout Plain Layout
478 \begin_layout Plain Layout
482 \begin_inset CommandInset label
484 name "fig:Test-de-figure"
501 \begin_layout Standard
508 \begin_layout Plain Layout
515 TeX can include blocks for defining and computing elements.
516 In this case, the block is not typeset in the final document, since we
523 \begin_inset Formula $x$
527 \begin_inset Formula $y=x^{2}+5x+2$
533 \begin_layout sagesilent
536 \begin_inset Newline newline
542 \begin_layout Standard
543 We can now compute an equation with an unknown
544 \begin_inset Formula $x$
547 : the roots of equation
548 \begin_inset Formula $x^{2}+5x+2$
551 are hence given by (computed by Sage):
554 \begin_layout sagedisplay
559 \begin_layout Standard
560 Another equation, third degree of
561 \begin_inset Formula $x$
565 \begin_inset Formula $x^{3}-10$
571 \begin_layout sagedisplay
576 \begin_layout Standard
577 A system of two equations:
580 \begin_layout sageblock
585 \begin_layout sageblock
587 z=solve([x+y==6,x-y==4],x,y)
590 \begin_layout Standard
591 The roots of the system
607 \begin_layout sagedisplay
612 \begin_layout Standard
613 Sage can do differentiation:
616 \begin_layout sageblock
621 \begin_layout Standard
625 \begin_inset Formula $\dfrac{\partial^{4}y}{\partial x^{4}}=\sage{diff(y,x,4)}$
631 \begin_layout Standard
632 Sage can also do integrals:
637 \int_{0}^{1}\frac{x}{x^{2}+1}
645 \begin_inset Flex sageinline
648 \begin_layout Plain Layout
650 integral(x/(x^2+1),x,0,1)
658 \begin_layout Standard
659 Sage can solve differential equations: we declare a variable
660 \begin_inset Formula $t$
664 \begin_inset Formula $t$
668 \begin_inset Formula $x(t)$
671 and a differential equation
684 \begin_layout sageblock
689 \begin_layout sageblock
694 \begin_layout sageblock
696 DE = diff(x, t) + x - 1
699 \begin_layout Standard
700 We can now solve the equation:
703 \begin_layout Standard
705 \begin_inset Formula $x(t)=\sage{desolve(DE,[x,t])}$