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
& escaped to & in tex ? #4251
Comments
Can you be more specific of what you are trying to convert (and which ipython version you are using)? \begin{eqnarray}
1 &=& 2*3\\
41 &=& 3*6
\end{eqnarray} this (currently) remains unchanged when converted to latex and compiles fine (ipython 1.1.0). |
Oh, sorry. The ipython version is the latest from github (version 2.0). In fact, I believe that for version 1.1 nbcovert wasn't even part of ipython, it was a separate tool.
I do have the ampersands in the output. I invoked nbconvert as python nbconvert --to latex Untitled0.ipynb without any extra switches. Untitled0.ipynb contains only the cell that you had, nothing more. |
Strange! Which version of pandoc do you have installed?
I guess you mean ipython ... Btw. the incorporation of nbconvert into ipython was THE major milestone for the 1.0 release. |
My pandoc version is 1.9.4.2. |
Can you provide your ipynb file (although it might be really simple). |
Hi Jakob, Sure. Here is my notebook file, and also the output of ipython notebook --to latex Cheers, On 23/09/13 11:28, Jakob Gager wrote:
|
@jakobgager Maybe it's not recognizing that latex environment? Strange that it isn't escaping incorrectly on yours. Do you have the branch we were working on earlier, including your fix? I know my fix will not parse this correctly (as you mentioned, it doesn't do inline latex) |
I tried with pandoc 1.10.1 and checked also the pandoc Json and pandoc clearly recognizes the @jdfreder I tried with ipython 1.1.0 and current master - not with any "advanced" markdown treatment. But maybe we should add such a check as well, because if we convert to html first this might appear in #3503. @v923z Can you try reinstalling ipython (doesn't matter if master or 1.1.0) and convert again? |
@v923z Can you try reinstalling ipython (doesn't matter if master or 1.1.0) and convert again? Hm. I thought it had been established that the problem originates from pandoc. As for re-installation, I do that every morning when I check out the new code from github. But there is another machine, on which I installed ipython completely from scratch just two days ago (pulled code from github, version 2.0.0), and the problem still persists. pandoc version is 1.9.1.1. For now, I can simply post-process the output (I have to remove & only, I presume), so I can live with this. On the other hand, I guess, this has to be sorted out sooner or later... |
Well I'm still not perfectly sure it is a pandoc issue. > echo '\begin{eqnarray}1&=&2\end{eqnarray}' | pandoc -f markdown -t json |
Yes, here is the output:
|
So pandoc works as expected! Found as raw latex and no html escape with the &. |
Maybe just for completion, can you try in a shell: > echo '\begin{eqnarray}1&=&2\end{eqnarray}' | pandoc -f markdown -t latex |
That leaves the input unchanged. Is it what's supposed to happen? |
Yes, exactly! |
I downgraded pandoc to 1.9.1.1 but still get correct conversion (with ipython master). > pandoc -f markdown -t html
\\begin{eqnarray}
1 &=& 2*3\\\\
\\end{eqnarray} This leads to
Looks similar but has some distinct differences, and most important is a conversion to html and not to latex. Maybe we have to start more fundamentally, which python, OS and shell are you using? |
The OS is either Mint Nadia, or ubuntu 12.04, and I ran the commands from the bash shell. The python version is 2.7, but I am not sure why that should matter. If you say that you don't see this problem anywhere else, then it's really weird... |
So far I tried with:
-> all worked fine
So maybe it is related to the "old" jinja2?? (asking @jdfreder ) |
The problem persists with an pandoc update (and jinja update). So no pandoc problem in the end! |
Ok the problem comes from the citation2latex filter -> Only appear in master (not in 1.1.0) In [1]: from IPython.nbconvert.filters import citation2latex
In [2]: s = "\\begin{eqnarray}\n1 &=&2 \\\\\n2 &=& 4\n\\end{eqnarray}"
In [3]: citation2latex(s)
Out[3]: u'\\begin{eqnarray}\n1 &=&2 \\\\\n2 &=& 4\n\\end{eqnarray}' 12.10: In [1]: from IPython.nbconvert.filters import citation2latex
In [2]: s = "\\begin{eqnarray}\n1 &=&2 \\\\\n2 &=& 4\n\\end{eqnarray}"
In [3]: citation2latex(s)
Out[3]: '\\begin{eqnarray}\n1 &=&2 \\\\\n2 &=& 4\n\\end{eqnarray}' I tried updating lxml but no success - any ideas @jdfreder, @ellisonbg |
Jakob, I completely lost the thread on the other issue: this particular problem with the ampersand is not related to the missing eqnarray environment in the html output, is it? |
No, the other issue IS a pandoc issue 😄 |
It looks like lxml is designed to replace Looking at citation.py, all of the text is processed through the lxml logic. |
The strange thing is that with 12.10 and 13.04 lxml does not replace |
|
Following your link, this might be a good starting point! |
If this is the case, wouldn't it make more sense to test for whether & is replaced, and then clean up the output, if it is? |
I prefer to correct this bug at its origin instead of just concealing its effects. If there is really no way around than a subsequent testing and correction could be applied, however. |
As @jdfreder noted lxml always replaces |
@v923z in the end your replace approach might be the best solution... from lxml import html
s = "\\begin{eqnarray}\n1 &=&2 \\\\\n2 &=& 4\n\\end{eqnarray}"
t1 = html.fragment_fromstring(s, create_parent='div')
html.tostring(t1, method='html')
from xml.sax.saxutils import unescape
unescape(html.tostring(t1)) gives
HoweverI discovered something more severe in this context - if someone has the completely insane idea of writing something like from lxml import html
s = "\\begin{eqnarray}\n1 &<&2 \\\\\n2 &=& 4\n\\end{eqnarray}"
t1 = html.fragment_fromstring(s, create_parent='div')
html.tostring(t1, method='html')
from xml.sax.saxutils import unescape
unescape(html.tostring(t1)) gives
or with our methods: citation2latex("1<2 is obviously true") gives
So I recommend to rewrite the |
Reported on list.
Hi all (most probably Matthias),
This is the first time I have had to use nbconvert, and I have noticed
that the ampersand symbol used in the eqnarray environment to align
equations is not replaced properly in the latex output. In the latex
file I still have &=& (which can't be compiled by latex), while
in the JSON file I have the correct form, &=&. Is this a known issue? If
so, what is the magic fix?
Cheers,
Zoltán
ping @jdfreder
The text was updated successfully, but these errors were encountered: