-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable Unicode Support (Alternative II) #89
Conversation
The advantage of this approach is that it allows us to define exactly what latex symbol to use for unicode characters. |
Is there a good way to catch it when new Unicode characters are added? |
Actually, I'm -1 to this. This prints Unicode characters with the wrong characters. And how would this even work for
I think if we are going to show off Unicode pretty printing, we need to use the actual characters emitted by the printer. For accents in names, it's less important. Those can be represented using pure (ASCII) LaTeX quite easily. If that's all we do (i.e., we decide we don't want to show off Unicode pretty printing in the paper), let's just add another field, I say we hold off on this for now until a) we figure out if we want to show off Unicode pretty printing and b) we determine if the journal we submit to can handle that. |
Then please merge alternative I. Holding off leaves serious issues. Yes, there is a way to tell. Latex now Sent from my mobile phone.
|
Alternative I (#88) was merged. I will keep this one open, as I think this PR shows how to get unicode working for sympy unicode output in the verbatim mode. I just need to play with it some more. |
My preferred way, if we can get it to work, is to use |
Ok, I am not against. Just a warning that e.g. we wouldn't be able to upload to arxiv.org, since it only seems to support pdflatex. |
Maybe let's just plan to not use any Unicode pretty printing examples for now. We can use ASCII pretty printing, or probably better (for space), the default Unless you really want to spend some time to figure out how to make it work (I personally don't). |
I'll have a look at this if I have time. The documentation to the |
One can use this to lookup the unicode symbols: http://www.fileformat.info/info/unicode/char/search.htm and then this to find the corresponding latex symbol: http://www.johndcook.com/unicode_latex.html E.g. This pdf has nice tables with all these symbols: ftp://ftp.dante.de/pub/tex/macros/latex/contrib/unicode-math/unimath-symbols.pdf |
I tried this. If I
Without it,
So it seems we need xetex. When I try compiling the paper with xelatex, I get
which I think is an error from the style file. The solution I've used in the past is to compile the LaTeX examples as separate documents with xetex, and include them using \includegraphics. I tested this and it works, although we would need to tweak it so that it lines up correctly. Alternately, we could just take a screenshot, and show that. That would also let us show the MathJax rendering in Jupyter. |
I see, so we would need to define |
I would use 2. to get one or two pdf screenshots, but I wouldn't inline them, but rather put them as Figures. Just to show how unicode printing looks like. The disadvantage of 3. is that the png screenshot will be ugly, wouldn't it? Also, how are we going to print the rest of sympy outputs in the paper? Cannot we use a latex printer and render it using latex? That would be the best. |
I want to show str, Unicode pprint, ASCII pprint, and LaTeX (and rendered LaTeX if we show a screenshot of the notebook). Would you make all of them figures? This would be different from all the other examples in the paper (or do you think every example in the paper should be a figure?). Or just the Unicode one should be a figure? Wouldn't that look very inconsistent?
It wouldn't be ugly if we use a high enough resolution :) It may also be possible to take a PDF rendering of the notebook. https://stackoverflow.com/questions/176476/how-can-i-automate-html-to-pdf-conversions suggests that http://wkhtmltopdf.org/ might be a way to do it. I know there's nbconvert, but that renders different from the notebook itself, and I'd like for the screenshot to actually look like the notebook in the browser.
I think it would be confusing to show the output as inline math. Can you show an example of what this would look like? |
We have two kinds of outputs: a) a regular output of most examples all over the paper For b), I would just put those into a pdf figure. Check in the pdf into git. We only submit a pdf to the journal. Provide scripts to regenerate the pdf (for example using xetex, or ipython notebook, or whatever else that works). For a), we still need to investigate. I would like a) to be doctested in either case. I was thinking of a special environment, that uses monospace for the commands after
Where the latex output is obtained using If this is too much work to setup, then we can use str printing, or ascii printing and use verbatim. Finally, the last option is to try unicode printing, but then we are running into the issues you described. Of all these options, latex will look the best in my opinion. So let's see if I can come up with something. |
The problem is that it's confusing, because you have a Python prompt, but the output is rendered math. There's no SymPy shell that actually works that way. I suppose we could use Jupyter prompts, with the rendered math, since that would match the notebook (assuming we put We could show something similar, like Here is the square root of $\pi$:
\begin{verbatim}
In [3]: sqrt(pi)
Out[3]:
\end{verbatim}
$$\sqrt{\pi}$$ That would look something like this Upsides to this:
Downsides:
And obviously neither case really solves the issue of how to display Unicode pretty printing. I like my option 2, but it will take some LaTeX fiddling to make it render as if it were just another example. And yes, you're right, we would just submit the built PDF for the Unicode example to the journal. Another thing I haven't checked is how good or bad the Unicode printing looks in the monospace font the SIAM style file uses. I know it looks good using DejaVu Sans Mono, and generally less good with any other font, but it might be bad (i.e., the font might not even have those characters). |
Ok, so regarding a), you seem to be leaning towards using str printing or str pretty printing? We can get inspired with what SageTex does, see an example in sagetex.pdf, page 11, output 5 and 6. This renders the output in latex. Regarding b), we just have to figure out a robust solution to generate the pdf out of it, we seem to be in agreement there. |
Btw, in [1] we used str printing (not pretty printing) and we used the IPython prompts In/Out with numbers reset to 1 for each example (i.e. if the example had 3 prompts, they would always be numbered 1, 2, 3). For Mathematica we used the default text style. An example from the paper:
[1] Čertík, O., Paprocki, M., Meurer, A., Granger, B., & Rathnayake, T. (2015). Symbolic Computing. In Encyclopedia of Applied and Computational Mathematics (pp. 1431–1439). Springer Berlin Heidelberg. http://doi.org/10.1007/978-3-540-70529-1_429 So that's one option for a). |
I am leaning towards str printing, but not strongly, i.e., if you or someone else wants to go in and change the examples, I wouldn't be opposed to it, but I'm not going to do it myself. Actually we already need to go through the examples and make them consistent, so maybe it's something that we really should decide about. |
Let's use str printing then. We will provide the nice pdf figures with all kinds of pretty printing, showing that it really looks nice. But for examples, the str printing is great, since that's what you get if you just print an expression in Python. That way we stress that SymPy is just a Python library. In addition, for example in the following example:
the complicated expression is actually in the input field, not the output field. So even latex printing can't fix that. For this reason, I think we should just use str printing. |
My thoughts exactly. |
For the examples that have large inputs, we should have some text preceding them with rendered mathematics, so it's easier to see the expression being computed. |
I am closing this one, further discussion is at #122 (comment). |
This is an alternative, perhaps a better, patch to #88, since this shows how to make unicode printing work with pdflatex.