Comments (8)
I'm sorry, but I do not fully understand what you want. Of course, you can do the following.
#+BEGIN_SRC sage
def my_latex(a):
print r'\(%s\)' % latex(a)
#+END_SRC
#+RESULTS:
#+BEGIN_SRC sage :results raw
K.<zeta> = CyclotomicField(8)
h = -36*zeta^3 + 44*zeta^2 + 14*zeta + 28
my_latex(h)
#+END_SRC
#+RESULTS:
\(-36 \zeta_{8}^{3} + 44 \zeta_{8}^{2} + 14 \zeta_{8} + 28\)
But do you want to do this without modifying the Sage code? If so, I will implement it when I have free time.
from ob-sagemath.
Hi, sorry for not being clear earlier. Indeed, I'd like to have an option such that I don't have to call my_latex myself, i.e. LaTeX output is handled transparently.
from ob-sagemath.
Hi. I added some support for LaTeX.
Because :results latex
has a special meaning and it seems that we cannot use result parameters latex
and raw
at the same time, I added a new result parameter tolatex
. Currently this feature is available only in the dev
branch of ob-sagemath
.
Here is an example.
#+BEGIN_SRC sage :results tolatex
K.<zeta> = CyclotomicField(8)
h = -36*zeta^3 + 44*zeta^2 + 14*zeta + 28; h
#+END_SRC
#+RESULTS:
: -36 \zeta_{8}^{3} + 44 \zeta_{8}^{2} + 14 \zeta_{8} + 28
The result is same as the output of the Sage's function latex
. Because I implemented this by changing the display manager of Sage, the following code does not show LaTeX code.
#+BEGIN_SRC sage :results tolatex
K.<zeta> = CyclotomicField(8)
h = -36*zeta^3 + 44*zeta^2 + 14*zeta + 28
print h
#+END_SRC
In your example, LaTeX parentheses \(...\)
appeared. But not everyone needs them. So I added a new header argument :latexwrap
.
Its value should be a cons and the result will be wrapped with car
and cdr
of it. Here is an example.
#+BEGIN_SRC sage :results raw tolatex :latexwrap '("\\(" . "\\)")
K.<zeta> = CyclotomicField(8)
h = -36*zeta^3 + 44*zeta^2 + 14*zeta + 28; h
#+END_SRC
#+RESULTS:
\(-36 \zeta_{8}^{3} + 44 \zeta_{8}^{2} + 14 \zeta_{8} + 28\)
I have implemented these features in the dev
branch. But I'm not sure if it is a right solution to add such a new result parameter or a new header argument. So I will consider it before merging the dev
branch into the master branch.
from ob-sagemath.
Thanks, that was quick! After looking at what ob-R.el does, it seems that a header argument is the more canonical solution, e.g. one which allows to do arbitrary post processing using a Sage function or so and the latex one is simply pre-implemented for convenience? However you decide, thanks!
from ob-sagemath.
Sorry for taking long time. I deleted :results tolatex
and added a header argument :tolatex
. :tolatex
(or :tolatex yes
) is same as :results tolatex
in the previous version. One can pass a Python function to the header argument :tolatex
. The Python function takes a Sage object and should return a LaTeX code (string). Here is an example.
#+BEGIN_SRC sage :tolatex lambda obj: r'\(%s\)' % latex(obj)
sqrt(x)
#+END_SRC
#+RESULTS:
: \(\sqrt{x}\)
You can also use :latexwrap
. If you want to always wrap the results by \(...\)
, then please try the following configuration:
(push '(:latexwrap ("\\(" . "\\)")) org-babel-default-header-args:sage)
Then the following code returns the same result above.
#+BEGIN_SRC sage :tolatex
sqrt(x)
#+END_SRC
I also added a new header argument :latexnewline
. One can pass an elisp string to it and if the result is a LaTeX code, the newline characters in the result will be replaced by the string. Here is an example of usage:
With the configuration
(push '(:latexnewline . "\\\\\n") org-babel-default-header-args:sage)
the code below
#+BEGIN_SRC sage :results raw :tolatex :latexwrap '("\\begin{gather*}\n" . "\n\\end{gather*}")
sqrt(x)
sqrt(x^2 + 1)
#+END_SRC
returns the following.
#+RESULTS:
\begin{gather*}
\sqrt{x}\\
\sqrt{x^{2} + 1}
\end{gather*}
Thanks for the suggestion!
from ob-sagemath.
I have just merged the dev
branch to the master branch. Thanks.
from ob-sagemath.
Thanks! This is great.
from ob-sagemath.
This (closed) issue is the sole documentation of these features, which are, as far as I can tell, unique in the org-mode universe. They should be documented at least in the README.org file.
from ob-sagemath.
Related Issues (9)
- The ob-sagemath should match org-babel load convention. HOT 2
- error when generating sage pdf files HOT 4
- Slight encoding problem with `org-mode` HOT 1
- writing output to file HOT 2
- Runs very slow and cannot reuse session in my setting HOT 3
- python3.* does `print('...')` but not `print '...'` HOT 1
- When plotting ":exports both" fails but ":results file" works
- Opening sage session HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ob-sagemath.