Opened 12 years ago

Closed 12 years ago

# Xelatex and Sage notebook

Reported by: Owned by: klee tbd minor sage-4.4 misc sage-4.4.alpha0 Kwankyu Lee Dan Drake, John Palmieri N/A

I think I want, e.g., the following works in Sage notebook.

%latex

실수 $x$에 대해서 다음이 성립한다.

$\sqrt{x2}=|x|$

Dan writes:

I've recently learned about xelatex and think it's awesome -- I can *finally* include Hangeul in my documents! We should definitely have a xelatex function, although it would usually be necessary to add stuff to the preamble to get the right fonts set up. But we already have latex.add_to_preamble(), so it should be easy to get xelatex working.

### comment:1 Changed 12 years ago by klee

• Description modified (diff)

### comment:2 Changed 12 years ago by klee

• Description modified (diff)

### Changed 12 years ago by klee

Example Sage notebook

### comment:3 Changed 12 years ago by klee

• Authors set to Kwankyu Lee
• Status changed from new to needs_review

### comment:4 Changed 12 years ago by klee

• Description modified (diff)

### comment:5 Changed 12 years ago by klee

The example Sage notebook use the font AppleGothic? which is perhaps only found in Mac OS.

### comment:6 Changed 12 years ago by ddrake

This looks pretty good. I have some comments and it will need some minor changes, but already it seems to work!

For anyone else wanting to test this who's using Linux, you can replace the latex.extra_preamble with something like

latex.extra_preamble("\\"+r"usepackage{fontspec,xunicode,xltxtra}\setmainfont[Mapping=tex-text]{UnBatang}\setmonofont[Mapping=tex-text,Colour=0000AA]{UnDotum}")


In Linux, you should be able to do fc-list :lang=ko to get a list of fonts installed that support Korean; pick one and put that in and try this out. XeTeX is a standard part of TeXLive as of TL 2008, so it's not too hard to get.

I'll look over this patch and post my comments soon.

### comment:7 Changed 12 years ago by ddrake

• Status changed from needs_review to needs_work

Hrm, this doesn't pass doctests. The first problem is that the "official" way to do deprecation is like this: for the pdflatex function (line 1188), you should do:

from sage.misc.misc import deprecation
if t is None:
return _Latex_prefs._option["engine"] == "pdflatex"
self.engine("pdflatex")


and then in the first doctest that uses the function:

sage: latex.pdflatex()
doctest:1: DeprecationWarning: Use engine("pdflatex") instead.
False


Also, I see that the pdflatex function never unsets the pdflatex engine -- I think we need

if t is None:
return _Latex_prefs._option["engine"] == "pdflatex"
elif t:
self.engine("pdflatex")
else:
self.engine("latex")


so that pdflatex(False) does properly reset the engine.

Finally, in the png function (line 1749 or so), you need to change the pdflatex keyword to engine, and change the _run_latex_ command on line 1795 or so.

Hmmm, it seems like the view command can call {{{png}} with the pdflatex keyword: see line 1721 or so (I've fiddled with latex.py, so my line numbers are a bit off):

png(objects, os.path.join(base_dir, png_file),
debug=debug, do_in_background=False, pdflatex=pdflatex)


I think you'll need to move up the little snippet where you use the pdflatex keyword to decide what engine to use.

With these changes, doctests should pass.

### comment:8 Changed 12 years ago by klee

Thank you, Dan. I will work on that.

### comment:9 Changed 12 years ago by klee

• Status changed from needs_work to needs_review

Updated the patch. Now all doctests pass.

### comment:10 Changed 12 years ago by ddrake

• Reviewers set to Dan Drake
• Status changed from needs_review to positive_review

Doctests pass, and the code looks good. Positive review.

I did write up a little bit of extra documentation; I'll post that patch in a moment. Could you look it over? It just adds a bit of explanation about adding to the preamble.

### Changed 12 years ago by ddrake

add a bit of new documentation.

### comment:11 Changed 12 years ago by jhpalmieri

• Status changed from positive_review to needs_work

Using os.system('which xelatex >/dev/null') won't work right on Solaris: on that OS, "which" has a return value of 0 even if the command is not found, so

not bool(os.system('which xelatex >/dev/null'))


will always return True there. Use the function have_program from #8474 instead.

### comment:12 follow-up: ↓ 13 Changed 12 years ago by jhpalmieri

Expanding on this a bit: there has been a fair amount of work getting Sage to work on Solaris, and I think it does as of version 4.3.4.alpha1. So I think that it is not a good time to put in a patch that doesn't work on Solaris; hence I've marked this as "needs work". All you have to do to fix it is apply the patch at #8474 (now merged in 4.3.4.rc0) and then make the obvious change to this one line of the program...

### comment:13 in reply to: ↑ 12 ; follow-up: ↓ 14 Changed 12 years ago by ddrake

Expanding on this a bit: there has been a fair amount of work getting Sage to work on Solaris, and I think it does as of version 4.3.4.alpha1. So I think that it is not a good time to put in a patch that doesn't work on Solaris; hence I've marked this as "needs work". All you have to do to fix it is apply the patch at #8474 (now merged in 4.3.4.rc0) and then make the obvious change to this one line of the program...

That sounds good. I was aware of #8474 and decided to ignore that problem and open #8552, so that Kwankyu wouldn't have to rebase his patch -- but if it's a simple one-line change, then I suppose that's more reasonable.

If I rebase his patch, will you do a quick review?

### comment:14 in reply to: ↑ 13 Changed 12 years ago by jhpalmieri

If I rebase his patch, will you do a quick review?

Sure, and thanks for offering to rebase it. (I understand your point, but I don't want to break Solaris support right away. Let's wait a few weeks instead. :)

### Changed 12 years ago by ddrake

one-line change to use have_program

### comment:15 Changed 12 years ago by ddrake

• Status changed from needs_work to needs_review

John, could you take a look at attachment:trac_8486_use_have_program.patch and attachment:trac_8486_extra_documentation.patch? The first fixes the problem you mentioned and preserves Solaris compatibility (I'm sure Dave Kirkby will appreciate that) and the second just adds a bit of extra documentation.

### comment:16 Changed 12 years ago by jhpalmieri

• Status changed from needs_review to positive_review

Looks good to me. One docstring is missing the "r" before the triple quotes, so I've added that.

### Changed 12 years ago by klee

combines and replaces all previous patches

### comment:17 Changed 12 years ago by klee

I looked at Dan's extra documentation. It is nice. But I deleted the last comment in the doc of "engine" because r"\usepackage..." only fails in the notebook. See the discussion in

So I think the problem of "\u" in the raw string in notebook is only temporary, assuming the ticket 3154 is reviewed sooner or later.

### comment:18 Changed 12 years ago by jhpalmieri

• Reviewers changed from Dan Drake to Dan Drake, John Palmieri

Okay, the new "v2" patch doesn't require the "referee" patch. Only apply the "v2" patch.

### comment:19 Changed 12 years ago by jhpalmieri

• Merged in set to sage-4.4.alpha0
• Resolution set to fixed
• Status changed from positive_review to closed

Merged "trac_8486_v2.patch" into 4.4.alpha0.

Note: See TracTickets for help on using tickets.